delivery.vue 11 KB

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