|
- const navigationBarHeight = (getApp().statusBarHeight + 60) + 'px'
- const util = require("../../utils/util.js");
- const Http = require("../../utils/HttpBasics");
- const config = require("../../config/config");
- const imgurl = require("../../utils/imgurl");
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- navigationBarHeight,
- tabIndex: 0,
- pdwSwitch: 0,
- isShowPwd: false,
- isChangePhone: false,
- isSHowInfoCard: false,
- code: "",
- title: "",
- name: "",
- phone: "",
- tempPhone: "",
- password: ""
- },
-
- // 查询
- searchCard(e) {
- let code = e.detail.value.code;
- this.setData({
- code: code
- })
- this.getCardDetail(code)
- },
-
- // 更改手机号
- changePhone() {
- this.setData({
- isChangePhone: true,
- tempPhone: this.data.phone
- })
- },
-
- // 输入手机号
- phoneInput(e) {
- this.setData({
- phone: e.detail.value
- })
- },
-
- // 输入密码
- pwdInput(e) {
- this.setData({
- password: e.detail.value,
- })
- },
-
- // 确认手机号更改
- confirmPhone() {
- const phoneReg = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/
- const phoneValid = phoneReg.test(this.data.phone)
- if (!phoneValid) {
- this.Toast('请输入正确的手机号!', 'none')
- return
- }
- this.setData({
- isChangePhone: false,
- })
- },
-
- // 取消更改
- cancelChangePhone() {
- this.setData({
- isChangePhone: false,
- phone: this.data.tempPhone
- })
- },
-
- // 更改tab栏
- changeTabs(e) {
- console.log(e, 'changeTabs');
- this.setData({
- tabIndex: e.target.id,
- code: '',
- password: '',
- isSHowInfoCard: false
- })
- },
-
- // 支付安全设置
- securityChange(e) {
- this.setData({
- pdwSwitch: e.detail.value * 1
- })
- },
-
- codeInput(e) {
- console.log(e);
- this.setData({
- code: e.detail.value
- })
- },
-
- // 扫描二维码
- goScanCode() {
- console.log('scan!!!');
- const that = this
- wx.scanCode({
- success: (res) => {
- console.log(res, 'res');
- const num = res.result
- that.setData({
- code: num
- })
- const e = {
- detail: { value: { code: num } }
- }
- that.searchCard(e)
- },
- fail: (res) => {
- console.log(res, 'fail');
- }
- })
- },
-
- /** 根据卡id查询卡详情*/
- getCardDetail(cardId) {
- const that = this
- Http.get({
- url: config.api.getCardDetail,
- data: { cardId }
- })
- .then(res => {
- console.log(res, 'res');
- // 取不到时清空参数
- that.setData({
- title: res.data.title || "",
- phone: res.data.ownerPhone || "",
- ownerUserId: res.data.ownerUserId || "",
- eCardId: res.data.eCardId || "",
- owned: res.data.owned || "",
- remainAmount: res.data.remainAmount / 100 || "",
- isSHowInfoCard: true // 显示卡详情
- })
- })
- .catch(err => {
- console.log(err);
- this.Toast(err.message, 'none')
- })
- },
-
- getCouponOrderByPassword(password) {
- Http.post({
- url: config.api.getCouponOrderByPassword,
- data: {
- password,
- }
- })
- .then(res => {
- wx.showModal({
- title: '激活成功',
- content: '消费卡已发放到"我的卡包"',
- showCancel: true,
- cancelText: "知道了",
- cancelColor: '',
- confirmText: "去查看",
- confirmColor: '#FD832D',
- success: function (res) {
- if (res.cancel) {
- //点击取消,默认隐藏弹框
- } else {
- wx.redirectTo({
- url: '/pages/cardorder/index/index',
- })
- }
- },
- fail: function (res) { },
- complete: function (res) { }
- })
- })
- .catch(err => {
- wx.showToast({
- title: err.message,
- icon: 'none',
- duration: 2000
- })
- })
- },
-
- setPwdShow() {
- const isShowPwd = this.data.isShowPwd
- this.setData({
- isShowPwd: !isShowPwd
- })
- },
-
- submit() {
- const data = this.data
- const e = {
- detail: { value: { code: this.data.code } }
- }
- this.searchCard(e)
- this.getCouponOrderByPassword(data.code)
- },
-
- goGive() {
- if (this.data.ownerUserId && this.data.eCardId) {
- if (this.data.owned && this.data.owned == 1) {
- wx.navigateTo({
- url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.eCardId}`,
- })
- } else {
- this.Toast('当前用户不是该卡的持有者,无法转赠!', 'none')
- }
- } else {
- this.Toast('该卡未绑定', 'none')
- }
- },
-
- // 检查用户登录状态
- checkPhoneStatus() {
- let that = this;
- Http.get({
- url: config.api.checkPhoneStatus,
- })
- .then(res => {
- })
- .catch(err => {
- if (err.code == 11005) {
- // 手机号没有授权,将值传到用户手机号授权的页面
- wx.redirectTo({
- url: "/pages/getphoneInfo/index?path=exchangeCard",
- })
- } else {
- wx.showToast({
- title: err.message,
- icon: 'none',
- duration: 2500
- })
- }
- })
- },
-
- Toast(message, icon) {
- wx.showToast({
- title: message,
- icon: icon
- })
- },
- onLoad() {
- setTimeout(() => {
- this.checkPhoneStatus()
- }, 2000);
- }
- })
|