type-business-edit.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <template>
  2. <view>
  3. <view class="box">
  4. <view class="top">
  5. <text class="title">{{ goods.name }}</text>
  6. </view>
  7. <view class="item" v-if="goods.needDeclare==1">
  8. <view class="l">
  9. <text style="color: red;" v-if="goods.needDeclare==1">*</text>
  10. 申报单号:
  11. </view>
  12. <view class="r">
  13. <u-input placeholder="申报订单号" v-model="form.declareNo" clearable readonly>
  14. <text slot="suffix" style="font-size: 50rpx;" @click="selectDeclare">+</text>
  15. </u-input>
  16. </view>
  17. </view>
  18. <view class="item" v-if="goods.needCustomer==1">
  19. <view class="l">客户:</view>
  20. <view class="r" style="flex: 12;">
  21. <picker :disabled="goods.needDeclare==1" v-if="customer.customerList.length>0" class="p-picker"
  22. @change="customerChange($event)" :value="customer.index" :range="customer.customerList"
  23. range-key="name">
  24. <text class="p-text">{{ customer.customerList[customer.index].name }}</text>
  25. </picker>
  26. </view>
  27. </view>
  28. <view class="item" v-if="goods.needOwner==1">
  29. <view class="l">
  30. <text style="color: red;">*</text>
  31. 货物:
  32. </view>
  33. <view class="r">
  34. <u-input placeholder="输入货物" v-model="form.businessGoodsName">
  35. </u-input>
  36. </view>
  37. </view>
  38. <view class="item">
  39. <view class="l">
  40. <text style="color: red;" v-if="goods.needOperateTime">*</text>
  41. 件数:
  42. </view>
  43. <view class="r">
  44. <u-input v-model="form.businessGoodsNum" type="number">
  45. </u-input>
  46. </view>
  47. </view>
  48. <view class="item">
  49. <view class="l">作业人员:</view>
  50. <view class="r">
  51. <u-input placeholder="输入作业人员" v-model="form.operator">
  52. </u-input>
  53. </view>
  54. </view>
  55. <view class="item-line">
  56. <u-row style="height: 40px;">
  57. <u-col span=4>车辆</u-col>
  58. <u-col span=8>
  59. <u-button type="primary" text="添加" @click="addCar" icon="plus"
  60. style="width: 60px;height: 26px;" v-if="goods.mulCar==1||car.list.length==0"/>
  61. </u-col>
  62. </u-row>
  63. </view>
  64. <view class="item" v-for="(car,index) in car.list" :key="index">
  65. <view class="l">车牌:</view>
  66. <view class="r">
  67. <u-input placeholder="车辆" v-model="car.carNo" readonly>
  68. <view slot="suffix" style="display: flex;">
  69. <u-icon @click="editCar(car)" size="20" name="edit-pen-fill" color="blue"></u-icon>
  70. <u-icon style="margin-left:20rpx;" size="20" @click="delCar(car)" name="close-circle-fill"
  71. color="red"></u-icon>
  72. </view>
  73. </u-input>
  74. </view>
  75. </view>
  76. <view class="item-line" style="margin-top: 30rpx;">
  77. 业务项
  78. </view>
  79. <view class="business-list" v-for="(item,index) in typeList">
  80. <u-row>
  81. <u-col span="4">
  82. <text>
  83. <text style="color: red;display: inline;" v-if="item.need==1">*</text>
  84. {{ item.name }}:
  85. </text>
  86. </u-col>
  87. <u-col span="8" style="display: flex;">
  88. <u-row>
  89. <u-col span="10" @click="showSelect(item)">
  90. {{ item.itemName ? item.itemName : '请选择' }}
  91. </u-col>
  92. <u-col span="2" @click="item.itemName='',item.itemId=''" v-if="item.itemId">
  93. <u-icon style="margin-left:15rpx;display: inline;" size="20" name="close-circle-fill"
  94. color="red"></u-icon>
  95. </u-col>
  96. </u-row>
  97. </u-col>
  98. </u-row>
  99. <view style="display: flex;position: relative;left: 30%;">
  100. <u-number-box style="margin-left: 15rpx;" v-if="item.itemName" :disabled="item.inc==0"
  101. v-model="item.num"></u-number-box>
  102. <text style="margin-left: 20rpx;color: red;" v-if="item.itemName">
  103. ¥{{ item.num * item.price }}
  104. </text>
  105. <view style="margin-left: 60rpx;" @click="remarkFn(item)">
  106. 备注
  107. </view>
  108. </view>
  109. <u-line></u-line>
  110. </view>
  111. <view class="hj" v-show="totalPrice>0">
  112. 合计:{{ totalPrice }}元
  113. </view>
  114. </view>
  115. <u-button type="primary" text="确定" @click="saveFn" v-show="perList.indexOf('tb-flex-business-edit')!==-1">
  116. </u-button>
  117. <!-- ---------------------------------------------------------- -->
  118. <view class="bottom-safety"></view>
  119. <u-picker :show="show" :columns="columns" @confirm="confirmFn" keyName="itemName" @cancel="show=false">
  120. </u-picker>
  121. </view>
  122. </template>
  123. <script>
  124. export default {
  125. data() {
  126. return {
  127. show: false,
  128. columns: [],
  129. customerId: '1',
  130. customer: {
  131. index: 0,
  132. customerList: [],
  133. },
  134. goods: {
  135. id: '',
  136. name: '',
  137. mulCar: 0
  138. },
  139. typeList: [],
  140. allTypeList: [],
  141. form: {
  142. customerId: '',
  143. declareNo: '',
  144. carNo: '',
  145. owner: '',
  146. carSize: '',
  147. goodsName: '',
  148. netWeight: '',
  149. },
  150. show: false,
  151. item: {
  152. items: []
  153. },
  154. car: {
  155. list: [{
  156. id: '',
  157. carNo: '',
  158. index: 0
  159. }]
  160. },
  161. perList: []
  162. }
  163. },
  164. computed: {
  165. totalPrice() {
  166. let typeList = this.typeList.filter(obj => obj.itemName);
  167. let price = 0;
  168. for (let i in typeList) {
  169. let type = typeList[i];
  170. price = price + type.price * type.num;
  171. }
  172. return price;
  173. },
  174. },
  175. onLoad(options) {
  176. let id = options.id;
  177. this.form.id = id;
  178. this.customerId = uni.getStorageSync('customerId');
  179. this.goods = JSON.parse(options.goodsJson);
  180. this.getOtherBusinessById();
  181. let that = this;
  182. uni.$on('getSelectDeclare', declare => {
  183. that.$nextTick(() => {
  184. that.handlerSelectDeclare(declare)
  185. })
  186. })
  187. uni.$on('getCar', car => {
  188. that.$nextTick(() => {
  189. that.handlerCar(car)
  190. })
  191. })
  192. uni.$on('getRemark', type => {
  193. that.$nextTick(() => {
  194. that.handlerRemark(type)
  195. })
  196. })
  197. },
  198. onShow() {
  199. this.perList = uni.getStorageSync('perList')
  200. },
  201. methods: {
  202. remarkFn(type) {
  203. console.log(type)
  204. let remark = type.remark ? type.remark : '';
  205. this.$common.to('/pages/onely-disinfect/add-remark?needRemark=' + type.needRemark + '&typeId=' + type.id + '&remark=' + remark)
  206. },
  207. handlerRemark(type) {
  208. let typeList = this.typeList;
  209. typeList.filter(obj => type.typeId == obj.id).forEach(obj => obj.remark = type.remark)
  210. },
  211. addCar() {
  212. this.car.list.push({
  213. index: Math.random(),
  214. id: '',
  215. carNo: '',
  216. index: 0
  217. })
  218. },
  219. filterItems(car) {
  220. let carList = this.car.list;
  221. let filterTypeList = JSON.parse(JSON.stringify(this.allTypeList));
  222. if (carList.length == 0) {
  223. this.typeList = filterTypeList;
  224. return;
  225. }
  226. if (!car) {
  227. let checkList = carList.filter(obj => obj.carType.indexOf('空') === -1);
  228. if (checkList.length > 0) {
  229. car = checkList[0];
  230. }
  231. }
  232. let carSize = car.carSize;
  233. let carType = car.carType;
  234. if (carType.indexOf('空') !== -1 && carList.length > 1) {
  235. return;
  236. }
  237. let netWeight = car.netWeight;
  238. let tempList = [];
  239. for (let i in filterTypeList) {
  240. let type = filterTypeList[i];
  241. let items = type.items;
  242. if (carType) {
  243. items = items.filter(item => item.itemType && item.itemType.indexOf(carType) !== -1);
  244. }
  245. if (carSize && carSize > 1) {
  246. items = items.filter(item => item.minLength <= carSize && item.carLength >= carSize);
  247. }
  248. if (netWeight && netWeight > 1 && carType.indexOf('空') == -1) {
  249. items = items.filter(item => item.minWeight <= netWeight && item.maxWeight >= netWeight);
  250. }
  251. let itemIds = items.map(item => item.id);
  252. if (itemIds.indexOf(type.itemId) == -1) {
  253. this.cleanItem(type);
  254. }
  255. type.items = items;
  256. tempList.push(type);
  257. }
  258. this.typeList = tempList;
  259. },
  260. cleanItem(type) {
  261. type.itemId = '';
  262. type.itemName = '';
  263. type.price = '';
  264. },
  265. getOtherBusinessById() {
  266. this.$api.getOtherBusinessById({
  267. id: this.form.id
  268. }).then(resp => {
  269. let data = resp.data;
  270. this.car.list = data.cars;
  271. let items = data.items;
  272. this.form = data;
  273. this.getTypeByGoodsId(items);
  274. this.getCustomerList(data.customerId);
  275. })
  276. },
  277. showSelect(item) {
  278. if (this.validBefore()) {
  279. this.columns = [];
  280. this.columns.push(item.items);
  281. this.show = true;
  282. }
  283. },
  284. confirmFn(e) {
  285. let selects = e.value;
  286. if (selects.length > 0) {
  287. let item = selects[0];
  288. let typeId = item.typeId;
  289. let typeList = this.typeList;
  290. typeList.filter(obj => obj.id == typeId).forEach(obj => {
  291. obj.itemId = item.id;
  292. obj.itemName = item.itemName;
  293. obj.inc = item.inc;
  294. obj.price = item.price;
  295. obj.needRemark = item.needRemark;
  296. })
  297. }
  298. this.show = false;
  299. },
  300. getTypeByGoodsId(items) {
  301. this.$api.getTypeByGoodsId({
  302. goodsId: this.goods.id
  303. }).then(resp => {
  304. let list = resp.data;
  305. for (let i in items) {
  306. let item = items[i];
  307. for (let j in list) {
  308. let type = list[j];
  309. if (type.id == item.itemTypeId) {
  310. type.items.filter(obj => obj.id == item.itemId)
  311. .forEach(obj => {
  312. console.log(obj)
  313. type.num = item.num;
  314. type.price = item.itemPrice;
  315. type.itemName = item.itemName;
  316. type.itemId = item.itemId;
  317. type.inc = obj.inc;
  318. type.remark = item.remark;
  319. })
  320. }
  321. }
  322. }
  323. this.allTypeList = JSON.parse(JSON.stringify(list));
  324. this.typeList = list;
  325. })
  326. },
  327. getCustomerList(customerId) {
  328. this.$api.getCustomerList({
  329. pageNo: 1,
  330. pageSize: 100
  331. }).then(resp => {
  332. let list = resp.data;
  333. console.log(list.map(obj => obj.id).indexOf(customerId))
  334. this.customer.index = list.map(obj => obj.id).indexOf(customerId);
  335. this.customer.customerList = list;
  336. console.log(this.customer)
  337. })
  338. },
  339. customerChange(e) {
  340. var value = e.detail.value; //当前picker选中的值
  341. this.customer.index = value;
  342. },
  343. handlerCar(car) {
  344. let list = this.car.list;
  345. let check = list.filter(obj => obj.carNo == car.carNo).pop();
  346. if (check) {
  347. check.carSize = car.carSize;
  348. check.netWeight = car.netWeight;
  349. check.carType = car.carType;
  350. } else {
  351. this.car.list.push(car);
  352. }
  353. this.clearEmptyCar(car);
  354. },
  355. clearEmptyCar(car) {
  356. let list = this.car.list;
  357. let obj = list.filter(obj => !obj.carNo).pop();
  358. if (obj) {
  359. this.car.list.splice(list.indexOf(obj), 1);
  360. }
  361. this.filterItems(car);
  362. },
  363. handlerSelectDeclare(declare) {
  364. let oldDeclareNo = this.form.declareNo;
  365. if (oldDeclareNo && oldDeclareNo !== declare.declareNo) {
  366. this.car.list = [];
  367. }
  368. this.form.declareNo = declare.declareNo;
  369. this.form.cardNo = declare.carNo;
  370. this.form.chinaCarNo = declare.chinaCarNo;
  371. this.form.netWeight = declare.grossWeight;
  372. this.form.owner = declare.sendUnit;
  373. let customerList = this.customer.customerList;
  374. this.customer.index = customerList.map(customer => customer.id).indexOf(declare.customerId);
  375. let carNo = declare.carNo;
  376. let grossWeight = declare.grossWeight;
  377. let carList = this.car.list;
  378. let exit = carList.filter(obj => obj.carNo == carNo).pop();
  379. if (!exit) {
  380. let car = {
  381. carNo: carNo,
  382. netWeight: grossWeight,
  383. carType: '载重'
  384. }
  385. this.car.list.push(car)
  386. }
  387. this.form.cardNo = declare.carNo;
  388. this.form.chinaCarNo = declare.chinaCarNo;
  389. this.form.netWeight = declare.grossWeight;
  390. let chinaCarNo = declare.chinaCarNo;
  391. if (chinaCarNo) {
  392. let list = [];
  393. chinaCarNo.replace(",", ",").split(",").forEach(carNo => {
  394. let exit = carList.filter(obj => obj.carNo == carNo).pop();
  395. if (!exit) {
  396. let car = {
  397. carNo: carNo,
  398. carType: '空车'
  399. }
  400. this.car.list.push(car)
  401. }
  402. })
  403. }
  404. this.clearEmptyCar();
  405. },
  406. selectDeclare() {
  407. this.$common.to('/pages/business-entering/declare-select?declareNo=' + this.form.declareNo)
  408. },
  409. editCar(car) {
  410. let goods = this.goods;
  411. this.$common.to('/pages/onely-disinfect/car-manager?carJson=' + JSON.stringify(car) + "&needCarSize=" +
  412. goods.needCarSize + '&needWeight=' + goods.needWeight)
  413. },
  414. delCar(car) {
  415. let list = this.car.list;
  416. if (list.length == 1) {
  417. this.$common.toast('至少有一辆车');
  418. return;
  419. }
  420. this.car.list.splice(list.indexOf(car), 1);
  421. this.filterItems();
  422. },
  423. validBefore() {
  424. let form = this.form;
  425. let goods = this.goods;
  426. let needDeclare = goods.needDeclare;
  427. let needCustomer = goods.needCustomer;
  428. let index = this.customer.index;
  429. if (needDeclare == 1 && !form.declareNo) {
  430. this.$common.toast('请选择申报单');
  431. return false;
  432. }
  433. if (!form.businessGoodsName && goods.needOwner == 1) {
  434. this.$common.toast('请填写货物');
  435. return false;
  436. }
  437. let needOperateTime = goods.needOperateTime;
  438. let businessGoodsNum = form.businessGoodsNum;
  439. if ((!businessGoodsNum || businessGoodsNum <= 0) && needOperateTime == '1') {
  440. this.$common.toast('请填写件数');
  441. return false;
  442. }
  443. let carList = this.car.list;
  444. if (carList.length == 0) {
  445. this.$common.toast('请录入车辆');
  446. return false;
  447. }
  448. let needCarSize = goods.needCarSize;
  449. let needWeight = goods.needWeight;
  450. for (let i in carList) {
  451. let car = carList[i];
  452. if (needCarSize == 1 && !car.carSize) {
  453. this.$common.toast('请补充' + car.carNo + '的规格');
  454. return false;
  455. }
  456. if (needWeight == 1 && car.carType.indexOf('重') !== -1 && !car.netWeight) {
  457. this.$common.toast('请补充' + car.carNo + '载重');
  458. return false;
  459. }
  460. }
  461. return true;
  462. },
  463. check() {
  464. let form = this.form;
  465. let goods = this.goods;
  466. let needDeclare = goods.needDeclare;
  467. let needCustomer = goods.needCustomer;
  468. let index = this.customer.index;
  469. if (needDeclare == 1 && !form.declareNo) {
  470. this.$common.toast('请选择申报单');
  471. return false;
  472. }
  473. if (!form.businessGoodsName && goods.needOwner == 1) {
  474. this.$common.toast('请填写货物');
  475. return false;
  476. }
  477. let needOperateTime = goods.needOperateTime;
  478. let businessGoodsNum = form.businessGoodsNum;
  479. if ((!businessGoodsNum || businessGoodsNum <= 0) && needOperateTime == '1') {
  480. this.$common.toast('请填写件数');
  481. return false;
  482. }
  483. let carList = this.car.list;
  484. if (carList.length == 0) {
  485. this.$common.toast('请录入车辆');
  486. return false;
  487. }
  488. let needCarSize = goods.needCarSize;
  489. let needWeight = goods.needWeight;
  490. for (let i in carList) {
  491. let car = carList[i];
  492. if (needCarSize == 1 && !car.carSize) {
  493. this.$common.toast('请补充' + car.carNo + '的规格');
  494. return false;
  495. }
  496. if (needWeight == 1 && car.carType && car.carType.indexOf('重') !== -1 && !car.netWeight) {
  497. this.$common.toast('请补充' + car.carNo + '载重');
  498. return false;
  499. }
  500. }
  501. let typeList = this.typeList;
  502. let selectList = [];
  503. for (let i in typeList) {
  504. let type = typeList[i];
  505. if (type.need == 1 && !type.itemId) {
  506. this.$common.toast('【' + type.name + '】必选');
  507. return false;
  508. }
  509. if (type.needRemark == 1 && !type.remark) {
  510. this.$common.toast('请录入【' + type.name + '】备注');
  511. return false;
  512. }
  513. if (type.itemId) {
  514. let obj = {
  515. typeId: type.id,
  516. typeName: type.name,
  517. id: type.itemId,
  518. num: type.num,
  519. price: type.price,
  520. remark: type.remark
  521. }
  522. selectList.push(obj);
  523. }
  524. }
  525. this.form.itemJson = JSON.stringify(selectList);
  526. this.form.carJson = JSON.stringify(this.car.list);
  527. this.form.items = null;
  528. this.form.cars = null;
  529. if (needCustomer == 1) {
  530. let customerList = this.customer.customerList;
  531. let index = this.customer.index;
  532. let customer = customerList[index];
  533. this.form.customerId = customer.id;
  534. this.form.customerName = customer.name;
  535. } else {
  536. this.form.customerId = '';
  537. this.form.customerName = '';
  538. }
  539. this.form.goodsId = this.goods.id;
  540. this.form.goodsName = this.goods.name;
  541. let chinaCarNo = carList
  542. .filter(car => this.$common.isCarNo(car.carNo.toUpperCase()))
  543. .map(car => car.carNo.toUpperCase())
  544. .join("、");
  545. let yueCarNo = carList
  546. .filter(car => !this.$common.isCarNo(car.carNo.toUpperCase()))
  547. .map(car => car.carNo.toUpperCase())
  548. .join("、");
  549. this.form.cardNo = yueCarNo;
  550. this.form.chinaCarNo = chinaCarNo;
  551. return true;
  552. },
  553. saveFn() {
  554. if (this.check()) {
  555. let obj = this.$common.removeNull(this.form);
  556. this.$api.editOtherBusiness(obj).then(resp => {
  557. if (resp.code == 200) {
  558. this.$common.toast('修改成功');
  559. setTimeout(() => {
  560. this.$common.to('/pages/onely-disinfect/Index')
  561. }, 1000)
  562. }
  563. })
  564. }
  565. },
  566. }
  567. }
  568. </script>
  569. <style lang="scss">
  570. page {
  571. background-color: #fff;
  572. }
  573. .hs-item {
  574. text-align: center;
  575. }
  576. .item-line {
  577. color: #a2a2a2;
  578. padding: 5px 0 10px 29px;
  579. border-bottom: 1px solid #E5E5E5;
  580. }
  581. .hj {
  582. padding: 50rpx;
  583. font-size: 40rpx;
  584. color: red;
  585. font-weight: bold;
  586. }
  587. .business-list {
  588. line-height: 75rpx;
  589. margin: 4rpx 0 0 48rpx;
  590. }
  591. .save-btn {
  592. background-color: #ff4200;
  593. height: 88rpx;
  594. display: flex;
  595. justify-content: center;
  596. align-items: center;
  597. margin: 60rpx;
  598. color: #fff;
  599. font-size: 30rpx;
  600. font-weight: bold;
  601. border-radius: 10rpx;
  602. }
  603. @import '@/common/common.scss'
  604. </style>