type-business.vue 16 KB

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