order.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  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"
  56. v-if="discount&&discount>0">¥{{(totalPrice - (totalPrice*discount)).toFixed(2)}}</span>
  57. <span class="fs-30 fc-ED301D fw-600" v-if="discount&&discount>0">{{discount*10||'0'}}折</span>
  58. </view>
  59. <view class="">
  60. <span class="fs-30 fc-3">合计</span>
  61. <span class="fs-30 fc-ED301D">¥</span>
  62. <span class="fs-40 fc-ED301D fw-600"
  63. v-if="discount&&discount>0">{{(totalPrice*discount).toFixed(2)}}</span>
  64. <span class="fs-40 fc-ED301D fw-600" v-else>{{totalPrice}}</span>
  65. </view>
  66. </view>
  67. <view class="to-save text-align-center fs-32 fc-f" @click="save()">去结算</view>
  68. </view>
  69. </view>
  70. <keyboard-listener v-if="outscan" @keyup="monitorKeyboard"></keyboard-listener>
  71. <!-- 支付类型 -->
  72. <uni-popup ref="popup" :mask-click="false">
  73. <view class="">
  74. <view class="pop-view mb-25">
  75. <view class="fs-32 fw-600 pop-1 pop-view-1">请选择支付类型</view>
  76. <view class="pop-2">
  77. <view class="fs-32 pop-1 pop-view-1 fc-lv" @click="selectTyep(1)">微信</view>
  78. <view class="fs-32 pop-1 fc-lan" @click="selectTyep(2)">支付宝</view>
  79. </view>
  80. </view>
  81. <view class="code-view-1" @click="closePay()">取消支付</view>
  82. </view>
  83. </uni-popup>
  84. <!-- 付款码 -->
  85. <uni-popup ref="popupCode" :mask-click="false">
  86. <view class="">
  87. <view class="code-view">
  88. <view class="fs-42 fw-b fc-lan text-align-center">请出示{{payType == 1?'微信':'支付宝'}}付款码</view>
  89. <view class="text-align-center">
  90. <span class="fs-30 fc-9">应付</span>
  91. <span class="fs-42 fc-ED301D fw-b">¥{{totalPrice}}</span>
  92. </view>
  93. <image src="@/static/img/code-1.png" mode="scaleToFill"></image>
  94. <view class="fs-30 fc-6 text-align-center">对准下方扫描口</view>
  95. </view>
  96. <view class="code-view-1" @click="closePay()">取消支付</view>
  97. </view>
  98. </uni-popup>
  99. <!-- 手动输入 -->
  100. <uni-popup ref="inputDialog" type="dialog">
  101. <uni-popup-dialog v-model="headValue" mode="input" title="输入条码" placeholder="请输入条码"
  102. @confirm="dialogInputConfirm"></uni-popup-dialog>
  103. </uni-popup>
  104. <!-- 会员码 -->
  105. <uni-popup ref="inputMember" type="bottom" :mask-click="false">
  106. <view class="flex-common-css member-pop-view">
  107. <view class="member-pop-view-1"></view>
  108. <view class="member-pop-view-2 flex-1">
  109. <view class="flex-justify-space align-items-center mb-40">
  110. <image class="img-11" src="@/static/member/shuom.png" mode=""></image>
  111. <image @click="closePOP()" class="img-close" src="@/static/member/close.png" mode=""></image>
  112. </view>
  113. <view class="mb-40">
  114. <view class="align-items-center mb-13">
  115. <view class="yuan">1</view>
  116. <view class="align-items-center">
  117. <view class="fs-30">微信搜索</view>
  118. <view class="fs-30 fc-1778FD">振合网实体联盟</view>
  119. <view class="fs-30">公众号,点击</view>
  120. <view class="fs-30 fc-1778FD">民营经济</view>
  121. </view>
  122. </view>
  123. <view class="bg-1 flex-justify-center align-items-center">
  124. <image class="img-12" src="@/static/member/1.png" mode=""></image>
  125. <image class="img-13" src="@/static/member/right.png" mode=""></image>
  126. <image class="img-12" src="@/static/member/2.png" mode=""></image>
  127. </view>
  128. </view>
  129. <view class="mb-40">
  130. <view class="align-items-center mb-13">
  131. <view class="yuan">2</view>
  132. <view class="align-items-center">
  133. <view class="fs-30">找到个人中心点击</view>
  134. <view class="fs-30 fc-1778FD">分享码</view>
  135. </view>
  136. </view>
  137. <view class="bg-1 flex-justify-center align-items-center">
  138. <image class="img-12" src="@/static/member/3.png" mode=""></image>
  139. <image class="img-13" src="@/static/member/right.png" mode=""></image>
  140. <image class="img-12" src="@/static/member/4.png" mode=""></image>
  141. </view>
  142. </view>
  143. <view class="">
  144. <view class="align-items-center mb-13">
  145. <view class="yuan">3</view>
  146. <view class="align-items-center">
  147. <view class="fs-30">二维码对准扫描口,</view>
  148. <view class="fs-30 fc-1778FD">识别完成,显示会员IP</view>
  149. </view>
  150. </view>
  151. <view class="bg-1 flex-justify-center align-items-center">
  152. <image class="img-12" src="@/static/member/5.png" mode=""></image>
  153. <image class="img-13" src="@/static/member/right.png" mode=""></image>
  154. <image class="img-12" src="@/static/member/6.png" mode=""></image>
  155. </view>
  156. </view>
  157. </view>
  158. </view>
  159. </uni-popup>
  160. </view>
  161. </template>
  162. <script>
  163. import {
  164. projectDiscount
  165. } from '@/api/project.js';
  166. import keyboardListener from 'uniapp-keyboard-listener';
  167. import {
  168. GoodsInfo,
  169. OrderCreate,
  170. OrderPay
  171. } from '@/api/cashierApi.js'
  172. import tools from '@/common/js/tools';
  173. import Countdown from '../mod/countdown.vue'
  174. export default {
  175. components: {
  176. keyboardListener,
  177. Countdown
  178. },
  179. data() {
  180. return {
  181. isMemeber: false,
  182. discount: 0, //折扣
  183. member_id: '', //会员id
  184. invite_code: '', //推荐码
  185. totalNum: 0, //总数量
  186. totalPrice: 0, //总金额
  187. payType: '', //1微信 2支护宝
  188. goodsList: [], //商品列表
  189. outscan: false,
  190. keyArr: [],
  191. nvalue: '',
  192. auth_code: '', //付款码
  193. order_id: '',
  194. payFLag: true, //支付还是添加商品 true 添加商品 false 结算扫码
  195. isAJAX: false,
  196. headValue: '', //手动输入的值
  197. shop_id: '',
  198. };
  199. },
  200. onLoad() {
  201. this.outscan = true
  202. },
  203. beforeDestroy() {
  204. this.outscan = false
  205. },
  206. deactivated() {
  207. this.outscan = false
  208. },
  209. onShow() {
  210. this.shop_id = uni.getStorageSync('shop_id')
  211. },
  212. methods: {
  213. monitorKeyboard(e) {
  214. if (e.key.length == 1) { // 字母和数字的长度都是1,所以只要字母和数字的按键,适配不同的设备
  215. this.keyArr.push(e.key)
  216. } else if (e.key == 'Enter') { // 监听到回车
  217. let newArr = [];
  218. this.nvalue = '';
  219. // 条码中可能会有大写字母和未定义的按键,所以要过滤出来
  220. newArr = this.keyArr.filter(item => item != 'Shift' && item != 'Enter' && item != 'Unidentified')
  221. if (this.isMemeber) {
  222. if (this.isAJAX) {
  223. return
  224. }
  225. this.isAJAX = true;
  226. let href = newArr.join("")
  227. let index = href.indexOf('membercode=') + 11
  228. this.invite_code = href.substring(index, index + 8)
  229. projectDiscount({
  230. invite_code: this.invite_code
  231. }).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 / 10;
  236. this.isMemeber = false;
  237. this.$refs.inputMember.close();
  238. } else {
  239. this.isAJAX = false;
  240. tools.error(res.msg)
  241. }
  242. })
  243. } else {
  244. if (this.payFLag) {
  245. // 添加商品
  246. if (this.isAJAX) {
  247. return
  248. }
  249. this.isAJAX = true;
  250. this.nvalue = newArr.join("")
  251. this.getGoods();
  252. } else {
  253. // 支付扫码
  254. if (this.isAJAX) {
  255. return
  256. }
  257. this.isAJAX = true;
  258. this.auth_code = newArr.join("")
  259. OrderPay({
  260. order_id: this.order_id,
  261. pay_type: this.payType,
  262. auth_code: this.auth_code
  263. }).then((res) => {
  264. if (res.code == 1) {
  265. this.payFLag = true;
  266. this.isAJAX = false;
  267. uni.redirectTo({
  268. url: '/pages/index/success?money=' + this.totalPrice +
  269. "&discount=" + this.discount + '&invite_code=' + this
  270. .invite_code
  271. })
  272. } else {
  273. this.isAJAX = false;
  274. tools.error(res.msg)
  275. }
  276. })
  277. }
  278. }
  279. this.keyArr = [];
  280. }
  281. },
  282. // 获取商品
  283. getGoods() {
  284. GoodsInfo({
  285. goods_sn: this.nvalue
  286. }).then((res) => {
  287. if (res.code == 1) {
  288. this.isAJAX = false;
  289. if (this.goodsList.length == 0) {
  290. let obj = res.data;
  291. obj.num = 1;
  292. this.goodsList.push(obj)
  293. this.totalNum = 1;
  294. this.totalPrice = res.data.price;
  295. } else {
  296. let obj = res.data;
  297. let flag = true;
  298. this.goodsList.forEach((v, i) => {
  299. if (v.id == obj.id) {
  300. v.num += 1;
  301. this.totalNum += 1;
  302. this.totalPrice = (this.totalPrice * 1 + v.price * 1).toFixed(2);
  303. flag = false;
  304. }
  305. })
  306. if (flag) {
  307. obj.num = 1;
  308. this.goodsList.push(obj)
  309. this.totalNum += 1;
  310. this.totalPrice = (this.totalPrice * 1 + res.data.price * 1).toFixed(2);
  311. }
  312. }
  313. this.headValue = '';
  314. } else {
  315. this.isAJAX = false;
  316. this.headValue = '';
  317. tools.error(res.msg)
  318. }
  319. })
  320. },
  321. // 删除商品
  322. delGoods(i) {
  323. this.totalNum = this.totalNum - this.goodsList[i].num;
  324. this.totalPrice = (this.totalPrice * 1 - (this.goodsList[i].price * this.goodsList[i].num)).toFixed(2);
  325. this.goodsList.splice(i, 1)
  326. },
  327. // 减少
  328. reduce(i) {
  329. this.goodsList[i].num -= 1
  330. this.totalNum -= 1;
  331. this.totalPrice = (this.totalPrice * 1 - (this.goodsList[i].price * 1)).toFixed(2);
  332. },
  333. // 添加
  334. add(i) {
  335. this.goodsList[i].num += 1
  336. this.totalNum += 1;
  337. this.totalPrice = (this.totalPrice * 1 + this.goodsList[i].price * 1).toFixed(2);
  338. },
  339. // 支付
  340. save() {
  341. if (this.goodsList.length > 0) {
  342. this.payFLag = false;
  343. this.$refs.popup.open('center')
  344. } else {
  345. this.payFLag = true;
  346. tools.error('请添加商品')
  347. }
  348. },
  349. // 选择支付类型
  350. selectTyep(type) {
  351. this.payType = type;
  352. if (this.isAJAX) {
  353. return
  354. }
  355. this.isAJAX = true;
  356. OrderCreate({
  357. goods: this.goodsList,
  358. discount: this.discount
  359. }).then((res) => {
  360. if (res.code == 1) {
  361. this.isAJAX = false;
  362. this.order_id = res.data.order_id;
  363. this.$refs.popup.close();
  364. this.$refs.countdown.timeFun();
  365. // 扫码弹窗
  366. this.$refs.popupCode.open('center')
  367. } else {
  368. tools.error(res.msg)
  369. this.isAJAX = false;
  370. this.payFLag = true;
  371. this.order_id = '';
  372. this.payType = '';
  373. this.$refs.popup.close();
  374. }
  375. })
  376. },
  377. // 取消支付
  378. closePay() {
  379. this.payFLag = true;
  380. this.order_id = '';
  381. this.payType = '';
  382. this.$refs.popup.close();
  383. this.$refs.popupCode.close();
  384. },
  385. // 手动输入
  386. headInput() {
  387. this.$refs.inputDialog.open();
  388. },
  389. // 手动输入获取商品
  390. dialogInputConfirm() {
  391. this.nvalue = this.headValue;
  392. this.getGoods();
  393. },
  394. // 会员扫码
  395. openMenber() {
  396. // let href = "https;//finance.jhcs888.com/3/pages/finance/index/membercode=16772058project=1";
  397. // let index = href.indexOf('membercode=') + 11
  398. // this.invite_code = href.substring(index,index+8)
  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. ;
  468. height: 210rpx;
  469. }
  470. .img-13 {
  471. width: 42rpx;
  472. ;
  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>