index.vue 6.6 KB

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