type-business.vue 14 KB

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