type-business.vue 16 KB

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