pay.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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?shopInfo.store_logo_url:''" mode=""></image>
  6. <h4 class="shopName">{{shopInfo?shopInfo.store_name:""}}</h4>
  7. </view>
  8. </view>
  9. <view class="login-contont">
  10. <view class="uInput">
  11. <u-input placeholder="请输入金额" border="bottom" :fontSize="40" type="digit"
  12. @change="validateInput($event,1)" v-model="price" :customStyle="inpustyle">
  13. <span slot="prefix" style="font-size: 30px">¥</span>
  14. </u-input>
  15. </view>
  16. <view class="login-contont-button">
  17. <button class="btn" @click="Pay">立即支付</button>
  18. <view style="margin-top: 20rpx; font-size: 26rpx">
  19. 支付成功后,次日有奖励红包,农商直采小程序领取
  20. <!-- 支付成功立返
  21. <span
  22. style="color: red">
  23. {{ requestConfig.pay }}元</span>红包,可进入农商网小程序查看
  24. -->
  25. </view>
  26. </view>
  27. </view>
  28. <u-popup :zIndex="200" :overlayStyle={zIndex:200} :show="showPhone" @close="close" @open="open"
  29. :safeAreaInsetTop="true" round="20">
  30. <view class="popup">
  31. <view class="header">
  32. <h4>绑定手机号</h4>
  33. <p class="tip">注意:首次登录,需绑定手机号才可成功领取农商网红包</p>
  34. </view>
  35. <view class="main">
  36. <view style="height: 70rpx">
  37. <u--input placeholder="请输入手机号" type="number" border="surround" v-model="phone"
  38. style="background: #F4F4F4;height:100%" />
  39. </view>
  40. <view style="margin-top: 20px;height: 70rpx">
  41. <u--input placeholder="验证码" border="surround" v-model="yzm"
  42. style="background: #F4F4F4;height:100%">
  43. <template slot="suffix">
  44. <u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
  45. <!-- <u-button @tap="getCode" :text="tips" type="success" size="mini"></u-button> -->
  46. <text class="yzm" @tap="getCode">{{tips?tips:'发送验证码'}}</text>
  47. </template>
  48. </u--input>
  49. </view>
  50. </view>
  51. <view class="footer">
  52. <u-button type="primary" class="btn" text="确定" @click="submitOk"></u-button>
  53. </view>
  54. </view>
  55. </u-popup>
  56. </view>
  57. </template>
  58. <script>
  59. import {
  60. requestConfig
  61. } from "@/app.config.js";
  62. import axios from "axios";
  63. export default {
  64. data() {
  65. return {
  66. showPhone: false,
  67. requestConfig: requestConfig,
  68. code: "",
  69. appid: "",
  70. value: "",
  71. userInfo: {},
  72. inpustyle: {
  73. fontWeight: "bold",
  74. fontSize: "40px",
  75. },
  76. phone: "",
  77. yzm: "",
  78. tips: null,
  79. price: null,
  80. shopId: "",
  81. shopInfo: {},
  82. localUserInfo: {}
  83. };
  84. },
  85. onLoad(options) {
  86. this.shopId = options.shopId
  87. let info = localStorage.getItem('weChatUserInfo');
  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
  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}`, {
  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}`, {
  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 if (res.data.code == 403) {
  243. uni.$u.toast('登录已过期,请重新登录!');
  244. localStorage.removeItem('weChatUserInfo');
  245. setTimeout(() => {
  246. uni.redirectTo({
  247. url: '/pages/index/index'
  248. })
  249. }, 1000)
  250. return;
  251. } else {
  252. uni.$u.toast('线下订单创建失败!');
  253. }
  254. },
  255. async getInfo() {
  256. let code = this.GetQueryString("code");
  257. const res = await axios.post(
  258. `${requestConfig.BaseUrl}user/app/v1/user/weChatH5Login?code=${code}`
  259. );
  260. if (res.data.code == 200) {
  261. this.userInfo = res.data.data;
  262. localStorage.setItem('weChatUserInfo', JSON.stringify(this.userInfo))
  263. if (this.userInfo.bindPhoneStatus == 0) {
  264. this.showPhone = true
  265. } else {
  266. this.showPhone = false
  267. this.getShopInfo()
  268. }
  269. } else {
  270. uni.$u.toast('获取微信登录信息失败!');
  271. }
  272. },
  273. GetQueryString(name) {
  274. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  275. var r = window.location.search.substr(1).match(reg);
  276. if (r != null) return unescape(r[2]);
  277. return null;
  278. },
  279. },
  280. };
  281. </script>
  282. <style lang="scss">
  283. .shopName {
  284. font-weight: bold;
  285. font-size: 36rpx;
  286. color: #333333;
  287. }
  288. /* 修改加载提示框的遮罩层 z-index */
  289. .uni-loading__mask {
  290. z-index: 10076;
  291. }
  292. /* 修改加载提示框本身的 z-index */
  293. .uni-loading {
  294. z-index: 10076;
  295. }
  296. .yzm {
  297. font-weight: 500;
  298. font-size: 28rpx;
  299. color: #00D36D;
  300. }
  301. .popup {
  302. height: 300px;
  303. padding: 20px;
  304. .footer {
  305. margin-top: 150rpx;
  306. .btn {
  307. width: 100%;
  308. background: linear-gradient(275deg, #01CF6C 0%, #07E278 100%);
  309. border-radius: 46rpx;
  310. border: none;
  311. }
  312. }
  313. .main {
  314. margin-top: 20rpx;
  315. }
  316. .header {
  317. margin-bottom: 20rpx;
  318. text-align: center;
  319. .tip {
  320. margin-top: 20rpx;
  321. font-weight: 500;
  322. font-size: 26rpx;
  323. color: #FF8B2F;
  324. }
  325. }
  326. }
  327. .u-radio-group--row {
  328. justify-content: center;
  329. }
  330. .radioText {
  331. font-weight: 500;
  332. font-size: 24rpx;
  333. color: #999999;
  334. line-height: 34rpx;
  335. text-align: left;
  336. font-style: normal;
  337. }
  338. .login-main {
  339. width: 100%;
  340. display: flex;
  341. flex-direction: column;
  342. /* justify-content: space-between; */
  343. align-items: center;
  344. height: 100vh;
  345. }
  346. .login-contont-button {
  347. text-align: center;
  348. .btn {
  349. margin-top: 20px;
  350. width: 95%;
  351. height: 90rpx;
  352. background: linear-gradient(275deg, #01cf6c 0%, #07e278 100%);
  353. border-radius: 44rpx;
  354. color: #fff;
  355. }
  356. }
  357. .login-contont {
  358. width: 90%;
  359. height: 50%;
  360. .uInput {
  361. padding: 10px 0px;
  362. border-bottom: 0.5px solid #97979740;
  363. }
  364. .login-contont-info {
  365. text-align: center;
  366. .text {
  367. margin-top: 10px;
  368. font-weight: 500;
  369. font-size: 28rpx;
  370. color: #999999;
  371. line-height: 40rpx;
  372. font-style: normal;
  373. }
  374. }
  375. }
  376. .radio {
  377. text-align: center;
  378. margin-top: 10px;
  379. }
  380. .login-main-content {
  381. background: url("../../static/images/payBack.png") no-repeat;
  382. background-size: 100% 100%;
  383. text-align: center;
  384. width: 100%;
  385. height: 120px;
  386. .img {
  387. margin-top: 70px;
  388. width: 80px;
  389. height: 80px;
  390. border-radius: 50%;
  391. }
  392. }
  393. </style>