vip-login.js 6.21 KB
let Date = require('../../utils/date.js');
let Utils = require('../../utils/util.js');

let app = getApp();
Page({
  data: {
    authorizeVisible: false,
    // form start
    name: "",
    mobile: "",
    verifyCode: "",
    imageUrl: "",
    auth_time: 0,
    sendAuthCode: true,
    membersShipIndex: 0,
    membersShipList: [{
        value: "",
        label: "请选择",
      },
      {
        value: "总代理",
        label: "总代理",
      },
      {
        value: "经销商",
        label: "经销商",
      },
      {
        value: "专业电工",
        label: "专业电工",
      },
      {
        value: "其他用户",
        label: "其他用户",
      }
    ],
    maxImg: 1, // 上传数量
    files: [], // 上传文件列表
    provinceId: "",
    cityId: "",
    provinceList: [],
    cityList: [],
    // form end
  },
  onShareAppMessage() {},
  showAuth() {
    this.setData({
      authorizeVisible: true
    })
  },
  onLoad(options) {
    this.initData();
  },
  initData() {
    this.getProvince();
  },

  /**
   * 会员身份
   */
  onSelectMembersShipHandler() {

  },

  getProvince() {
    return new Promise((resolve, reject) => {
      app.post({
        mode: "custom",
        url: app.api.areaQuery,
        data: {
          parentId: ""
        }
      }).then((result) => {
        this.setData({
          provinceList: result
        })
        console.log("provinceList:", result);
      })
    });
  },

  getCity() {
    return new Promise((resolve, reject) => {
      app.post({
        mode: "custom",
        url: app.api.areaQuery,
        data: {
          parentId: this.data.provinceId
        }
      }).then((result) => {
        this.setData({
          cityList: result
        })
        console.log("city:", result);
      })
    });
  },

  bindPickerChangeProvince(e) {
    let index = e.detail.value;
    this.setData({
      provinceIndex: index,
      provinceId: this.data.provinceList[index].areaId,
      cityList: [],
      cityIndex: -1,
    })
    this.getCity();
  },

  bindPickerChangeCity(e) {
    let index = e.detail.value;
    this.setData({
      cityIndex: index,
      cityId: this.data.cityList[index].areaId,
    })
  },

  /**
   * 参考 contact-table同名方法
   * 提交表单
   *
   */
  onSubmitHandler() {
    let {
      name,
      phone,
      verifyCode,
      files
    } = this.data;

    app.router.push({
      // openType:"redirect",
      path: "vipVerify"
    })
  },

  /**
   * 调起微信图片上传
   */
  onUploadHandler() {
    let _this = this;
    let count = _this.data.maxImg - _this.data.length;
    wx.chooseImage({
      sizeType: ['original', 'compressed'],
      sourceType: ['album'],
      count: 1,
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFiles = res.tempFiles
        let maxImg = _this.data.maxImg;
        let files = _this.data.files;
        files = files.concat(tempFiles);
        if (files.length > maxImg) {
          files.splice(0, maxImg);
        }
        _this.setData({
          files
        });
        console.log("files:", files);
        console.log("files[0]:", files[0]);
      }
    })
  },

  /**
   * 上传到自定义服务器
   * urlList 需要上传的图片地址
   */
  uploadToCustomService(urlList) {
    let _this = this;
    return new Promise((resolve, reject) => {
      // promise列表
      let p = [];
      // 用promise上传音频
      urlList.forEach(element => {
        let myPromise = new Promise((resolve2, reject2) => {
          _this.uploadfileMultiple(element).then((result2) => {
            resolve2(result2)
          }).catch((err) => {
            // _this.tip("声音上传失败")
            reject2();
          });
        });
        p.push(myPromise);
      });
      Promise.all(p).then(uploadFiles => {
        resolve(uploadFiles)
      }, reason => {
        reject();
      });
    });
  },
  /**
   * 多文件上传
   * @param {*} filePath
   */
  uploadfileMultiple(filePath) {
    let _this = this;
    return new Promise((resolve, reject) => {
      wx.uploadFile({
        url: app.config.NET_CONFIG.commonApi + app.api.uploadFile,
        filePath: filePath,
        name: 'file',
        // header: {}, // 设置请求的 header
        header: {
          'content-type': 'multipart/form-data'
        },
        formData: {
          path: '/weapp/zhiliang-light/'
        },
        // HTTP 请求中其他额外的 form data
        success(res) {
          let result = JSON.parse(res.data).content;
          resolve(result);
        },
        fail() {
          reject()
        },
        complete: function () {}
      })
    });
  },

  // 获取验证码
  reqGetSmsRequest() {
    if (!this.data.sendAuthCode) return;
    let mobile = this.data.mobile
    if (!mobile || !Utils.checkMobile(mobile)) {
      this.showLog("请输入正确的手机号码");
      return
    }
    this.getAuthCode();
    app.post({
      url: app.api.memberPhone,
      data: {
        picVerifyCode: "",
        mobile: mobile,
        forRegister: 1
      }
    }).then((result) => {
      wx.showToast({
        title: "短信发送成功",
        icon: "none"
      })
    });
  },
  // 倒数
  getAuthCode() {
    let _this = this;
    _this.setData({
      sendAuthCode: false,
      auth_time: 60
    })
    var auth_timetimer = setInterval(() => {
      _this.setData({
        auth_time: _this.data.auth_time - 1
      })
      if (_this.data.auth_time <= 0) {
        _this.setData({
          sendAuthCode: true
        });
        clearInterval(auth_timetimer)
      }
    }, 1000)
  },
  bindMobileInput(e) {
    this.setData({
      "mobile": e.detail.value
    })
  },
  bindNameInput(e) {
    this.setData({
      name: e.detail.value
    })
  },
  bindVerifyCodeInput(e) {
    this.setData({
      verifyCode: e.detail.value
    })
  },
  bindMembersShipChange(e) {
    let index = e.detail.value;
    this.setData({
      membersShipIndex: index
    })
  },

  hideMask() {
    // this.setData({
    //   productDetailVisible: false
    // })
  },
  // 子组件事件
  evtcomp(evt) {
    let {
      name,
      data
    } = evt.detail;
    switch (name) {

      case "_evt_hide_mask":
        break;

      default:
        break;
    }
  },
})