type-business.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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.needOwner==1">
  18. <view class="l">
  19. <text style="color: red;">*</text>
  20. 货物:
  21. </view>
  22. <view class="r">
  23. <u-input placeholder="输入货物" v-model="form.businessGoodsName">
  24. </u-input>
  25. </view>
  26. </view>
  27. <view class="item">
  28. <view class="l">
  29. <text style="color: red;" v-if="goods.needOperateTime">*</text>
  30. 数量(件):
  31. </view>
  32. <view class="r">
  33. <u-input v-model="form.businessGoodsNum" type="number">
  34. </u-input>
  35. </view>
  36. </view>
  37. <view class="item">
  38. <view class="l">作业人员:</view>
  39. <view class="r">
  40. <u-input placeholder="输入作业人员" v-model="form.operator">
  41. </u-input>
  42. </view>
  43. </view>
  44. <view class="item-line">
  45. <u-row style="height: 40px;">
  46. <u-col span=4>车辆</u-col>
  47. <u-col span=8>
  48. <u-button type="primary" text="添加" @click="addCar" icon="plus" style="width: 60px;height: 26px;"
  49. v-if="goods.mulCar==1||car.list.length==0" />
  50. </u-col>
  51. </u-row>
  52. </view>
  53. <view class="item" v-for="(car,index) in car.list" :key="index">
  54. <view class="l">车牌:</view>
  55. <view class="r">
  56. <u-input placeholder="车辆" v-model="car.carNo" readonly>
  57. <view slot="suffix" style="display: flex;">
  58. <u-icon @click="editCar(car)" size="20" name="edit-pen-fill" color="blue"></u-icon>
  59. <u-icon style="margin-left:20rpx;" size="20" @click="delCar(car)" name="close-circle-fill"
  60. color="red"></u-icon>
  61. </view>
  62. </u-input>
  63. </view>
  64. </view>
  65. <view class="item-line" style="margin-top: 30rpx;">
  66. 业务项
  67. </view>
  68. <view class="business-list" v-for="(item,index) in typeList">
  69. <u-row>
  70. <u-col span="4.5">
  71. <text>
  72. <text style="color: red;display: inline;" v-if="item.need==1">*</text>
  73. {{ 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" v-model="item.num"></u-number-box>
  90. <text style="margin-left: 20rpx;color: red;">
  91. ¥{{ item.num * item.price }}
  92. </text>
  93. <view style="margin-left: 60rpx;" @click="remarkFn(item)">
  94. 备注
  95. </view>
  96. </view>
  97. <u-line></u-line>
  98. </view>
  99. <view class="hj" v-show="totalPrice>0">
  100. 合计:{{ totalPrice }}元
  101. </view>
  102. </view>
  103. <u-button type="primary" text="确定" @click="saveFn" v-show="perList.indexOf('tb-flex-business-add')!==-1">
  104. </u-button>
  105. <!-- ---------------------------------------------------------- -->
  106. <view class="bottom-safety"></view>
  107. <u-picker :show="show" :columns="columns" @confirm="confirmFn" keyName="itemName" @cancel="show=false">
  108. </u-picker>
  109. </view>
  110. </template>
  111. <script>
  112. export default {
  113. data() {
  114. return {
  115. show: false,
  116. columns: [],
  117. customerId: '1',
  118. customer: {
  119. index: 0,
  120. customerList: [],
  121. },
  122. goods: {
  123. id: '',
  124. name: '',
  125. mulCar: 0
  126. },
  127. typeList: [],
  128. allTypeList: [],
  129. form: {
  130. customerId: '',
  131. declareNo: '',
  132. carNo: '',
  133. owner: '',
  134. carSize: '',
  135. goodsName: '',
  136. netWeight: '',
  137. businessGoodsName: '',
  138. businessGoodsNum: 1
  139. },
  140. show: false,
  141. item: {
  142. items: []
  143. },
  144. car: {
  145. list: [{
  146. id: '',
  147. carNo: '',
  148. index: 0
  149. }]
  150. },
  151. perList: []
  152. }
  153. },
  154. onShow() {
  155. this.perList = uni.getStorageSync('perList')
  156. },
  157. computed: {
  158. totalPrice() {
  159. let typeList = this.typeList.filter(obj => obj.itemName);
  160. let price = 0;
  161. for (let i in typeList) {
  162. let type = typeList[i];
  163. price = price + type.price * type.num;
  164. }
  165. return price;
  166. },
  167. },
  168. onLoad(options) {
  169. this.customerId = uni.getStorageSync('customerId');
  170. this.goods = JSON.parse(options.goodsJson);
  171. this.getCustomerList();
  172. this.getTypeByGoodsId();
  173. let that = this;
  174. uni.$on('getCar', car => {
  175. that.$nextTick(() => {
  176. that.handlerCar(car)
  177. })
  178. })
  179. uni.$on('getRemark', type => {
  180. that.$nextTick(() => {
  181. that.handlerRemark(type)
  182. })
  183. })
  184. },
  185. methods: {
  186. remarkFn(type) {
  187. let remark = type.remark ? type.remark : '';
  188. this.$common.to('/pages/onely-disinfect/add-remark?needRemark=' + type.needRemark + '&typeId=' + type.id +
  189. '&remark=' + remark)
  190. },
  191. handlerRemark(type) {
  192. let typeList = this.typeList;
  193. typeList.filter(obj => type.typeId == obj.id).forEach(obj => obj.remark = type.remark)
  194. },
  195. addCar() {
  196. this.car.list.push({
  197. index: Math.random(),
  198. id: '',
  199. carNo: '',
  200. index: 0
  201. })
  202. },
  203. filterItems(car) {
  204. let carList = this.car.list;
  205. let filterTypeList = JSON.parse(JSON.stringify(this.allTypeList));
  206. if (carList.length == 0) {
  207. this.typeList = filterTypeList;
  208. return;
  209. }
  210. if (!car) {
  211. let checkList = carList.filter(obj => obj.carType.indexOf('空') === -1);
  212. if (checkList.length > 0) {
  213. car = checkList[0];
  214. }
  215. }
  216. let carSize = car.carSize;
  217. let carType = car.carType;
  218. if (carType.indexOf('空') !== -1 && carList.length > 1) {
  219. return;
  220. }
  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. showSelect(item) {
  250. if (this.validBefore()) {
  251. this.columns = [];
  252. this.columns.push(item.items);
  253. this.show = true;
  254. }
  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. editCar(car) {
  319. let goods = this.goods;
  320. this.$common.to('/pages/onely-disinfect/car-manager?carJson=' + JSON.stringify(car) + "&needCarSize=" +
  321. goods.needCarSize + '&needWeight=' + goods.needWeight)
  322. },
  323. delCar(car) {
  324. let list = this.car.list;
  325. if (list.length == 1) {
  326. this.$common.toast('至少有一辆车');
  327. return;
  328. }
  329. this.car.list.splice(list.indexOf(car), 1);
  330. this.filterItems();
  331. },
  332. validBefore() {
  333. let form = this.form;
  334. let goods = this.goods;
  335. let needCustomer = goods.needCustomer;
  336. let index = this.customer.index;
  337. if (!form.businessGoodsName && goods.needOwner == 1) {
  338. this.$common.toast('请填写货物');
  339. return false;
  340. }
  341. let needOperateTime = goods.needOperateTime;
  342. let businessGoodsNum = form.businessGoodsNum;
  343. if ((!businessGoodsNum || businessGoodsNum <= 0) && needOperateTime == '1') {
  344. this.$common.toast('请填写件数');
  345. return false;
  346. }
  347. let carList = this.car.list;
  348. if (carList.length == 0) {
  349. this.$common.toast('请录入车辆');
  350. return false;
  351. }
  352. let needCarSize = goods.needCarSize;
  353. let needWeight = goods.needWeight;
  354. for (let i in carList) {
  355. let car = carList[i];
  356. if (needCarSize == 1 && !car.carSize) {
  357. this.$common.toast('请补充' + car.carNo + '的规格');
  358. return false;
  359. }
  360. if (needWeight == 1 && car.carType.indexOf('重') !== -1 && !car.netWeight) {
  361. this.$common.toast('请补充' + car.carNo + '载重');
  362. return false;
  363. }
  364. }
  365. return true;
  366. },
  367. check() {
  368. let form = this.form;
  369. let goods = this.goods;
  370. let needCustomer = goods.needCustomer;
  371. let index = this.customer.index;
  372. if (!form.businessGoodsName && goods.needOwner == 1) {
  373. this.$common.toast('请填写货物');
  374. return false;
  375. }
  376. let needOperateTime = goods.needOperateTime;
  377. let businessGoodsNum = form.businessGoodsNum;
  378. if ((!businessGoodsNum || businessGoodsNum <= 0) && needOperateTime == '1') {
  379. this.$common.toast('请填写件数');
  380. return false;
  381. }
  382. let carList = this.car.list;
  383. if (carList.length == 0) {
  384. this.$common.toast('请录入车辆');
  385. return false;
  386. }
  387. let needCarSize = goods.needCarSize;
  388. let needWeight = goods.needWeight;
  389. for (let i in carList) {
  390. let car = carList[i];
  391. if (needCarSize == 1 && !car.carSize) {
  392. this.$common.toast('请补充' + car.carNo + '的规格');
  393. return false;
  394. }
  395. if (needWeight == 1 && car.carType.indexOf('重') !== -1 && !car.netWeight) {
  396. this.$common.toast('请补充' + car.carNo + '载重');
  397. return false;
  398. }
  399. }
  400. let typeList = this.typeList;
  401. let selectList = [];
  402. for (let i in typeList) {
  403. let type = typeList[i];
  404. if (type.need == 1 && !type.itemId) {
  405. this.$common.toast('【' + type.name + '】必选');
  406. return false;
  407. }
  408. if (type.needRemark == 1 && !type.remark) {
  409. this.$common.toast('请录入【' + type.name + '】备注');
  410. return false;
  411. }
  412. if (type.itemId) {
  413. let obj = {
  414. typeId: type.id,
  415. typeName: type.name,
  416. id: type.itemId,
  417. num: type.num,
  418. price: type.price,
  419. remark: type.remark
  420. }
  421. selectList.push(obj);
  422. }
  423. }
  424. this.form.itemJson = JSON.stringify(selectList);
  425. this.form.carJson = JSON.stringify(this.car.list);
  426. this.form.items = null;
  427. if (needCustomer == 1) {
  428. let customerList = this.customer.customerList;
  429. let index = this.customer.index;
  430. let customer = customerList[index];
  431. this.form.customerId = customer.id;
  432. this.form.customerName = customer.name;
  433. } else {
  434. this.form.customerId = '';
  435. this.form.customerName = '';
  436. }
  437. this.form.goodsId = this.goods.id;
  438. this.form.goodsName = this.goods.name;
  439. let chinaCarNo = carList
  440. .filter(car => this.$common.isCarNo(car.carNo.toUpperCase()))
  441. .map(car => car.carNo.toUpperCase())
  442. .join("、");
  443. let yueCarNo = carList
  444. .filter(car => !this.$common.isCarNo(car.carNo.toUpperCase()))
  445. .map(car => car.carNo.toUpperCase())
  446. .join("、");
  447. this.form.cardNo = yueCarNo;
  448. this.form.chinaCarNo = chinaCarNo;
  449. return true;
  450. },
  451. saveFn() {
  452. if (this.check()) {
  453. let obj = this.$common.removeNull(this.form);
  454. this.$api.addOtherBusiness(obj).then(resp => {
  455. if (resp.code == 200) {
  456. this.$common.toast('录入成功');
  457. setTimeout(() => {
  458. this.$common.to('/pages/onely-disinfect/Index')
  459. }, 1000)
  460. }
  461. })
  462. }
  463. },
  464. }
  465. }
  466. </script>
  467. <style lang="scss">
  468. page {
  469. background-color: #fff;
  470. }
  471. .hs-item {
  472. text-align: center;
  473. }
  474. .item-line {
  475. color: #a2a2a2;
  476. padding: 5px 0 10px 29px;
  477. border-bottom: 1px solid #E5E5E5;
  478. }
  479. .hj {
  480. padding: 50rpx;
  481. font-size: 40rpx;
  482. color: red;
  483. font-weight: bold;
  484. }
  485. .business-list {
  486. line-height: 75rpx;
  487. margin: 4rpx 0 0 48rpx;
  488. }
  489. .save-btn {
  490. background-color: #ff4200;
  491. height: 88rpx;
  492. display: flex;
  493. justify-content: center;
  494. align-items: center;
  495. margin: 60rpx;
  496. color: #fff;
  497. font-size: 30rpx;
  498. font-weight: bold;
  499. border-radius: 10rpx;
  500. }
  501. @import '@/common/common.scss'
  502. </style>