delivery.vue 10 KB

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