type-business-edit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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.needOwner==1">
  17. <view class="l">
  18. <text style="color: red;">*</text>
  19. 货物:
  20. </view>
  21. <view class="r">
  22. <u-input placeholder="输入货物" v-model="form.businessGoodsName">
  23. </u-input>
  24. </view>
  25. </view>
  26. <view class="item">
  27. <view class="l">
  28. <text style="color: red;" v-if="goods.needOperateTime">*</text>
  29. 数量(件):
  30. </view>
  31. <view class="r">
  32. <u-input v-model="form.businessGoodsNum" type="number">
  33. </u-input>
  34. </view>
  35. </view>
  36. <view class="item">
  37. <view class="l">作业人员:</view>
  38. <view class="r">
  39. <u-input placeholder="输入作业人员" v-model="form.operator">
  40. </u-input>
  41. </view>
  42. </view>
  43. <view class="item-line">
  44. <u-row style="height: 40px;">
  45. <u-col span=4>车辆</u-col>
  46. <u-col span=8>
  47. <u-button type="primary" text="添加" @click="addCar" icon="plus" style="width: 60px;height: 26px;"
  48. v-if="goods.mulCar==1||car.list.length==0" />
  49. </u-col>
  50. </u-row>
  51. </view>
  52. <view class="item" v-for="(car,index) in car.list" :key="index">
  53. <view class="l">车牌:</view>
  54. <view class="r">
  55. <u-input placeholder="车辆" v-model="car.carNo" readonly>
  56. <view slot="suffix" style="display: flex;">
  57. <u-icon @click="editCar(car)" size="20" name="edit-pen-fill" color="blue"></u-icon>
  58. <u-icon style="margin-left:20rpx;" size="20" @click="delCar(car)" name="close-circle-fill"
  59. color="red"></u-icon>
  60. </view>
  61. </u-input>
  62. </view>
  63. </view>
  64. <view class="item-line" style="margin-top: 30rpx;">
  65. 业务项
  66. </view>
  67. <view class="business-list" v-for="(item,index) in typeList">
  68. <u-row>
  69. <u-col span="4">
  70. <text>
  71. <text style="color: red;display: inline;" v-if="item.need==1">*</text>
  72. {{ item.name }}:
  73. </text>
  74. </u-col>
  75. <u-col span="8" style="display: flex;">
  76. <u-row>
  77. <u-col span="10" @click="showSelect(item)">
  78. {{ item.itemName ? item.itemName : '请选择' }}
  79. </u-col>
  80. <u-col span="2" @click="item.itemName='',item.itemId=''" v-if="item.itemId">
  81. <u-icon style="margin-left:15rpx;display: inline;" size="20" name="close-circle-fill"
  82. color="red"></u-icon>
  83. </u-col>
  84. </u-row>
  85. </u-col>
  86. </u-row>
  87. <view style="display: flex;position: relative;left: 30%;">
  88. <u-number-box style="margin-left: 15rpx;" v-if="item.itemName" :disabled="item.inc==0"
  89. v-model="item.num"></u-number-box>
  90. <text style="margin-left: 20rpx;color: red;" v-if="item.itemName">
  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-edit')!==-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. computed: {
  153. totalPrice() {
  154. let typeList = this.typeList.filter(obj => obj.itemName);
  155. let price = 0;
  156. for (let i in typeList) {
  157. let type = typeList[i];
  158. price = price + type.price * type.num;
  159. }
  160. return price;
  161. },
  162. },
  163. onLoad(options) {
  164. let id = options.id;
  165. this.form.id = id;
  166. this.customerId = uni.getStorageSync('customerId');
  167. this.goods = JSON.parse(options.goodsJson);
  168. this.getOtherBusinessById();
  169. let that = this;
  170. uni.$on('getCar', car => {
  171. that.$nextTick(() => {
  172. that.handlerCar(car)
  173. })
  174. })
  175. uni.$on('getRemark', type => {
  176. that.$nextTick(() => {
  177. that.handlerRemark(type)
  178. })
  179. })
  180. },
  181. onShow() {
  182. this.perList = uni.getStorageSync('perList')
  183. },
  184. methods: {
  185. remarkFn(type) {
  186. console.log(type)
  187. let remark = type.remark ? type.remark : '';
  188. this.$common.to('/pages/onely-disinfect/add-remark?needRemark=' + type.needRemark + '&typeId=' + type.id +
  189. '&remark=' + remark)
  190. },
  191. handlerRemark(type) {
  192. let typeList = this.typeList;
  193. typeList.filter(obj => type.typeId == obj.id).forEach(obj => obj.remark = type.remark)
  194. },
  195. addCar() {
  196. this.car.list.push({
  197. index: Math.random(),
  198. id: '',
  199. carNo: '',
  200. index: 0
  201. })
  202. },
  203. filterItems(car) {
  204. let carList = this.car.list;
  205. let filterTypeList = JSON.parse(JSON.stringify(this.allTypeList));
  206. if (carList.length == 0) {
  207. this.typeList = filterTypeList;
  208. return;
  209. }
  210. if (!car) {
  211. let checkList = carList.filter(obj => obj.carType.indexOf('空') === -1);
  212. if (checkList.length > 0) {
  213. car = checkList[0];
  214. }
  215. }
  216. let carSize = car.carSize;
  217. let carType = car.carType;
  218. if (carType.indexOf('空') !== -1 && carList.length > 1) {
  219. return;
  220. }
  221. let netWeight = car.netWeight;
  222. let tempList = [];
  223. for (let i in filterTypeList) {
  224. let type = filterTypeList[i];
  225. let items = type.items;
  226. if (carType) {
  227. items = items.filter(item => item.itemType && item.itemType.indexOf(carType) !== -1);
  228. }
  229. if (carSize && carSize > 1) {
  230. items = items.filter(item => item.minLength <= carSize && item.carLength >= carSize);
  231. }
  232. if (netWeight && netWeight > 1 && carType.indexOf('空') == -1) {
  233. items = items.filter(item => item.minWeight <= netWeight && item.maxWeight >= netWeight);
  234. }
  235. let itemIds = items.map(item => item.id);
  236. if (itemIds.indexOf(type.itemId) == -1) {
  237. this.cleanItem(type);
  238. }
  239. type.items = items;
  240. tempList.push(type);
  241. }
  242. this.typeList = tempList;
  243. },
  244. cleanItem(type) {
  245. type.itemId = '';
  246. type.itemName = '';
  247. type.price = '';
  248. },
  249. getOtherBusinessById() {
  250. this.$api.getOtherBusinessById({
  251. id: this.form.id
  252. }).then(resp => {
  253. let data = resp.data;
  254. this.car.list = data.cars;
  255. let items = data.items;
  256. this.form = data;
  257. this.getTypeByGoodsId(items);
  258. this.getCustomerList(data.customerId);
  259. })
  260. },
  261. showSelect(item) {
  262. if (this.validBefore()) {
  263. this.columns = [];
  264. this.columns.push(item.items);
  265. this.show = true;
  266. }
  267. },
  268. confirmFn(e) {
  269. let selects = e.value;
  270. if (selects.length > 0) {
  271. let item = selects[0];
  272. let typeId = item.typeId;
  273. let typeList = this.typeList;
  274. typeList.filter(obj => obj.id == typeId).forEach(obj => {
  275. obj.itemId = item.id;
  276. obj.itemName = item.itemName;
  277. obj.inc = item.inc;
  278. obj.price = item.price;
  279. obj.needRemark = item.needRemark;
  280. })
  281. }
  282. this.show = false;
  283. },
  284. getTypeByGoodsId(items) {
  285. this.$api.getTypeByGoodsId({
  286. goodsId: this.goods.id
  287. }).then(resp => {
  288. let list = resp.data;
  289. for (let i in items) {
  290. let item = items[i];
  291. for (let j in list) {
  292. let type = list[j];
  293. if (type.id == item.itemTypeId) {
  294. type.items.filter(obj => obj.id == item.itemId)
  295. .forEach(obj => {
  296. console.log(obj)
  297. type.num = item.num;
  298. type.price = item.itemPrice;
  299. type.itemName = item.itemName;
  300. type.itemId = item.itemId;
  301. type.inc = obj.inc;
  302. type.remark = item.remark;
  303. })
  304. }
  305. }
  306. }
  307. this.allTypeList = JSON.parse(JSON.stringify(list));
  308. this.typeList = list;
  309. })
  310. },
  311. getCustomerList(customerId) {
  312. this.$api.getCustomerList({
  313. pageNo: 1,
  314. pageSize: 100
  315. }).then(resp => {
  316. let list = resp.data;
  317. console.log(list.map(obj => obj.id).indexOf(customerId))
  318. this.customer.index = list.map(obj => obj.id).indexOf(customerId);
  319. this.customer.customerList = list;
  320. console.log(this.customer)
  321. })
  322. },
  323. customerChange(e) {
  324. var value = e.detail.value; //当前picker选中的值
  325. this.customer.index = value;
  326. },
  327. handlerCar(car) {
  328. let list = this.car.list;
  329. let check = list.filter(obj => obj.carNo == car.carNo).pop();
  330. if (check) {
  331. check.carSize = car.carSize;
  332. check.netWeight = car.netWeight;
  333. check.carType = car.carType;
  334. } else {
  335. this.car.list.push(car);
  336. }
  337. this.clearEmptyCar(car);
  338. },
  339. clearEmptyCar(car) {
  340. let list = this.car.list;
  341. let obj = list.filter(obj => !obj.carNo).pop();
  342. if (obj) {
  343. this.car.list.splice(list.indexOf(obj), 1);
  344. }
  345. this.filterItems(car);
  346. },
  347. editCar(car) {
  348. let goods = this.goods;
  349. this.$common.to('/pages/onely-disinfect/car-manager?carJson=' + JSON.stringify(car) + "&needCarSize=" +
  350. goods.needCarSize + '&needWeight=' + goods.needWeight)
  351. },
  352. delCar(car) {
  353. let list = this.car.list;
  354. if (list.length == 1) {
  355. this.$common.toast('至少有一辆车');
  356. return;
  357. }
  358. this.car.list.splice(list.indexOf(car), 1);
  359. this.filterItems();
  360. },
  361. validBefore() {
  362. let form = this.form;
  363. let goods = this.goods;
  364. let needCustomer = goods.needCustomer;
  365. let index = this.customer.index;
  366. if (!form.businessGoodsName && goods.needOwner == 1) {
  367. this.$common.toast('请填写货物');
  368. return false;
  369. }
  370. let needOperateTime = goods.needOperateTime;
  371. let businessGoodsNum = form.businessGoodsNum;
  372. if ((!businessGoodsNum || businessGoodsNum <= 0) && needOperateTime == '1') {
  373. this.$common.toast('请填写件数');
  374. return false;
  375. }
  376. let carList = this.car.list;
  377. if (carList.length == 0) {
  378. this.$common.toast('请录入车辆');
  379. return false;
  380. }
  381. let needCarSize = goods.needCarSize;
  382. let needWeight = goods.needWeight;
  383. for (let i in carList) {
  384. let car = carList[i];
  385. if (needCarSize == 1 && !car.carSize) {
  386. this.$common.toast('请补充' + car.carNo + '的规格');
  387. return false;
  388. }
  389. if (needWeight == 1 && car.carType.indexOf('重') !== -1 && !car.netWeight) {
  390. this.$common.toast('请补充' + car.carNo + '载重');
  391. return false;
  392. }
  393. }
  394. return true;
  395. },
  396. check() {
  397. let form = this.form;
  398. let goods = this.goods;
  399. let needCustomer = goods.needCustomer;
  400. let index = this.customer.index;
  401. if (!form.businessGoodsName && goods.needOwner == 1) {
  402. this.$common.toast('请填写货物');
  403. return false;
  404. }
  405. let needOperateTime = goods.needOperateTime;
  406. let businessGoodsNum = form.businessGoodsNum;
  407. if ((!businessGoodsNum || businessGoodsNum <= 0) && needOperateTime == '1') {
  408. this.$common.toast('请填写件数');
  409. return false;
  410. }
  411. let carList = this.car.list;
  412. if (carList.length == 0) {
  413. this.$common.toast('请录入车辆');
  414. return false;
  415. }
  416. let needCarSize = goods.needCarSize;
  417. let needWeight = goods.needWeight;
  418. for (let i in carList) {
  419. let car = carList[i];
  420. if (needCarSize == 1 && !car.carSize) {
  421. this.$common.toast('请补充' + car.carNo + '的规格');
  422. return false;
  423. }
  424. if (needWeight == 1 && car.carType && car.carType.indexOf('重') !== -1 && !car.netWeight) {
  425. this.$common.toast('请补充' + car.carNo + '载重');
  426. return false;
  427. }
  428. }
  429. let typeList = this.typeList;
  430. let selectList = [];
  431. for (let i in typeList) {
  432. let type = typeList[i];
  433. if (type.need == 1 && !type.itemId) {
  434. this.$common.toast('【' + type.name + '】必选');
  435. return false;
  436. }
  437. if (type.needRemark == 1 && !type.remark) {
  438. this.$common.toast('请录入【' + type.name + '】备注');
  439. return false;
  440. }
  441. if (type.itemId) {
  442. let obj = {
  443. typeId: type.id,
  444. typeName: type.name,
  445. id: type.itemId,
  446. num: type.num,
  447. price: type.price,
  448. remark: type.remark
  449. }
  450. selectList.push(obj);
  451. }
  452. }
  453. this.form.itemJson = JSON.stringify(selectList);
  454. this.form.carJson = JSON.stringify(this.car.list);
  455. this.form.items = null;
  456. this.form.cars = null;
  457. if (needCustomer == 1) {
  458. let customerList = this.customer.customerList;
  459. let index = this.customer.index;
  460. let customer = customerList[index];
  461. this.form.customerId = customer.id;
  462. this.form.customerName = customer.name;
  463. } else {
  464. this.form.customerId = '';
  465. this.form.customerName = '';
  466. }
  467. this.form.goodsId = this.goods.id;
  468. this.form.goodsName = this.goods.name;
  469. let chinaCarNo = carList
  470. .filter(car => this.$common.isCarNo(car.carNo.toUpperCase()))
  471. .map(car => car.carNo.toUpperCase())
  472. .join("、");
  473. let yueCarNo = carList
  474. .filter(car => !this.$common.isCarNo(car.carNo.toUpperCase()))
  475. .map(car => car.carNo.toUpperCase())
  476. .join("、");
  477. this.form.cardNo = yueCarNo;
  478. this.form.chinaCarNo = chinaCarNo;
  479. return true;
  480. },
  481. saveFn() {
  482. if (this.check()) {
  483. let obj = this.$common.removeNull(this.form);
  484. this.$api.editOtherBusiness(obj).then(resp => {
  485. if (resp.code == 200) {
  486. this.$common.toast('修改成功');
  487. setTimeout(() => {
  488. this.$common.to('/pages/onely-disinfect/Index')
  489. }, 1000)
  490. }
  491. })
  492. }
  493. },
  494. }
  495. }
  496. </script>
  497. <style lang="scss">
  498. page {
  499. background-color: #fff;
  500. }
  501. .hs-item {
  502. text-align: center;
  503. }
  504. .item-line {
  505. color: #a2a2a2;
  506. padding: 5px 0 10px 29px;
  507. border-bottom: 1px solid #E5E5E5;
  508. }
  509. .hj {
  510. padding: 50rpx;
  511. font-size: 40rpx;
  512. color: red;
  513. font-weight: bold;
  514. }
  515. .business-list {
  516. line-height: 75rpx;
  517. margin: 4rpx 0 0 48rpx;
  518. }
  519. .save-btn {
  520. background-color: #ff4200;
  521. height: 88rpx;
  522. display: flex;
  523. justify-content: center;
  524. align-items: center;
  525. margin: 60rpx;
  526. color: #fff;
  527. font-size: 30rpx;
  528. font-weight: bold;
  529. border-radius: 10rpx;
  530. }
  531. @import '@/common/common.scss'
  532. </style>