type-business-edit.vue 15 KB

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