batchbyOneModal.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <el-drawer
  3. v-loading="load"
  4. title="短驳生成单"
  5. :visible.sync="drawer"
  6. @close="close"
  7. :direction="direction"
  8. size="50%">
  9. <div class="content">
  10. <div class="order-top" v-if="data.length > 1">
  11. <el-pagination
  12. background
  13. :page-size="1"
  14. :current-page="currentOrder + 1"
  15. layout="prev, pager, next"
  16. @current-change="currentChange"
  17. :total="data.length">
  18. </el-pagination>
  19. </div>
  20. <deliveryGoodsInfo :hideOrderCode="true" @editState="editState" @editResult="editResult" @qtyChange="qtyChange" ref="info" />
  21. <!-- <deliveryPrice :data="priceObj[data[currentOrder].omsOrderIds]" ref="price" v-if="data[currentOrder] && priceObj[data[currentOrder].omsOrderIds]"
  22. @prichChange="prichChange" :currentValue="currentPrice[data[currentOrder].omsOrderIds]" /> -->
  23. </div>
  24. <div class="space"></div>
  25. <div class="deli-footer">
  26. <div class="d-left">
  27. <!-- <div class="estimate-total">
  28. 订单小计<span class="total">¥{{data[currentOrder] && currentPrice[data[currentOrder].omsOrderIds]?currentPrice[data[currentOrder].omsOrderIds].estimateFreight:'0.00'}}</span>
  29. </div> -->
  30. <!-- <div class="agreement">
  31. <el-checkbox v-model="checked">已读并同意《XXX电子运单协议》</el-checkbox>
  32. </div> -->
  33. </div>
  34. <div class="btn-box">
  35. <div class="send-btn" @click="btn">提交</div>
  36. </div>
  37. </div>
  38. </el-drawer>
  39. </template>
  40. <script lang="ts">
  41. import { Component, Prop, Vue, Watch } from "vue-property-decorator";
  42. import DeliveryGoodsInfo from "./deliveryGoodsInfo.vue";
  43. import DeliveryPrice from "./deliveryPrice.vue";
  44. import { add,multiply,subtract,divide } from '@/benyun/utils/accuracy'
  45. import { getShortBargePrice,WMSAddEntryOrder,getInventoryByStoreHouseIdAndSkuids } from '@/api/delivery'
  46. import Format from '@/benyun/utils/dateFormat'
  47. @Component({components:{DeliveryGoodsInfo,DeliveryPrice}})
  48. export default class BatchbyOneModal extends Vue {
  49. drawer=false;
  50. direction='rtl'
  51. checked=false;
  52. data:Array<any>=[];
  53. currentOrder=0;
  54. isSuccess=false;
  55. stopHandle=false;
  56. load = false;
  57. priceObj:any={};
  58. currentPrice:any={};
  59. setShow(v:boolean){
  60. this.drawer=v;
  61. this.priceObj={};
  62. this.currentPrice={};
  63. this.isSuccess = false;
  64. this.stopHandle = false;
  65. this.currentOrder = 0;
  66. this.checked = false;
  67. }
  68. close(){
  69. if(this.isSuccess){
  70. this.$emit('handleSuccess');
  71. }
  72. }
  73. editResult(v:any){
  74. this.data[this.currentOrder] = v;
  75. this.getStoreCount(v);
  76. // this.getPriceInfo(v);
  77. }
  78. prichChange(index:number){
  79. this.currentPrice[this.data[this.currentOrder].omsOrderIds] = this.priceObj[this.data[this.currentOrder].omsOrderIds][index];
  80. this.$forceUpdate();
  81. }
  82. currentChange(v:number){
  83. this.currentOrder = v-1;
  84. this.$forceUpdate();
  85. this.$nextTick(()=>{
  86. this.setInfo();
  87. })
  88. }
  89. setInfo(){
  90. (this.$refs.info as any).setValue(this.data[this.currentOrder]);
  91. }
  92. setValue(data:Array<any>){
  93. this.data = [];
  94. const requestId = new Date().getTime() + this.getUuid()
  95. let obj:any={
  96. // tmsBusinessMan: (this as any).$store.getters.userInfo.userName,
  97. // tmsBusinessPhone: (this as any).$store.getters.userInfo.phonenumber,
  98. requestId:requestId
  99. };
  100. obj.subItem=[];
  101. for(const item of data){
  102. obj.subItem.push({
  103. requestId:requestId,
  104. barCode:item.barCode,
  105. omsOrderItemId: item.id,
  106. tmsGoodsModel:item.itemNumber,
  107. tmsGoodsCode:item.skuCode,
  108. tmsQuantity:1,
  109. tmsGoodsTotalPrice:item.price,
  110. name:item.skuTitle,
  111. price:item.price,
  112. weight:item.weight
  113. })
  114. }
  115. this.data.push(obj)
  116. this.$nextTick(()=>{
  117. (this.$refs.info as any).setValue(this.data[this.currentOrder])
  118. })
  119. }
  120. getUuid(){
  121. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  122. }
  123. btn(){
  124. // this.noSentOrder();
  125. if(!this.data[this.currentOrder]){
  126. this.$message('没有需要发货的订单!')
  127. return
  128. }
  129. if(this.stopHandle){
  130. this.$message('库存不足!')
  131. return
  132. }
  133. // if(!this.checked){
  134. // this.$message('请阅读并同意运单协议!')
  135. // return
  136. // }
  137. if(!this.data[this.currentOrder].tmsShipmentConsignor || !this.data[this.currentOrder].tmsUnloadingConsignor || !this.data[this.currentOrder].out_storeHouseId){
  138. this.$message("请编辑订单信息");
  139. return
  140. }
  141. // if(!this.currentPrice[this.data[this.currentOrder].omsOrderIds]){
  142. // this.$message("请选择价格!");
  143. // return
  144. // }
  145. this.sendGoods(this.data[0]);
  146. }
  147. nextBtn(){
  148. if(this.stopHandle){
  149. this.$message('库存不足!')
  150. return
  151. }
  152. // if(!this.checked){
  153. // this.$message('请阅读并同意运单协议!')
  154. // return
  155. // }
  156. const _value = this.data[this.currentOrder];
  157. if(!_value.tmsShipmentAddress || !_value.tmsShipmentConsignor || !_value.tmsUnloadingAddress || !_value.tmsUnloadingConsignor){
  158. this.$message("请编辑订单信息");
  159. return
  160. }
  161. // if(!this.currentPrice[_value.omsOrderIds]){
  162. // this.$message('请选择价格!')
  163. // return
  164. // }
  165. if(_value.isSuccess){
  166. this.$message('订单:'+_value.omsOrderIds+'已执行过发货操作!');
  167. return
  168. }
  169. this.sendGoods(_value,true);
  170. }
  171. qtyChange(v:any){
  172. this.data[this.currentOrder] = v;
  173. this.getStoreCount(v);
  174. // this.getPriceInfo(v);
  175. }
  176. //查库存
  177. getStoreCount(item:any,callback?:Function){
  178. if(!item){
  179. return
  180. }
  181. if(!item.out_storeHouseId || item.subItem.length == 0){
  182. return
  183. }
  184. let params:any={};
  185. params.storeHouseId = item.out_storeHouseId;
  186. params.skuIds=[];
  187. if(item.subItem){
  188. for(const i of item.subItem){
  189. if(params.skuIds.indexOf(i.omsOrderItemId) == -1){
  190. params.skuIds.push(i.omsOrderItemId);
  191. }
  192. }
  193. }
  194. this.load = true;
  195. getInventoryByStoreHouseIdAndSkuids(params).then((res:any) => {
  196. this.load = false;
  197. let m='';
  198. for(const i of item.subItem){
  199. for(const d of res.data){
  200. let s = Number(d.inventory) - Number(d.useInventory) - Number(i.tmsQuantity);
  201. if(i.omsOrderItemId == d.skuid && s < 0){
  202. m = m ? m + ',' + i.name : i.name;
  203. }else{
  204. d.inventory = subtract(d.inventory, i.tmsQuantity);
  205. }
  206. }
  207. }
  208. if(m){
  209. this.$message({
  210. message:'商品“'+m+'”库存不足!',
  211. type:'error'
  212. })
  213. this.stopHandle = true;
  214. return
  215. }else{
  216. this.stopHandle = false
  217. }
  218. if(callback) callback(item,this.sendGoods)
  219. }).catch(()=>{
  220. this.load = false;
  221. })
  222. }
  223. //发货
  224. sendGoods(item:any,isNext?:boolean){
  225. if(!item){
  226. this.$message('信息不存在!')
  227. return
  228. }
  229. let params:any=(this as any).$lodash.cloneDeep(item);
  230. // if(this.priceObj[item.omsOrderIds]){
  231. // try{
  232. // params.pricePlan = JSON.stringify(this.priceObj[item.omsOrderIds])
  233. // }catch(e){}
  234. // }
  235. // if(this.currentPrice[item.omsOrderIds]){
  236. // params.priceId = this.currentPrice[item.omsOrderIds].id;
  237. // }
  238. params.tmsMaterials=[];
  239. if(item.subItem){
  240. let skuIds:Array<any>=[];
  241. for(const i of item.subItem){
  242. let ind = skuIds.indexOf(item.omsOrderItemId)
  243. if(ind == -1){
  244. skuIds.push(item.omsOrderItemId);
  245. params.tmsMaterials.push({
  246. qty:i.tmsQuantity,
  247. materialSkuId:i.omsOrderItemId,
  248. storeHouseId:item.out_storeHouseId,
  249. storingLocationId:item.entry_storeHouseId
  250. })
  251. }else{
  252. for(let paramsItem of params.tmsMaterials){
  253. if(paramsItem.materialSkuId == i.omsOrderItemId){
  254. paramsItem.qty = add(Number(paramsItem.qty),Number(i.tmsQuantity))
  255. break
  256. }
  257. }
  258. }
  259. }
  260. }
  261. delete params.subItem;
  262. this.load = true;
  263. WMSAddEntryOrder(params).then((res:any) => {
  264. this.load = false;
  265. if(res.code == 200){
  266. this.isSuccess = true;
  267. this.$message({
  268. message:'操作成功!',
  269. type:'success'
  270. })
  271. this.drawer = false;
  272. this.$forceUpdate();
  273. }
  274. }).catch(() => {
  275. this.load = false;
  276. })
  277. }
  278. //寻找未发货订单
  279. noSentOrder(){
  280. this.currentOrder = this.data.length;
  281. for(let i = 0; i < this.data.length; i++){
  282. if(!this.data[i].isSuccess){
  283. this.currentOrder = i;
  284. break
  285. }
  286. }
  287. // if(this.data[this.currentOrder]){
  288. this.setInfo();
  289. // }
  290. }
  291. setOnEditOrderInfo(ids:string){
  292. let _value = this.data[0]
  293. for(const item of this.data){
  294. if(ids.indexOf(item.omsOrderIds) > -1 && !item.isSuccess){
  295. item.orderType = _value.orderType;
  296. item.storeHouseId = _value.storeHouseId;
  297. item.tmsArrivalDate = _value.tmsArrivalDate;
  298. item.tmsDeliveryDate =_value.tmsDeliveryDate;
  299. item.tmsTransportMethod = _value.tmsTransportMethod;
  300. item.tmsBusinessMan = _value.tmsBusinessMan;
  301. item.tmsBusinessPhone = _value.tmsBusinessPhone;
  302. item.tmsShipmentConsignor = _value.tmsShipmentConsignor;
  303. item.tmsShipmentContacts = _value.tmsShipmentContacts;
  304. item.tmsShipmentProvince = _value.tmsShipmentProvince;
  305. item.tmsShipmentProvinceNo = _value.tmsShipmentProvinceNo;
  306. item.tmsShipmentCity = _value.tmsShipmentCity;
  307. item.tmsShipmentCityNo = _value.tmsShipmentCityNo;
  308. item.tmsShipmentRegion = _value.tmsShipmentRegion;
  309. item.tmsShipmentRegionNo = _value.tmsShipmentRegionNo;
  310. item.tmsShipmentStreetNo = _value.tmsShipmentStreetNo;
  311. item.tmsShipmentStreet = _value.tmsShipmentStreet;
  312. item.tmsShipmentAddress = _value.tmsShipmentAddress;
  313. item.tmsUnloadingConsignor = _value.tmsUnloadingConsignor;
  314. item.tmsUnloadingContacts = _value.tmsUnloadingContacts;
  315. item.tmsUnloadingProvince = _value.tmsUnloadingProvince;
  316. item.tmsUnloadingProvinceNo = _value.tmsUnloadingProvinceNo;
  317. item.tmsUnloadingCity = _value.tmsUnloadingCity;
  318. item.tmsUnloadingCityNo = _value.tmsUnloadingCityNo;
  319. item.tmsUnloadingRegion = _value.tmsUnloadingRegion;
  320. item.tmsUnloadingRegionNo = _value.tmsUnloadingRegionNo;
  321. item.tmsUnloadingStreetNo = _value.tmsUnloadingStreetNo;
  322. item.tmsUnloadingStreet = _value.tmsUnloadingStreet;
  323. item.tmsUnloadingAddress = _value.tmsUnloadingAddress;
  324. }
  325. }
  326. }
  327. //获取价格
  328. getPriceInfo(data:any,callback?:Function){
  329. let params:any={};
  330. if(!data.out_storeHouseId || !data.entry_storeHouseId || data.subItem.length == 0){
  331. return
  332. }
  333. params.startStoreHouseId = data.out_storeHouseId;
  334. params.endStoreHouseId = data.entry_storeHouseId;
  335. params.materialInfos = []
  336. if(data.subItem){
  337. for(const i of data.subItem){
  338. params.materialInfos.push({
  339. skuId: i.omsOrderItemId,
  340. qty:i.tmsQuantity,
  341. })
  342. }
  343. }
  344. this.load = true;
  345. getShortBargePrice(params).then((res:any) => {
  346. // if(this.currentPrice && this.currentPrice[data.omsOrderIds]){
  347. // delete this.currentPrice[data.omsOrderIds]
  348. // }
  349. this.load=false;
  350. let current:any=null;
  351. for(let item of res.data[0].data){
  352. let d = new Date().getTime() + item.duration*60*60*1000;
  353. item.endTime=Format(new Date(d),'MM月dd日 HH:mm');
  354. if(!current) current = item;
  355. if(Number(current.estimateFreight) > Number(item.estimateFreight)){
  356. current = item
  357. }
  358. }
  359. this.priceObj[data.omsOrderIds] = res.data[0].data;
  360. this.currentPrice[data.omsOrderIds] = current;
  361. this.$forceUpdate();
  362. if(callback){
  363. callback(data)
  364. }
  365. }).catch((err:any)=>{
  366. this.load = false;
  367. })
  368. }
  369. editState(v:boolean){
  370. this.drawer = v
  371. }
  372. }
  373. </script>
  374. <style lang="scss" scoped>
  375. .content{
  376. width: 100%;
  377. box-sizing: border-box;
  378. padding: 0 16px;
  379. background-color: #FFF;
  380. .order-top{
  381. padding-bottom: 16px;
  382. display: flex;
  383. justify-content: center;
  384. }
  385. }
  386. .deli-footer{
  387. height: 80px;
  388. width: 100%;
  389. box-shadow: 0 -5px 10px #EEE;
  390. padding: 0 16px 8px;
  391. box-sizing: border-box;
  392. display: flex;
  393. justify-content: space-between;
  394. align-items:flex-end;
  395. position: absolute;
  396. background-color: #FFF;
  397. left: 0;
  398. bottom: 0;
  399. z-index: 10;
  400. .d-left{
  401. width: 50%;
  402. .estimate-total{
  403. font-size: 14px;
  404. padding-bottom: 4px;
  405. .total{
  406. font-size: 16px;
  407. color: #F00;
  408. }
  409. .detail{
  410. color: #1684FC;
  411. padding-left: 16px;
  412. cursor: pointer;
  413. }
  414. }
  415. }
  416. .send-btn{
  417. width: 120px;
  418. height: 40px;
  419. line-height: 40px;
  420. margin-left: 16px;
  421. border-radius: 8px;
  422. background: linear-gradient(129.2deg, rgba(22,132,252,1) 9.81%,rgba(93,167,249,1) 97.4%);
  423. color: rgba(255, 255, 255, 100);
  424. font-size: 14px;
  425. text-align: center;
  426. box-shadow: 0px 2px 6px 0px rgba(93, 167, 249, 100);
  427. cursor: pointer;
  428. }
  429. .stopBtn{
  430. opacity: 0.7;
  431. }
  432. .btn-box{
  433. width: 50%;
  434. display: flex;
  435. justify-content: flex-end;
  436. align-items: center;
  437. }
  438. }
  439. .space{
  440. height: 80px;
  441. width: 100%;
  442. margin-top: 16px;
  443. }
  444. </style>