order.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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. <!-- 3 -->
  36. <view class="box-2">
  37. <view class="">
  38. {{msgTest}}
  39. </view>
  40. <view class="box-2-shou flex-justify-center align-items-center" @click="headInput()">
  41. <image src="@/static/img/txm.png" mode=""></image>
  42. <view class="fs-30 fc-3 fw-400">手输条码</view>
  43. </view>
  44. <view class="flex-justify-space">
  45. <view class="">
  46. <view class="fs-30 fc-3">共{{totalNum}}件</view>
  47. <view class="">
  48. <span class="fs-30 fc-3">合计</span>
  49. <span class="fs-30 fc-ED301D">¥</span>
  50. <span class="fs-40 fc-ED301D fw-600">{{totalPrice}}</span>
  51. </view>
  52. </view>
  53. <view class="to-save text-align-center fs-32 fc-f" @click="save()">去结算</view>
  54. </view>
  55. </view>
  56. <keyboard-listener v-if="outscan" @keyup="monitorKeyboard"></keyboard-listener>
  57. <!-- 支付类型 -->
  58. <uni-popup ref="popup" :mask-click="false">
  59. <view class="">
  60. <view class="pop-view mb-25">
  61. <view class="fs-32 fw-600 pop-1 pop-view-1">请选择支付类型</view>
  62. <view class="pop-2">
  63. <view class="fs-32 pop-1 pop-view-1 fc-lv" @click="selectTyep(1)">微信</view>
  64. <view class="fs-32 pop-1 fc-lan" @click="selectTyep(2)">支付宝</view>
  65. </view>
  66. </view>
  67. <view class="code-view-1" @click="closePay()">取消支付</view>
  68. </view>
  69. </uni-popup>
  70. <!-- 付款码 -->
  71. <uni-popup ref="popupCode" :mask-click="false">
  72. <view class="">
  73. <view class="code-view">
  74. <view class="fs-42 fw-b fc-lan text-align-center">请出示{{payType == 1?'微信':'支付宝'}}付款码</view>
  75. <view class="text-align-center">
  76. <span class="fs-30 fc-9">应付</span>
  77. <span class="fs-42 fc-ED301D fw-b">¥{{totalPrice}}</span>
  78. </view>
  79. <image src="@/static/img/code-1.png" mode="scaleToFill"></image>
  80. <view class="fs-30 fc-6 text-align-center">对准下方扫描口</view>
  81. </view>
  82. <view class="code-view-1" @click="closePay()">取消支付</view>
  83. </view>
  84. </uni-popup>
  85. <!-- 手动输入 -->
  86. <uni-popup ref="inputDialog" type="dialog">
  87. <uni-popup-dialog v-model="headValue" mode="input" title="输入条码" placeholder="请输入条码" @confirm="dialogInputConfirm"></uni-popup-dialog>
  88. </uni-popup>
  89. </view>
  90. </template>
  91. <script>
  92. import keyboardListener from 'uniapp-keyboard-listener';
  93. import {GoodsInfo,OrderCreate,OrderPay} from '@/api/cashierApi.js'
  94. import tools from '@/common/js/tools';
  95. import Countdown from '../mod/countdown.vue'
  96. export default {
  97. components: {keyboardListener,Countdown},
  98. data() {
  99. return {
  100. totalNum:0,//总数量
  101. totalPrice:0,//总金额
  102. payType:'',//1微信 2支护宝
  103. goodsList:[],//商品列表
  104. outscan:false,
  105. keyArr:[],
  106. nvalue:'',
  107. auth_code:'',//付款码
  108. order_id:'',
  109. payFLag:true,//支付还是添加商品 true 添加商品 false 结算扫码
  110. isAJAX:false,
  111. headValue:'',//手动输入的值
  112. msgTest:'',
  113. };
  114. },
  115. onLoad() {
  116. this.outscan=true
  117. },
  118. beforeDestroy() {
  119. this.outscan=false
  120. },
  121. deactivated() {
  122. this.outscan=false
  123. },
  124. mounted() {
  125. },
  126. methods: {
  127. monitorKeyboard(e) {
  128. if (e.key.length == 1) { // 字母和数字的长度都是1,所以只要字母和数字的按键,适配不同的设备
  129. this.keyArr.push(e.key)
  130. } else if (e.key == 'Enter') { // 监听到回车
  131. let newArr = [];
  132. this.nvalue = '';
  133. // 条码中可能会有大写字母和未定义的按键,所以要过滤出来
  134. newArr = this.keyArr.filter(item => item != 'Shift' && item != 'Enter' && item != 'Unidentified')
  135. if(this.payFLag){
  136. // 添加商品
  137. if(this.isAJAX){
  138. return
  139. }
  140. this.isAJAX = true;
  141. this.nvalue = newArr.join("")
  142. this.getGoods();
  143. }else{
  144. // 支付扫码
  145. if(this.isAJAX){
  146. return
  147. }
  148. this.isAJAX = true;
  149. this.auth_code = newArr.join("")
  150. OrderPay({order_id:this.order_id,pay_type:this.payType,auth_code:this.auth_code}).then((res)=>{
  151. this.msgTest = res
  152. if(res.code == 1){
  153. this.payFLag = true;
  154. this.isAJAX = false;
  155. uni.redirectTo({
  156. url:'/pages/index/success?money=' + this.totalPrice
  157. })
  158. }else{
  159. this.isAJAX = false;
  160. tools.error(res.msg)
  161. }
  162. })
  163. }
  164. this.keyArr = [];
  165. }
  166. },
  167. // 获取商品
  168. getGoods(){
  169. GoodsInfo({goods_sn:this.nvalue}).then((res)=>{
  170. if(res.code == 1){
  171. this.isAJAX = false;
  172. if(this.goodsList.length == 0){
  173. let obj = res.data;
  174. obj.num = 1;
  175. this.goodsList.push(obj)
  176. this.totalNum = 1;
  177. this.totalPrice = res.data.price;
  178. }else{
  179. let obj = res.data;
  180. let flag = true;
  181. this.goodsList.forEach((v,i)=>{
  182. if(v.id == obj.id){
  183. v.num += 1;
  184. this.totalNum += 1;
  185. this.totalPrice = (this.totalPrice*1 + v.price*1).toFixed(2);
  186. flag = false;
  187. }
  188. })
  189. if(flag){
  190. obj.num = 1;
  191. this.goodsList.push(obj)
  192. this.totalNum += 1;
  193. this.totalPrice = (this.totalPrice*1 + res.data.price*1).toFixed(2);
  194. }
  195. }
  196. this.headValue = '';
  197. }else{
  198. this.isAJAX = false;
  199. this.headValue = '';
  200. tools.error(res.msg)
  201. }
  202. })
  203. },
  204. // 删除商品
  205. delGoods(i){
  206. this.totalNum = this.totalNum - this.goodsList[i].num;
  207. this.totalPrice = (this.totalPrice*1 - (this.goodsList[i].price*this.goodsList[i].num)).toFixed(2);
  208. this.goodsList.splice(i,1)
  209. },
  210. // 减少
  211. reduce(i){
  212. this.goodsList[i].num -= 1
  213. this.totalNum -= 1;
  214. this.totalPrice = (this.totalPrice*1 - (this.goodsList[i].price*1)).toFixed(2);
  215. },
  216. // 添加
  217. add(i){
  218. this.goodsList[i].num += 1
  219. this.totalNum += 1;
  220. this.totalPrice = (this.totalPrice*1 + this.goodsList[i].price*1).toFixed(2);
  221. },
  222. // 支付
  223. save(){
  224. if(this.goodsList.length > 0){
  225. this.payFLag = false;
  226. this.$refs.popup.open('center')
  227. }else{
  228. this.payFLag = true;
  229. tools.error('请添加商品')
  230. }
  231. },
  232. // 选择支付类型
  233. selectTyep(type){
  234. this.payType = type;
  235. if(this.isAJAX){
  236. return
  237. }
  238. this.isAJAX = true;
  239. OrderCreate({goods:this.goodsList}).then((res)=>{
  240. if(res.code == 1){
  241. this.isAJAX = false;
  242. this.order_id = res.data.order_id;
  243. this.$refs.popup.close();
  244. this.$refs.countdown.timeFun();
  245. // 扫码弹窗
  246. this.$refs.popupCode.open('center')
  247. }else{
  248. tools.error(res.msg)
  249. this.isAJAX = false;
  250. this.payFLag = true;
  251. this.order_id = '';
  252. this.payType = '';
  253. this.$refs.popup.close();
  254. }
  255. })
  256. },
  257. // 取消支付
  258. closePay(){
  259. this.payFLag = true;
  260. this.order_id = '';
  261. this.payType = '';
  262. this.$refs.popup.close();
  263. this.$refs.popupCode.close();
  264. },
  265. // 手动输入
  266. headInput(){
  267. this.$refs.inputDialog.open();
  268. },
  269. // 手动输入获取商品
  270. dialogInputConfirm(){
  271. this.nvalue = this.headValue;
  272. this.getGoods();
  273. },
  274. },
  275. };
  276. </script>
  277. <style scoped lang="scss">
  278. .index-home{
  279. .no-img{
  280. width: 200rpx;
  281. height: 200rpx;
  282. margin: 30% auto 30rpx auto;
  283. }
  284. .box-1{
  285. width: 100%;
  286. height: 150rpx;
  287. box-sizing: border-box;
  288. padding: 80rpx 0 0 24rpx;
  289. position: relative;
  290. .box-1-time{
  291. position: absolute;
  292. bottom: 20rpx;
  293. right: 20rpx;
  294. }
  295. image{
  296. width: 48rpx;
  297. height: 48rpx;
  298. margin-right: 10rpx;
  299. }
  300. }
  301. .list-box{
  302. background-color: #F2F3F5;
  303. box-sizing: border-box;
  304. padding: 17rpx 24rpx;
  305. .goods-box{
  306. width: 100%;
  307. height: 179rpx;
  308. background: #FFFFFF;
  309. border-radius: 17rpx;
  310. margin-bottom: 17rpx;
  311. box-sizing: border-box;
  312. padding: 25rpx;
  313. image{
  314. width: 129rpx;
  315. height: 129rpx;
  316. border-radius: 14rpx;
  317. margin-right: 16rpx;
  318. }
  319. .text-1{
  320. width: 440rpx;
  321. font-size: 25rpx;
  322. margin-bottom: 40rpx;
  323. }
  324. .num-buttom{
  325. width: 50rpx;
  326. height: 50rpx;
  327. line-height: 50rpx;
  328. border-radius: 50%;
  329. background-color: #DAE9FF;
  330. color: #1778FD;
  331. font-weight: 600;
  332. text-align: center;
  333. font-size: 32rpx
  334. }
  335. .num-box{
  336. width: 110rpx;
  337. height: 50rpx;
  338. line-height: 50rpx;
  339. text-align: center;
  340. font-size: 33rpx;
  341. font-weight: 600;
  342. }
  343. }
  344. }
  345. .box-2{
  346. width: 100%;
  347. height: 220rpx;
  348. box-sizing: border-box;
  349. padding: 20rpx 16rpx;
  350. .box-2-shou{
  351. width: 177rpx;
  352. height: 58rpx;
  353. border-radius: 104rpx;
  354. border: 2rpx solid #CCCCCC;
  355. margin: 0 0 20rpx auto;
  356. image{
  357. width: 25rpx;
  358. height: 25rpx;
  359. }
  360. }
  361. .to-save{
  362. margin-top: auto;
  363. width: 292rpx;
  364. height: 83rpx;
  365. line-height: 83rpx;
  366. background: linear-gradient( 90deg, #4AB6FF 0%, #1778FD 100%);
  367. box-shadow: 0rpx 0rpx 4rpx 0rpx rgba(108,168,252,0.64);
  368. border-radius: 104rpx;
  369. }
  370. }
  371. }
  372. .pop-view{
  373. width: 500rpx;
  374. min-height: 100rpx;
  375. background-color: #fff;
  376. border-radius: 20rpx;
  377. .pop-1{
  378. box-sizing: border-box;
  379. height: 120rpx;
  380. width: 100%;
  381. text-align: center;
  382. line-height: 120rpx;
  383. }
  384. .pop-2{
  385. box-sizing: border-box;
  386. padding: 0 50rpx;
  387. }
  388. .pop-view-1{
  389. border-bottom: 1rpx solid #ccc;
  390. }
  391. }
  392. .code-view{
  393. width: 633rpx;
  394. height: 710rpx;
  395. background-image: url('@/static/img/code-bg.png');
  396. background-size: 100% 100%;
  397. box-sizing: border-box;
  398. padding: 62rpx 0 0 0;
  399. margin-bottom: 62rpx;
  400. image{
  401. width: 327rpx;
  402. height: 327rpx;
  403. margin: 50rpx auto 25rpx auto;
  404. }
  405. }
  406. .code-view-1{
  407. text-align: center;
  408. margin: 0 auto;
  409. width: 223rpx;
  410. height: 57rpx;
  411. line-height: 57rpx;
  412. border-radius: 104rpx;
  413. border: 2rpx solid #fff;
  414. text-align: center;
  415. color: #fff;
  416. font-size: 32rpx;
  417. }
  418. </style>