pay.vue 8.3 KB

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