type-business-edit.vue 14 KB

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