pay.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <view class="login-main">
  3. <view style="width: 100%; height: 220px">
  4. <view class="login-main-content">
  5. <image class="img" :src="shopInfo.store_logo_url?shopInfo.store_logo_url:'/static/images/error.jpeg'"
  6. mode=""></image>
  7. <h4 class="shopName">{{shopInfo?shopInfo.store_name:""}}</h4>
  8. </view>
  9. </view>
  10. <view class="login-contont">
  11. <view class="uInput">
  12. <u-input placeholder="请输入金额" border="bottom" :fontSize="40" type="digit"
  13. @change="validateInput($event,1)" v-model="price" :customStyle="inpustyle">
  14. <span slot="prefix" style="font-size: 30px">¥</span>
  15. </u-input>
  16. </view>
  17. <view class="login-contont-button">
  18. <button class="btn" @click="Pay">立即支付</button>
  19. <view style="margin-top: 20rpx; font-size: 26rpx">
  20. 支付成功后,次日有奖励红包,农商直采小程序领取
  21. </view>
  22. </view>
  23. </view>
  24. <u-popup :zIndex="200" :overlayStyle={zIndex:200} :show="showPhone" @close="close" @open="open"
  25. :safeAreaInsetTop="true" round="20">
  26. <view class="popup">
  27. <view class="header">
  28. <h4>绑定手机号</h4>
  29. <p class="tip">注意:首次登录,需绑定手机号才可成功领取农商网红包</p>
  30. </view>
  31. <view class="main">
  32. <view style="height: 70rpx">
  33. <u--input placeholder="请输入手机号" type="number" border="surround" v-model="phone"
  34. style="background: #F4F4F4;height:100%" />
  35. </view>
  36. <view style="margin-top: 20px;height: 70rpx">
  37. <u--input placeholder="验证码" border="surround" v-model="yzm"
  38. style="background: #F4F4F4;height:100%">
  39. <template slot="suffix">
  40. <u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
  41. <!-- <u-button @tap="getCode" :text="tips" type="success" size="mini"></u-button> -->
  42. <text class="yzm" @tap="getCode">{{tips?tips:'发送验证码'}}</text>
  43. </template>
  44. </u--input>
  45. </view>
  46. </view>
  47. <view class="footer">
  48. <u-button type="primary" class="btn" text="确定" @click="submitOk"></u-button>
  49. </view>
  50. </view>
  51. </u-popup>
  52. </view>
  53. </template>
  54. <script>
  55. import {
  56. requestConfig
  57. } from "@/app.config.js";
  58. import axios from "axios";
  59. export default {
  60. data() {
  61. return {
  62. showPhone: false,
  63. requestConfig: requestConfig,
  64. code: "",
  65. appid: "",
  66. value: "",
  67. userInfo: {},
  68. inpustyle: {
  69. fontWeight: "bold",
  70. fontSize: "40px",
  71. },
  72. phone: "",
  73. yzm: "",
  74. tips: null,
  75. price: null,
  76. shopId: "",
  77. shopInfo: {},
  78. localUserInfo: {},
  79. uid: ""
  80. };
  81. },
  82. onLoad(options) {
  83. this.shopId = options.shopId
  84. this.uid = options.uid || ''
  85. console.log(this.uid);
  86. let info = localStorage.getItem('weChatUserInfo');
  87. console.log(info);
  88. this.localUserInfo = JSON.parse(info)
  89. if (this.localUserInfo) {
  90. this.vidTokenExist()
  91. } else {
  92. this.getShopInfo();
  93. this.getInfo();
  94. }
  95. },
  96. methods: {
  97. async vidTokenExist() {
  98. let res = await axios.get(
  99. `${requestConfig.BaseUrl}user/app/v1/user/vidTokenExist`, {
  100. headers: {
  101. 'token': `${this.localUserInfo.token}`
  102. }
  103. });
  104. if (res.data.code == 200) {
  105. this.userInfo = this.localUserInfo;
  106. this.getShopInfo();
  107. } else {
  108. uni.$u.toast('登录已过期,请重新登录!');
  109. localStorage.removeItem('weChatUserInfo');
  110. setTimeout(() => {
  111. uni.redirectTo({
  112. url: '/pages/index/index?shopId=' + this.shopId + '&uid=' + this.uid
  113. })
  114. }, 1000)
  115. }
  116. },
  117. validateInput(e, num) {
  118. const inputTypeNum = /[^\d]/g //数字
  119. switch (num) {
  120. case 1:
  121. //要写nextTick 不然无效
  122. this.$nextTick(() => {
  123. this.listData.integral = e.replace(inputTypeNum, '');
  124. })
  125. break;
  126. }
  127. },
  128. async getShopInfo() {
  129. let res = await axios.get(
  130. `${requestConfig.BaseUrl}user/app/v1/store/getStoreInfoByScan?shopId=${this.shopId}${this.uid?'&uid='+this.uid:''}`, {
  131. headers: {
  132. 'token': `${this.userInfo.token}`
  133. }
  134. });
  135. if (res.data.code == 200) {
  136. this.shopInfo = res.data.data
  137. } else {
  138. uni.$u.toast(res.data.msg);
  139. }
  140. },
  141. async submitOk() {
  142. if (this.phone == "") {
  143. uni.$u.toast('请输入手机号');
  144. } else if (this.yzm == "") {
  145. uni.$u.toast('请输入验证码');
  146. }
  147. const res = await axios.post(
  148. `${requestConfig.BaseUrl}user/app/v1/user/bindPhone?mpOpenid=${this.userInfo.mpOpenid}&phone=${this.phone}&code=${this.yzm}&unionid=${this.userInfo.unionid}`
  149. );
  150. if (res.data.code == 200) {
  151. uni.$u.toast('绑定手机号成功');
  152. this.userInfo = res.data.data
  153. this.showPhone = false
  154. this.getShopInfo()
  155. } else {
  156. uni.$u.toast('绑定手机号失败!');
  157. }
  158. },
  159. codeChange(text) {
  160. this.tips = text;
  161. },
  162. async getCode() {
  163. if (this.$refs.uCode.canGetCode) {
  164. const res = await axios.post(
  165. `${requestConfig.BaseUrl}third/app/v1/third/getSMSCode?phone=${this.phone}`
  166. );
  167. uni.showLoading({
  168. title: '正在获取验证码'
  169. })
  170. setTimeout(() => {
  171. uni.hideLoading();
  172. uni.$u.toast('验证码已发送');
  173. this.$refs.uCode.start();
  174. }, 2000);
  175. } else {
  176. uni.$u.toast('倒计时结束后再发送');
  177. }
  178. },
  179. async Pay() {
  180. uni.showLoading({
  181. title: '支付中'
  182. });
  183. // uni.hideLoading();
  184. // window.open(`${requestConfig.redirectOpen}pages/index/paySuccess`)
  185. if (!this.price) {
  186. uni.$u.toast('请输入支付金额!');
  187. }
  188. let res = await axios.get(`${requestConfig.BaseUrl}order/app/v1/buyer/order/createOfflineOrder
  189. ?shopId=${this.shopId}&price=${this.price}${this.uid?'&uid='+this.uid:''}`, {
  190. headers: {
  191. 'token': `${this.userInfo.token}`
  192. }
  193. });
  194. if (res.data.code == 200) {
  195. //post请求
  196. let data = {
  197. "orderId": res.data.data, //订单id
  198. "orderType": 11, //订单类型 -1--其他 2-司机保证金 3-商品交易 4-线下交易
  199. "payKinds": 0, //支付类型 0-微信 1-支付宝
  200. "payMeth": 6 //5-微信小程序支付 6-微信H5支付 7-支付宝app支付
  201. }
  202. const pay = await axios.post(`${requestConfig.BaseUrl}order/app/v1/buyer/order/offlineOrderPay
  203. `, data, {
  204. headers: {
  205. 'Token': `${this.userInfo.token}`
  206. }
  207. });
  208. if (pay.data.code == 200) {
  209. let res = JSON.parse(pay.data.data.result)
  210. console.log(res);
  211. WeixinJSBridge.invoke(
  212. "getBrandWCPayRequest", {
  213. // 公众号名称,由商户传入
  214. appId: res.appId,
  215. // 时间戳,自1970年以来的秒数
  216. timeStamp: res.timeStamp,
  217. // 随机串
  218. nonceStr: res.nonceStr,
  219. package: res.package,
  220. // 微信签名方式:
  221. signType: res.signType,
  222. // 微信签名
  223. paySign: res.paySign,
  224. },
  225. function(res) {
  226. if (res.err_msg == "get_brand_wcpay_request:ok") {
  227. // 使用以上方式判断前端返回,
  228. // 微信团队郑重提示:
  229. uni.hideLoading();
  230. window.location.href = requestConfig.redirectOpen
  231. // res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  232. } else {
  233. uni.hideLoading();
  234. uni.$u.toast('支付失败!');
  235. }
  236. }
  237. );
  238. } else {
  239. uni.hideLoading();
  240. uni.$u.toast('支付失败!');
  241. }
  242. } else {
  243. uni.$u.toast('线下订单创建失败!');
  244. }
  245. },
  246. async getInfo() {
  247. let code = this.GetQueryString("code");
  248. const res = await axios.post(
  249. `${requestConfig.BaseUrl}user/app/v1/user/weChatH5Login?code=${code}`
  250. );
  251. if (res.data.code == 200) {
  252. this.userInfo = res.data.data;
  253. localStorage.setItem('weChatUserInfo', JSON.stringify(this.userInfo))
  254. if (this.userInfo.bindPhoneStatus == 0) {
  255. this.showPhone = true
  256. } else {
  257. this.showPhone = false
  258. this.getShopInfo()
  259. }
  260. } else {
  261. uni.$u.toast('获取微信登录信息失败,请重新登录!');
  262. // localStorage.removeItem('weChatUserInfo');
  263. // setTimeout(() => {
  264. // uni.redirectTo({
  265. // url: '/pages/index/index?shopId=' + this.shopId + '&uid=' + this.uid
  266. // })
  267. // }, 1000)
  268. }
  269. },
  270. GetQueryString(name) {
  271. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  272. var r = window.location.search.substr(1).match(reg);
  273. if (r != null) return unescape(r[2]);
  274. return null;
  275. },
  276. },
  277. };
  278. </script>
  279. <style lang="scss">
  280. .shopName {
  281. font-weight: bold;
  282. font-size: 36rpx;
  283. color: #333333;
  284. }
  285. /* 修改加载提示框的遮罩层 z-index */
  286. .uni-loading__mask {
  287. z-index: 10076;
  288. }
  289. /* 修改加载提示框本身的 z-index */
  290. .uni-loading {
  291. z-index: 10076;
  292. }
  293. .yzm {
  294. font-weight: 500;
  295. font-size: 28rpx;
  296. color: #00D36D;
  297. }
  298. .popup {
  299. height: 300px;
  300. padding: 20px;
  301. .footer {
  302. margin-top: 150rpx;
  303. .btn {
  304. width: 100%;
  305. background: linear-gradient(275deg, #01CF6C 0%, #07E278 100%);
  306. border-radius: 46rpx;
  307. border: none;
  308. }
  309. }
  310. .main {
  311. margin-top: 20rpx;
  312. }
  313. .header {
  314. margin-bottom: 20rpx;
  315. text-align: center;
  316. .tip {
  317. margin-top: 20rpx;
  318. font-weight: 500;
  319. font-size: 26rpx;
  320. color: #FF8B2F;
  321. }
  322. }
  323. }
  324. .u-radio-group--row {
  325. justify-content: center;
  326. }
  327. .radioText {
  328. font-weight: 500;
  329. font-size: 24rpx;
  330. color: #999999;
  331. line-height: 34rpx;
  332. text-align: left;
  333. font-style: normal;
  334. }
  335. .login-main {
  336. width: 100%;
  337. display: flex;
  338. flex-direction: column;
  339. /* justify-content: space-between; */
  340. align-items: center;
  341. height: 100vh;
  342. }
  343. .login-contont-button {
  344. text-align: center;
  345. .btn {
  346. margin-top: 20px;
  347. width: 95%;
  348. height: 90rpx;
  349. background: linear-gradient(275deg, #01cf6c 0%, #07e278 100%);
  350. border-radius: 44rpx;
  351. color: #fff;
  352. }
  353. }
  354. .login-contont {
  355. width: 90%;
  356. height: 50%;
  357. .uInput {
  358. padding: 10px 0px;
  359. border-bottom: 0.5px solid #97979740;
  360. }
  361. .login-contont-info {
  362. text-align: center;
  363. .text {
  364. margin-top: 10px;
  365. font-weight: 500;
  366. font-size: 28rpx;
  367. color: #999999;
  368. line-height: 40rpx;
  369. font-style: normal;
  370. }
  371. }
  372. }
  373. .radio {
  374. text-align: center;
  375. margin-top: 10px;
  376. }
  377. .login-main-content {
  378. background: url("../../static/images/payBack.png") no-repeat;
  379. background-size: 100% 100%;
  380. text-align: center;
  381. width: 100%;
  382. height: 120px;
  383. .img {
  384. margin-top: 70px;
  385. width: 80px;
  386. height: 80px;
  387. border-radius: 50%;
  388. }
  389. }
  390. </style>