order.vue 9.9 KB

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