AddPurchaseReturn.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <view class="detail-view">
  3. <u-form label-width="150" :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/order/selPurchase')" class="dis-input" disabled
  7. v-model="add_form.originNo" placeholder="请选择" />
  8. <u-icon name="arrow-right" size="24" color="#6c6c6c"></u-icon>
  9. </u-form-item>
  10. <block v-if="!!add_form.originNo">
  11. <u-form-item label="退货仓库">
  12. <view class="form-value">{{ add_form.warehouseName }}</view>
  13. </u-form-item>
  14. <u-form-item label="供应商">
  15. <view class="form-value">{{ add_form.supplierName }}</view>
  16. </u-form-item>
  17. <u-form-item label="采购员">
  18. <view class="form-value">{{ add_form.buyerName }}</view>
  19. </u-form-item>
  20. </block>
  21. </view>
  22. <view class="form-model-view">
  23. <u-form-item required label="商品清单">
  24. <view @click="selGoodsPage" class="form-value add-btn-go">
  25. <u-icon name="plus" size="24"></u-icon>
  26. <text>选择商品</text>
  27. </view>
  28. </u-form-item>
  29. <view class="goods-ul" v-if="goods_list.length">
  30. <block v-for="(item, index) in goods_list" :key="index">
  31. <view class="goods-li clearfix">
  32. <view class="goods-img float_left">
  33. <u-icon size="40" name="shangpin" custom-prefix="custom-icon" color="#cccccc"></u-icon>
  34. </view>
  35. <view class="del-icon" @click="delGoods(index, item)">
  36. <u-icon size="40" name="minus-circle-fill" color="#fa3534"></u-icon>
  37. </view>
  38. <view class="float_left info">
  39. <view class="goods-name ellipsis">{{ item.goodsName }}</view>
  40. <view class="goods-code">{{ item.goodsCode }}</view>
  41. <view class="goods-num clearfix">
  42. <view class="float_left">{{ item.unitName }};{{ item.skuName }}</view>
  43. <text
  44. class="float_right">可退:{{ $utils.formatNub(item.returnOnNum) }}{{ item.unitName }}</text>
  45. </view>
  46. <view class="goods-num clearfix">
  47. <view class="float_left ">
  48. <text class="price">{{ $utils.formattedNumber(item.buyerUnitPrice) }}</text>
  49. <text style="margin: 0 10rpx;">x</text>
  50. <input type="digit" @blur="buyerNumChange(index)" placeholder="退货数量"
  51. v-model="item.buyerNum" />
  52. </view>
  53. <view class="float_right">
  54. 小计:
  55. <text class="price">{{ $utils.formattedNumber(item.subtotalPrice) }}</text>
  56. </view>
  57. </view>
  58. <view class="goods-num clearfix" v-if="item.isEq === 5">
  59. <view class="float_left ">
  60. <input type="digit" @blur="buyerNumChange(index)" placeholder="其他单位"
  61. v-model="item.otherNum" />
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </block>
  67. </view>
  68. </view>
  69. <view class="form-model-view">
  70. <u-form-item label="其他金额"><input type="digit" v-model="add_form.otherAmount" placeholder="请输入" />
  71. </u-form-item>
  72. <u-form-item label="退货金额"><input type="digit" v-model="purchaseAmount" placeholder="请输入" />
  73. </u-form-item>
  74. </view>
  75. <view class="form-model-view">
  76. <u-form-item label="备注" label-position="top">
  77. <u-input type="textarea" v-model="add_form.remark" />
  78. </u-form-item>
  79. </view>
  80. </u-form>
  81. <view class="detail-bottom">
  82. <view class="handel-btn" @click="submit">提交</view>
  83. </view>
  84. </view>
  85. </template>
  86. <script>
  87. export default {
  88. data() {
  89. return {
  90. purchaseData: '',
  91. pusrchaseOut_id: '',
  92. goods_list: [],
  93. goodsArrData: [],
  94. deleteArray: [],
  95. purchaseGoodsData: [],
  96. add_form: {
  97. originId: '',
  98. originNo: '',
  99. supplierId: '',
  100. supplierName: '',
  101. warehouseId: '',
  102. warehouseName: '',
  103. buyerId: '',
  104. buyerName: '',
  105. operatorName: '',
  106. couponAmount: '',
  107. otherAmount: '',
  108. remark: '',
  109. goodsData: [],
  110. shopId: '',
  111. shopName: ''
  112. }
  113. };
  114. },
  115. watch: {
  116. purchaseData(val) {
  117. if (val) {
  118. this.selpurchase(val);
  119. }
  120. },
  121. purchaseGoodsData(val) {
  122. if (val) {
  123. this.goods_list = val;
  124. }
  125. }
  126. },
  127. computed: {
  128. userName() {
  129. return this.$store.state.userInfo.name;
  130. },
  131. purchaseAmount() {
  132. let sum = 0;
  133. if (this.goods_list.length > 1) {
  134. this.goods_list.forEach(item => {
  135. sum = this.$NP.plus(sum, Number(item.subtotalPrice));
  136. });
  137. } else if (this.goods_list.length === 1) {
  138. sum = Number(this.goods_list[0].subtotalPrice);
  139. } else {
  140. sum = 0;
  141. }
  142. return this.$NP.plus(sum, this.add_form.otherAmount);
  143. }
  144. },
  145. onLoad(options) {
  146. if (options.id) {
  147. this.pusrchaseOut_id = options.id;
  148. uni.setNavigationBarTitle({
  149. title: '编辑采购退货单'
  150. });
  151. this.getPurchaseOutInfoById();
  152. }
  153. },
  154. methods: {
  155. // 详情
  156. getPurchaseOutInfoById() {
  157. this.$u.api.getPurchaseOutInfoById(this.pusrchaseOut_id).then(({
  158. data
  159. }) => {
  160. this.add_form.warehouseName = data.warehouseName;
  161. this.add_form.warehouseId = data.warehouseId;
  162. this.add_form.originId = data.originId;
  163. this.add_form.originNo = data.originNo;
  164. this.add_form.shopId = data.shopId;
  165. this.add_form.shopName = data.shopName;
  166. this.add_form.supplierId = data.supplierId;
  167. this.add_form.supplierName = data.supplierName;
  168. this.add_form.buyerId = data.buyerId;
  169. this.add_form.buyerName = data.buyerName;
  170. this.add_form.operatorName = data.operatorName;
  171. this.add_form.couponAmount = data.couponAmount;
  172. this.add_form.otherAmount = data.otherAmount;
  173. this.add_form.remark = data.remark;
  174. this.goods_list = data.details.map(item => {
  175. return {
  176. ...item,
  177. buyerNum: Number(item.buyerNum)
  178. };
  179. });
  180. this.getPurchaseInfoById(data.originId, data.warehouseId, 'detail');
  181. });
  182. },
  183. selGoodsPage() {
  184. const obj = {
  185. goodsArrData: this.goodsArrData,
  186. goods_list: this.goods_list
  187. };
  188. uni.setStorageSync('purchaseGoods', obj);
  189. this.goPage('/pagesT/order/purchaseGoods');
  190. },
  191. buyerNumChange(index) {
  192. const target = this.$u.deepClone(this.goods_list);
  193. if (Number(target[index].buyerNum) > Number(target[index].returnOnNum)) {
  194. target[index].buyerNum = this.$utils.formatNub(target[index].returnOnNum);
  195. }
  196. target[index].subtotalPrice = this.$NP.times(target[index].buyerNum, target[index].buyerUnitPrice);
  197. this.goods_list = target;
  198. },
  199. submit() {
  200. if (!this.add_form.originNo) {
  201. this.$u.toast('请选择关联的采购单');
  202. return;
  203. }
  204. if (!this.goods_list) {
  205. this.$u.toast('请选择退货商品');
  206. return;
  207. }
  208. const params = {
  209. ...this.add_form,
  210. deleteArray: this.deleteArray,
  211. goodsData: this.$u.deepClone(this.goods_list).map(item => {
  212. delete item.num;
  213. if (!this.pusrchaseOut_id) {
  214. delete item.id;
  215. }
  216. return item;
  217. })
  218. };
  219. if (this.pusrchaseOut_id) {
  220. this.$u.api.editPurchaseOut(this.pusrchaseOut_id, params).then(res => {
  221. this.$u.toast('编辑成功');
  222. uni.navigateBack();
  223. });
  224. } else {
  225. (params.operatorName = this.userName),
  226. this.$u.api.addPurchaseOut(params).then(res => {
  227. this.$u.toast('提交成功');
  228. uni.navigateBack();
  229. });
  230. }
  231. },
  232. // 选择采购单 selpurchase
  233. selpurchase(val) {
  234. const id = val.id;
  235. const warehouseId = val.warehouseId;
  236. this.getPurchaseInfoById(id, warehouseId);
  237. this.add_form.originId = val.id;
  238. this.add_form.originNo = val.no;
  239. this.add_form.shopId = val.shopId;
  240. this.add_form.shopName = val.shopName;
  241. this.add_form.buyerId = val.buyerId;
  242. this.add_form.buyerName = val.buyerName;
  243. this.add_form.remark = val.remark;
  244. this.add_form.supplierId = val.supplierId;
  245. this.add_form.supplierName = val.supplierName;
  246. this.add_form.warehouseName = val.warehouseName;
  247. this.add_form.warehouseId = val.warehouseId;
  248. },
  249. // 获取采购单详情
  250. async getPurchaseInfoById(id, warehouseId, isdetail) {
  251. this.$u.api
  252. .getPurchaseAndBatchInfoById({
  253. id: id,
  254. warehouseId: warehouseId
  255. })
  256. .then(({
  257. data
  258. }) => {
  259. if (!isdetail) {
  260. this.goods_list = data.map(item => {
  261. return {
  262. id: item.id,
  263. goodsId: item.basicGoodsId,
  264. goodsCode: item.goodsCode,
  265. goodsName: item.goodsName,
  266. unitName: item.unitName,
  267. skuName: item.skuName,
  268. skuId: item.skuId,
  269. purchaseNum: this.$utils.formatNub(item.buyerNum),
  270. buyerNum: this.$utils.formatNub(item.returnOnNum),
  271. inNum: item.inNum,
  272. inOfNum: item.inOfNum,
  273. returnOnNum: item.returnOnNum,
  274. returnNum: item.returnNum,
  275. inventoryNum: this.$utils.formatNub(item.num),
  276. buyerUnitPrice: this.$utils.formatNub(item.buyerUnitPrice),
  277. subtotalPrice: this.$utils.formatNub(item.subtotalPrice),
  278. couponAmount: this.$utils.formatNub(item.couponAmount),
  279. otherAmount: this.$utils.formatNub(item.otherAmount),
  280. isEq: item.isEq,
  281. otherNum: item.otherNum,
  282. };
  283. });
  284. }
  285. console.log(this.goods_list);
  286. this.goodsArrData = data;
  287. });
  288. },
  289. delGoods(index, row) {
  290. if (this.goods_list.length === 1) {
  291. this.$u.toast('至少保留一条数据');
  292. return;
  293. }
  294. if (row.id) {
  295. this.deleteArray.push(row.id);
  296. }
  297. this.goods_list.splice(index, 1);
  298. }
  299. }
  300. };
  301. </script>
  302. <style lang="scss" scoped>
  303. .goods-ul {
  304. padding-top: 10rpx;
  305. .more-goods {
  306. line-height: 80rpx;
  307. border-top: 1px solid #eeeeee;
  308. text-align: center;
  309. font-size: 24rpx;
  310. }
  311. .goods-title {
  312. margin-bottom: 20rpx;
  313. line-height: 80rpx;
  314. font-size: 24rpx;
  315. border-bottom: 1px solid #eeeeee;
  316. .float_right {
  317. color: $uni-color-primary;
  318. }
  319. }
  320. .goods-li {
  321. line-height: 32rpx;
  322. padding-bottom: 24rpx;
  323. position: relative;
  324. .del-icon {
  325. position: absolute;
  326. top: 50%;
  327. left: 0;
  328. transform: translateY(-50%);
  329. }
  330. .goods-img {
  331. margin-right: 20rpx;
  332. image {
  333. width: 150rpx;
  334. height: 150rpx;
  335. border-radius: 8rpx;
  336. display: block;
  337. }
  338. }
  339. .info {
  340. width: 640rpx;
  341. .goods-name {
  342. width: 640rpx;
  343. height: 34rpx;
  344. line-height: 34rpx;
  345. }
  346. .goods-code {
  347. font-size: 24rpx;
  348. padding-top: 10rpx;
  349. }
  350. .goods-num {
  351. padding-top: 10rpx;
  352. font-size: 24rpx;
  353. .float_left {
  354. input {
  355. display: inline-block;
  356. border: 1px solid #eeeeee;
  357. border-radius: 10rpx;
  358. padding: 0 10rpx;
  359. vertical-align: middle;
  360. text-align: center;
  361. }
  362. }
  363. .price {
  364. font-size: 28rpx;
  365. font-weight: bold;
  366. color: $uni-color-error;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. </style>