type-business-edit.vue 17 KB

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