index.vue 6.6 KB

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