type-business.vue 14 KB

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