send-code.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <view class="code">
  3. <view class="info_box">
  4. <view class="user flexS" v-if="userInfo">
  5. <text>客户:</text>
  6. <view>{{userInfo.nickname|getName(15)||''}}</view>
  7. <view v-if="userInfo.phone!=userInfo.nickname">{{userInfo.phone||''}}</view>
  8. </view>
  9. <view class="info flexS" style="border-top:2rpx solid #eee;">
  10. <view class="top_left">
  11. <text>款式</text>
  12. <text>状态</text>
  13. </view>
  14. <view>纯棉版</view>
  15. <view>精装版</view>
  16. <view>老人版</view>
  17. <view>简约版</view>
  18. <view>总计</view>
  19. </view>
  20. <view class="info order_num flexS">
  21. <view style="line-height: 7vh;">应发货</view>
  22. <view>{{cottonNum}}</view>
  23. <view>{{hardNum}}</view>
  24. <view>{{oldNum}}</view>
  25. <view>{{simpleNum}}</view>
  26. <view>{{orderTotal}}</view>
  27. </view>
  28. <view class="info num flexS">
  29. <view style="line-height: 7vh;">已扫码</view>
  30. <view>{{cotton}}</view>
  31. <view>{{hard}}</view>
  32. <view>{{old}}</view>
  33. <view>{{simple}}</view>
  34. <view>{{total}}</view>
  35. </view>
  36. </view>
  37. <view class="scroll">
  38. <scroll-view scroll-y="true">
  39. <view class="code_box">
  40. <view class="code_info flexB" v-for="(item,idx) in codeList" :key="idx">
  41. <text>{{item.security_code}}</text>
  42. <text>{{item.good_select_id|getGoods}}</text>
  43. <view class="search_btn" @click="delCode(item.id,idx)">删除</view>
  44. </view>
  45. </view>
  46. </scroll-view>
  47. </view>
  48. <view class="fixed_box flexB">
  49. <view @click="cancel">重新扫描</view>
  50. <view class="scan_code flexC" @click="scanCode()">扫描</view>
  51. <view @click="submit">确认发货</view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import {
  57. getUser,
  58. scanCodeInfo,
  59. submitCodeInfo,
  60. orderQuery,
  61. delScancode
  62. } from '../../../apis/shop.js'
  63. export default {
  64. data() {
  65. return {
  66. codeList: [], //防伪码
  67. userInfo: '', // 用户信息
  68. cotton: 0, //纯棉老人版
  69. hard: 0, //精装
  70. old: 0, //老人
  71. simple: 0, //简约
  72. // total: 0, //防伪码数量
  73. order_no: '', //订单编号
  74. user_id: '', //用户id
  75. orderTotal: 0, //订单里的商品数量
  76. isPoint: true, //是否可以点击
  77. goods: '', //订商品详情
  78. cottonNum: 0,
  79. hardNum: 0,
  80. oldNum: 0,
  81. simpleNum: 0,
  82. goods_id: [],
  83. ids: [] //重新扫描时需要删除的id合集
  84. }
  85. },
  86. onLoad(ops) {
  87. this.getOrder(ops.order_no);
  88. this.order_no = ops.order_no;
  89. },
  90. computed: {
  91. total() {
  92. return this.cotton + this.hard + this.old + this.simple || 0
  93. }
  94. },
  95. filters: {
  96. getGoods(id) {
  97. switch (id) {
  98. case 1:
  99. return '精装版'
  100. break;
  101. case 2:
  102. return '简约版'
  103. break;
  104. case 3:
  105. return '老人版'
  106. break;
  107. case 4:
  108. return '纯棉老人版'
  109. break;
  110. default:
  111. break;
  112. }
  113. },
  114. },
  115. methods: {
  116. //总件数
  117. totalNum(data) {
  118. let total = 0
  119. for (let k in data) {
  120. total += data[k].sku.reduce((t, e) => t + Number(e.num), 0)
  121. }
  122. return total;
  123. },
  124. /*获取订单详情*/
  125. getOrder(order_no) {
  126. orderQuery({
  127. order_no
  128. })
  129. .then(res => {
  130. if (res.code == 200) {
  131. let list = res.data;
  132. const {
  133. code,
  134. goods
  135. } = res.data;
  136. code.map(j => {
  137. this.codeList.push({
  138. good_select_id: j.good_select_id,
  139. code: j.code,
  140. security_code: j.security_code,
  141. id: j.id,
  142. })
  143. this.ids.push(j.id)
  144. this.changeNum(j.good_select_id, true)
  145. })
  146. goods.map(i => {
  147. let num = i.sku.reduce((t, e) => t + Number(e.num), 0);
  148. if (i.id == 1) {
  149. this.hardNum = num
  150. }
  151. if (i.id == 2) {
  152. this.simpleNum = num
  153. }
  154. if (i.id == 3) {
  155. this.oldNum = num
  156. }
  157. if (i.id == 4) {
  158. this.cottonNum = num
  159. }
  160. this.goods_id.push(i.id);
  161. })
  162. this.userInfo = res.data.user;
  163. this.orderTotal = this.totalNum(goods)
  164. } else {
  165. uni.showModal({
  166. content: res.data || '获取订单详情失败',
  167. showCancel: false
  168. });
  169. }
  170. })
  171. .catch(err => {});
  172. },
  173. //扫码发货
  174. submit() {
  175. let code = [];
  176. this.codeList.map(i => {
  177. if (!i.id) {
  178. code.push(i.code)
  179. }
  180. })
  181. if (this.codeList.length != this.orderTotal) {
  182. uni.showModal({
  183. content: '发货防伪码数量与订单套数不一致',
  184. showCancel: false
  185. })
  186. return false;
  187. };
  188. if (code.length == 0) {
  189. uni.redirectTo({
  190. url: '../delivery-method/delivery-method?user_id=' +
  191. this.userInfo.id + '&order_no=' + this
  192. .order_no
  193. })
  194. return false
  195. }
  196. uni.showLoading({
  197. title: '提交中...',
  198. mask: true
  199. })
  200. submitCodeInfo({
  201. code,
  202. order_no: this.order_no
  203. }).then(res => {
  204. if (res.code == 200) {
  205. uni.showModal({
  206. content: '发货防伪码提交成功',
  207. showCancel: false,
  208. success: res => {
  209. if (res.confirm) {
  210. uni.redirectTo({
  211. url: '../delivery-method/delivery-method?user_id=' +
  212. this.userInfo.id + '&order_no=' + this
  213. .order_no
  214. })
  215. }
  216. }
  217. })
  218. } else {
  219. uni.showModal({
  220. content: res.data || '提交失败',
  221. showCancel: false
  222. })
  223. }
  224. uni.hideLoading()
  225. }).catch(err => {
  226. uni.hideLoading()
  227. })
  228. },
  229. changeNum(id, type) {
  230. switch (id) {
  231. case 1:
  232. type ? this.hard++ : this.hard--
  233. return '精装版'
  234. break;
  235. case 2:
  236. type ? this.simple++ : this.simple--
  237. return '简约版'
  238. break;
  239. case 3:
  240. type ? this.old++ : this.old--
  241. return '老人版'
  242. break;
  243. case 4:
  244. type ? this.cotton++ : this.cotton--
  245. return '纯棉老人版'
  246. break;
  247. default:
  248. break;
  249. }
  250. },
  251. //重新扫描
  252. cancel() {
  253. uni.showModal({
  254. content: '确定要重新扫描吗,重新扫描将清除所有数据',
  255. success: res => {
  256. if (res.confirm) {
  257. if (this.ids.length == 0) {
  258. this.codeList = [];
  259. this.cotton = this.hard = this.old = this.simple = 0;
  260. return false
  261. }
  262. delScancode({
  263. ids: this.ids
  264. }).then(res => {
  265. if (res.code == 200) {
  266. uni.showToast({
  267. title: '删除成功'
  268. })
  269. this.ids = [];
  270. this.codeList = [];
  271. this.cotton = this.hard = this.old = this.simple = 0;
  272. } else {
  273. uni.showModal({
  274. content: res.data || '删除失败',
  275. showCancel: false
  276. })
  277. }
  278. })
  279. }
  280. }
  281. })
  282. },
  283. //删除
  284. delCode(id, idx) {
  285. uni.showModal({
  286. content: '确定要删除当前数据吗?',
  287. success: res => {
  288. if (res.confirm) {
  289. if (id) { //删除已提交的code码
  290. this.delOrderCode(id, idx);
  291. return false;
  292. }
  293. this.changeNum(this.codeList[idx].good_select_id, false)
  294. this.codeList.splice(idx, 1)
  295. uni.showToast({
  296. title: '删除成功'
  297. })
  298. }
  299. }
  300. })
  301. },
  302. //删除订单列表中的code
  303. delOrderCode(id, idx) {
  304. let ids = [id]
  305. delScancode({
  306. ids
  307. }).then(res => {
  308. if (res.code == 200) {
  309. uni.showToast({
  310. title: '删除成功'
  311. })
  312. //删除数组中的id
  313. let index = this.ids.indexOf(id)
  314. if (index > -1) {
  315. this.ids.splice(index, 1);
  316. }
  317. this.changeNum(this.codeList[idx].good_select_id, false)
  318. this.codeList.splice(idx, 1)
  319. } else {
  320. uni.showModal({
  321. content: res.data || '删除失败',
  322. showCancel: false
  323. })
  324. }
  325. })
  326. },
  327. //直接扫码发货
  328. scanCode() {
  329. let list = [];
  330. this.codeList.map(i => {
  331. list.push(i.code)
  332. })
  333. uni.scanCode({
  334. success: res => {
  335. var idx = res.result.lastIndexOf("\?"); //idx等于-1代表扫的是新码
  336. var index = idx === -1 ? res.result.lastIndexOf("\/") : res.result;
  337. let codeNum = res.result.substring(index + 1, res.result.length);
  338. if (list.indexOf(codeNum) === -1) {
  339. uni.showLoading({
  340. title: '识别中...'
  341. })
  342. scanCodeInfo({
  343. code: codeNum
  344. }).then(res => {
  345. if (res.code == 200) {
  346. if (this.goods_id.indexOf(res.data.good_select_id) === -1) {
  347. uni.showModal({
  348. content: '订单不存在此规格',
  349. showCancel: false
  350. })
  351. return false;
  352. }
  353. this.changeNum(res.data.good_select_id, true)
  354. if (this.hard > this.hardNum || this.cotton > this.cottonNum ||
  355. this.simple > this.simpleNum || this
  356. .old > this.oldNum) {
  357. uni.showModal({
  358. content: '超出此规格数量',
  359. showCancel: false,
  360. })
  361. this.changeNum(res.data.good_select_id, false)
  362. return false;
  363. }
  364. this.codeList.push({
  365. good_select_id: res.data.good_select_id,
  366. code: res.data.code,
  367. security_code: res.data.security_code,
  368. id: '',
  369. })
  370. } else {
  371. uni.showModal({
  372. content: res.data || '扫码失败,请重试',
  373. showCancel: false
  374. })
  375. }
  376. uni.hideLoading()
  377. }).catch(err => {
  378. uni.hideLoading()
  379. })
  380. } else {
  381. uni.showModal({
  382. content: '防伪码已存在',
  383. showCancel: false
  384. })
  385. }
  386. },
  387. fail: err => {
  388. uni.showModal({
  389. content: '扫码失败',
  390. showCancel: false
  391. })
  392. }
  393. });
  394. },
  395. }
  396. }
  397. </script>
  398. <style lang="scss" scoped>
  399. .code {
  400. width: 100%;
  401. height: 100vh;
  402. position: relative;
  403. .info_box {
  404. width: 100%;
  405. height: 28vh;
  406. .top_left {
  407. position: relative;
  408. text {
  409. position: absolute;
  410. }
  411. text:first-child {
  412. top: 2rpx;
  413. right: 7rpx;
  414. }
  415. text:last-child {
  416. bottom: 2rpx;
  417. left: 7rpx;
  418. }
  419. &::after {
  420. display: block;
  421. content: '';
  422. width: 147rpx;
  423. height: 2rpx;
  424. background: #eee;
  425. transform: rotate(34deg);
  426. position: absolute;
  427. top: 43rpx;
  428. left: -12rpx;
  429. }
  430. }
  431. .info,
  432. .user {
  433. width: 100%;
  434. height: 7vh;
  435. view,
  436. text {
  437. font-size: 28rpx;
  438. font-weight: bold;
  439. }
  440. }
  441. .info {
  442. >view {
  443. width: 20%;
  444. text-align: center;
  445. height: 7vh;
  446. border-right: 2rpx solid #EEEEEE;
  447. }
  448. >view:not(:first-child) {
  449. line-height: 7vh;
  450. }
  451. }
  452. .user {
  453. padding-left: 30rpx;
  454. box-sizing: border-box;
  455. }
  456. .num {
  457. background: #FFF4F3;
  458. view {
  459. color: $base-color;
  460. }
  461. }
  462. .order_num {
  463. background: #f8f8f8;
  464. view {
  465. color: #333;
  466. }
  467. }
  468. }
  469. .scroll {
  470. width: 100%;
  471. height: 68vh;
  472. scroll-view {
  473. width: 100%;
  474. height: 100%;
  475. }
  476. .code_box {
  477. padding-bottom: 140rpx;
  478. width: 100%;
  479. .code_info {
  480. width: 100%;
  481. padding: 0 24rpx;
  482. box-sizing: border-box;
  483. height: 104rpx;
  484. text {
  485. width: 33.33%;
  486. text-align: left;
  487. font-size: 32rpx;
  488. }
  489. }
  490. .code_info:nth-child(2n) {
  491. background: #F8F8F8;
  492. }
  493. }
  494. }
  495. }
  496. .fixed_box {
  497. width: 100%;
  498. height: 100rpx;
  499. background: #fff;
  500. position: fixed;
  501. box-shadow: 0px -4rpx 24rpx rgba(0, 0, 0, 0.1);
  502. bottom: 0;
  503. left: 0;
  504. padding: 0 50rpx;
  505. box-sizing: border-box;
  506. view {
  507. font-size: 32rpx;
  508. color: $base-color;
  509. font-weight: bold;
  510. }
  511. .scan_code {
  512. width: 172rpx;
  513. height: 172rpx;
  514. background: $base-line-bg;
  515. box-shadow: 0px 6rpx 20rpx rgba(254, 34, 0, 0.43);
  516. font-size: 40rpx;
  517. border-radius: 50%;
  518. color: #fff;
  519. margin-top: -108rpx;
  520. letter-spacing: 5rpx;
  521. }
  522. }
  523. </style>