type-business-edit.vue 19 KB

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