index.vue 7.6 KB

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