type-business-edit.vue 15 KB

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