type-business.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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.needCustomer==1">
  8. <view class="l">客户:</view>
  9. <view class="r" style="flex: 12;">
  10. <picker v-if="customer.customerList.length>0" class="p-picker"
  11. @change="customerChange($event)" :value="customer.index" :range="customer.customerList"
  12. range-key="name">
  13. <text class="p-text">{{ customer.customerList[customer.index].name }}</text>
  14. </picker>
  15. </view>
  16. </view>
  17. <view class="item" v-if="goods.needPartner==1">
  18. <view class="l">合作伙伴:</view>
  19. <view class="r" style="flex: 12;">
  20. <picker v-if="partner.partnerList.length>0" class="p-picker"
  21. @change="partnerChange($event)" :value="partner.index" :range="partner.partnerList"
  22. range-key="name">
  23. <text class="p-text">{{ partner.partnerList[partner.index].name }}</text>
  24. </picker>
  25. </view>
  26. </view>
  27. <view class="item" v-if="goods.needOwner==1">
  28. <view class="l">
  29. <text style="color: red;">*</text>
  30. 货物:
  31. </view>
  32. <view class="r">
  33. <u-input placeholder="输入货物" v-model="form.businessGoodsName">
  34. </u-input>
  35. </view>
  36. </view>
  37. <view class="item">
  38. <view class="l">
  39. <text style="color: red;" v-if="goods.needOperateTime">*</text>
  40. 数量(件):
  41. </view>
  42. <view class="r">
  43. <u-input v-model="form.businessGoodsNum" type="number">
  44. </u-input>
  45. </view>
  46. </view>
  47. <view class="item">
  48. <view class="l">作业人员:</view>
  49. <view class="r">
  50. <u-input placeholder="输入作业人员" v-model="form.operator">
  51. </u-input>
  52. </view>
  53. </view>
  54. <view class="item-line">
  55. <u-row style="height: 40px;">
  56. <u-col span=4>车辆</u-col>
  57. <u-col span=8>
  58. <u-button type="primary" text="添加" @click="addCar" icon="plus" style="width: 60px;height: 26px;"
  59. v-if="goods.mulCar==1||car.list.length==0" />
  60. </u-col>
  61. </u-row>
  62. </view>
  63. <view class="item" v-for="(car,index) in car.list" :key="index">
  64. <view class="l">车牌:</view>
  65. <view class="r">
  66. <u-input placeholder="车辆" v-model="car.carNo" readonly>
  67. <view slot="suffix" style="display: flex;">
  68. <u-icon @click="editCar(car)" size="20" name="edit-pen-fill" color="blue"></u-icon>
  69. <u-icon style="margin-left:20rpx;" size="20" @click="delCar(car)" name="close-circle-fill"
  70. color="red"></u-icon>
  71. </view>
  72. </u-input>
  73. </view>
  74. </view>
  75. <view class="item-line" style="margin-top: 30rpx;">
  76. 业务项
  77. </view>
  78. <view class="business-list" v-for="(item,index) in typeList">
  79. <u-row>
  80. <u-col span="4.5">
  81. <text>
  82. <text style="color: red;display: inline;" v-if="item.need==1">*</text>
  83. {{ item.name }}:
  84. </text>
  85. </u-col>
  86. <u-col span="7.5">
  87. <u-row>
  88. <u-col span="10" @click="showSelect(item)">
  89. {{ item.itemName ? item.itemName : '请选择' }}
  90. </u-col>
  91. <u-col span="2" @click="item.itemName='',item.itemId=''" v-if="item.itemId">
  92. <u-icon style="margin-left:15rpx;display: inline;" size="20" name="close-circle-fill"
  93. color="red"></u-icon>
  94. </u-col>
  95. </u-row>
  96. </u-col>
  97. </u-row>
  98. <view style="display: flex;position: relative;left: 30%;" v-if="item.itemName">
  99. <u-number-box style="margin-left: 15rpx;" :disabled="item.inc==0" v-model="item.num"></u-number-box>
  100. <text style="margin-left: 20rpx;color: red;">
  101. ¥{{ item.num * item.price }}
  102. </text>
  103. <view style="margin-left: 60rpx;" @click="remarkFn(item)">
  104. 备注
  105. </view>
  106. </view>
  107. <u-line></u-line>
  108. </view>
  109. <view class="hj" v-show="totalPrice>0">
  110. 合计:{{ totalPrice }}元
  111. </view>
  112. </view>
  113. <u-button type="primary" text="确定" @click="saveFn" v-show="perList.indexOf('tb-flex-business-add')!==-1">
  114. </u-button>
  115. <!-- ---------------------------------------------------------- -->
  116. <view class="bottom-safety"></view>
  117. <u-picker :show="show" :columns="columns" @confirm="confirmFn" keyName="itemName" @cancel="show=false">
  118. </u-picker>
  119. </view>
  120. </template>
  121. <script>
  122. export default {
  123. data() {
  124. return {
  125. show: false,
  126. columns: [],
  127. customerId: '1',
  128. customer: {
  129. index: 0,
  130. customerList: [],
  131. },
  132. partner: {
  133. index: 0,
  134. partnerList: [],
  135. },
  136. goods: {
  137. id: '',
  138. name: '',
  139. mulCar: 0
  140. },
  141. typeList: [],
  142. allTypeList: [],
  143. form: {
  144. customerId: '',
  145. declareNo: '',
  146. carNo: '',
  147. owner: '',
  148. carSize: '',
  149. goodsName: '',
  150. netWeight: '',
  151. businessGoodsName: '',
  152. businessGoodsNum: 1
  153. },
  154. show: false,
  155. item: {
  156. items: []
  157. },
  158. car: {
  159. list: [{
  160. id: '',
  161. carNo: '',
  162. index: 0
  163. }]
  164. },
  165. perList: []
  166. }
  167. },
  168. onShow() {
  169. this.perList = uni.getStorageSync('perList')
  170. },
  171. computed: {
  172. totalPrice() {
  173. let typeList = this.typeList.filter(obj => obj.itemName);
  174. let price = 0;
  175. for (let i in typeList) {
  176. let type = typeList[i];
  177. price = price + type.price * type.num;
  178. }
  179. return price;
  180. },
  181. },
  182. onLoad(options) {
  183. this.customerId = uni.getStorageSync('customerId');
  184. this.goods = JSON.parse(options.goodsJson);
  185. this.getCustomerList();
  186. this.getTypeByGoodsId();
  187. let that = this;
  188. uni.$on('getCar', car => {
  189. that.$nextTick(() => {
  190. that.handlerCar(car)
  191. })
  192. })
  193. uni.$on('getRemark', type => {
  194. that.$nextTick(() => {
  195. that.handlerRemark(type)
  196. })
  197. })
  198. },
  199. methods: {
  200. remarkFn(type) {
  201. let remark = type.remark ? type.remark : '';
  202. this.$common.to('/pages/onely-disinfect/add-remark?needRemark=' + type.needRemark + '&typeId=' + type.id +
  203. '&remark=' + remark)
  204. },
  205. handlerRemark(type) {
  206. let typeList = this.typeList;
  207. typeList.filter(obj => type.typeId == obj.id).forEach(obj => obj.remark = type.remark)
  208. },
  209. addCar() {
  210. this.car.list.push({
  211. index: Math.random(),
  212. id: '',
  213. carNo: '',
  214. index: 0
  215. })
  216. },
  217. filterItems(car) {
  218. let carList = this.car.list;
  219. let filterTypeList = JSON.parse(JSON.stringify(this.allTypeList));
  220. if (carList.length == 0) {
  221. this.typeList = filterTypeList;
  222. return;
  223. }
  224. if (!car) {
  225. let checkList = carList.filter(obj => obj.carType.indexOf('空') === -1);
  226. if (checkList.length > 0) {
  227. car = checkList[0];
  228. }
  229. }
  230. let carSize = car.carSize;
  231. let carType = car.carType;
  232. if (carType.indexOf('空') !== -1 && carList.length > 1) {
  233. return;
  234. }
  235. let netWeight = car.netWeight;
  236. let tempList = [];
  237. for (let i in filterTypeList) {
  238. let type = filterTypeList[i];
  239. let items = type.items;
  240. if (carType) {
  241. items = items.filter(item => item.itemType && item.itemType.indexOf(carType) !== -1);
  242. }
  243. if (carSize && carSize > 1) {
  244. items = items.filter(item => item.minLength <= carSize && item.carLength >= carSize);
  245. }
  246. if (netWeight && netWeight > 1 && carType.indexOf('空') == -1) {
  247. items = items.filter(item => item.minWeight <= netWeight && item.maxWeight >= netWeight);
  248. }
  249. let itemIds = items.map(item => item.id);
  250. if (itemIds.indexOf(type.itemId) == -1) {
  251. this.cleanItem(type);
  252. }
  253. type.items = items;
  254. tempList.push(type);
  255. }
  256. this.typeList = tempList;
  257. },
  258. cleanItem(type) {
  259. type.itemId = '';
  260. type.itemName = '';
  261. type.price = '';
  262. },
  263. showSelect(item) {
  264. if (this.validBefore()) {
  265. this.columns = [];
  266. this.columns.push(item.items);
  267. this.show = true;
  268. }
  269. },
  270. confirmFn(e) {
  271. let selects = e.value;
  272. if (selects.length > 0) {
  273. let item = selects[0];
  274. let typeId = item.typeId;
  275. let typeList = this.typeList;
  276. typeList.filter(obj => obj.id == typeId).forEach(obj => {
  277. obj.itemId = item.id;
  278. obj.itemName = item.itemName;
  279. obj.inc = item.inc;
  280. obj.price = item.price;
  281. obj.needRemark = item.needRemark;
  282. })
  283. }
  284. this.show = false;
  285. },
  286. getTypeByGoodsId() {
  287. this.$api.getTypeByGoodsId({
  288. goodsId: this.goods.id
  289. }).then(resp => {
  290. let list = resp.data;
  291. this.allTypeList = JSON.parse(JSON.stringify(list));
  292. this.typeList = list;
  293. })
  294. },
  295. getCustomerList() {
  296. this.$api.getCustomerList({
  297. pageNo: 1,
  298. pageSize: 100
  299. }).then(resp => {
  300. let list = resp.data;
  301. let customerId = this.customerId;
  302. if (customerId !== '1') {
  303. this.customer.index = list.map(obj => obj.id).indexOf(customerId);
  304. }
  305. this.customer.customerList = list;
  306. this.partner.partnerList = list.filter(obj=>obj.type!=0);
  307. })
  308. },
  309. customerChange(e) {
  310. var value = e.detail.value; //当前picker选中的值
  311. this.customer.index = value;
  312. },
  313. partnerChange(e) {
  314. var value = e.detail.value; //当前picker选中的值
  315. this.partner.index = value;
  316. },
  317. handlerCar(car) {
  318. let list = this.car.list;
  319. let check = list.filter(obj => obj.carNo == car.carNo).pop();
  320. if (check) {
  321. check.carSize = car.carSize;
  322. check.netWeight = car.netWeight;
  323. check.carType = car.carType;
  324. } else {
  325. this.car.list.push(car);
  326. }
  327. this.clearEmptyCar(car);
  328. },
  329. clearEmptyCar(car) {
  330. let list = this.car.list;
  331. let obj = list.filter(obj => !obj.carNo).pop();
  332. if (obj) {
  333. this.car.list.splice(list.indexOf(obj), 1);
  334. }
  335. this.filterItems(car);
  336. },
  337. editCar(car) {
  338. let goods = this.goods;
  339. this.$common.to('/pages/onely-disinfect/car-manager?carJson=' + JSON.stringify(car) + "&needCarSize=" +
  340. goods.needCarSize + '&needWeight=' + goods.needWeight)
  341. },
  342. delCar(car) {
  343. let list = this.car.list;
  344. if (list.length == 1) {
  345. this.$common.toast('至少有一辆车');
  346. return;
  347. }
  348. this.car.list.splice(list.indexOf(car), 1);
  349. this.filterItems();
  350. },
  351. validBefore() {
  352. let form = this.form;
  353. let goods = this.goods;
  354. let needCustomer = goods.needCustomer;
  355. let index = this.customer.index;
  356. if (!form.businessGoodsName && goods.needOwner == 1) {
  357. this.$common.toast('请填写货物');
  358. return false;
  359. }
  360. let needOperateTime = goods.needOperateTime;
  361. let businessGoodsNum = form.businessGoodsNum;
  362. if ((!businessGoodsNum || businessGoodsNum <= 0) && needOperateTime == '1') {
  363. this.$common.toast('请填写件数');
  364. return false;
  365. }
  366. let carList = this.car.list;
  367. if (carList.length == 0) {
  368. this.$common.toast('请录入车辆');
  369. return false;
  370. }
  371. let needCarSize = goods.needCarSize;
  372. let needWeight = goods.needWeight;
  373. for (let i in carList) {
  374. let car = carList[i];
  375. if (needCarSize == 1 && !car.carSize) {
  376. this.$common.toast('请补充' + car.carNo + '的规格');
  377. return false;
  378. }
  379. if (needWeight == 1 && car.carType.indexOf('重') !== -1 && !car.netWeight) {
  380. this.$common.toast('请补充' + car.carNo + '载重');
  381. return false;
  382. }
  383. }
  384. return true;
  385. },
  386. check() {
  387. let form = this.form;
  388. let goods = this.goods;
  389. let needCustomer = goods.needCustomer;
  390. let index = this.customer.index;
  391. if (!form.businessGoodsName && goods.needOwner == 1) {
  392. this.$common.toast('请填写货物');
  393. return false;
  394. }
  395. let needOperateTime = goods.needOperateTime;
  396. let businessGoodsNum = form.businessGoodsNum;
  397. if ((!businessGoodsNum || businessGoodsNum <= 0) && needOperateTime == '1') {
  398. this.$common.toast('请填写件数');
  399. return false;
  400. }
  401. let carList = this.car.list;
  402. if (carList.length == 0) {
  403. this.$common.toast('请录入车辆');
  404. return false;
  405. }
  406. let needCarSize = goods.needCarSize;
  407. let needWeight = goods.needWeight;
  408. for (let i in carList) {
  409. let car = carList[i];
  410. if (needCarSize == 1 && !car.carSize) {
  411. this.$common.toast('请补充' + car.carNo + '的规格');
  412. return false;
  413. }
  414. if (needWeight == 1 && car.carType.indexOf('重') !== -1 && !car.netWeight) {
  415. this.$common.toast('请补充' + car.carNo + '载重');
  416. return false;
  417. }
  418. }
  419. let typeList = this.typeList;
  420. let selectList = [];
  421. for (let i in typeList) {
  422. let type = typeList[i];
  423. if (type.need == 1 && !type.itemId) {
  424. this.$common.toast('【' + type.name + '】必选');
  425. return false;
  426. }
  427. if (type.needRemark == 1 && !type.remark) {
  428. this.$common.toast('请录入【' + type.name + '】备注');
  429. return false;
  430. }
  431. if (type.itemId) {
  432. let obj = {
  433. typeId: type.id,
  434. typeName: type.name,
  435. id: type.itemId,
  436. num: type.num,
  437. price: type.price,
  438. remark: type.remark
  439. }
  440. selectList.push(obj);
  441. }
  442. }
  443. this.form.itemJson = JSON.stringify(selectList);
  444. this.form.carJson = JSON.stringify(this.car.list);
  445. this.form.items = null;
  446. if (needCustomer == 1) {
  447. let customerList = this.customer.customerList;
  448. let index = this.customer.index;
  449. let customer = customerList[index];
  450. this.form.customerId = customer.id;
  451. this.form.customerName = customer.name;
  452. } else {
  453. this.form.customerId = '';
  454. this.form.customerName = '';
  455. }
  456. let needPartner = goods.needPartner;
  457. if (needPartner == 1) {
  458. let partnerList = this.partner.partnerList;
  459. let index = this.partner.index;
  460. let partner = partnerList[index];
  461. this.form.pickCustomerId = partner.id;
  462. this.form.pickCustomerName = partner.name;
  463. } else {
  464. this.form.pickCustomerId = '';
  465. this.form.pickCustomerName = '';
  466. }
  467. this.form.goodsId = this.goods.id;
  468. this.form.goodsName = this.goods.name;
  469. let chinaCarNo = carList
  470. .filter(car => this.$common.isCarNo(car.carNo.toUpperCase()))
  471. .map(car => car.carNo.toUpperCase())
  472. .join("、");
  473. let yueCarNo = carList
  474. .filter(car => !this.$common.isCarNo(car.carNo.toUpperCase()))
  475. .map(car => car.carNo.toUpperCase())
  476. .join("、");
  477. this.form.cardNo = yueCarNo;
  478. this.form.chinaCarNo = chinaCarNo;
  479. return true;
  480. },
  481. saveFn() {
  482. if (this.check()) {
  483. let obj = this.$common.removeNull(this.form);
  484. this.$api.addOtherBusiness(obj).then(resp => {
  485. if (resp.code == 200) {
  486. this.$common.toast('录入成功');
  487. setTimeout(() => {
  488. this.$common.to('/pages/onely-disinfect/Index')
  489. }, 1000)
  490. }
  491. })
  492. }
  493. },
  494. }
  495. }
  496. </script>
  497. <style lang="scss">
  498. page {
  499. background-color: #fff;
  500. }
  501. .hs-item {
  502. text-align: center;
  503. }
  504. .item-line {
  505. color: #a2a2a2;
  506. padding: 5px 0 10px 29px;
  507. border-bottom: 1px solid #E5E5E5;
  508. }
  509. .hj {
  510. padding: 50rpx;
  511. font-size: 40rpx;
  512. color: red;
  513. font-weight: bold;
  514. }
  515. .business-list {
  516. line-height: 75rpx;
  517. margin: 4rpx 0 0 48rpx;
  518. }
  519. .save-btn {
  520. background-color: #ff4200;
  521. height: 88rpx;
  522. display: flex;
  523. justify-content: center;
  524. align-items: center;
  525. margin: 60rpx;
  526. color: #fff;
  527. font-size: 30rpx;
  528. font-weight: bold;
  529. border-radius: 10rpx;
  530. }
  531. @import '@/common/common.scss'
  532. </style>