index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. console.log(res);
  157. return
  158. if (res.code === 1) {
  159. this.order_id = res.data.order_id
  160. if (res.data.is_bank == 0 && res.data.is_yee == 1) {
  161. if (pay_type === 1) {
  162. this.isAJAX = false
  163. if (res.data.pay_data) {
  164. this.weiXinPayH5(res.data.pay_data);
  165. } else {
  166. tools.error("支付生成失败");
  167. }
  168. } else {
  169. window.location.href = res.data.pay_data;
  170. }
  171. } else {
  172. window.location.href = res.data.pay_data;
  173. }
  174. } else {
  175. this.isAJAX = false
  176. tools.error(res.msg);
  177. }
  178. })
  179. },
  180. payOk(rs_sn) {
  181. // uni.redirectTo({
  182. // url: `/pages-order/pay-success/index?order_id=${this.order_id}&money=${this.totalNum}&rs_sn=${rs_sn}`,
  183. // });
  184. },
  185. async weiXinPayH5(wxPayData) {
  186. const res = await tools.weiXinPay(wxPayData);
  187. if (res) {
  188. console.log(res);
  189. this.payOk(wxPayData.rs_sn);
  190. }
  191. },
  192. },
  193. }
  194. </script>
  195. <style scoped lang="scss">
  196. .pay-view {
  197. width: 100%;
  198. height: 100vh;
  199. display: flex;
  200. flex-direction: column;
  201. .pay-head {
  202. font-size: 40rpx;
  203. font-weight: 600;
  204. text-align: center;
  205. background-color: #fff;
  206. }
  207. .pay-info {
  208. flex: 1;
  209. overflow: auto;
  210. box-sizing: border-box;
  211. padding: 20rpx;
  212. .pay-info-sumit {
  213. margin-top: 30rpx;
  214. width: 100%;
  215. height: 90rpx;
  216. line-height: 90rpx;
  217. text-align: center;
  218. border-radius: 200rpx;
  219. background: linear-gradient(to right, #FE9387, #FB604E, #F83820);
  220. color: #fff;
  221. font-size: 32rpx;
  222. }
  223. .pay-info-input {
  224. width: 100%;
  225. height: 330rpx;
  226. background-color: #fff;
  227. box-sizing: border-box;
  228. padding: 20rpx;
  229. .info-text {
  230. font-size: 30rpx;
  231. color: #aaa;
  232. }
  233. .info-input {
  234. width: 100%;
  235. height: 100rpx;
  236. line-height: 100rpx;
  237. margin: 36rpx 0;
  238. padding-bottom: 20rpx;
  239. border-bottom: 1rpx solid #E4E4E4;
  240. font-size: 52rpx;
  241. font-weight: 600;
  242. }
  243. }
  244. }
  245. .pay-num {
  246. width: 100%;
  247. height: 600rpx;
  248. background: rgb(208, 211, 220);
  249. display: flex;
  250. justify-content: space-between;
  251. flex-flow: row wrap;
  252. box-sizing: border-box;
  253. padding: 30rpx;
  254. .pay-num-input {
  255. width: 215rpx;
  256. height: 110rpx;
  257. background-color: #fff;
  258. border-radius: 16rpx;
  259. text-align: center;
  260. line-height: 110rpx;
  261. font-size: 40rpx;
  262. font-weight: bold;
  263. }
  264. $height: 20rpx;
  265. .pay-num-del {
  266. margin-top: 38rpx;
  267. box-sizing: border-box;
  268. padding-left: 25rpx;
  269. line-height: 35rpx !important;
  270. font-weight: 400 !important;
  271. &-wrap {
  272. margin: 0 auto;
  273. width: 40rpx;
  274. height: $height * 2;
  275. background-color: #dedede;
  276. position: relative;
  277. &::after {
  278. content: '';
  279. position: absolute;
  280. left: -$height * 2;
  281. border: $height solid transparent;
  282. border-right: $height solid #dedede;
  283. }
  284. }
  285. }
  286. }
  287. }
  288. </style>