type-business-edit.vue 14 KB

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