type-business.vue 14 KB

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