type-business.vue 18 KB

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