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 v-if="shop_id == 299" 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:0,//折扣
  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. shop_id:'',
  186. };
  187. },
  188. onLoad() {
  189. this.outscan=true
  190. },
  191. beforeDestroy() {
  192. this.outscan=false
  193. },
  194. deactivated() {
  195. this.outscan=false
  196. },
  197. onShow() {
  198. this.shop_id = uni.getStorageSync('shop_id')
  199. },
  200. methods: {
  201. monitorKeyboard(e) {
  202. if (e.key.length == 1) { // 字母和数字的长度都是1,所以只要字母和数字的按键,适配不同的设备
  203. this.keyArr.push(e.key)
  204. } else if (e.key == 'Enter') { // 监听到回车
  205. let newArr = [];
  206. this.nvalue = '';
  207. // 条码中可能会有大写字母和未定义的按键,所以要过滤出来
  208. newArr = this.keyArr.filter(item => item != 'Shift' && item != 'Enter' && item != 'Unidentified')
  209. if(this.isMemeber){
  210. if(this.isAJAX){
  211. return
  212. }
  213. this.isAJAX = true;
  214. let href = newArr.join("")
  215. const urlArr = href.split('?')
  216. const rightUrlArr = urlArr[1].split('#/')
  217. const queryObj = {}
  218. rightUrlArr[0].split('&').map((item)=> {
  219. const splitStr = item.split('=')
  220. return{
  221. key:splitStr[0],
  222. value:splitStr[1]
  223. }
  224. }).forEach((item)=>{
  225. queryObj[item.key]= item.value
  226. })
  227. if(urlArr.length >= 3){
  228. rightUrlArr[1]="?"+ urlArr[2]
  229. }
  230. this.invite_code = queryObj.memberCode
  231. projectDiscount({invite_code:this.invite_code}).then((res)=>{
  232. if(res.code == 1){
  233. this.isAJAX = false;
  234. this.member_id = res.data.member_id;
  235. this.discount = res.data.discount * 1;
  236. this.closePOP();
  237. }else{
  238. this.isAJAX = false;
  239. tools.error(res.msg)
  240. }
  241. })
  242. }else{
  243. if(this.payFLag){
  244. // 添加商品
  245. if(this.isAJAX){
  246. return
  247. }
  248. this.isAJAX = true;
  249. this.nvalue = newArr.join("")
  250. this.getGoods();
  251. }else{
  252. // 支付扫码
  253. if(this.isAJAX){
  254. return
  255. }
  256. this.isAJAX = true;
  257. this.auth_code = newArr.join("")
  258. OrderPay({order_id:this.order_id,pay_type:this.payType,auth_code:this.auth_code}).then((res)=>{
  259. if(res.code == 1){
  260. this.payFLag = true;
  261. this.isAJAX = false;
  262. uni.redirectTo({
  263. url:'/pages/index/success?money=' + this.totalPrice + "&discount=" + this.discount + '&invite_code=' + this.invite_code
  264. })
  265. }else{
  266. this.isAJAX = false;
  267. tools.error(res.msg)
  268. }
  269. })
  270. }
  271. }
  272. this.keyArr = [];
  273. }
  274. },
  275. // 获取商品
  276. getGoods(){
  277. GoodsInfo({goods_sn:this.nvalue}).then((res)=>{
  278. if(res.code == 1){
  279. this.isAJAX = false;
  280. if(this.goodsList.length == 0){
  281. let obj = res.data;
  282. obj.num = 1;
  283. this.goodsList.push(obj)
  284. this.totalNum = 1;
  285. this.totalPrice = res.data.price;
  286. }else{
  287. let obj = res.data;
  288. let flag = true;
  289. this.goodsList.forEach((v,i)=>{
  290. if(v.id == obj.id){
  291. v.num += 1;
  292. this.totalNum += 1;
  293. this.totalPrice = (this.totalPrice*1 + v.price*1).toFixed(2);
  294. flag = false;
  295. }
  296. })
  297. if(flag){
  298. obj.num = 1;
  299. this.goodsList.push(obj)
  300. this.totalNum += 1;
  301. this.totalPrice = (this.totalPrice*1 + res.data.price*1).toFixed(2);
  302. }
  303. }
  304. this.headValue = '';
  305. }else{
  306. this.isAJAX = false;
  307. this.headValue = '';
  308. tools.error(res.msg)
  309. }
  310. })
  311. },
  312. // 删除商品
  313. delGoods(i){
  314. this.totalNum = this.totalNum - this.goodsList[i].num;
  315. this.totalPrice = (this.totalPrice*1 - (this.goodsList[i].price*this.goodsList[i].num)).toFixed(2);
  316. this.goodsList.splice(i,1)
  317. },
  318. // 减少
  319. reduce(i){
  320. this.goodsList[i].num -= 1
  321. this.totalNum -= 1;
  322. this.totalPrice = (this.totalPrice*1 - (this.goodsList[i].price*1)).toFixed(2);
  323. },
  324. // 添加
  325. add(i){
  326. this.goodsList[i].num += 1
  327. this.totalNum += 1;
  328. this.totalPrice = (this.totalPrice*1 + this.goodsList[i].price*1).toFixed(2);
  329. },
  330. // 支付
  331. save(){
  332. if(this.goodsList.length > 0){
  333. this.payFLag = false;
  334. this.$refs.popup.open('center')
  335. }else{
  336. this.payFLag = true;
  337. tools.error('请添加商品')
  338. }
  339. },
  340. // 选择支付类型
  341. selectTyep(type){
  342. this.payType = type;
  343. if(this.isAJAX){
  344. return
  345. }
  346. this.isAJAX = true;
  347. OrderCreate({goods:this.goodsList}).then((res)=>{
  348. if(res.code == 1){
  349. this.isAJAX = false;
  350. this.order_id = res.data.order_id;
  351. this.$refs.popup.close();
  352. this.$refs.countdown.timeFun();
  353. // 扫码弹窗
  354. this.$refs.popupCode.open('center')
  355. }else{
  356. tools.error(res.msg)
  357. this.isAJAX = false;
  358. this.payFLag = true;
  359. this.order_id = '';
  360. this.payType = '';
  361. this.$refs.popup.close();
  362. }
  363. })
  364. },
  365. // 取消支付
  366. closePay(){
  367. this.payFLag = true;
  368. this.order_id = '';
  369. this.payType = '';
  370. this.$refs.popup.close();
  371. this.$refs.popupCode.close();
  372. },
  373. // 手动输入
  374. headInput(){
  375. this.$refs.inputDialog.open();
  376. },
  377. // 手动输入获取商品
  378. dialogInputConfirm(){
  379. this.nvalue = this.headValue;
  380. this.getGoods();
  381. },
  382. // 会员扫码
  383. openMenber(){
  384. // let href = "http://test-wapadopted.jhcs888.com/#/pages/index/index?memberCode=53913013";
  385. // const urlArr = href.split('?')
  386. // const rightUrlArr = urlArr[1].split('#/')
  387. // const queryObj = {}
  388. // rightUrlArr[0].split('&').map((item)=> {
  389. // const splitStr = item.split('=')
  390. // return{
  391. // key:splitStr[0],
  392. // value:splitStr[1]
  393. // }
  394. // }).forEach((item)=>{
  395. // queryObj[item.key]= item.value
  396. // })
  397. // if(urlArr.length >= 3){
  398. // rightUrlArr[1]="?"+ urlArr[2]
  399. // }
  400. // this.invite_code = queryObj.memberCode
  401. // projectDiscount({invite_code:this.invite_code}).then((res)=>{
  402. // if(res.code == 1){
  403. // this.isAJAX = false;
  404. // this.member_id = res.data.member_id;
  405. // this.discount = res.data.discount * 1;
  406. // }else{
  407. // this.isAJAX = false;
  408. // tools.error(res.msg)
  409. // }
  410. // })
  411. this.isMemeber = true;
  412. this.$refs.inputMember.open();
  413. },
  414. closePOP(){
  415. this.isMemeber = false;
  416. this.$refs.inputMember.close();
  417. },
  418. lookBigImg(list, index) {
  419. uni.previewImage({
  420. urls: list,
  421. current: index,
  422. })
  423. },
  424. },
  425. };
  426. </script>
  427. <style scoped lang="scss">
  428. .member-pop-view{
  429. width: 100%;
  430. height: 100vh;
  431. background: #939394;
  432. .member-pop-view-1{
  433. width: 100%;
  434. height: 187rpx;
  435. }
  436. .member-pop-view-2{
  437. background-color: #fff;
  438. box-sizing: border-box;
  439. padding: 38rpx;
  440. border-radius: 20rpx;
  441. .img-11{
  442. width: 258rpx;
  443. height: 50rpx;
  444. }
  445. .img-close{
  446. width: 58rpx;
  447. height: 58rpx;
  448. }
  449. .yuan{
  450. width: 41rpx;
  451. height: 41rpx;
  452. border-radius: 50%;
  453. background: #1778FD;
  454. margin-right: 17rpx;
  455. text-align: center;
  456. line-height: 41rpx;
  457. font-size: 24rpx;
  458. font-weight: bold;
  459. color: #fff;
  460. }
  461. .bg-1{
  462. width: 100%;
  463. height: 221rpx;
  464. background: #E8EFF9;
  465. border-radius: 25rpx;
  466. }
  467. .img-12{
  468. width: 270rpx;;
  469. height: 210rpx;
  470. }
  471. .img-13{
  472. width: 42rpx;;
  473. height: 42rpx;
  474. }
  475. }
  476. }
  477. .index-home{
  478. .no-img{
  479. width: 200rpx;
  480. height: 200rpx;
  481. margin: 30% auto 30rpx auto;
  482. }
  483. .box-1{
  484. width: 100%;
  485. height: 150rpx;
  486. box-sizing: border-box;
  487. padding: 80rpx 0 0 24rpx;
  488. position: relative;
  489. .box-1-time{
  490. position: absolute;
  491. bottom: 20rpx;
  492. right: 20rpx;
  493. }
  494. image{
  495. width: 48rpx;
  496. height: 48rpx;
  497. margin-right: 10rpx;
  498. }
  499. }
  500. .list-box{
  501. background-color: #F2F3F5;
  502. box-sizing: border-box;
  503. padding: 17rpx 24rpx;
  504. .goods-box{
  505. width: 100%;
  506. height: 179rpx;
  507. background: #FFFFFF;
  508. border-radius: 17rpx;
  509. margin-bottom: 17rpx;
  510. box-sizing: border-box;
  511. padding: 25rpx;
  512. image{
  513. width: 129rpx;
  514. height: 129rpx;
  515. border-radius: 14rpx;
  516. margin-right: 16rpx;
  517. }
  518. .text-1{
  519. width: 440rpx;
  520. font-size: 25rpx;
  521. margin-bottom: 40rpx;
  522. }
  523. .num-buttom{
  524. width: 50rpx;
  525. height: 50rpx;
  526. line-height: 50rpx;
  527. border-radius: 50%;
  528. background-color: #DAE9FF;
  529. color: #1778FD;
  530. font-weight: 600;
  531. text-align: center;
  532. font-size: 32rpx
  533. }
  534. .num-box{
  535. width: 110rpx;
  536. height: 50rpx;
  537. line-height: 50rpx;
  538. text-align: center;
  539. font-size: 33rpx;
  540. font-weight: 600;
  541. }
  542. }
  543. }
  544. .box-2-b{
  545. width: 100%;
  546. height: 83rpx;
  547. background: #E6E7E9;
  548. box-sizing: border-box;
  549. padding: 12rpx 23rpx;
  550. .box-2-shou{
  551. width: 177rpx;
  552. height: 58rpx;
  553. border-radius: 104rpx;
  554. background: #fff;
  555. margin-right: 20rpx;
  556. image{
  557. width: 25rpx;
  558. height: 25rpx;
  559. }
  560. }
  561. }
  562. .box-2{
  563. width: 100%;
  564. height: 150rpx;
  565. box-sizing: border-box;
  566. padding: 20rpx 23rpx;
  567. .to-save{
  568. margin-top: auto;
  569. width: 292rpx;
  570. height: 83rpx;
  571. line-height: 83rpx;
  572. background: linear-gradient( 90deg, #4AB6FF 0%, #1778FD 100%);
  573. box-shadow: 0rpx 0rpx 4rpx 0rpx rgba(108,168,252,0.64);
  574. border-radius: 104rpx;
  575. }
  576. }
  577. }
  578. .pop-view{
  579. width: 500rpx;
  580. min-height: 100rpx;
  581. background-color: #fff;
  582. border-radius: 20rpx;
  583. .pop-1{
  584. box-sizing: border-box;
  585. height: 120rpx;
  586. width: 100%;
  587. text-align: center;
  588. line-height: 120rpx;
  589. }
  590. .pop-2{
  591. box-sizing: border-box;
  592. padding: 0 50rpx;
  593. }
  594. .pop-view-1{
  595. border-bottom: 1rpx solid #ccc;
  596. }
  597. }
  598. .code-view{
  599. width: 633rpx;
  600. height: 710rpx;
  601. background-image: url('@/static/img/code-bg.png');
  602. background-size: 100% 100%;
  603. box-sizing: border-box;
  604. padding: 62rpx 0 0 0;
  605. margin-bottom: 62rpx;
  606. image{
  607. width: 327rpx;
  608. height: 327rpx;
  609. margin: 50rpx auto 25rpx auto;
  610. }
  611. }
  612. .code-view-1{
  613. text-align: center;
  614. margin: 0 auto;
  615. width: 223rpx;
  616. height: 57rpx;
  617. line-height: 57rpx;
  618. border-radius: 104rpx;
  619. border: 2rpx solid #fff;
  620. text-align: center;
  621. color: #fff;
  622. font-size: 32rpx;
  623. }
  624. </style>