delivery.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <template>
  2. <!-- 确认送达 -->
  3. <view>
  4. <u-navbar :title="navTitle" autoBack placeholder @leftClick="leftClick"></u-navbar>
  5. <view class="card_order_details">
  6. <view style="display: flex;align-items: center;margin-bottom: 10rpx;">
  7. <view class="details_title">{{getTitle(navTitle)}} <span class="line_title">*</span></view>
  8. <uni-datetime-picker type="datetime" :start="start" :end="end" v-model="valueTime" />
  9. </view>
  10. <view class="card_search">
  11. <view class="details_title">运单号 <span class="line_title">*</span></view>
  12. <view class="card_input">
  13. <u-input border="surround" v-model="frequencyCoding">
  14. <template slot="suffix">
  15. <u-icon name="scan" size="26" @click="sweep"></u-icon>
  16. </template>
  17. </u-input>
  18. </view>
  19. <view class="deleteCurrent" @click="removeWaybill(frequencyCoding)">
  20. <u-icon class="icon_current" name="backspace" height="10" size="20"></u-icon>
  21. <view class="title_nape">删除</view>
  22. </view>
  23. </view>
  24. <view v-if="selectiveType != 'signfor'">
  25. <view class="card_frequency">
  26. <view class="card_high space_between">
  27. <view class="card_frequency_title">已录入运单号</view>
  28. <view class="card_bottle">已扫<span>{{list.length}}</span></view>
  29. </view>
  30. <view style="width: 100%;" v-if="list.length > 0">
  31. <view class="item_coding" v-for="(item,index) in list" :key="index">
  32. <view class="title_coding">{{item}}</view>
  33. <u-icon name="close-circle-fill" color="#c0c4cc" size="20"
  34. @click="removeWaybill(item)"></u-icon>
  35. </view>
  36. </view>
  37. <view class="card_empty" v-else>
  38. <u-empty mode="list"></u-empty>
  39. </view>
  40. </view>
  41. </view>
  42. <view v-else>
  43. <view class="card_sign_in">
  44. <view class="details_title1">运单签收图片 <span class="line_title">*</span></view>
  45. <view>
  46. <u-upload :fileList="fileList1" name="1" :maxCount="1" @afterRead="afterRead"
  47. @delete="deletePic"></u-upload>
  48. </view>
  49. </view>
  50. <view class="card_sign_in">
  51. <view class="details_title1">随货通行单图片 <span class="line_title">*</span></view>
  52. <view>
  53. <u-upload :fileList="fileList2" name="2" :maxCount="1" @afterRead="afterRead"
  54. @delete="deletePic"></u-upload>
  55. </view>
  56. </view>
  57. <view class="card_sign_in">
  58. <view class="details_title1">冷链交接单图片 <span class="line_title">*</span></view>
  59. <view>
  60. <u-upload :fileList="fileList3" name="3" :maxCount="1" @afterRead="afterRead"
  61. @delete="deletePic"></u-upload>
  62. </view>
  63. </view>
  64. </view>
  65. <view style="width: 100%;height: 120rpx;"></view>
  66. <view class="card_btn">
  67. <u-button style="margin-bottom: 20rpx;" type="primary" :disabled="jurisdiction"
  68. @click="submit">提交</u-button>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. const ENV = require('@/.env.js')
  75. export default {
  76. data() {
  77. return {
  78. frequencyCoding: '',
  79. navTitle: '',
  80. selectiveType: '',
  81. cmpCode: '',
  82. list: [],
  83. orderId: '',
  84. valueTime: this.getDateTime(new Date()),
  85. start: Date.now() - 10 * 24 * 3600000,
  86. end: Date.now() + 10 * 24 * 3600000,
  87. fileList1: [],
  88. fileList2: [],
  89. fileList3: [],
  90. }
  91. },
  92. computed: {
  93. jurisdiction() {
  94. if (this.selectiveType == 'signfor') {
  95. if (this.fileList1.length > 0 && this.fileList2.length > 0 && this.fileList3.length > 0) {
  96. if (this.fileList1[0].message == '成功' && this.fileList2[0].message == '成功' && this.fileList3[0]
  97. .message == '成功') {
  98. return false
  99. } else {
  100. return true
  101. }
  102. } else {
  103. return true
  104. }
  105. }
  106. }
  107. },
  108. onLoad(receive) {
  109. this.navTitle = receive.title
  110. this.selectiveType = receive.id
  111. },
  112. methods: {
  113. leftClick() {
  114. uni.$emit('refresh');
  115. },
  116. submit() {
  117. this.getEntering()
  118. if (this.list.length > 0) {
  119. if (this.valueTime) {
  120. if (this.selectiveType == 'put') {
  121. // 扫码入库
  122. this.scanCodes('/api/waybill/warehouse-in')
  123. } else if (this.selectiveType == 'out') {
  124. // 扫码出库
  125. this.scanCodes('/api/waybill/warehouse-out')
  126. } else if (this.selectiveType == 'truck') {
  127. // 扫码装车
  128. this.scanCodes('/api/waybill/car-in')
  129. } else if (this.selectiveType == 'unload') {
  130. // 扫码下车
  131. this.scanCodes('/api/waybill/car-out')
  132. } else if (this.selectiveType == 'signfor') {
  133. if (this.fileList1.length > 0 && this.fileList2.length > 0 && this.fileList3.length > 0) {
  134. // 扫码签收
  135. this.scanCodesSignFor('/api/waybill/receipt')
  136. } else {
  137. uni.$u.toast('请完善表单')
  138. }
  139. }
  140. } else {
  141. const title = this.getTitle(this.navTitle)
  142. uni.$u.toast('请先选择' + title + '时间')
  143. }
  144. } else {
  145. uni.$u.toast('请先录入运单号')
  146. }
  147. },
  148. getTitle(value) {
  149. const title = value.split('扫码')
  150. const headline = title[1] + '时间'
  151. return headline
  152. },
  153. // 提交扫码列表
  154. scanCodes(url) {
  155. uni.showLoading();
  156. this.$api.post(url, {
  157. startTime: this.valueTime,
  158. waybillNoList: this.list
  159. }).then(res => {
  160. if (res.code == 200) {
  161. this.frequencyCoding = ''
  162. this.list = []
  163. uni.$u.toast(res.msg)
  164. } else {
  165. uni.$u.toast(res.data.msg)
  166. }
  167. uni.hideLoading();
  168. }).catch(() => {
  169. uni.hideLoading();
  170. })
  171. },
  172. // 提交扫码签收列表
  173. scanCodesSignFor(url) {
  174. const signUrl = this.fileList1[0].url + ',' + this.fileList2[0].url + ',' + this.fileList3[0].url
  175. this.$api.post(url, {
  176. startTime: this.valueTime,
  177. waybillNo: this.frequencyCoding,
  178. receiptImg: signUrl,
  179. }).then(res => {
  180. if (res.code == 200) {
  181. this.frequencyCoding = ''
  182. this.fileList1 = []
  183. this.fileList2 = []
  184. this.fileList3 = []
  185. this.list = []
  186. uni.$u.toast(res.msg)
  187. } else {
  188. uni.$u.toast(res.data.msg)
  189. }
  190. })
  191. },
  192. // 扫码录入
  193. getEntering() {
  194. if (this.frequencyCoding) {
  195. this.list.push(this.frequencyCoding)
  196. function methods1(arr) {
  197. return Array.from(new Set(arr));
  198. }
  199. this.list = methods1(this.list)
  200. }
  201. },
  202. // 扫一扫
  203. sweep() {
  204. // 允许从相机和相册扫码
  205. uni.scanCode({
  206. scanType: ['barCode'],
  207. // scanType: ['qrCode'],
  208. autoZoom: false,
  209. success: (res) => {
  210. console.log(res);
  211. if (res.result) {
  212. let url = res.result;
  213. this.frequencyCoding = url
  214. this.list.push(url)
  215. function methods1(arr) {
  216. return Array.from(new Set(arr));
  217. }
  218. this.list = methods1(this.list)
  219. } else {
  220. console.log('请重新扫描');
  221. return false;
  222. }
  223. },
  224. fail: (res) => {
  225. console.log('未识别到二维码');
  226. }
  227. })
  228. },
  229. // 移除错误运单号
  230. removeWaybill(value) {
  231. if (this.frequencyCoding == value) {
  232. this.frequencyCoding = ''
  233. }
  234. const arr = deleteElementById(this.list, value)
  235. this.list = arr
  236. function deleteElementById(arr, key) {
  237. return arr.filter((item) => item !== key);
  238. }
  239. },
  240. // 新增图片
  241. async afterRead(event) {
  242. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  243. let lists = [].concat(event.file)
  244. let fileListLen = this[`fileList${event.name}`].length
  245. lists.map((item) => {
  246. this[`fileList${event.name}`].push({
  247. ...item,
  248. status: 'uploading',
  249. message: '上传中'
  250. })
  251. })
  252. for (let i = 0; i < lists.length; i++) {
  253. const result = await this.uploadFilePromise(lists[i].url)
  254. let item = this[`fileList${event.name}`][fileListLen]
  255. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  256. status: 'success',
  257. message: '成功',
  258. url: result
  259. }))
  260. fileListLen++
  261. }
  262. if (event.name == '1') {
  263. var arr = []
  264. this.fileList1.forEach(item1 => {
  265. arr.push(item1.url)
  266. })
  267. } else if (event.name == '2') {
  268. var arr1 = []
  269. this.fileList2.forEach(item2 => {
  270. arr1.push(item2.url)
  271. })
  272. } else if (event.name == '3') {
  273. var arr2 = []
  274. this.fileList3.forEach(item3 => {
  275. arr2.push(item3.url)
  276. })
  277. }
  278. },
  279. // 删除图片
  280. deletePic(event) {
  281. this[`fileList${event.name}`].splice(event.index, 1)
  282. },
  283. uploadFilePromise(url) {
  284. return new Promise((resolve, reject) => {
  285. let a = uni.uploadFile({
  286. url: ENV.APP_DEV_URL + '/api/upload', // 仅为示例,非真实的接口地址
  287. filePath: url,
  288. name: 'file',
  289. // formData: {
  290. // user: 'test'
  291. // },
  292. header: {
  293. 'Authorization': 'Bearer ' + uni.getStorageSync('access_token'),
  294. },
  295. success: (res) => {
  296. let state = JSON.parse(res.data)
  297. setTimeout(() => {
  298. if (state.code == 200) {
  299. resolve(state.data)
  300. }
  301. })
  302. }
  303. });
  304. })
  305. },
  306. getDateTime(date, addZero = true) {
  307. return `${this.getDate(date, addZero)} ${this.getTime(date, addZero)}`
  308. },
  309. getDate(date, addZero = true) {
  310. date = new Date(date)
  311. const year = date.getFullYear()
  312. const month = date.getMonth() + 1
  313. const day = date.getDate()
  314. return `${year}-${addZero ? this.addZero(month) : month}-${addZero ? this.addZero(day) : day}`
  315. },
  316. getTime(date, addZero = true) {
  317. date = new Date(date)
  318. const hour = date.getHours()
  319. const minute = date.getMinutes()
  320. const second = date.getSeconds()
  321. return this.hideSecond ?
  322. `${addZero ? this.addZero(hour) : hour}:${addZero ? this.addZero(minute) : minute}` :
  323. `${addZero ? this.addZero(hour) : hour}:${addZero ? this.addZero(minute) : minute}:${addZero ? this.addZero(second) : second}`
  324. },
  325. addZero(num) {
  326. if (num < 10) {
  327. num = `0${num}`
  328. }
  329. return num
  330. }
  331. }
  332. }
  333. </script>
  334. <style lang="scss">
  335. page {
  336. background-color: #fff !important;
  337. }
  338. .card_order_details {
  339. margin: 10rpx 30rpx 30rpx 30rpx;
  340. }
  341. .details_title {
  342. flex: none;
  343. color: #333;
  344. font-size: 32rpx;
  345. font-weight: 500;
  346. margin-bottom: 10rpx;
  347. margin-right: 15rpx;
  348. }
  349. .details_title1 {
  350. width: 140rpx;
  351. text-align: center;
  352. flex: none;
  353. color: #333;
  354. font-size: 32rpx;
  355. font-weight: 500;
  356. margin-bottom: 10rpx;
  357. margin-right: 15rpx;
  358. }
  359. .card_time {
  360. width: 100%;
  361. border: 1rpx solid #dadbde;
  362. border-radius: 10rpx;
  363. padding: 6px 9px;
  364. margin-left: 10rpx;
  365. line-height: 48rpx;
  366. }
  367. .card_search {
  368. display: flex;
  369. align-items: center;
  370. margin: 20rpx 0rpx;
  371. }
  372. .card_sign_in {
  373. margin-top: 30rpx;
  374. display: flex;
  375. }
  376. .scan_title {
  377. font-size: 20rpx;
  378. }
  379. .card_sweep {
  380. display: flex;
  381. flex-direction: column;
  382. align-items: center;
  383. flex: none;
  384. }
  385. .card_input {
  386. width: 100%;
  387. margin-left: 30rpx;
  388. }
  389. .line_title {
  390. color: red;
  391. }
  392. .card_high {
  393. margin-top: 30rpx;
  394. }
  395. .card_frequency {
  396. display: flex;
  397. flex-wrap: wrap;
  398. }
  399. .card_frequency_title {
  400. font-size: 32rpx;
  401. }
  402. .card_bottle {
  403. font-size: 30rpx;
  404. span {
  405. color: red;
  406. }
  407. }
  408. .item_coding {
  409. display: flex;
  410. justify-content: space-between;
  411. align-items: center;
  412. width: 100%;
  413. margin-top: 10px;
  414. padding: 25rpx 0rpx;
  415. border-bottom: 2rpx solid #dfdfdf;
  416. }
  417. .title_coding {
  418. font-size: 30rpx;
  419. }
  420. .card_empty {
  421. width: 100%;
  422. margin-top: 50rpx;
  423. display: flex;
  424. align-items: center;
  425. justify-content: center;
  426. }
  427. .card_btn {
  428. position: fixed;
  429. left: 0;
  430. right: 0;
  431. bottom: 0;
  432. padding-left: 30rpx;
  433. padding-right: 30rpx;
  434. padding-top: 20rpx;
  435. background-color: #fff;
  436. padding-bottom: constant(safe-area-inset-bottom); //兼容 IOS<11.2
  437. padding-bottom: env(safe-area-inset-bottom); //兼容 IOS>11.2
  438. }
  439. .deleteCurrent {
  440. display: flex;
  441. align-items: center;
  442. flex-direction: column;
  443. justify-content: center;
  444. border: 1px solid #e5e5e5;
  445. padding: 5rpx 0rpx 5rpx 5rpx;
  446. margin-left: 10rpx;
  447. border-radius: 8rpx;
  448. height: 66rpx;
  449. .icon_current {
  450. height: 15px;
  451. }
  452. .title_nape {
  453. margin: 0rpx 10rpx;
  454. display: flex;
  455. font-size: 20rpx;
  456. width: 40rpx;
  457. }
  458. }
  459. ::v-deep .u-border {
  460. border-width: 1px !important;
  461. border-color: #e5e5e5 !important;
  462. border-style: solid;
  463. }
  464. </style>