type-business.vue 14 KB

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