| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
-
- <script>
- import { requestConfig } from "@/app.config.js";
- import axios from "axios";
- export default {
- data() {
- return {
- showPhone: false,
- requestConfig: requestConfig,
- code: "",
- appid: "",
- value: "",
- userInfo: {},
- inpustyle: {
- fontWeight: "bold",
- fontSize: "40px",
- },
- phone: "",
- yzm: "",
- tips: null,
- price: null,
- shopId: "",
- shopInfo: {},
- localUserInfo: {},
- uid: "",
- };
- },
- onLoad(options) {
- // this.shopId = options.shopId
- // this.uid = options.uid || ''
- // console.log(this.uid);
- // let info = localStorage.getItem('weChatUserInfo');
- // console.log(info);
- // this.localUserInfo = JSON.parse(info)
- // if (this.localUserInfo) {
- // this.vidTokenExist()
- // } else {
- // this.getShopInfo();
- // this.getInfo();
- // }
- },
- methods: {
- async vidTokenExist() {
- let res = await axios.get(
- `${requestConfig.BaseUrl}user/app/v1/user/vidTokenExist`,
- {
- headers: {
- token: `${this.localUserInfo.token}`,
- },
- },
- );
- if (res.data.code == 200) {
- this.userInfo = this.localUserInfo;
- this.getShopInfo();
- } else {
- uni.$u.toast("登录已过期,请重新登录!");
- localStorage.removeItem("weChatUserInfo");
- setTimeout(() => {
- uni.redirectTo({
- url:
- "/pages/index/index?shopId=" + this.shopId + "&uid=" + this.uid,
- });
- }, 1000);
- }
- },
- validateInput(e, num) {
- const inputTypeNum = /[^\d]/g; //数字
- switch (num) {
- case 1:
- //要写nextTick 不然无效
- this.$nextTick(() => {
- this.listData.integral = e.replace(inputTypeNum, "");
- });
- break;
- }
- },
- async getShopInfo() {
- let res = await axios.get(
- `${requestConfig.BaseUrl}user/app/v1/store/getStoreInfoByScan?shopId=${this.shopId}${this.uid ? "&uid=" + this.uid : ""}`,
- {
- headers: {
- token: `${this.userInfo.token}`,
- },
- },
- );
- if (res.data.code == 200) {
- this.shopInfo = res.data.data;
- } else {
- uni.$u.toast(res.data.msg);
- }
- },
- async submitOk() {
- if (this.phone == "") {
- uni.$u.toast("请输入手机号");
- } else if (this.yzm == "") {
- uni.$u.toast("请输入验证码");
- }
- const res = await axios.post(
- `${requestConfig.BaseUrl}user/app/v1/user/bindPhone?mpOpenid=${this.userInfo.mpOpenid}&phone=${this.phone}&code=${this.yzm}&unionid=${this.userInfo.unionid}`,
- );
- if (res.data.code == 200) {
- uni.$u.toast("绑定手机号成功");
- this.userInfo = res.data.data;
- this.showPhone = false;
- this.getShopInfo();
- } else {
- uni.$u.toast("绑定手机号失败!");
- }
- },
- codeChange(text) {
- this.tips = text;
- },
- async getCode() {
- if (this.$refs.uCode.canGetCode) {
- const res = await axios.post(
- `${requestConfig.BaseUrl}third/app/v1/third/getSMSCode?phone=${this.phone}`,
- );
- uni.showLoading({
- title: "正在获取验证码",
- });
- setTimeout(() => {
- uni.hideLoading();
- uni.$u.toast("验证码已发送");
- this.$refs.uCode.start();
- }, 2000);
- } else {
- uni.$u.toast("倒计时结束后再发送");
- }
- },
- async Pay() {
- uni.showLoading({
- title: "支付中",
- });
- // uni.hideLoading();
- // window.open(`${requestConfig.redirectOpen}pages/index/paySuccess`)
- if (!this.price) {
- uni.$u.toast("请输入支付金额!");
- }
- let res = await axios.get(
- `${requestConfig.BaseUrl}order/app/v1/buyer/order/createOfflineOrder
- ?shopId=${this.shopId}&price=${this.price}${this.uid ? "&uid=" + this.uid : ""}`,
- {
- headers: {
- token: `${this.userInfo.token}`,
- },
- },
- );
- if (res.data.code == 200) {
- //post请求
- let data = {
- orderId: res.data.data, //订单id
- orderType: 11, //订单类型 -1--其他 2-司机保证金 3-商品交易 4-线下交易
- payKinds: 0, //支付类型 0-微信 1-支付宝
- payMeth: 6, //5-微信小程序支付 6-微信H5支付 7-支付宝app支付
- };
- const pay = await axios.post(
- `${requestConfig.BaseUrl}order/app/v1/buyer/order/offlineOrderPay
- `,
- data,
- {
- headers: {
- Token: `${this.userInfo.token}`,
- },
- },
- );
- if (pay.data.code == 200) {
- let res = JSON.parse(pay.data.data.result);
- console.log(res);
- WeixinJSBridge.invoke(
- "getBrandWCPayRequest",
- {
- // 公众号名称,由商户传入
- appId: res.appId,
- // 时间戳,自1970年以来的秒数
- timeStamp: res.timeStamp,
- // 随机串
- nonceStr: res.nonceStr,
- package: res.package,
- // 微信签名方式:
- signType: res.signType,
- // 微信签名
- paySign: res.paySign,
- },
- function (res) {
- if (res.err_msg == "get_brand_wcpay_request:ok") {
- // 使用以上方式判断前端返回,
- // 微信团队郑重提示:
- uni.hideLoading();
- window.location.href = requestConfig.redirectOpen;
- // res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
- } else {
- uni.hideLoading();
- uni.$u.toast("支付失败!");
- }
- },
- );
- } else {
- uni.hideLoading();
- uni.$u.toast("支付失败!");
- }
- } else {
- uni.$u.toast("线下订单创建失败!");
- }
- },
- async getInfo() {
- let code = this.GetQueryString("code");
- const res = await axios.post(
- `${requestConfig.BaseUrl}user/app/v1/user/weChatH5Login?code=${code}`,
- );
- if (res.data.code == 200) {
- this.userInfo = res.data.data;
- localStorage.setItem("weChatUserInfo", JSON.stringify(this.userInfo));
- if (this.userInfo.bindPhoneStatus == 0) {
- this.showPhone = true;
- } else {
- this.showPhone = false;
- this.getShopInfo();
- }
- } else {
- uni.$u.toast("获取微信登录信息失败,请重新登录!");
- // localStorage.removeItem('weChatUserInfo');
- // setTimeout(() => {
- // uni.redirectTo({
- // url: '/pages/index/index?shopId=' + this.shopId + '&uid=' + this.uid
- // })
- // }, 1000)
- }
- },
- GetQueryString(name) {
- var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
- var r = window.location.search.substr(1).match(reg);
- if (r != null) return unescape(r[2]);
- return null;
- },
- },
- };
- </script>
- <style lang="scss">
- ::v-deep .u-cell__title {
- flex: none !important;
- }
- .main {
- width: 100%;
- background: white;
- height: calc(100% - 280rpx);
- border-radius: 40rpx;
- }
- .shopName {
- font-weight: bold;
- font-size: 36rpx;
- color: #333333;
- }
- /* 修改加载提示框的遮罩层 z-index */
- .uni-loading__mask {
- z-index: 10076;
- }
- /* 修改加载提示框本身的 z-index */
- .uni-loading {
- z-index: 10076;
- }
- .yzm {
- font-weight: 500;
- font-size: 28rpx;
- color: #00d36d;
- }
- .popup {
- height: 300px;
- padding: 20px;
- .footer {
- margin-top: 150rpx;
- .btn {
- width: 100%;
- background: linear-gradient(152deg, #6F9DFD 0%, #1B71F2 100%);
- border-radius: 46rpx;
- border: none;
- }
- }
- .main {
- margin-top: 20rpx;
- }
- .header {
- margin-bottom: 20rpx;
- text-align: center;
- .tip {
- margin-top: 20rpx;
- font-weight: 500;
- font-size: 26rpx;
- color: #ff8b2f;
- }
- }
- }
- .u-radio-group--row {
- justify-content: center;
- }
- .radioText {
- font-weight: 500;
- font-size: 24rpx;
- color: #999999;
- line-height: 34rpx;
- text-align: left;
- font-style: normal;
- }
- .login-main {
- background: url("../../static/images/payBack.png");
- background-size: 100% 100%;
- width: 100%;
- display: flex;
- flex-direction: column;
- /* justify-content: space-between; */
- align-items: center;
- height: 100vh;
- }
- .login-contont-button {
- text-align: center;
- .btn {
- margin-top: 20px;
- width: 95%;
- height: 90rpx;
- background: linear-gradient(152deg, #6F9DFD 0%, #1B71F2 100%);
- border-radius: 44rpx;
- color: #fff;
- }
- }
- .login-contont {
- width: 100%;
- height: 600rpx;
- margin-top: 100rpx;
- .uInput {
- padding: 10px 0px;
- border-bottom: 0.5px solid #97979740;
- }
- .login-contont-info {
- text-align: center;
- .text {
- margin-top: 10px;
- font-weight: 500;
- font-size: 28rpx;
- color: #999999;
- line-height: 40rpx;
- font-style: normal;
- }
- }
- }
- .radio {
- text-align: center;
- margin-top: 10px;
- }
- .login-main-content {
- display: flex;
- flex-direction: row;
- align-items: center;
- padding: 9px 26px;
- .img {
- // margin-top: 70px;
- margin-right: 20rpx;
- width: 44rpx;
- height: 44rpx;
- border-radius: 50%;
- }
- }
- </style>
|