test.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. <template>
  2. <view>
  3. <view class="demo" style="height: 180rpx;">
  4. <view class="detailMiddle">
  5. <text>精装版</text>
  6. <text>简约版</text>
  7. <text>老人版</text>
  8. <text>纯棉版</text>
  9. <text>总计</text>
  10. </view>
  11. <view class="detailMiddleRed">
  12. <text v-for="(item,index) in numList" :key="index">{{ item }}</text>
  13. <text>{{ allNum }}</text>
  14. </view>
  15. </view>
  16. <!-- <view @click="getScan">
  17. 点击添加
  18. </view>
  19. <view @click="setC">
  20. 点击校验
  21. </view> -->
  22. <scroll-view :style="{height: scroll_height}" class="listBox" scroll-y="true">
  23. <view
  24. class="listBox_item"
  25. :class="(index + 1)%2 == 0 ? 'back' : ''"
  26. v-for="(item,index) in list"
  27. :key="index"
  28. >
  29. <view style="display: flex;align-items: center;">
  30. <view class="gray">
  31. {{ list.length - index }}
  32. </view>
  33. <view class="left">
  34. {{ item.style }}
  35. </view>
  36. </view>
  37. <view class="right" @click="del(item.style,index)">
  38. 删除
  39. </view>
  40. </view>
  41. </scroll-view>
  42. <view class="fiexedEnd">
  43. <view class="fiexedEnd_title" @click="allDel">
  44. 全部清除
  45. </view>
  46. <view class="fiexedEnd_red" @click="fillOut = true">
  47. 扫描
  48. </view>
  49. <view class="fiexedEnd_title" @click="sendSure">
  50. 确认发货
  51. </view>
  52. </view>
  53. <u-mask :show="fillOut">
  54. <view class="showTip">
  55. <image src="../../static/fangwei/show.png"></image>
  56. <view class="title">
  57. 温馨提示
  58. </view>
  59. <view class="remark">
  60. 是否确保这一件里的所有货没有调换过
  61. </view>
  62. <view class="btn">
  63. <view class="btn_left" @click="fillOut = false">
  64. 不确保
  65. </view>
  66. <view class="btn_right" @click="getCode">
  67. 确保
  68. </view>
  69. </view>
  70. </view>
  71. </u-mask>
  72. <u-mask :show="ifShow">
  73. <view class="showTip">
  74. <image src="../../static/fangwei/show.png"></image>
  75. <view class="title">
  76. 提示
  77. </view>
  78. <view class="remark">
  79. 添加成功!
  80. </view>
  81. <view class="btn">
  82. <view class="btn_left" @click="ifShow = false,clearTime()">
  83. 取消
  84. </view>
  85. <view class="btn_right" @click="getCode">
  86. 扫下一个({{ count }}s)
  87. </view>
  88. </view>
  89. </view>
  90. </u-mask>
  91. <u-modal v-model="show" :show-cancel-button="true" :content="content" @confirm="confirm"></u-modal>
  92. <u-toast ref="uToast" />
  93. </view>
  94. </template>
  95. <script>
  96. import { scanCode, UserSend, AllSendGood } from '../../apis/fangwei.js'
  97. export default {
  98. data() {
  99. return {
  100. show: false,
  101. fillOut: false,
  102. delShow: false,
  103. ifShow: false,
  104. content: '',
  105. count: 3,
  106. list: [],
  107. id: '',
  108. scroll_height: 0,
  109. numList: [0,0,0,0],
  110. info: {},
  111. code: '',
  112. allNum: 0,
  113. param: {}
  114. }
  115. },
  116. // 获取可滑动区域的高度
  117. onReady: function(res) {
  118. var _this = this;
  119. uni.getSystemInfo({
  120. success: (resu) => {
  121. const query = uni.createSelectorQuery()
  122. query.select('.listBox').boundingClientRect()
  123. query.exec(function(res) {
  124. _this.scroll_height = resu.windowHeight - res[0].top + 'px';
  125. })
  126. },
  127. fail: (res) => {}
  128. })
  129. },
  130. onLoad:function(option){
  131. this.id = option.id
  132. },
  133. methods: {
  134. setC() {
  135. this.count = 3
  136. this.ifShow = true
  137. this.setTime()
  138. let index = this.list.findIndex( item => item.code == '44444')
  139. if(index != -1) {
  140. console.log('存在')
  141. } else {
  142. console.log('不存在')
  143. }
  144. },
  145. // 测试扫描
  146. getScan() {
  147. var good = 4
  148. var style = this.getStyle(good)
  149. const data = {
  150. style: this.getStyle(good),
  151. styleId: 4,
  152. code: 44444
  153. }
  154. this.URLencode(data)
  155. console.log(data)
  156. this.list.unshift(data)
  157. console.log(this.list)
  158. this.addStyle(good)
  159. },
  160. setTime() {
  161. //设置定时器
  162. this.clearTimeSet = setInterval(() => {
  163. this.count--;
  164. if (this.count == 0) {
  165. this.ifShow = false
  166. this.clearTime()
  167. this.getCode()
  168. }
  169. }, 1000);
  170. },
  171. clearTime() {
  172. console.log('清除')
  173. //清除定时器
  174. clearInterval(this.clearTimeSet);
  175. },
  176. // 确认发货
  177. sendGood() {
  178. const data = {
  179. 1:[],
  180. 2:[],
  181. 3:[],
  182. 4:[]
  183. }
  184. this.list.forEach((item,index,arr) => {
  185. data[item.styleId].push(item.code)
  186. })
  187. AllSendGood({ id: this.id, code: data }).then(res => {
  188. if(res.code == 200) {
  189. uni.showToast({
  190. title: '发货成功',
  191. icon: 'none'
  192. })
  193. this.list = []
  194. this.numList = [0,0,0,0]
  195. this.allNum = 0
  196. } else {
  197. uni.showModal({
  198. title: '错误提示',
  199. content: res.message || '发货失败',
  200. showCancel: false
  201. })
  202. }
  203. })
  204. },
  205. // 删除单个 弹窗
  206. del(item, i) {
  207. this.item = item
  208. this.i = i
  209. this.type = 1
  210. this.content ='确定要删除吗?'
  211. this.show = true
  212. },
  213. // 删除所有 弹窗
  214. allDel() {
  215. if (this.list.length == 0) {
  216. uni.showToast({
  217. title: '暂无货物',
  218. icon: 'none'
  219. })
  220. return false
  221. }
  222. this.content ='确定要全部清除吗?'
  223. this.type = 2
  224. this.show = true
  225. },
  226. // 发货调起确认框
  227. sendSure() {
  228. if(this.list.length == 0) {
  229. uni.showToast({
  230. title: '暂无货物',
  231. icon: 'none'
  232. })
  233. return false
  234. }
  235. this.type = 3
  236. this.show = true
  237. this.content ='确定要发货吗?'
  238. },
  239. confirm() {
  240. // 删除单个
  241. if(this.type == 1) {
  242. this.list.splice(this.i,1)
  243. this.reduceStyle(this.item)
  244. uni.showToast({
  245. title: '删除成功',
  246. icon: 'none'
  247. })
  248. // 删除所有
  249. } else if (this.type == 2) {
  250. this.list = []
  251. this.numList = [0,0,0,0]
  252. this.allNum = 0
  253. } else if(this.type == 3) {
  254. this.sendGood()
  255. }
  256. },
  257. // 款式
  258. getStyle(v) {
  259. if (v == 1) {
  260. return '精装版'
  261. } else if (v === 2) {
  262. return '简约版'
  263. } else if (v === 3) {
  264. return '老人版'
  265. } else if (v === 4) {
  266. return '纯棉老人版'
  267. }
  268. },
  269. // 增加款式数量
  270. addStyle(v) {
  271. if (v == 1) {
  272. this.numList[0] += 1
  273. } else if (v === 2) {
  274. this.numList[1] += 1
  275. } else if (v === 3) {
  276. this.numList[2] += 1
  277. } else if (v === 4) {
  278. this.numList[3] += 1
  279. }
  280. this.allNum += 1
  281. },
  282. // 减少款式数量
  283. reduceStyle(v) {
  284. if (v === '精装版') {
  285. this.numList[0] -= 1
  286. } else if (v === '简约版') {
  287. this.numList[1] -= 1
  288. } else if (v === '老人版') {
  289. this.numList[2] -= 1
  290. } else if (v === '纯棉老人版') {
  291. this.numList[3] -= 1
  292. }
  293. this.allNum -= 1
  294. },
  295. //获取信息
  296. getInfo(params) {
  297. UserSend({ id: this.id, code: params }).then(res => {
  298. if (res.code == 200) {
  299. const data = {
  300. style: this.getStyle(res.data.good),
  301. styleId: res.data.good,
  302. code: params
  303. }
  304. this.list.unshift(data)
  305. this.addStyle(res.data.good)
  306. this.count = 3
  307. this.ifShow = true
  308. this.setTime()
  309. } else {
  310. uni.showModal({
  311. title: '错误提示',
  312. content: res.message || '获取信息失败',
  313. showCancel: false
  314. })
  315. }
  316. })
  317. },
  318. getCode(){
  319. this.ifShow = false
  320. this.clearTime()
  321. this.fillOut = false
  322. const script = document.createElement('script');
  323. script.type = 'text/javascript';
  324. script.src = 'http://res.wx.qq.com/open/js/jweixin-1.4.0.js';
  325. document.getElementsByTagName('head')[0].appendChild(script);
  326. script.onload = () => {
  327. scanCode().then(res => {
  328. if (res.code == 200) {
  329. wx.config({
  330. debug: false, // 开启调试模式
  331. appId: res.data.appId, // 必填,公众号的唯一标识
  332. timestamp: res.data.timestamp, // 必填,生成签名的时间戳
  333. nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
  334. signature: res.data.signature, // 必填,签名,见附录1
  335. jsApiList: res.data.jsApiList // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  336. })
  337. wx.ready(() => {
  338. wx.scanQRCode({
  339. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  340. scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
  341. success: res => {
  342. var result = res.resultStr; // 当needResult 为 1 时,扫码返回的结果
  343. var site = result.lastIndexOf('\/')
  344. var params = result.substring(site + 1, result.length)
  345. this.code = window.encodeURIComponent(params)
  346. let index = this.list.findIndex( item => item.code == this.code)
  347. if (index != -1) {
  348. uni.showModal({
  349. title: '错误提示',
  350. content: '此码已添加,请勿重复扫描',
  351. showCancel: false
  352. })
  353. } else {
  354. this.getInfo(this.code)
  355. }
  356. }
  357. })
  358. })
  359. } else {
  360. uni.showModal({
  361. title: '错误提示',
  362. content: res.message || '获取信息失败',
  363. showCancel: false
  364. })
  365. }
  366. });
  367. };
  368. }
  369. }
  370. }
  371. </script>
  372. <style>
  373. page {
  374. background-color: #fff;
  375. }
  376. </style>
  377. <style lang="scss" scoped>
  378. .showTip {
  379. position: fixed;
  380. left: 0;
  381. right: 0;
  382. top: 30%;
  383. margin: auto;
  384. width: 648rpx;
  385. height: 368rpx;
  386. background: #FFFFFF;
  387. border-radius: 24rpx;
  388. z-index: 10000;
  389. display: flex;
  390. justify-content: space-between;
  391. align-items: center;
  392. flex-direction: column;
  393. padding-bottom: 34rpx;
  394. image {
  395. width: 180rpx;
  396. height: 136rpx;
  397. margin-top: -68rpx;
  398. }
  399. .title {
  400. font-size: 38rpx;
  401. font-weight: bold;
  402. color: #333333;
  403. }
  404. .remark {
  405. font-size: 34rpx;
  406. font-weight: 400;
  407. color: #333333;
  408. }
  409. .btn {
  410. display: flex;
  411. view {
  412. width: 242rpx;
  413. height: 88rpx;
  414. border-radius: 44rpx;
  415. text-align: center;
  416. line-height: 88rpx;
  417. font-size: 32rpx;
  418. font-weight: bold;
  419. }
  420. &_left {
  421. background: #F5F5F5;
  422. color: #333333;
  423. }
  424. &_right {
  425. margin-left: 24rpx;
  426. background: linear-gradient(93deg, #F30000 0%, #FE4815 100%);
  427. color: #fff;
  428. }
  429. }
  430. }
  431. .detailTop {
  432. padding: 24rpx 0 0 24rpx;
  433. display: flex;
  434. align-items: center;
  435. &_left {
  436. width: 136rpx;
  437. font-size: 34rpx;
  438. font-weight: bold;
  439. color: #333333;
  440. }
  441. &_right {
  442. width: 566rpx;
  443. height: 104rpx;
  444. background: #F8F8F8;
  445. border-radius: 8rpx;
  446. line-height: 104rpx;
  447. padding-left: 28rpx;
  448. color: #333;
  449. font-size: 32rpx;
  450. }
  451. }
  452. .detailMiddle {
  453. text {
  454. display: flex;
  455. display: inline-block;
  456. width: 20%;
  457. text-align: center;
  458. line-height: 90rpx;
  459. font-size: 32rpx;
  460. font-weight: bold;
  461. }
  462. }
  463. .detailMiddleRed {
  464. text {
  465. display: flex;
  466. display: inline-block;
  467. width: 20%;
  468. text-align: center;
  469. line-height: 90rpx;
  470. font-size: 32rpx;
  471. font-weight: bold;
  472. background-color: #FFF4F3;
  473. color: #FB231F;
  474. }
  475. }
  476. .listBox {
  477. padding-bottom: 104rpx;
  478. // height: 1500rpx;
  479. .back {
  480. background-color: #F8F8F8;
  481. }
  482. &_item {
  483. display: flex;
  484. justify-content: space-between;
  485. align-items: center;
  486. padding: 0 24rpx;
  487. height: 104rpx;
  488. .left {
  489. margin-left: 70rpx;
  490. font-weight: bold;
  491. font-size: 32rpx;
  492. }
  493. .gray {
  494. width: 80rpx;
  495. text-align: center;
  496. font-size: 32rpx;
  497. font-weight: bold;
  498. color: #999999;
  499. }
  500. .right {
  501. width: 132rpx;
  502. height: 64rpx;
  503. background: linear-gradient(141deg, #F30000 0%, #FE4815 100%);
  504. border-radius: 34rpx;
  505. line-height: 64rpx;
  506. text-align: center;
  507. color: #fff;
  508. font-size: 28rpx;
  509. }
  510. }
  511. }
  512. .fiexedEnd {
  513. position: fixed;
  514. left: 0;
  515. bottom: 0;
  516. width: 100%;
  517. height: 104rpx;
  518. background: #FFFFFF;
  519. box-shadow: 0rpx -4rpx 24rpx rgba(0, 0, 0, 0.1);
  520. padding: 0 72rpx 18rpx 72rpx;
  521. font-size: 32rpx;
  522. font-weight: bold;
  523. display: flex;
  524. justify-content: space-between;
  525. align-items: flex-end;
  526. &_red {
  527. width: 172rpx;
  528. height: 172rpx;
  529. background: linear-gradient(150deg, #FFAA01 0%, #FE0000 100%);
  530. box-shadow: 0px 6rpx 20rpx rgba(254, 34, 0, 0.43);
  531. border-radius: 50%;
  532. font-size: 40rpx;
  533. color: #fff;
  534. line-height: 172rpx;
  535. text-align: center;
  536. }
  537. &_title {
  538. margin-bottom: 12rpx;
  539. }
  540. }
  541. </style>