pay.vue 9.1 KB

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