type-business-edit.vue 16 KB

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