receive-add.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <view class="mx3">
  3. <my-add-button @handleClick="openSpare" />
  4. <view class="main-color-bg main-bg-future"></view>
  5. <view class="p3 bg-color-white form-view">
  6. <u-form :model="form" :error-type="['message']" ref="uForm" >
  7. <view class="main-color-text f-size-32 f-weight-6">领用信息</view>
  8. <u-form-item label="仓库名称" prop="storeId" required label-width="150">
  9. <my-select
  10. :list="storeList"
  11. :value-name="'id'"
  12. :label-name="'name'"
  13. v-model="form.storeId"
  14. placeholder="请选择仓库"
  15. @selected="storeSelect"
  16. />
  17. </u-form-item>
  18. <u-form-item label="备品用途" prop="type" required label-width="150">
  19. <my-select
  20. :list="reasonList"
  21. v-model="form.reason"
  22. @selected="typeSelect"
  23. placeholder="请选择备品用途" />
  24. </u-form-item>
  25. <u-form-item label="领用说明" label-width="150">
  26. <u-input type="textarea" v-model="form.remark" />
  27. </u-form-item>
  28. </u-form>
  29. </view>
  30. <!-- <view class="m3">
  31. <u-button @click="openSpare" type="primary" shape="circle">添加领用明细</u-button>
  32. </view> -->
  33. <view class="p3 bg-color-white form-view mt-3-imt" v-if="receiveDetailFormList && receiveDetailFormList.length>0">
  34. <!-- <view class="main-color-text f-size-32 f-weight-6">领用明细</view> -->
  35. <u-form
  36. :error-type="['message']"
  37. v-for="(item,index) in receiveDetailFormList"
  38. :key="index"
  39. :model="receiveDetailFormList[index]"
  40. :ref="item.formName"
  41. >
  42. <view class="main-color-text f-size-32 f-weight-6 d-flex j-between" @tap="del(index)">
  43. 领用明细
  44. <u-icon name="close-circle" color="red"></u-icon>
  45. </view>
  46. <u-form-item label="名称" prop="spareId" required label-width="150">
  47. <!-- <my-select
  48. :list="sbSpareList"
  49. :value-name="'spareId'"
  50. :label-name="'spareName'"
  51. v-model="item.spareId"
  52. @selected="spareSelect"
  53. placeholder="请选择备品"
  54. />-->
  55. <u-input
  56. v-model="item.spareName"
  57. disabled
  58. @click="handleSelect(item.formName)"
  59. placeholder="请选择"
  60. type="select"
  61. />
  62. </u-form-item>
  63. <u-form-item label="数量" prop="num" required label-width="150">
  64. <u-input type="number" v-model="item.num" />
  65. </u-form-item>
  66. </u-form>
  67. </view>
  68. <view class="mt-3">
  69. <u-button @click="submit" type="primary" shape="circle">提交</u-button>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. data() {
  76. return {
  77. form: {
  78. storeId: '',
  79. type: '',
  80. reason: '',
  81. storeName: null
  82. },
  83. receiveDetailFormList: [
  84. ],
  85. backSpareId: '',
  86. backSpareName: '',
  87. backFormName: '',
  88. backPrice: 0,
  89. isRefreshDetail: true,
  90. sbSpareList: [],
  91. storeList: [],
  92. reasonList: [
  93. {
  94. label: '施工领用',
  95. value: '施工领用'
  96. }, {
  97. label: '办公领用',
  98. value: '办公领用'
  99. }, {
  100. label: '维修领用',
  101. value: '维修领用'
  102. }, {
  103. label: '其他领用',
  104. value: '其他领用'
  105. }
  106. ],
  107. rules: {
  108. reason: [
  109. {
  110. required: true,
  111. message: '请选择备品用途',
  112. trigger: ['change']
  113. }
  114. ],
  115. storeId: [
  116. {
  117. required: true,
  118. message: '请选择仓库',
  119. trigger: ['change']
  120. }
  121. ]
  122. },
  123. detailFormRules: {
  124. spareId: [
  125. {
  126. required: true,
  127. message: '请选择备品',
  128. trigger: ['change']
  129. }
  130. ],
  131. num: [
  132. {
  133. required: true,
  134. message: '请填写数量',
  135. trigger: ['change', 'blur']
  136. }
  137. ]
  138. },
  139. id: '', // 列表 id
  140. aId: 0
  141. };
  142. },
  143. created () {
  144. },
  145. onShow() {
  146. // 获取设备与仓库
  147. this.initData();
  148. const pages = getCurrentPages();
  149. const currPage = pages[pages.length - 1];
  150. if(currPage.backSpareId != null ){
  151. this.backSpareId = currPage.backSpareId;
  152. this.backSpareName = currPage.backSpareName;
  153. this.backFormName = currPage.backFormName;
  154. this.receiveDetailFormList.forEach(spare => {
  155. if (spare.formName === currPage.backFormName) {
  156. spare.spareId = currPage.backSpareId;
  157. spare.spareName = currPage.backSpareName;
  158. spare.price = currPage.backPrice;
  159. }
  160. })
  161. }
  162. },
  163. onLoad(options) {},
  164. methods: {
  165. del(index) {
  166. console.log(this.receiveDetailFormList);
  167. this.receiveDetailFormList.splice(index, 1)
  168. console.log(this.receiveDetailFormList);
  169. },
  170. handleSelect(formName) {
  171. console.log('formName:' + formName)
  172. uni.navigateTo({
  173. url: '/pages/search/spare-search?storeId=' + encodeURIComponent(JSON.stringify(this.form.storeId)) + '&formName=' + encodeURIComponent(JSON.stringify(formName))
  174. })
  175. },
  176. initData() {
  177. if(this.storeList.length == 0){
  178. this.$Http.getStorePage({ filter: 2, pageNum: 1, pageSize: 1000 })
  179. .then(res => {
  180. this.storeList = res.data.rows
  181. })
  182. }
  183. },
  184. openSpare() {
  185. /* if (this.$BaseTool.Object.isBlank(this.form.type)) {
  186. uni.showToast({
  187. title: '请先选择备品用途',
  188. icon: 'none'
  189. });
  190. return
  191. } */
  192. if (this.$BaseTool.String.isBlank(this.form.storeId)) {
  193. uni.showToast({
  194. title: '请先选择仓库',
  195. icon: 'none'
  196. });
  197. return
  198. }
  199. this.aId++
  200. const detailForm = {
  201. spareId: '',
  202. num: '1',
  203. spareName: '',
  204. formName: 'form' + this.aId,
  205. price: '',
  206. item: null
  207. };
  208. if (!this.isRefreshDetail) {
  209. this.receiveDetailFormList.push(detailForm)
  210. this.$nextTick(() => {
  211. this.$refs[detailForm.formName][0].setRules(this.detailFormRules);
  212. })
  213. return
  214. }
  215. if (!this.isRefreshDetail && this.sbSpareList != null && this.sbSpareList.length > 0) {
  216. return
  217. }
  218. this.$Http.getSpareStorePage({
  219. storeId: this.form.storeId,
  220. num: 0,
  221. pageNum: 1,
  222. pageSize: 10000,
  223. dataScope: {
  224. sortBy: 'desc',
  225. sortName: 'update_time'
  226. }
  227. }).then(res => {
  228. const sbSpareList = res.data.rows
  229. if (sbSpareList == null || sbSpareList.length === 0) {
  230. this.isRefreshDetail = true;
  231. uni.showToast({
  232. title: '该仓库没有备品',
  233. icon: 'none'
  234. });
  235. return
  236. }
  237. this.sbSpareList = res.data.rows
  238. this.receiveDetailFormList.push(detailForm)
  239. this.$nextTick(() => {
  240. this.$refs[detailForm.formName][0].setRules(this.detailFormRules);
  241. })
  242. this.isRefreshDetail = false;
  243. })
  244. },
  245. storeSelect(value, item) {
  246. this.form.storeName = item.name;
  247. this.isRefreshDetail = true;
  248. this.receiveDetailFormList = []
  249. },
  250. typeSelect(value, item) {
  251. this.isRefreshDetail = true;
  252. //this.receiveDetailFormList = []
  253. },
  254. spareSelect(value, item) {
  255. this.receiveDetailFormList.forEach(spare => {
  256. if (spare.spareId === item.spareId) {
  257. spare.item = item;
  258. } else {
  259. console.log(2222, spare.spareId, item.id)
  260. }
  261. })
  262. },
  263. // 提交
  264. submit() {
  265. if (this.receiveDetailFormList == null || this.receiveDetailFormList.length === 0) {
  266. uni.showToast({
  267. title: '请添加领用明细',
  268. icon: 'none'
  269. });
  270. return
  271. }
  272. const promiseList = []
  273. promiseList.push(
  274. new Promise((resolve, reject) => {
  275. this.$refs.uForm.validate().then(valid => {
  276. if (valid) {
  277. resolve(valid);
  278. } else {
  279. reject(valid);
  280. }
  281. })
  282. })
  283. );
  284. this.receiveDetailFormList.forEach(item => {
  285. promiseList.push(
  286. new Promise((resolve, reject) => {
  287. this.$refs[item.formName][0].validate(valid => {
  288. if (valid) {
  289. resolve(valid);
  290. } else {
  291. reject(valid);
  292. }
  293. })
  294. })
  295. );
  296. })
  297. Promise.all(promiseList).then(res => {
  298. // 执行
  299. const params = { ...this.form }
  300. const detailList = []
  301. this.receiveDetailFormList.forEach(item => {
  302. const space = item.item;
  303. const detail = {
  304. spareId: item.spareId,
  305. num: item.num,
  306. price: item.price,
  307. spareName: item.spareName,
  308. storeNum: item.num,
  309. totalPrice: this.$BaseTool.Number.mul(item.num, item.price)
  310. }
  311. detailList.push(detail);
  312. })
  313. params.detailList = detailList;
  314. console.log(33, params)
  315. this.$Http.addSparePickForm(params).then(res => {
  316. uni.redirectTo({
  317. url: '/pages/receive/receive'
  318. });
  319. })
  320. }, err => {
  321. console.log(err)
  322. })
  323. }
  324. },
  325. onReady() {
  326. console.log(4444, this.$refs.uForm)
  327. this.$refs.uForm.setRules(this.rules);
  328. }
  329. };
  330. </script>
  331. <style lang="less">
  332. page {
  333. background-color: #f4f4f4;
  334. }
  335. .mt-3-imt {
  336. margin-top: 30rpx;
  337. }
  338. </style>