order.vue 9.2 KB

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