receive-add-new.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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" 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="shop-car">
  31. <commonCar :list="goodsProducts" @delect="delect" @accounts="accounts">
  32. </commonCar>
  33. <image src="" mode=""></image>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import commonCar from '@/components/shopCar/shopCar.vue'
  39. export default {
  40. components: { commonCar },
  41. data() {
  42. return {
  43. goodsProducts: [{
  44. name: '华为旗舰店',
  45. checked: 1,
  46. goods: []
  47. }],
  48. form: {
  49. storeId: '',
  50. type: '',
  51. reason: '',
  52. storeName: null
  53. },
  54. receiveDetailFormList: [
  55. ],
  56. backSpareId: '',
  57. backSpareName: '',
  58. backFormName: '',
  59. backPrice: 0,
  60. isRefreshDetail: true,
  61. sbSpareList: [],
  62. storeList: [],
  63. reasonList: [
  64. {
  65. label: '施工领用',
  66. value: '施工领用'
  67. }, {
  68. label: '办公领用',
  69. value: '办公领用'
  70. }, {
  71. label: '维修领用',
  72. value: '维修领用'
  73. }, {
  74. label: '其他领用',
  75. value: '其他领用'
  76. }
  77. ],
  78. rules: {
  79. reason: [
  80. {
  81. required: true,
  82. message: '请选择备品用途',
  83. trigger: ['change']
  84. }
  85. ],
  86. storeId: [
  87. {
  88. required: true,
  89. message: '请选择仓库',
  90. trigger: ['change']
  91. }
  92. ]
  93. },
  94. detailFormRules: {
  95. spareId: [
  96. {
  97. required: true,
  98. message: '请选择备品',
  99. trigger: ['change']
  100. }
  101. ],
  102. num: [
  103. {
  104. required: true,
  105. message: '请填写数量',
  106. trigger: ['change', 'blur']
  107. }
  108. ]
  109. },
  110. id: '', // 列表 id
  111. aId: 0
  112. };
  113. },
  114. created () {
  115. },
  116. onShow() {
  117. // 获取设备与仓库
  118. this.initData();
  119. const pages = getCurrentPages();
  120. const currPage = pages[pages.length - 1];
  121. if(currPage.goods != null && currPage.goods.length > 0){
  122. currPage.goods.forEach(item => {
  123. let find = false
  124. this.goodsProducts[0].goods.forEach(spare => {
  125. if (spare.spareId === item.spareId) {
  126. find = true
  127. return
  128. }
  129. })
  130. if(!find){
  131. this.goodsProducts[0].goods.push(item)
  132. }
  133. })
  134. currPage.goods = null
  135. }
  136. },
  137. onLoad(options) {},
  138. methods: {
  139. // 刪除
  140. delect(e){
  141. this.goodsProducts[0].goods.forEach((item,index) => {
  142. if (item.checked === 2) {
  143. this.goodsProducts[0].goods.splice(index, 1)
  144. return
  145. }
  146. })
  147. },
  148. // 提交
  149. accounts(e){
  150. const params = { ...this.form }
  151. const detailList = []
  152. this.goodsProducts[0].goods.forEach(item => {
  153. const detail = {
  154. spareId: item.spareId,
  155. num: item.number,
  156. price: item.price,
  157. spareName: item.spareName,
  158. totalPrice: this.$BaseTool.Number.mul(item.number, item.price)
  159. }
  160. detailList.push(detail);
  161. })
  162. params.detailList = detailList;
  163. this.$Http.addSparePickForm(params).then(res => {
  164. uni.redirectTo({
  165. url: '/pages/receive/receive-detail?id=' + res.data.id
  166. });
  167. })
  168. },
  169. del(index) {
  170. console.log(this.receiveDetailFormList);
  171. this.receiveDetailFormList.splice(index, 1)
  172. console.log(this.receiveDetailFormList);
  173. },
  174. handleSelect(formName) {
  175. console.log('formName:' + formName)
  176. uni.navigateTo({
  177. url: '/pages/search/spare-search?storeId=' + encodeURIComponent(JSON.stringify(this.form.storeId)) + '&formName=' + encodeURIComponent(JSON.stringify(formName))
  178. })
  179. },
  180. initData() {
  181. if(this.storeList.length == 0){
  182. this.$Http.getStorePage({ filter: 2, pageNum: 1, pageSize: 1000 })
  183. .then(res => {
  184. this.storeList = res.data.rows
  185. })
  186. }
  187. },
  188. openSpare() {
  189. if (this.$BaseTool.String.isBlank(this.form.storeId)) {
  190. uni.showToast({
  191. title: '请先选择仓库',
  192. icon: 'none'
  193. });
  194. return
  195. }
  196. uni.navigateTo({
  197. url: '/pages/search/spare-search-goods?storeId=' + encodeURIComponent(JSON.stringify(this.form.storeId))
  198. })
  199. },
  200. storeSelect(value, item) {
  201. this.form.storeName = item.name;
  202. this.isRefreshDetail = true;
  203. this.receiveDetailFormList = []
  204. },
  205. typeSelect(value, item) {
  206. this.isRefreshDetail = true;
  207. //this.receiveDetailFormList = []
  208. },
  209. spareSelect(value, item) {
  210. this.receiveDetailFormList.forEach(spare => {
  211. if (spare.spareId === item.spareId) {
  212. spare.item = item;
  213. } else {
  214. console.log(2222, spare.spareId, item.id)
  215. }
  216. })
  217. },
  218. // 提交
  219. submit() {
  220. if (this.receiveDetailFormList == null || this.receiveDetailFormList.length === 0) {
  221. uni.showToast({
  222. title: '请添加领用明细',
  223. icon: 'none'
  224. });
  225. return
  226. }
  227. const promiseList = []
  228. promiseList.push(
  229. new Promise((resolve, reject) => {
  230. this.$refs.uForm.validate().then(valid => {
  231. if (valid) {
  232. resolve(valid);
  233. } else {
  234. reject(valid);
  235. }
  236. })
  237. })
  238. );
  239. this.receiveDetailFormList.forEach(item => {
  240. promiseList.push(
  241. new Promise((resolve, reject) => {
  242. this.$refs[item.formName][0].validate(valid => {
  243. if (valid) {
  244. resolve(valid);
  245. } else {
  246. reject(valid);
  247. }
  248. })
  249. })
  250. );
  251. })
  252. Promise.all(promiseList).then(res => {
  253. // 执行
  254. const params = { ...this.form }
  255. const detailList = []
  256. this.receiveDetailFormList.forEach(item => {
  257. const space = item.item;
  258. const detail = {
  259. spareId: item.spareId,
  260. num: item.num,
  261. price: item.price,
  262. spareName: item.spareName,
  263. storeNum: item.num,
  264. totalPrice: this.$BaseTool.Number.mul(item.num, item.price)
  265. }
  266. detailList.push(detail);
  267. })
  268. params.detailList = detailList;
  269. console.log(33, params)
  270. this.$Http.addSparePickForm(params).then(res => {
  271. uni.redirectTo({
  272. url: '/pages/receive/receive'
  273. });
  274. })
  275. }, err => {
  276. console.log(err)
  277. })
  278. }
  279. },
  280. onReady() {
  281. console.log(4444, this.$refs.uForm)
  282. this.$refs.uForm.setRules(this.rules);
  283. }
  284. };
  285. </script>
  286. <style lang="less">
  287. page {
  288. background-color: #f4f4f4;
  289. }
  290. .mt-3-imt {
  291. margin-top: 30rpx;
  292. }
  293. .shop-car {
  294. min-height: 100vh;
  295. display: flex;
  296. flex-direction: column;
  297. align-items: center;
  298. background: #F5F5F5;
  299. }
  300. </style>