order.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <template>
  2. <view class="index-home flex-common-css">
  3. <!-- 1 -->
  4. <view class="box-1 align-items-start">
  5. <image src="@/static/img/jiankong.png" mode=""></image>
  6. <view class="fs-32 fc-3 fw-b">你已进入监控区域</view>
  7. <view class="box-1-time">
  8. <Countdown ref="countdown"></Countdown>
  9. </view>
  10. </view>
  11. <!-- 2 -->
  12. <view v-if="goodsList.length == 0" class="scroll-view-css">
  13. <image class="no-img" src="@/static/img/no-goods.png" mode="scaleToFill"></image>
  14. <view class="fs-30 fc-6 text-align-center">请扫码添加商品</view>
  15. </view>
  16. <scroll-view v-else scroll-y="true" class="scroll-view-css list-box">
  17. <view class="goods-box flex-justify-space" v-for="(item,i) in goodsList" :key="i">
  18. <image :src="item.cover_img" mode="scaleToFill"></image>
  19. <view class="flex-1">
  20. <view class="flex-justify-space">
  21. <view class="text-1 text-overflow-ellipsis-one">{{item.goods_name}}</view>
  22. <uni-icons @click="delGoods(i)" type="trash" size="20"></uni-icons>
  23. </view>
  24. <view class="flex-justify-space">
  25. <view class="fs-24 fc-ED301D">¥{{item.price}}</view>
  26. <view class="align-items-center">
  27. <view class="num-buttom" v-if="item.num > 1" @click="reduce(i)">-</view>
  28. <view class="num-box">{{item.num}}</view>
  29. <view class="num-buttom" @click="add(i)">+</view>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </scroll-view>
  35. <view class="box-2-b align-items-center">
  36. <view class="box-2-shou flex-justify-center align-items-center" @click="headInput()">
  37. <image src="@/static/img/txm.png" mode=""></image>
  38. <view class="fs-30 fc-3 fw-400">手输条码</view>
  39. </view>
  40. <view class="box-2-shou flex-justify-center align-items-center" @click="openMenber()">
  41. <image src="@/static/img/txm.png" mode=""></image>
  42. <view class="fs-30 fc-3 fw-400">扫会员码</view>
  43. </view>
  44. <view v-if="member_id" class="flex-justify-center align-items-center">
  45. <view class="fs-24 fc-074B86 fw-400">会员ID {{member_id}}</view>
  46. </view>
  47. </view>
  48. <!-- 3 -->
  49. <view class="box-2">
  50. <view class="flex-justify-space">
  51. <view class="">
  52. <view class="fs-30 fc-3">
  53. 共{{totalNum}}件
  54. <span v-if="discount&&discount>0">,已优惠</span>
  55. <span class="fs-30 fc-ED301D fw-600 mr-10" v-if="discount&&discount>0">¥{{(totalPrice - (totalPrice*discount)).toFixed(2)}}</span>
  56. <span class="fs-30 fc-ED301D fw-600" v-if="discount&&discount>0">{{discount*10||'0'}}折</span>
  57. </view>
  58. <view class="">
  59. <span class="fs-30 fc-3">合计</span>
  60. <span class="fs-30 fc-ED301D">¥</span>
  61. <span class="fs-40 fc-ED301D fw-600" v-if="discount&&discount>0">{{(totalPrice*discount).toFixed(2)}}</span>
  62. <span class="fs-40 fc-ED301D fw-600" v-else>{{totalPrice}}</span>
  63. </view>
  64. </view>
  65. <view class="to-save text-align-center fs-32 fc-f" @click="save()">去结算</view>
  66. </view>
  67. </view>
  68. <keyboard-listener v-if="outscan" @keyup="monitorKeyboard"></keyboard-listener>
  69. <!-- 支付类型 -->
  70. <uni-popup ref="popup" :mask-click="false">
  71. <view class="">
  72. <view class="pop-view mb-25">
  73. <view class="fs-32 fw-600 pop-1 pop-view-1">请选择支付类型</view>
  74. <view class="pop-2">
  75. <view class="fs-32 pop-1 pop-view-1 fc-lv" @click="selectTyep(1)">微信</view>
  76. <view class="fs-32 pop-1 fc-lan" @click="selectTyep(2)">支付宝</view>
  77. </view>
  78. </view>
  79. <view class="code-view-1" @click="closePay()">取消支付</view>
  80. </view>
  81. </uni-popup>
  82. <!-- 付款码 -->
  83. <uni-popup ref="popupCode" :mask-click="false">
  84. <view class="">
  85. <view class="code-view">
  86. <view class="fs-42 fw-b fc-lan text-align-center">请出示{{payType == 1?'微信':'支付宝'}}付款码</view>
  87. <view class="text-align-center">
  88. <span class="fs-30 fc-9">应付</span>
  89. <span class="fs-42 fc-ED301D fw-b">¥{{totalPrice}}</span>
  90. </view>
  91. <image src="@/static/img/code-1.png" mode="scaleToFill"></image>
  92. <view class="fs-30 fc-6 text-align-center">对准下方扫描口</view>
  93. </view>
  94. <view class="code-view-1" @click="closePay()">取消支付</view>
  95. </view>
  96. </uni-popup>
  97. <!-- 手动输入 -->
  98. <uni-popup ref="inputDialog" type="dialog">
  99. <uni-popup-dialog v-model="headValue" mode="input" title="输入条码" placeholder="请输入条码" @confirm="dialogInputConfirm"></uni-popup-dialog>
  100. </uni-popup>
  101. <!-- 会员码 -->
  102. <uni-popup ref="inputMember" type="bottom" :mask-click="false">
  103. <view class="flex-common-css member-pop-view">
  104. <view class="member-pop-view-1"></view>
  105. <view class="member-pop-view-2 flex-1">
  106. <view class="flex-justify-space align-items-center mb-40">
  107. <image class="img-11" src="@/static/member/shuom.png" mode=""></image>
  108. <image @click="closePOP()" class="img-close" src="@/static/member/close.png" mode=""></image>
  109. </view>
  110. <view class="mb-40">
  111. <view class="align-items-center mb-13">
  112. <view class="yuan">1</view>
  113. <view class="align-items-center">
  114. <view class="fs-30">微信搜索</view>
  115. <view class="fs-30 fc-1778FD">振合网实体联盟</view>
  116. <view class="fs-30">公众号,点击</view>
  117. <view class="fs-30 fc-1778FD">民营经济</view>
  118. </view>
  119. </view>
  120. <view class="bg-1 flex-justify-center align-items-center">
  121. <image class="img-12" src="@/static/member/1.png" mode=""></image>
  122. <image class="img-13" src="@/static/member/right.png" mode=""></image>
  123. <image class="img-12" src="@/static/member/2.png" mode=""></image>
  124. </view>
  125. </view>
  126. <view class="mb-40">
  127. <view class="align-items-center mb-13">
  128. <view class="yuan">2</view>
  129. <view class="align-items-center">
  130. <view class="fs-30">找到个人中心点击</view>
  131. <view class="fs-30 fc-1778FD">分享码</view>
  132. </view>
  133. </view>
  134. <view class="bg-1 flex-justify-center align-items-center">
  135. <image class="img-12" src="@/static/member/3.png" mode=""></image>
  136. <image class="img-13" src="@/static/member/right.png" mode=""></image>
  137. <image class="img-12" src="@/static/member/4.png" mode=""></image>
  138. </view>
  139. </view>
  140. <view class="">
  141. <view class="align-items-center mb-13">
  142. <view class="yuan">3</view>
  143. <view class="align-items-center">
  144. <view class="fs-30">二维码对准扫描口,</view>
  145. <view class="fs-30 fc-1778FD">识别完成,显示会员IP</view>
  146. </view>
  147. </view>
  148. <view class="bg-1 flex-justify-center align-items-center">
  149. <image class="img-12" src="@/static/member/5.png" mode=""></image>
  150. <image class="img-13" src="@/static/member/right.png" mode=""></image>
  151. <image class="img-12" src="@/static/member/6.png" mode=""></image>
  152. </view>
  153. </view>
  154. </view>
  155. </view>
  156. </uni-popup>
  157. </view>
  158. </template>
  159. <script>
  160. import {projectDiscount} from '@/api/project.js';
  161. import keyboardListener from 'uniapp-keyboard-listener';
  162. import {GoodsInfo,OrderCreate,OrderPay} from '@/api/cashierApi.js'
  163. import tools from '@/common/js/tools';
  164. import Countdown from '../mod/countdown.vue'
  165. export default {
  166. components: {keyboardListener,Countdown},
  167. data() {
  168. return {
  169. isMemeber:false,
  170. discount:'',//折扣
  171. member_id:'',//会员id
  172. invite_code:'',//推荐码
  173. totalNum:0,//总数量
  174. totalPrice:0,//总金额
  175. payType:'',//1微信 2支护宝
  176. goodsList:[],//商品列表
  177. outscan:false,
  178. keyArr:[],
  179. nvalue:'',
  180. auth_code:'',//付款码
  181. order_id:'',
  182. payFLag:true,//支付还是添加商品 true 添加商品 false 结算扫码
  183. isAJAX:false,
  184. headValue:'',//手动输入的值
  185. };
  186. },
  187. onLoad() {
  188. this.outscan=true
  189. },
  190. beforeDestroy() {
  191. this.outscan=false
  192. },
  193. deactivated() {
  194. this.outscan=false
  195. },
  196. mounted() {
  197. },
  198. methods: {
  199. monitorKeyboard(e) {
  200. if (e.key.length == 1) { // 字母和数字的长度都是1,所以只要字母和数字的按键,适配不同的设备
  201. this.keyArr.push(e.key)
  202. } else if (e.key == 'Enter') { // 监听到回车
  203. let newArr = [];
  204. this.nvalue = '';
  205. // 条码中可能会有大写字母和未定义的按键,所以要过滤出来
  206. newArr = this.keyArr.filter(item => item != 'Shift' && item != 'Enter' && item != 'Unidentified')
  207. if(this.isMemeber){
  208. if(this.isAJAX){
  209. return
  210. }
  211. this.isAJAX = true;
  212. let href = newArr.join("")
  213. const urlArr = href.split('?')
  214. const rightUrlArr = urlArr[1].split('#/')
  215. const queryObj = {}
  216. rightUrlArr[0].split('&').map((item)=> {
  217. const splitStr = item.split('=')
  218. return{
  219. key:splitStr[0],
  220. value:splitStr[1]
  221. }
  222. }).forEach((item)=>{
  223. queryObj[item.key]= item.value
  224. })
  225. if(urlArr.length >= 3){
  226. rightUrlArr[1]="?"+ urlArr[2]
  227. }
  228. this.invite_code = queryObj.memberCode
  229. projectDiscount({invite_code:this.invite_code}).then((res)=>{
  230. if(res.code == 1){
  231. this.isAJAX = false;
  232. this.member_id = res.data.member_id;
  233. this.discount = res.data.discount * 1;
  234. this.closePOP();
  235. }else{
  236. this.isAJAX = false;
  237. tools.error(res.msg)
  238. }
  239. })
  240. }else{
  241. if(this.payFLag){
  242. // 添加商品
  243. if(this.isAJAX){
  244. return
  245. }
  246. this.isAJAX = true;
  247. this.nvalue = newArr.join("")
  248. this.getGoods();
  249. }else{
  250. // 支付扫码
  251. if(this.isAJAX){
  252. return
  253. }
  254. this.isAJAX = true;
  255. this.auth_code = newArr.join("")
  256. OrderPay({order_id:this.order_id,pay_type:this.payType,auth_code:this.auth_code}).then((res)=>{
  257. if(res.code == 1){
  258. this.payFLag = true;
  259. this.isAJAX = false;
  260. uni.redirectTo({
  261. url:'/pages/index/success?money=' + this.totalPrice + "&discount=" + this.discount + '&invite_code=' + this.invite_code
  262. })
  263. }else{
  264. this.isAJAX = false;
  265. tools.error(res.msg)
  266. }
  267. })
  268. }
  269. }
  270. this.keyArr = [];
  271. }
  272. },
  273. // 获取商品
  274. getGoods(){
  275. GoodsInfo({goods_sn:this.nvalue}).then((res)=>{
  276. if(res.code == 1){
  277. this.isAJAX = false;
  278. if(this.goodsList.length == 0){
  279. let obj = res.data;
  280. obj.num = 1;
  281. this.goodsList.push(obj)
  282. this.totalNum = 1;
  283. this.totalPrice = res.data.price;
  284. }else{
  285. let obj = res.data;
  286. let flag = true;
  287. this.goodsList.forEach((v,i)=>{
  288. if(v.id == obj.id){
  289. v.num += 1;
  290. this.totalNum += 1;
  291. this.totalPrice = (this.totalPrice*1 + v.price*1).toFixed(2);
  292. flag = false;
  293. }
  294. })
  295. if(flag){
  296. obj.num = 1;
  297. this.goodsList.push(obj)
  298. this.totalNum += 1;
  299. this.totalPrice = (this.totalPrice*1 + res.data.price*1).toFixed(2);
  300. }
  301. }
  302. this.headValue = '';
  303. }else{
  304. this.isAJAX = false;
  305. this.headValue = '';
  306. tools.error(res.msg)
  307. }
  308. })
  309. },
  310. // 删除商品
  311. delGoods(i){
  312. this.totalNum = this.totalNum - this.goodsList[i].num;
  313. this.totalPrice = (this.totalPrice*1 - (this.goodsList[i].price*this.goodsList[i].num)).toFixed(2);
  314. this.goodsList.splice(i,1)
  315. },
  316. // 减少
  317. reduce(i){
  318. this.goodsList[i].num -= 1
  319. this.totalNum -= 1;
  320. this.totalPrice = (this.totalPrice*1 - (this.goodsList[i].price*1)).toFixed(2);
  321. },
  322. // 添加
  323. add(i){
  324. this.goodsList[i].num += 1
  325. this.totalNum += 1;
  326. this.totalPrice = (this.totalPrice*1 + this.goodsList[i].price*1).toFixed(2);
  327. },
  328. // 支付
  329. save(){
  330. if(this.goodsList.length > 0){
  331. this.payFLag = false;
  332. this.$refs.popup.open('center')
  333. }else{
  334. this.payFLag = true;
  335. tools.error('请添加商品')
  336. }
  337. },
  338. // 选择支付类型
  339. selectTyep(type){
  340. this.payType = type;
  341. if(this.isAJAX){
  342. return
  343. }
  344. this.isAJAX = true;
  345. OrderCreate({goods:this.goodsList}).then((res)=>{
  346. if(res.code == 1){
  347. this.isAJAX = false;
  348. this.order_id = res.data.order_id;
  349. this.$refs.popup.close();
  350. this.$refs.countdown.timeFun();
  351. // 扫码弹窗
  352. this.$refs.popupCode.open('center')
  353. }else{
  354. tools.error(res.msg)
  355. this.isAJAX = false;
  356. this.payFLag = true;
  357. this.order_id = '';
  358. this.payType = '';
  359. this.$refs.popup.close();
  360. }
  361. })
  362. },
  363. // 取消支付
  364. closePay(){
  365. this.payFLag = true;
  366. this.order_id = '';
  367. this.payType = '';
  368. this.$refs.popup.close();
  369. this.$refs.popupCode.close();
  370. },
  371. // 手动输入
  372. headInput(){
  373. this.$refs.inputDialog.open();
  374. },
  375. // 手动输入获取商品
  376. dialogInputConfirm(){
  377. this.nvalue = this.headValue;
  378. this.getGoods();
  379. },
  380. // 会员扫码
  381. openMenber(){
  382. // let href = "http://test-wapadopted.jhcs888.com/#/pages/index/index?memberCode=53913013";
  383. // const urlArr = href.split('?')
  384. // const rightUrlArr = urlArr[1].split('#/')
  385. // const queryObj = {}
  386. // rightUrlArr[0].split('&').map((item)=> {
  387. // const splitStr = item.split('=')
  388. // return{
  389. // key:splitStr[0],
  390. // value:splitStr[1]
  391. // }
  392. // }).forEach((item)=>{
  393. // queryObj[item.key]= item.value
  394. // })
  395. // if(urlArr.length >= 3){
  396. // rightUrlArr[1]="?"+ urlArr[2]
  397. // }
  398. // this.invite_code = queryObj.memberCode
  399. // projectDiscount({invite_code:this.invite_code}).then((res)=>{
  400. // if(res.code == 1){
  401. // this.isAJAX = false;
  402. // this.member_id = res.data.member_id;
  403. // this.discount = res.data.discount * 1;
  404. // }else{
  405. // this.isAJAX = false;
  406. // tools.error(res.msg)
  407. // }
  408. // })
  409. this.isMemeber = true;
  410. this.$refs.inputMember.open();
  411. },
  412. closePOP(){
  413. this.isMemeber = false;
  414. this.$refs.inputMember.close();
  415. },
  416. lookBigImg(list, index) {
  417. uni.previewImage({
  418. urls: list,
  419. current: index,
  420. })
  421. },
  422. },
  423. };
  424. </script>
  425. <style scoped lang="scss">
  426. .member-pop-view{
  427. width: 100%;
  428. height: 100vh;
  429. background: #939394;
  430. .member-pop-view-1{
  431. width: 100%;
  432. height: 187rpx;
  433. }
  434. .member-pop-view-2{
  435. background-color: #fff;
  436. box-sizing: border-box;
  437. padding: 38rpx;
  438. border-radius: 20rpx;
  439. .img-11{
  440. width: 258rpx;
  441. height: 50rpx;
  442. }
  443. .img-close{
  444. width: 58rpx;
  445. height: 58rpx;
  446. }
  447. .yuan{
  448. width: 41rpx;
  449. height: 41rpx;
  450. border-radius: 50%;
  451. background: #1778FD;
  452. margin-right: 17rpx;
  453. text-align: center;
  454. line-height: 41rpx;
  455. font-size: 24rpx;
  456. font-weight: bold;
  457. color: #fff;
  458. }
  459. .bg-1{
  460. width: 100%;
  461. height: 221rpx;
  462. background: #E8EFF9;
  463. border-radius: 25rpx;
  464. }
  465. .img-12{
  466. width: 270rpx;;
  467. height: 210rpx;
  468. }
  469. .img-13{
  470. width: 42rpx;;
  471. height: 42rpx;
  472. }
  473. }
  474. }
  475. .index-home{
  476. .no-img{
  477. width: 200rpx;
  478. height: 200rpx;
  479. margin: 30% auto 30rpx auto;
  480. }
  481. .box-1{
  482. width: 100%;
  483. height: 150rpx;
  484. box-sizing: border-box;
  485. padding: 80rpx 0 0 24rpx;
  486. position: relative;
  487. .box-1-time{
  488. position: absolute;
  489. bottom: 20rpx;
  490. right: 20rpx;
  491. }
  492. image{
  493. width: 48rpx;
  494. height: 48rpx;
  495. margin-right: 10rpx;
  496. }
  497. }
  498. .list-box{
  499. background-color: #F2F3F5;
  500. box-sizing: border-box;
  501. padding: 17rpx 24rpx;
  502. .goods-box{
  503. width: 100%;
  504. height: 179rpx;
  505. background: #FFFFFF;
  506. border-radius: 17rpx;
  507. margin-bottom: 17rpx;
  508. box-sizing: border-box;
  509. padding: 25rpx;
  510. image{
  511. width: 129rpx;
  512. height: 129rpx;
  513. border-radius: 14rpx;
  514. margin-right: 16rpx;
  515. }
  516. .text-1{
  517. width: 440rpx;
  518. font-size: 25rpx;
  519. margin-bottom: 40rpx;
  520. }
  521. .num-buttom{
  522. width: 50rpx;
  523. height: 50rpx;
  524. line-height: 50rpx;
  525. border-radius: 50%;
  526. background-color: #DAE9FF;
  527. color: #1778FD;
  528. font-weight: 600;
  529. text-align: center;
  530. font-size: 32rpx
  531. }
  532. .num-box{
  533. width: 110rpx;
  534. height: 50rpx;
  535. line-height: 50rpx;
  536. text-align: center;
  537. font-size: 33rpx;
  538. font-weight: 600;
  539. }
  540. }
  541. }
  542. .box-2-b{
  543. width: 100%;
  544. height: 83rpx;
  545. background: #E6E7E9;
  546. box-sizing: border-box;
  547. padding: 12rpx 23rpx;
  548. .box-2-shou{
  549. width: 177rpx;
  550. height: 58rpx;
  551. border-radius: 104rpx;
  552. background: #fff;
  553. margin-right: 20rpx;
  554. image{
  555. width: 25rpx;
  556. height: 25rpx;
  557. }
  558. }
  559. }
  560. .box-2{
  561. width: 100%;
  562. height: 150rpx;
  563. box-sizing: border-box;
  564. padding: 20rpx 23rpx;
  565. .to-save{
  566. margin-top: auto;
  567. width: 292rpx;
  568. height: 83rpx;
  569. line-height: 83rpx;
  570. background: linear-gradient( 90deg, #4AB6FF 0%, #1778FD 100%);
  571. box-shadow: 0rpx 0rpx 4rpx 0rpx rgba(108,168,252,0.64);
  572. border-radius: 104rpx;
  573. }
  574. }
  575. }
  576. .pop-view{
  577. width: 500rpx;
  578. min-height: 100rpx;
  579. background-color: #fff;
  580. border-radius: 20rpx;
  581. .pop-1{
  582. box-sizing: border-box;
  583. height: 120rpx;
  584. width: 100%;
  585. text-align: center;
  586. line-height: 120rpx;
  587. }
  588. .pop-2{
  589. box-sizing: border-box;
  590. padding: 0 50rpx;
  591. }
  592. .pop-view-1{
  593. border-bottom: 1rpx solid #ccc;
  594. }
  595. }
  596. .code-view{
  597. width: 633rpx;
  598. height: 710rpx;
  599. background-image: url('@/static/img/code-bg.png');
  600. background-size: 100% 100%;
  601. box-sizing: border-box;
  602. padding: 62rpx 0 0 0;
  603. margin-bottom: 62rpx;
  604. image{
  605. width: 327rpx;
  606. height: 327rpx;
  607. margin: 50rpx auto 25rpx auto;
  608. }
  609. }
  610. .code-view-1{
  611. text-align: center;
  612. margin: 0 auto;
  613. width: 223rpx;
  614. height: 57rpx;
  615. line-height: 57rpx;
  616. border-radius: 104rpx;
  617. border: 2rpx solid #fff;
  618. text-align: center;
  619. color: #fff;
  620. font-size: 32rpx;
  621. }
  622. </style>