index.vue 6.9 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 {payImgInfo,payPay} from '@/http/shop_order.js';
  29. import {memberLogin} from '@/http/member.js';
  30. import tools from "@/service/tools.js";
  31. import {
  32. getPhoneTopHeight,
  33. getNavHeight,
  34. isWx,
  35. } from "@/service/utils.js";
  36. export default {
  37. data() {
  38. return {
  39. shop_name: '',
  40. shop_id: '',
  41. order_id: '',
  42. headH: 0,
  43. headPTop: 0,
  44. numList: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '0'],
  45. totalNum: '',
  46. isAJAX: false,
  47. zfbUrl: '',
  48. code_type: 1,
  49. shop_code: '',
  50. m_id:'',
  51. token:'',
  52. }
  53. },
  54. onLoad(data) {
  55. // #ifdef H5
  56. let isWeiXin = isWx();
  57. if (isWeiXin) {
  58. const href = window.location.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. memberLogin(from).then((res)=>{
  80. if (res.code == 1) {
  81. uni.setStorageSync('m_id',res.data.m_id)
  82. uni.setStorageSync('token',res.data.token)
  83. }
  84. })
  85. } else {
  86. // 认证失败
  87. tools.wxLogin();
  88. }
  89. }
  90. if(isWeiXin){
  91. tools.wxInitialize(["chooseWXPay"]);
  92. }
  93. // #endif
  94. this.headH = getNavHeight();
  95. this.headPTop = getPhoneTopHeight();
  96. if (data.shop_code !== undefined) {
  97. this.shop_code = data.shop_code
  98. this.code_type = data.img_type
  99. } else {
  100. uni.reLaunch({
  101. url: `/pages/error?msg=` + '店铺信息错误,请重新扫码。'
  102. })
  103. return
  104. }
  105. payImgInfo({
  106. code: this.shop_code
  107. }).then((res) => {
  108. if (res.code === 1) {
  109. this.shop_id = res.data.id;
  110. this.shop_name = res.data.shop_name;
  111. uni.setStorageSync("shopName", this.shop_name)
  112. }
  113. })
  114. },
  115. methods: {
  116. setNum(item) {
  117. this.totalNum += item
  118. },
  119. delNum() {
  120. if (this.totalNum) {
  121. this.totalNum = this.totalNum.slice(0, this.totalNum.length - 1)
  122. } else {
  123. tools.error('请输入金额')
  124. }
  125. },
  126. sumbit() {
  127. if (!this.totalNum || this.totalNum * 1 <= 0) {
  128. return tools.error('请输入金额')
  129. }
  130. let reg = /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
  131. if (!reg.test(this.totalNum)) {
  132. return tools.error('金额格式错误')
  133. }
  134. let pay_type //1:微信,2:支付宝
  135. let ua = navigator.userAgent.toLowerCase();
  136. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  137. pay_type = 1
  138. } else {
  139. pay_type = 2
  140. }
  141. if (this.isAJAX) {
  142. return
  143. }
  144. this.isAJAX = true
  145. if (!this.code_type) {
  146. this.code_type = 1 //烟草码
  147. }
  148. payPay({
  149. code: this.shop_code,
  150. pay_money: this.totalNum,
  151. pay_code_source: this.code_type,
  152. pay_type: pay_type,
  153. m_id:uni.getStorageSync('m_id')?uni.getStorageSync('m_id'):0,
  154. token:uni.getStorageSync('token')?uni.getStorageSync('token'):''
  155. }).then((res) => {
  156. if (res.code === 1) {
  157. this.order_id = res.data.order_id
  158. if (res.data.is_bank == 0 && res.data.is_yee == 1) {
  159. if (pay_type === 1) {
  160. this.isAJAX = false
  161. if (res.data.pay_data) {
  162. this.weiXinPayH5(res.data.pay_data);
  163. } else {
  164. tools.error("支付生成失败");
  165. }
  166. } else {
  167. window.location.href = res.data.pay_data;
  168. }
  169. } else {
  170. window.location.href = res.data.pay_data;
  171. }
  172. } else {
  173. this.isAJAX = false
  174. tools.error(res.msg);
  175. }
  176. })
  177. },
  178. payOk(rs_sn) {
  179. // uni.redirectTo({
  180. // url: `/pages-order/pay-success/index?order_id=${this.order_id}&money=${this.totalNum}&rs_sn=${rs_sn}`,
  181. // });
  182. },
  183. async weiXinPayH5(wxPayData) {
  184. const res = await tools.weiXinPay(wxPayData);
  185. if (res) {
  186. console.log(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>