AddPurchase.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <view class="detail-view">
  3. <u-form label-width="160" :model="add_form" ref="uForm">
  4. <view class="form-model-view">
  5. <u-form-item required label="采购仓库" prop="warehouseName">
  6. <u-input @click="goPage('/pagesT/werahouse/selWerahouse')" class="dis-input" disabled v-model="add_form.warehouseName" placeholder="请选择" />
  7. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  8. </u-form-item>
  9. <u-form-item required label="供应商" prop="supplierName">
  10. <u-input @click="goPage('/pagesT/supplier/selSupplier')" class="dis-input" disabled v-model="add_form.supplierName" placeholder="请选择" />
  11. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  12. </u-form-item>
  13. <u-form-item required label="采购员" prop="buyerName">
  14. <u-input @click="goPage('/pagesT/staff/selStaff')" class="dis-input" disabled v-model="add_form.buyerName" placeholder="请选择" />
  15. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  16. </u-form-item>
  17. </view>
  18. <view class="form-model-view">
  19. <u-form-item required label="商品清单">
  20. <view @click="selGoodsPage" class="form-value add-btn-go">
  21. <u-icon name="plus" size="24"></u-icon>
  22. <text>选择商品</text>
  23. </view>
  24. </u-form-item>
  25. <view class="goods-ul" v-if="goods_list.length">
  26. <view class="goods-title clearfix" @click="goMoreGoods">
  27. <view class="float_left">请核对已选商品</view>
  28. <view class="float_right">编辑</view>
  29. </view>
  30. <block v-for="(item, index) in goods_list" :key="index">
  31. <view class="goods-li clearfix" v-if="index < 6">
  32. <view class="goods-img float_left"><u-icon size="40" name="shangpin" custom-prefix="custom-icon" color="#cccccc"></u-icon></view>
  33. <view class="float_left info">
  34. <view class="goods-name ellipsis">{{ item.goodsName }}</view>
  35. <view class="goods-code clearfix">
  36. <view class="float_left">{{ item.goodsCode }}</view>
  37. <view class="float_right">x{{ $utils.formatNub(item.buyerNum) }}</view>
  38. </view>
  39. <view class="goods-num clearfix">
  40. <view class="float_left">{{ item.unitName }};{{ item.specGropName }}</view>
  41. <view @click="goMoreGoods" class="float_right" v-if="item.isEq === 5">
  42. 其他单位:
  43. <text v-if="Number(item.otherNum) > 0">{{ $utils.formatNub(item.otherNum) }}</text>
  44. <text v-else style="color: #2979FF;">编辑</text>
  45. </view>
  46. </view>
  47. <view class="goods-num clearfix" v-if="item.skuValue">
  48. <view class="float_left">换算比例:{{ item.skuValue }}</view>
  49. <text class="float_right">转换数量:{{ item.skuNum }}</text>
  50. </view>
  51. <view class="goods-num clearfix">
  52. <view class="float_left ">
  53. <text class="price">{{ $utils.formattedNumber(item.buyerUnitPrice) }}</text>
  54. </view>
  55. <view class="float_right">
  56. 小计:
  57. <text class="price">{{ $utils.formattedNumber(item.subtotalPrice) }}</text>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </block>
  63. <view @click="goMoreGoods" class="more-goods" v-if="goods_list.length >= 6">
  64. 查看更多商品
  65. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  66. </view>
  67. </view>
  68. </view>
  69. <view class="form-model-view">
  70. <u-form-item label="其他金额">
  71. <input type="digit" v-model="add_form.otherAmount" class="dis-input" placeholder="请输入" />
  72. <text class="rem-unit">元</text>
  73. </u-form-item>
  74. <u-form-item label="优惠金额">
  75. <input type="digit" v-model="add_form.couponAmount" class="dis-input" placeholder="请输入" />
  76. <text class="rem-unit">元</text>
  77. </u-form-item>
  78. <u-form-item label="合计">
  79. <input type="digit" v-model="purchaseAmount" class="dis-input" placeholder="请输入" />
  80. <text class="rem-unit">元</text>
  81. </u-form-item>
  82. </view>
  83. </u-form>
  84. <view class="detail-bottom"><view class="handel-btn" @click="submit">提交订单</view></view>
  85. </view>
  86. </template>
  87. <script>
  88. const goods = {
  89. basicGoodsId: '',
  90. goodsCode: '',
  91. goodsName: '',
  92. skuId: '',
  93. unitName: '',
  94. categoryId: '',
  95. categoryName: '',
  96. buyerNum: 0,
  97. buyerUnitPrice: 0,
  98. subtotalPrice: 0,
  99. couponAmount: 0,
  100. otherAmount: 0
  101. };
  102. export default {
  103. data() {
  104. return {
  105. err_tip_list: [], // 错误提示
  106. rules: {
  107. warehouseName: [
  108. {
  109. required: true,
  110. message: '请选择采购仓库',
  111. trigger: ['change', 'blur']
  112. }
  113. ],
  114. supplierName: [
  115. {
  116. required: true,
  117. message: '请选择供应商',
  118. trigger: ['change', 'blur']
  119. }
  120. ],
  121. buyerName: [
  122. {
  123. required: true,
  124. message: '请选择采购员',
  125. trigger: ['change', 'blur']
  126. }
  127. ]
  128. },
  129. goods_id: [],
  130. werahouseData: '',
  131. supplierData: '',
  132. staffData: '',
  133. goodsData: '',
  134. purchaseGoods: '',
  135. goods_num: '',
  136. add_form: {
  137. code: '',
  138. shopId: '',
  139. shopName: '',
  140. supplierId: '',
  141. supplierName: '',
  142. buyerId: '',
  143. buyerName: '',
  144. operatorName: '',
  145. couponAmount: 0,
  146. otherAmount: 0,
  147. remark: '',
  148. goodsData: [],
  149. warehouseName: '',
  150. warehouseId: '',
  151. purchaseType: 4
  152. },
  153. goods_list: []
  154. };
  155. },
  156. computed: {
  157. userName() {
  158. return this.$store.state.userInfo.name;
  159. },
  160. purchaseAmount() {
  161. let sum = 0;
  162. if (this.goods_list.length > 1) {
  163. this.goods_list.forEach(item => {
  164. sum = this.$NP.plus(sum, Number(item.subtotalPrice));
  165. });
  166. } else if (this.goods_list.length === 1) {
  167. sum = Number(this.goods_list[0].subtotalPrice);
  168. } else {
  169. sum = 0;
  170. }
  171. return this.$NP.plus(sum, this.$NP.minus(this.add_form.otherAmount, this.add_form.couponAmount)) || 0;
  172. }
  173. },
  174. watch: {
  175. werahouseData(val) {
  176. if (val) {
  177. this.add_form.warehouseId = val.id;
  178. this.add_form.warehouseName = val.warehouseName;
  179. }
  180. },
  181. supplierData(val) {
  182. if (val) {
  183. this.add_form.supplierId = val.id;
  184. this.add_form.supplierName = val.title;
  185. }
  186. },
  187. staffData(val) {
  188. if (val) {
  189. this.add_form.buyerId = val.id;
  190. this.add_form.buyerName = val.staffName;
  191. }
  192. },
  193. // 选择商品资料页面返回
  194. goodsData(list) {
  195. if (list) {
  196. this.selGoods(list);
  197. }
  198. },
  199. // 已选择采购商品页面返回
  200. purchaseGoods(list) {
  201. if (list) {
  202. this.goods_list = list;
  203. }
  204. }
  205. },
  206. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  207. onReady() {
  208. this.$refs.uForm.setRules(this.rules);
  209. },
  210. onLoad(options) {
  211. if (options.id) {
  212. this.purchase_id = options.id;
  213. uni.setNavigationBarTitle({
  214. title: '编辑采购单'
  215. });
  216. this.getPurchaseInfoById();
  217. }
  218. // // 获取sku换算关系
  219. // this.getSkuNum();
  220. // });
  221. },
  222. methods: {
  223. selGoodsPage() {
  224. uni.setStorageSync('purGoods', this.goods_list);
  225. this.goPage('/pagesT/goods/selGoodsBasicBySku?pageName=purchase');
  226. },
  227. goMoreGoods() {
  228. uni.setStorageSync('PurchaseGoods', this.goods_list);
  229. this.goPage(`/pagesT/Purchase/PurchaseGoods`);
  230. },
  231. // 详情
  232. getPurchaseInfoById() {
  233. this.$u.api.getPurchaseInfoById(this.purchase_id).then(({ data }) => {
  234. this.add_form = {
  235. code: data.code,
  236. shopId: data.shopId,
  237. shopName: data.shopName,
  238. supplierId: data.supplierId,
  239. supplierName: data.supplierName,
  240. buyerId: data.buyerId,
  241. buyerName: data.buyerName,
  242. operatorName: data.operatorName,
  243. couponAmount: data.couponAmount,
  244. otherAmount: data.otherAmount,
  245. remark: data.remark,
  246. goodsData: data.details,
  247. warehouseName: data.warehouseName,
  248. warehouseId: data.warehouseId,
  249. purchaseType: 4
  250. };
  251. // 商品
  252. this.goods_list = data.details.map(item => {
  253. return {
  254. ...item,
  255. skuId: item.skuId,
  256. specGropName: item.skuName
  257. };
  258. });
  259. // 获取sku换算关系
  260. this.getSkuNum();
  261. });
  262. },
  263. // 多选商品确定
  264. selGoods(list) {
  265. uni.showLoading()
  266. const goodsD = list.map(item => {
  267. let specGropName = '';
  268. if (item.specGroup) {
  269. specGropName = item.specGroup
  270. .map(itemS => {
  271. return itemS.specValueName;
  272. })
  273. .join('_');
  274. } else {
  275. specGropName = item.specGropName;
  276. }
  277. const buyerNum = item.buyNum || item.buyerNum || 1;
  278. return {
  279. isEq: item.isEq,
  280. basicGoodsId: item.id || item.basicGoodsId,
  281. goodsCode: item.code,
  282. goodsName: item.title,
  283. skuId: item.skuId,
  284. specGropName: specGropName,
  285. unitName: item.unitName,
  286. categoryId: item.categoryId,
  287. categoryName: item.categoryName,
  288. buyerNum: buyerNum,
  289. buyerUnitPrice: item.buyerUnitPrice || '',
  290. subtotalPrice: this.$NP.times(buyerNum, item.buyerUnitPrice || 0),
  291. couponAmount: item.couponAmount || '',
  292. otherAmount: item.otherAmount || ''
  293. };
  294. });
  295. const skuIdArr = goodsD.map(item => {
  296. return item.skuId;
  297. });
  298. this.pricePauseSave(skuIdArr, goodsD);
  299. },
  300. // 价格暂存查询
  301. async pricePauseSave(skuId, goodsData) {
  302. uni.showLoading()
  303. await this.$u.api
  304. .getMoneyPauseSave({
  305. skuIds: skuId
  306. })
  307. .then(({ data }) => {
  308. this.goods_list = goodsData.map(item => {
  309. return {
  310. ...item,
  311. buyerUnitPrice: item.buyerUnitPrice > 0.1 ? item.buyerUnitPrice : data[item.skuId] || 0.1,
  312. subtotalPrice: item.subtotalPrice > 0.1 ? item.subtotalPrice : data[item.skuId] || 0.1
  313. };
  314. });
  315. // 获取sku换算关系
  316. this.getSkuNum();
  317. });
  318. },
  319. //换算sku数量
  320. getSkuNum() {
  321. uni.showLoading()
  322. const skuNum = this.goods_list
  323. .map(item => {
  324. return {
  325. skuId: item.skuId,
  326. goodsBasicId: item.basicGoodsId,
  327. num: Number(item.buyerNum) || 1
  328. };
  329. })
  330. .filter(item => item.skuId);
  331. if (!skuNum.length) {
  332. return;
  333. }
  334. this.$u.api.getMasterSkuNum(skuNum).then(({ data }) => {
  335. this.goods_list = this.goods_list.map(item => {
  336. let obj = {};
  337. if (data[item.skuId]) {
  338. obj = {
  339. title: data[item.skuId].title || '',
  340. buyerNum: data[item.skuId].num,
  341. skuValue: data[item.skuId].skuValue,
  342. skuNum: data[item.skuId].masterNum + data[item.skuId].masterName
  343. };
  344. }
  345. return {
  346. ...item,
  347. ...obj
  348. };
  349. });
  350. this.goMoreGoods()
  351. });
  352. },
  353. // 改变数量
  354. editNumChange(index, tag) {
  355. const target = this.$u.deepClone(this.goods_list);
  356. target[index].subtotalPrice = (target[index].buyerNum || 1) * target[index].buyerUnitPrice;
  357. this.goods_list = target;
  358. if (!target[index].skuId) return;
  359. if (tag === 'buyerNum') {
  360. // 获取sku换算关系
  361. this.getSkuNum();
  362. }
  363. },
  364. // 价格暂存提交
  365. async addMoneyPauseSave() {
  366. const priceData = this.goods_list.map(item => {
  367. return {
  368. skuId: item.skuId,
  369. money: item.buyerUnitPrice
  370. };
  371. });
  372. await this.$u.api
  373. .addMoneyPauseSave({
  374. data: priceData
  375. })
  376. .then(res => {});
  377. },
  378. submit() {
  379. this.$refs.uForm.validate(valid => {
  380. if (valid) {
  381. if (!this.goods_list.length) {
  382. this.$u.toast('请选择商品');
  383. return;
  384. }
  385. const isbuyerNum = this.goods_list.every(item => item.buyerNum > 0);
  386. if (!isbuyerNum) {
  387. this.$u.toast('采购数量必须大于0');
  388. return;
  389. }
  390. const isbuyerUnitPrice = this.goods_list.every(item => item.buyerUnitPrice > 0);
  391. if (!isbuyerUnitPrice) {
  392. this.$u.toast('采购单价必须大于0');
  393. return;
  394. }
  395. let goodsData = this.goods_list.map(item => {
  396. let goods = {
  397. basicGoodsId: item.basicGoodsId,
  398. goodsCode: item.goodsCode,
  399. goodsName: item.goodsName,
  400. skuId: item.skuId,
  401. unitName: item.unitName,
  402. skuName: item.specGropName,
  403. buyerNum: item.buyerNum,
  404. buyerUnitPrice: item.buyerUnitPrice,
  405. subtotalPrice: item.subtotalPrice,
  406. couponAmount: Number(item.couponAmount),
  407. otherAmount: Number(item.otherAmount),
  408. categoryId: item.categoryId,
  409. categoryName: item.categoryName,
  410. otherNum: item.otherNum
  411. };
  412. if (item.id) {
  413. goods.id = item.id;
  414. }
  415. return goods;
  416. });
  417. const params = {
  418. ...this.add_form,
  419. operatorName: this.userName,
  420. goodsData: goodsData
  421. };
  422. if (this.purchase_id) {
  423. this.$u.api.editPurchase(this.purchase_id, params).then(res => {
  424. this.$u.toast('修改成功');
  425. // 价格暂存添加
  426. this.addMoneyPauseSave();
  427. setTimeout(() => {
  428. uni.navigateBack();
  429. }, 2000);
  430. });
  431. } else {
  432. this.$u.api.addPurchase(params).then(res => {
  433. this.$u.toast('新建成功');
  434. // 价格暂存添加
  435. this.addMoneyPauseSave();
  436. setTimeout(() => {
  437. uni.navigateBack();
  438. }, 2000);
  439. });
  440. }
  441. }
  442. });
  443. }
  444. }
  445. };
  446. </script>
  447. <style lang="scss" scoped>
  448. .goods-ul {
  449. .more-goods {
  450. line-height: 80rpx;
  451. border-top: 1px solid #eeeeee;
  452. text-align: center;
  453. font-size: 24rpx;
  454. }
  455. .goods-title {
  456. margin-bottom: 20rpx;
  457. line-height: 80rpx;
  458. font-size: 24rpx;
  459. border-bottom: 1px solid #eeeeee;
  460. .float_right {
  461. color: $uni-color-primary;
  462. }
  463. }
  464. .goods-li {
  465. line-height: 32rpx;
  466. padding-bottom: 24rpx;
  467. .goods-img {
  468. margin-right: 20rpx;
  469. image {
  470. width: 150rpx;
  471. height: 150rpx;
  472. border-radius: 8rpx;
  473. display: block;
  474. }
  475. }
  476. .info {
  477. .goods-name {
  478. width: 640rpx;
  479. height: 34rpx;
  480. line-height: 34rpx;
  481. }
  482. .goods-code {
  483. font-size: 24rpx;
  484. padding-top: 10rpx;
  485. }
  486. .goods-num {
  487. padding-top: 10rpx;
  488. font-size: 24rpx;
  489. .price {
  490. font-size: 28rpx;
  491. font-weight: bold;
  492. color: $uni-color-error;
  493. }
  494. }
  495. }
  496. }
  497. }
  498. </style>