index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <view class="pay-view">
  3. <view class="pay-head" :style="{
  4. 'height':headH*2+'rpx',
  5. 'padding-top':headPTop*2+'rpx',
  6. 'line-height':headH*2+'rpx',
  7. }">{{shop_name}}</view>
  8. <view class="pay-info">
  9. <view class="pay-info-input">
  10. <view class="info-text">消费总额</view>
  11. <view class="info-input">¥ {{totalNum}}</view>
  12. <view class="info-text">可询问工作人员应缴费用总额</view>
  13. </view>
  14. <view class="pay-info-sumit" @click="sumbit()">支付</view>
  15. </view>
  16. <view class="pay-num">
  17. <view class="pay-num-input" @click="setNum(item)" v-for="(item,i) in numList" :key="i">{{item}}</view>
  18. <view class="pay-num-input" @click="delNum()">
  19. <view class="pay-num-del">
  20. <view class="pay-num-del-wrap">x</view>
  21. </view>
  22. </view>
  23. </view>
  24. <view v-html="zfbUrl"></view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. payImgInfo,payPay
  30. } from '@/http/shop_order.js'
  31. import tools from "@/service/tools.js";
  32. import {
  33. getPhoneTopHeight,
  34. getNavHeight,
  35. isWx,
  36. } from "@/service/utils.js";
  37. export default {
  38. data() {
  39. return {
  40. shop_name: '',
  41. shop_id: '',
  42. order_id: '',
  43. headH: 0,
  44. headPTop: 0,
  45. numList: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '0'],
  46. totalNum: '',
  47. isAJAX: false,
  48. zfbUrl: '',
  49. code_type: 1,
  50. shop_code: '',
  51. }
  52. },
  53. onLoad(data) {
  54. // #ifdef H5
  55. let isWeiXin = isWx();
  56. if (isWeiXin) {
  57. const href = window.location.href
  58. if (href.indexOf('?code=') > -1 || href.indexOf('&code=') > -1) {
  59. const urlArr = href.split('?')
  60. const rightUrlArr = urlArr[1].split('#/')
  61. const queryObj = {}
  62. rightUrlArr[0].split('&').map((item) => {
  63. const splitStr = item.split('=')
  64. return {
  65. key: splitStr[0],
  66. value: splitStr[1],
  67. }
  68. }).forEach((item) => {
  69. queryObj[item.key] = item.value
  70. })
  71. if (urlArr.length >= 3) {
  72. rightUrlArr[1] = "?" + urlArr[2]
  73. }
  74. let from = {
  75. code: queryObj.code,
  76. wx_type: 1,
  77. }
  78. // await getUserInfo(from).then(async (res) => {
  79. // if (res.code === 1) {
  80. // uni.setStorageSync('m_id')
  81. // uni.setStorageSync('token')
  82. // }
  83. // })
  84. } else {
  85. // 认证失败
  86. tools.wxLogin();
  87. }
  88. }
  89. if(isWeiXin){
  90. tools.wxInitialize(["chooseWXPay"]);
  91. }
  92. // #endif
  93. this.headH = getNavHeight();
  94. this.headPTop = getPhoneTopHeight();
  95. if (data.shop_code !== undefined) {
  96. this.shop_code = data.shop_code
  97. this.code_type = data.img_type
  98. } else {
  99. uni.reLaunch({
  100. url: `/pages/error?msg=` + '店铺信息错误,请重新扫码。'
  101. })
  102. return
  103. }
  104. payImgInfo({
  105. code: this.shop_code
  106. }).then((res) => {
  107. if (res.code === 1) {
  108. this.shop_id = res.data.id;
  109. this.shop_name = res.data.shop_name;
  110. uni.setStorageSync("shopName", this.shop_name)
  111. }
  112. })
  113. },
  114. methods: {
  115. setNum(item) {
  116. this.totalNum += item
  117. },
  118. delNum() {
  119. if (this.totalNum) {
  120. this.totalNum = this.totalNum.slice(0, this.totalNum.length - 1)
  121. } else {
  122. tools.error('请输入金额')
  123. }
  124. },
  125. sumbit() {
  126. if (!this.totalNum || this.totalNum * 1 <= 0) {
  127. return tools.error('请输入金额')
  128. }
  129. let reg = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
  130. if (!reg.test(this.totalNum)) {
  131. return tools.error('金额格式错误')
  132. }
  133. let pay_type //1:微信,2:支付宝
  134. let ua = navigator.userAgent.toLowerCase();
  135. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  136. pay_type = 1
  137. } else {
  138. pay_type = 2
  139. }
  140. if (this.isAJAX) {
  141. return
  142. }
  143. this.isAJAX = true
  144. if (!this.code_type) {
  145. this.code_type = 1 //烟草码
  146. }
  147. payPay({
  148. code: this.shop_code,
  149. pay_money: this.totalNum,
  150. pay_code_source: this.code_type,
  151. pay_type: pay_type,
  152. m_id:uni.getStorageSync('m_id')?uni.getStorageSync('m_id'):0,
  153. token:uni.getStorageSync('token')?uni.getStorageSync('token'):''
  154. }).then((res) => {
  155. if (res.code === 1) {
  156. this.order_id = res.data.order_id
  157. if (res.data.is_bank == 0 && res.data.is_yee == 1) {
  158. if (pay_type === 1) {
  159. this.isAJAX = false
  160. if (res.data.wx_pay) {
  161. this.weiXinPayH5(res.data.wx_pay);
  162. } else {
  163. tools.error("支付生成失败");
  164. }
  165. } else {
  166. window.location.href = res.data.pay_data;
  167. }
  168. } else {
  169. window.location.href = res.data.pay_data;
  170. }
  171. } else {
  172. this.isAJAX = false
  173. tools.error(res.msg);
  174. }
  175. })
  176. },
  177. payOk(rs_sn) {
  178. // uni.redirectTo({
  179. // url: `/pages-order/pay-success/index?order_id=${this.order_id}&money=${this.totalNum}&rs_sn=${rs_sn}`,
  180. // });
  181. },
  182. async weiXinPayH5(wxPayData) {
  183. const res = await tools.weiXinPay(wxPayData);
  184. if (res) {
  185. this.payOk(wxPayData.rs_sn);
  186. }
  187. },
  188. },
  189. }
  190. </script>
  191. <style scoped lang="scss">
  192. .pay-view {
  193. width: 100%;
  194. height: 100vh;
  195. display: flex;
  196. flex-direction: column;
  197. .pay-head {
  198. font-size: 40rpx;
  199. font-weight: 600;
  200. text-align: center;
  201. background-color: #fff;
  202. }
  203. .pay-info {
  204. flex: 1;
  205. overflow: auto;
  206. box-sizing: border-box;
  207. padding: 20rpx;
  208. .pay-info-sumit {
  209. margin-top: 30rpx;
  210. width: 100%;
  211. height: 90rpx;
  212. line-height: 90rpx;
  213. text-align: center;
  214. border-radius: 200rpx;
  215. background: linear-gradient(to right, #FE9387, #FB604E, #F83820);
  216. color: #fff;
  217. font-size: 32rpx;
  218. }
  219. .pay-info-input {
  220. width: 100%;
  221. height: 330rpx;
  222. background-color: #fff;
  223. box-sizing: border-box;
  224. padding: 20rpx;
  225. .info-text {
  226. font-size: 30rpx;
  227. color: #aaa;
  228. }
  229. .info-input {
  230. width: 100%;
  231. height: 100rpx;
  232. line-height: 100rpx;
  233. margin: 36rpx 0;
  234. padding-bottom: 20rpx;
  235. border-bottom: 1rpx solid #E4E4E4;
  236. font-size: 52rpx;
  237. font-weight: 600;
  238. }
  239. }
  240. }
  241. .pay-num {
  242. width: 100%;
  243. height: 600rpx;
  244. background: rgb(208, 211, 220);
  245. display: flex;
  246. justify-content: space-between;
  247. flex-flow: row wrap;
  248. box-sizing: border-box;
  249. padding: 30rpx;
  250. .pay-num-input {
  251. width: 215rpx;
  252. height: 110rpx;
  253. background-color: #fff;
  254. border-radius: 16rpx;
  255. text-align: center;
  256. line-height: 110rpx;
  257. font-size: 40rpx;
  258. font-weight: bold;
  259. }
  260. $height: 20rpx;
  261. .pay-num-del {
  262. margin-top: 38rpx;
  263. box-sizing: border-box;
  264. padding-left: 25rpx;
  265. line-height: 35rpx !important;
  266. font-weight: 400 !important;
  267. &-wrap {
  268. margin: 0 auto;
  269. width: 40rpx;
  270. height: $height * 2;
  271. background-color: #dedede;
  272. position: relative;
  273. &::after {
  274. content: '';
  275. position: absolute;
  276. left: -$height * 2;
  277. border: $height solid transparent;
  278. border-right: $height solid #dedede;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. </style>