pay.vue 10 KB

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