pay.vue 11 KB

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