index.vue 5.7 KB

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