index.vue 6.6 KB

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