pay.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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" type="number" v-model="price" :customStyle="inpustyle">
  12. <span slot="prefix" style="font-size: 30px">¥</span>
  13. </u-input>
  14. </view>
  15. <view class="login-contont-button">
  16. <button class="btn" @click="Pay">立即支付</button>
  17. <view style="margin-top: 20rpx; font-size: 26rpx">
  18. 支付成功后,次日有奖励红包,农商网小程序领取
  19. <!-- 支付成功立返
  20. <span
  21. style="color: red">
  22. {{ requestConfig.pay }}元</span>红包,可进入农商网小程序查看
  23. -->
  24. </view>
  25. </view>
  26. </view>
  27. <u-popup :zIndex="200" :overlayStyle={zIndex:200} :show="showPhone" @close="close" @open="open"
  28. :safeAreaInsetTop="true" round="20">
  29. <view class="popup">
  30. <view class="header">
  31. <h4>绑定手机号</h4>
  32. <p class="tip">注意:首次登录,需绑定手机号才可成功领取农商网红包</p>
  33. </view>
  34. <view class="main">
  35. <view style="height: 70rpx">
  36. <u--input placeholder="请输入手机号" type="number" border="surround" v-model="phone"
  37. style="background: #F4F4F4;height:100%" />
  38. </view>
  39. <view style="margin-top: 20px;height: 70rpx">
  40. <u--input placeholder="验证码" border="surround" v-model="yzm"
  41. style="background: #F4F4F4;height:100%">
  42. <template slot="suffix">
  43. <u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
  44. <!-- <u-button @tap="getCode" :text="tips" type="success" size="mini"></u-button> -->
  45. <text class="yzm" @tap="getCode">{{tips?tips:'发送验证码'}}</text>
  46. </template>
  47. </u--input>
  48. </view>
  49. </view>
  50. <view class="footer">
  51. <u-button type="primary" class="btn" text="确定" @click="submitOk"></u-button>
  52. </view>
  53. </view>
  54. </u-popup>
  55. </view>
  56. </template>
  57. <script>
  58. import {
  59. requestConfig
  60. } from "@/app.config.js";
  61. import axios from "axios";
  62. export default {
  63. data() {
  64. return {
  65. showPhone: false,
  66. requestConfig: requestConfig,
  67. code: "",
  68. appid: "",
  69. value: "",
  70. userInfo: {},
  71. inpustyle: {
  72. fontWeight: "bold",
  73. fontSize: "40px",
  74. },
  75. phone: "",
  76. yzm: "",
  77. tips: null,
  78. price: null,
  79. shopId: "",
  80. shopInfo: {}
  81. };
  82. },
  83. onLoad(options) {
  84. this.shopId = options.shopId
  85. this.getInfo();
  86. },
  87. methods: {
  88. async getShopInfo() {
  89. let res = await axios.get(
  90. `${requestConfig.BaseUrl}user/app/v1/store/getStoreInfoByScan?shopId=${this.shopId}`, {
  91. headers: {
  92. 'token': `${this.userInfo.token}`
  93. }
  94. });
  95. if (res.data.code == 200) {
  96. this.shopInfo = res.data.data
  97. }
  98. },
  99. async submitOk() {
  100. if (this.phone == "") {
  101. uni.$u.toast('请输入手机号');
  102. } else if (this.yzm == "") {
  103. uni.$u.toast('请输入验证码');
  104. }
  105. const res = await axios.post(
  106. `${requestConfig.BaseUrl}user/app/v1/user/bindPhone?mpOpenid=${this.userInfo.mpOpenid}&phone=${this.phone}&code=${this.yzm}&unionid=${this.userInfo.unionid}`
  107. );
  108. if (res.data.code == 200) {
  109. uni.$u.toast('绑定手机号成功');
  110. this.showPhone = false
  111. }
  112. },
  113. codeChange(text) {
  114. this.tips = text;
  115. },
  116. async getCode() {
  117. if (this.$refs.uCode.canGetCode) {
  118. const res = await axios.post(
  119. `${requestConfig.BaseUrl}third/app/v1/third/getSMSCode?phone=${this.phone}`
  120. );
  121. uni.showLoading({
  122. title: '正在获取验证码'
  123. })
  124. setTimeout(() => {
  125. uni.hideLoading();
  126. uni.$u.toast('验证码已发送');
  127. this.$refs.uCode.start();
  128. }, 2000);
  129. } else {
  130. uni.$u.toast('倒计时结束后再发送');
  131. }
  132. },
  133. async Pay() {
  134. let res = await axios.get(`${requestConfig.BaseUrl}order/app/v1/buyer/order/createOfflineOrder
  135. ?shopId=110351${this.shopId}&price=${this.price}`, {
  136. headers: {
  137. 'token': `${this.userInfo.token}`
  138. }
  139. });
  140. if (res.data.code == 200) {
  141. uni.$u.toast('线下订单创建成功!订单id=', res.data.data);
  142. }
  143. //post请求
  144. // const res = await axios.get(`${requestConfig.BaseUrl}order/app/v1/buyer/order/createOfflineOrder
  145. // ?shopId=110330&price=${this.price}`, {}, {
  146. // headers: {
  147. // 'Token': `${this.userInfo.token}`
  148. // }
  149. // });
  150. // WeixinJSBridge.invoke(
  151. // "getBrandWCPayRequest", {
  152. // // 公众号名称,由商户传入
  153. // appId: requestConfig.appID,
  154. // // 时间戳,自1970年以来的秒数
  155. // timeStamp: '',
  156. // // 随机串
  157. // nonceStr: '',
  158. // package: "",
  159. // // 微信签名方式:
  160. // signType: "MD5",
  161. // // 微信签名
  162. // paySign: '',
  163. // },
  164. // function(res) {
  165. // if (res.err_msg == "get_brand_wcpay_request:ok") {
  166. // // 使用以上方式判断前端返回,微信团队郑重提示:
  167. // // res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
  168. // }
  169. // }
  170. // );
  171. },
  172. async getInfo() {
  173. let code = this.GetQueryString("code");
  174. const res = await axios.post(
  175. `${requestConfig.BaseUrl}user/app/v1/user/weChatH5Login?code=${code}`
  176. );
  177. if (res.data.code == 200) {
  178. this.userInfo = res.data.data;
  179. if (this.userInfo.bindPhoneStatus == 0) {
  180. this.showPhone = true
  181. } else {
  182. this.showPhone = false
  183. }
  184. this.getShopInfo()
  185. } else {
  186. uni.$u.toast('获取微信登录信息失败!');
  187. }
  188. },
  189. GetQueryString(name) {
  190. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  191. var r = window.location.search.substr(1).match(reg);
  192. if (r != null) return unescape(r[2]);
  193. return null;
  194. },
  195. },
  196. };
  197. </script>
  198. <style lang="scss">
  199. .shopName {
  200. font-weight: bold;
  201. font-size: 36rpx;
  202. color: #333333;
  203. }
  204. /* 修改加载提示框的遮罩层 z-index */
  205. .uni-loading__mask {
  206. z-index: 10076;
  207. }
  208. /* 修改加载提示框本身的 z-index */
  209. .uni-loading {
  210. z-index: 10076;
  211. }
  212. .yzm {
  213. font-weight: 500;
  214. font-size: 28rpx;
  215. color: #00D36D;
  216. }
  217. .popup {
  218. height: 300px;
  219. padding: 20px;
  220. .footer {
  221. margin-top: 150rpx;
  222. .btn {
  223. width: 100%;
  224. background: linear-gradient(275deg, #01CF6C 0%, #07E278 100%);
  225. border-radius: 46rpx;
  226. border: none;
  227. }
  228. }
  229. .main {
  230. margin-top: 20rpx;
  231. }
  232. .header {
  233. margin-bottom: 20rpx;
  234. text-align: center;
  235. .tip {
  236. margin-top: 20rpx;
  237. font-weight: 500;
  238. font-size: 26rpx;
  239. color: #FF8B2F;
  240. }
  241. }
  242. }
  243. .u-radio-group--row {
  244. justify-content: center;
  245. }
  246. .radioText {
  247. font-weight: 500;
  248. font-size: 24rpx;
  249. color: #999999;
  250. line-height: 34rpx;
  251. text-align: left;
  252. font-style: normal;
  253. }
  254. .login-main {
  255. width: 100%;
  256. display: flex;
  257. flex-direction: column;
  258. /* justify-content: space-between; */
  259. align-items: center;
  260. height: 100vh;
  261. }
  262. .login-contont-button {
  263. text-align: center;
  264. .btn {
  265. margin-top: 20px;
  266. width: 95%;
  267. height: 90rpx;
  268. background: linear-gradient(275deg, #01cf6c 0%, #07e278 100%);
  269. border-radius: 44rpx;
  270. color: #fff;
  271. }
  272. }
  273. .login-contont {
  274. width: 90%;
  275. height: 50%;
  276. .uInput {
  277. padding: 10px 0px;
  278. border-bottom: 0.5px solid #97979740;
  279. }
  280. .login-contont-info {
  281. text-align: center;
  282. .text {
  283. margin-top: 10px;
  284. font-weight: 500;
  285. font-size: 28rpx;
  286. color: #999999;
  287. line-height: 40rpx;
  288. font-style: normal;
  289. }
  290. }
  291. }
  292. .radio {
  293. text-align: center;
  294. margin-top: 10px;
  295. }
  296. .login-main-content {
  297. background: url("../../static/images/payBack.png") no-repeat;
  298. background-size: 100% 100%;
  299. text-align: center;
  300. width: 100%;
  301. height: 120px;
  302. .img {
  303. margin-top: 70px;
  304. width: 80px;
  305. height: 80px;
  306. border-radius: 50%;
  307. }
  308. }
  309. </style>