type-business.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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" style="width: 60px;height: 26px;"
  60. 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.5">
  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="7.5">
  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%;" v-if="item.itemName">
  100. <u-number-box style="margin-left: 15rpx;" :disabled="item.inc==0" v-model="item.num"></u-number-box>
  101. <text style="margin-left: 20rpx;color: red;">
  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-add')!==-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. businessGoodsName: '',
  149. businessGoodsNum: 1
  150. },
  151. show: false,
  152. item: {
  153. items: []
  154. },
  155. car: {
  156. list: [{
  157. id: '',
  158. carNo: '',
  159. index: 0
  160. }]
  161. },
  162. perList: []
  163. }
  164. },
  165. onShow() {
  166. this.perList = uni.getStorageSync('perList')
  167. },
  168. computed: {
  169. totalPrice() {
  170. let typeList = this.typeList.filter(obj => obj.itemName);
  171. let price = 0;
  172. for (let i in typeList) {
  173. let type = typeList[i];
  174. price = price + type.price * type.num;
  175. }
  176. return price;
  177. },
  178. },
  179. onLoad(options) {
  180. this.customerId = uni.getStorageSync('customerId');
  181. this.goods = JSON.parse(options.goodsJson);
  182. this.getCustomerList();
  183. this.getTypeByGoodsId();
  184. let that = this;
  185. uni.$on('getSelectDeclare', declare => {
  186. that.$nextTick(() => {
  187. that.handlerSelectDeclare(declare)
  188. })
  189. })
  190. uni.$on('getCar', car => {
  191. that.$nextTick(() => {
  192. that.handlerCar(car)
  193. })
  194. })
  195. uni.$on('getRemark', type => {
  196. that.$nextTick(() => {
  197. that.handlerRemark(type)
  198. })
  199. })
  200. },
  201. methods: {
  202. remarkFn(type) {
  203. let remark = type.remark ? type.remark : '';
  204. this.$common.to('/pages/onely-disinfect/add-remark?needRemark=' + type.needRemark + '&typeId=' + type.id +
  205. '&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. showSelect(item) {
  266. if (this.validBefore()) {
  267. this.columns = [];
  268. this.columns.push(item.items);
  269. this.show = true;
  270. }
  271. },
  272. confirmFn(e) {
  273. let selects = e.value;
  274. if (selects.length > 0) {
  275. let item = selects[0];
  276. let typeId = item.typeId;
  277. let typeList = this.typeList;
  278. typeList.filter(obj => obj.id == typeId).forEach(obj => {
  279. obj.itemId = item.id;
  280. obj.itemName = item.itemName;
  281. obj.inc = item.inc;
  282. obj.price = item.price;
  283. obj.needRemark = item.needRemark;
  284. })
  285. }
  286. this.show = false;
  287. },
  288. getTypeByGoodsId() {
  289. this.$api.getTypeByGoodsId({
  290. goodsId: this.goods.id
  291. }).then(resp => {
  292. let list = resp.data;
  293. this.allTypeList = JSON.parse(JSON.stringify(list));
  294. this.typeList = list;
  295. })
  296. },
  297. getCustomerList() {
  298. this.$api.getCustomerList({
  299. pageNo: 1,
  300. pageSize: 100
  301. }).then(resp => {
  302. let list = resp.data;
  303. let customerId = this.customerId;
  304. if (customerId !== '1') {
  305. this.customer.index = list.map(obj => obj.id).indexOf(customerId);
  306. }
  307. this.customer.customerList = list;
  308. })
  309. },
  310. customerChange(e) {
  311. var value = e.detail.value; //当前picker选中的值
  312. this.customer.index = value;
  313. },
  314. handlerCar(car) {
  315. let list = this.car.list;
  316. let check = list.filter(obj => obj.carNo == car.carNo).pop();
  317. if (check) {
  318. check.carSize = car.carSize;
  319. check.netWeight = car.netWeight;
  320. check.carType = car.carType;
  321. } else {
  322. this.car.list.push(car);
  323. }
  324. this.clearEmptyCar(car);
  325. },
  326. clearEmptyCar(car) {
  327. let list = this.car.list;
  328. let obj = list.filter(obj => !obj.carNo).pop();
  329. if (obj) {
  330. this.car.list.splice(list.indexOf(obj), 1);
  331. }
  332. this.filterItems(car);
  333. },
  334. handlerSelectDeclare(declare) {
  335. let oldDeclareNo = this.form.declareNo;
  336. if (oldDeclareNo && oldDeclareNo !== declare.declareNo) {
  337. this.car.list = [];
  338. }
  339. this.form.declareNo = declare.declareNo;
  340. this.form.cardNo = declare.carNo;
  341. this.form.chinaCarNo = declare.chinaCarNo;
  342. this.form.netWeight = declare.grossWeight;
  343. this.form.owner = declare.sendUnit;
  344. let customerList = this.customer.customerList;
  345. this.customer.index = customerList.map(customer => customer.id).indexOf(declare.customerId);
  346. let carNo = declare.carNo;
  347. let grossWeight = declare.grossWeight;
  348. let carList = this.car.list;
  349. let exit = carList.filter(obj => obj.carNo == carNo).pop();
  350. if (!exit) {
  351. let car = {
  352. carNo: carNo,
  353. netWeight: grossWeight,
  354. carType: '载重'
  355. }
  356. this.car.list.push(car)
  357. }
  358. this.form.cardNo = declare.carNo;
  359. this.form.chinaCarNo = declare.chinaCarNo;
  360. this.form.netWeight = declare.grossWeight;
  361. let chinaCarNo = declare.chinaCarNo;
  362. if (chinaCarNo) {
  363. let list = [];
  364. chinaCarNo.replace(",", ",").split(",").forEach(carNo => {
  365. let exit = carList.filter(obj => obj.carNo == carNo).pop();
  366. if (!exit) {
  367. let car = {
  368. carNo: carNo,
  369. carType: '空车',
  370. }
  371. this.car.list.push(car)
  372. }
  373. })
  374. }
  375. this.clearEmptyCar();
  376. },
  377. selectDeclare() {
  378. this.$common.to('/pages/business-entering/declare-select?declareNo=' + this.form.declareNo)
  379. },
  380. editCar(car) {
  381. let goods = this.goods;
  382. this.$common.to('/pages/onely-disinfect/car-manager?carJson=' + JSON.stringify(car) + "&needCarSize=" +
  383. goods.needCarSize + '&needWeight=' + goods.needWeight)
  384. },
  385. delCar(car) {
  386. let list = this.car.list;
  387. if (list.length == 1) {
  388. this.$common.toast('至少有一辆车');
  389. return;
  390. }
  391. this.car.list.splice(list.indexOf(car), 1);
  392. this.filterItems();
  393. },
  394. validBefore() {
  395. let form = this.form;
  396. let goods = this.goods;
  397. let needDeclare = goods.needDeclare;
  398. let needCustomer = goods.needCustomer;
  399. let index = this.customer.index;
  400. if (needDeclare == 1 && !form.declareNo) {
  401. this.$common.toast('请选择申报单');
  402. return false;
  403. }
  404. if (!form.businessGoodsName && goods.needOwner == 1) {
  405. this.$common.toast('请填写货物');
  406. return false;
  407. }
  408. let needOperateTime = goods.needOperateTime;
  409. let businessGoodsNum = form.businessGoodsNum;
  410. if ((!businessGoodsNum || businessGoodsNum <= 0) && needOperateTime == '1') {
  411. this.$common.toast('请填写件数');
  412. return false;
  413. }
  414. let carList = this.car.list;
  415. if (carList.length == 0) {
  416. this.$common.toast('请录入车辆');
  417. return false;
  418. }
  419. let needCarSize = goods.needCarSize;
  420. let needWeight = goods.needWeight;
  421. for (let i in carList) {
  422. let car = carList[i];
  423. if (needCarSize == 1 && !car.carSize) {
  424. this.$common.toast('请补充' + car.carNo + '的规格');
  425. return false;
  426. }
  427. if (needWeight == 1 && car.carType.indexOf('重') !== -1 && !car.netWeight) {
  428. this.$common.toast('请补充' + car.carNo + '载重');
  429. return false;
  430. }
  431. }
  432. return true;
  433. },
  434. check() {
  435. let form = this.form;
  436. let goods = this.goods;
  437. let needDeclare = goods.needDeclare;
  438. let needCustomer = goods.needCustomer;
  439. let index = this.customer.index;
  440. if (needDeclare == 1 && !form.declareNo) {
  441. this.$common.toast('请选择申报单');
  442. return false;
  443. }
  444. if (!form.businessGoodsName && goods.needOwner == 1) {
  445. this.$common.toast('请填写货物');
  446. return false;
  447. }
  448. let needOperateTime = goods.needOperateTime;
  449. let businessGoodsNum = form.businessGoodsNum;
  450. if ((!businessGoodsNum || businessGoodsNum <= 0) && needOperateTime == '1') {
  451. this.$common.toast('请填写件数');
  452. return false;
  453. }
  454. let carList = this.car.list;
  455. if (carList.length == 0) {
  456. this.$common.toast('请录入车辆');
  457. return false;
  458. }
  459. let needCarSize = goods.needCarSize;
  460. let needWeight = goods.needWeight;
  461. for (let i in carList) {
  462. let car = carList[i];
  463. if (needCarSize == 1 && !car.carSize) {
  464. this.$common.toast('请补充' + car.carNo + '的规格');
  465. return false;
  466. }
  467. if (needWeight == 1 && car.carType.indexOf('重') !== -1 && !car.netWeight) {
  468. this.$common.toast('请补充' + car.carNo + '载重');
  469. return false;
  470. }
  471. }
  472. let typeList = this.typeList;
  473. let selectList = [];
  474. for (let i in typeList) {
  475. let type = typeList[i];
  476. if (type.need == 1 && !type.itemId) {
  477. this.$common.toast('【' + type.name + '】必选');
  478. return false;
  479. }
  480. if (type.needRemark == 1 && !type.remark) {
  481. this.$common.toast('请录入【' + type.name + '】备注');
  482. return false;
  483. }
  484. if (type.itemId) {
  485. let obj = {
  486. typeId: type.id,
  487. typeName: type.name,
  488. id: type.itemId,
  489. num: type.num,
  490. price: type.price,
  491. remark: type.remark
  492. }
  493. selectList.push(obj);
  494. }
  495. }
  496. this.form.itemJson = JSON.stringify(selectList);
  497. this.form.carJson = JSON.stringify(this.car.list);
  498. this.form.items = null;
  499. if (needCustomer == 1) {
  500. let customerList = this.customer.customerList;
  501. let index = this.customer.index;
  502. let customer = customerList[index];
  503. this.form.customerId = customer.id;
  504. this.form.customerName = customer.name;
  505. } else {
  506. this.form.customerId = '';
  507. this.form.customerName = '';
  508. }
  509. this.form.goodsId = this.goods.id;
  510. this.form.goodsName = this.goods.name;
  511. let chinaCarNo = carList
  512. .filter(car => this.$common.isCarNo(car.carNo.toUpperCase()))
  513. .map(car => car.carNo.toUpperCase())
  514. .join("、");
  515. let yueCarNo = carList
  516. .filter(car => !this.$common.isCarNo(car.carNo.toUpperCase()))
  517. .map(car => car.carNo.toUpperCase())
  518. .join("、");
  519. this.form.cardNo = yueCarNo;
  520. this.form.chinaCarNo = chinaCarNo;
  521. return true;
  522. },
  523. saveFn() {
  524. if (this.check()) {
  525. let obj = this.$common.removeNull(this.form);
  526. this.$api.addOtherBusiness(obj).then(resp => {
  527. if (resp.code == 200) {
  528. this.$common.toast('录入成功');
  529. setTimeout(() => {
  530. this.$common.to('/pages/onely-disinfect/Index')
  531. }, 1000)
  532. }
  533. })
  534. }
  535. },
  536. }
  537. }
  538. </script>
  539. <style lang="scss">
  540. page {
  541. background-color: #fff;
  542. }
  543. .hs-item {
  544. text-align: center;
  545. }
  546. .item-line {
  547. color: #a2a2a2;
  548. padding: 5px 0 10px 29px;
  549. border-bottom: 1px solid #E5E5E5;
  550. }
  551. .hj {
  552. padding: 50rpx;
  553. font-size: 40rpx;
  554. color: red;
  555. font-weight: bold;
  556. }
  557. .business-list {
  558. line-height: 75rpx;
  559. margin: 4rpx 0 0 48rpx;
  560. }
  561. .save-btn {
  562. background-color: #ff4200;
  563. height: 88rpx;
  564. display: flex;
  565. justify-content: center;
  566. align-items: center;
  567. margin: 60rpx;
  568. color: #fff;
  569. font-size: 30rpx;
  570. font-weight: bold;
  571. border-radius: 10rpx;
  572. }
  573. @import '@/common/common.scss'
  574. </style>