index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view class="page-container">
  3. <web-view
  4. src="https://tq.5000v.com:8025/enterprises/">
  5. </web-view>
  6. </view>
  7. </template>
  8. <script>
  9. import {userProfile} from '@/api/common/user.js'
  10. import {addMaterialApply,queryOneById,queryMaterialList} from '@/api/system/material.js'
  11. import {clearProps,copyProps} from '@/utils/gdtq.js'
  12. import {isEmpty} from 'lodash'
  13. export default {
  14. components: {
  15. },
  16. data() {
  17. return {
  18. model: {
  19. form: {
  20. outflowUserId: "",
  21. outflowUser: "",
  22. deptId: "",
  23. deptName: "",
  24. outflowType: "",
  25. outflowTypeName: "",
  26. backDate: "",
  27. remark: "",
  28. // materialId: "",
  29. // materialName: "",
  30. outList: [
  31. /* {
  32. materialId: 1,
  33. materialName: 'testest',
  34. amountTotal: 0,
  35. num: ''
  36. } */
  37. ],
  38. }
  39. },
  40. rules: {
  41. 'form.outflowType': [
  42. {
  43. type: 'string',
  44. required: true,
  45. message: '请选择',
  46. trigger: ['blur', 'change']
  47. },
  48. ],
  49. 'form.backDate': {
  50. type: 'string',
  51. required: true,
  52. message: '请选择',
  53. trigger: ['blur', 'change']
  54. },
  55. 'form.outList': {
  56. type: 'array',
  57. required: true,
  58. message: '请选择',
  59. trigger: ['blur', 'change']
  60. },
  61. },
  62. /* 物品数组校验规则 start */
  63. outListRules: {
  64. num: [
  65. {
  66. type: 'number' ,
  67. required: true,
  68. message: '请输入',
  69. trigger: ['blur', 'change']
  70. },
  71. {
  72. pattern: /^[1-9]\d*$/g,
  73. // 正则检验前先将值转为字符串
  74. transform(value) {
  75. return String(value);
  76. },
  77. message: '请输入大于0的正整数',
  78. // 触发器可以同时用blur和change
  79. trigger: ['change','blur'],
  80. }
  81. ],
  82. },
  83. materialList: [],
  84. userInfo: null,
  85. }
  86. },
  87. onLoad({id}) {
  88. // console.log(id,'id')
  89. this.queryMaterialListData()
  90. if(id) {
  91. this.getInfo(id)
  92. } else {
  93. this.getUserInfo()
  94. }
  95. },
  96. onShow() {
  97. },
  98. onHide() {
  99. },
  100. onReady() {
  101. this.resetRules()
  102. },
  103. methods: {
  104. resetRules() {
  105. this.$refs.uForm.setRules(this.rules)
  106. for (let i in this.model.form.outList) {
  107. this.$refs.outListRef[i].setRules(this.outListRules);
  108. }
  109. },
  110. async queryMaterialListData() {
  111. let {code,data} = await queryMaterialList({})
  112. if(code == 0) {
  113. this.materialList = data.map((e) => {
  114. return {
  115. ...e,
  116. tip: `(可用库存${e.amountTotal})`,
  117. disabled: !(e.amountTotal>0)
  118. }
  119. })
  120. }
  121. },
  122. async getInfo(id) {
  123. let {code,data} = await queryOneById({id})
  124. if(code == 0) {
  125. copyProps(this.model.form,data)
  126. }
  127. },
  128. getUserInfo() {
  129. userProfile().then((res) => {
  130. this.userInfo = res.data
  131. this.model.form.outflowUserId = res.data.userId
  132. this.model.form.outflowUser = res.data.nickName
  133. this.model.form.deptId = res.data.deptId
  134. this.model.form.deptName = res.data.deptName
  135. })
  136. },
  137. // 提交
  138. async handleSubmit() {
  139. for (let i in this.model.form.outList) {
  140. this.$refs.outListRef[i].validate(valid => {
  141. if (!valid) return
  142. })
  143. }
  144. this.$refs.uForm.validate().then(async res => {
  145. for (let i in this.model.form.outList) {
  146. await this.$refs.outListRef[i].validate()
  147. }
  148. let ajaxData = {
  149. ...this.model.form,
  150. }
  151. let { data, code,msg } = await addMaterialApply(ajaxData)
  152. if (code == 0) {
  153. uni.showModal({
  154. title: '提示',
  155. content: `提交成功~`,
  156. showCancel:false,
  157. confirmText: '好的',
  158. success: function(res) {
  159. if (res.confirm) {
  160. uni.switchTab({url: '/pages/index/index'})
  161. }
  162. }
  163. })
  164. }
  165. }).catch(errors => {
  166. console.log('校验失败',errors)
  167. })
  168. },
  169. handleClear() {
  170. clearProps(this.model.form,['outflowUserId','outflowUser','deptId','deptName'])
  171. },
  172. updateMeterial(data) {
  173. // console.log(data,'data')
  174. if(!isEmpty(data)) {
  175. this.model.form.outList = data.map((e) => {
  176. return {
  177. materialId: e.materialId,
  178. materialName: e.materialName,
  179. amountTotal: e.amountTotal,
  180. num: ''
  181. }
  182. })
  183. } else {
  184. this.model.form.outList = []
  185. }
  186. this.model.form.materialId = data.materialId
  187. this.model.form.materialName = data.materialName
  188. this.$refs.uForm.validateField('form.outList')
  189. this.$nextTick(() => {
  190. this.resetRules()
  191. })
  192. },
  193. deleteItem(index) {
  194. this.model.form.outList.splice(index, 1)
  195. this.$nextTick(() => {
  196. this.resetRules()
  197. })
  198. },
  199. handleNumChange(row,index) {
  200. if(row.materialId) {
  201. if(row.num > row.amountTotal) {
  202. this.$modal.msg(`已超过可用申领数${row.amountTotal}`)
  203. // row.num = row.amountTotal
  204. }
  205. } else {
  206. this.$modal.msg('请先选择物品')
  207. row.num = ''
  208. }
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .disflex-center {
  215. display: flex;
  216. justify-content: center;
  217. align-items: center;
  218. }
  219. .disflex-right {
  220. display: flex;
  221. justify-content: right;
  222. align-items: center;
  223. }
  224. .page-container {
  225. font-size: 28rpx;
  226. min-height: 100%;
  227. position: relative;
  228. // padding-bottom: 60rpx;
  229. .box {
  230. margin: 20rpx;
  231. border-radius: 10rpx;
  232. background: #fff;
  233. }
  234. .page-body {
  235. padding-bottom: 120rpx;
  236. }
  237. .page-footer {
  238. padding: 0rpx 0;
  239. position: fixed;
  240. width: 100%;
  241. left: 0;
  242. bottom: 0;
  243. }
  244. }
  245. ::v-deep {
  246. .u-form-item__body {
  247. padding: 0;
  248. }
  249. .hidde-cell-title {
  250. .u-cell__body__content {
  251. width: auto;
  252. flex: none;
  253. }
  254. .u-cell__body {
  255. .value {
  256. flex: 1;
  257. }
  258. }
  259. }
  260. }
  261. </style>