forked from gzzfw/frontEnd/gzDyh

liuwh
2024-09-13 6613c11627b5e0be1629f3784acf0245a8040ea1
gz-wxparty/components/personal-data-dom/index.js
@@ -5,193 +5,165 @@
// 获取信息
function getUserInfoApi() {
    return $$.request({
        url: 'paUser/getUserInfo',
        type: 'get',
        service: 'cust'
    });
  return $$.request({
    url: 'paUser/getUserInfo',
    type: 'get',
    service: 'cust'
  });
}
Component({
    /**
     * 组件的属性列表
     * submitData: object form数据
     * type: string 判断当前使用组件的页面realNameAuthentication为实名认证页面
     * isCheck: boolean 判断是否只读不可修改
     * isImproveData: boolean 判断是否是完善资料,则不显示证件信息
     */
    properties: {
        submitData: {
            type: Object,
            value: {},
        },
        type: {
            type: String,
            value: '',
        },
        isCheck: {
            type: Boolean,
            value: false,
        },
        isImproveData: {
            type: Boolean,
            value: false,
        },
  /**
   * 组件的属性列表
   * submitData: object form数据
   * type: string 判断当前使用组件的页面realNameAuthentication为实名认证页面
   * isCheck: boolean 判断是否只读不可修改
   * isImproveData: boolean 判断是否是完善资料,则不显示证件信息
   */
  properties: {
    submitData: {
      type: Object,
      value: {},
    },
    /**
     * 组件的初始数据
     */
    select: {}, // 下拉框资源
    location: [],
    data: {},
    pageLifetimes: {
        show() {
            $$.showLoading();
            this._getSelectOptionData();
            this._getLocationData();
            this._getUserInfo();
        },
    type: {
      type: String,
      value: '',
    },
    /**
     * 组件的方法列表
     */
    methods: {
        //
        _handleChange(e) {
            let key = e.currentTarget.dataset.key;
            if (key === 'clearidcard') {
                this.triggerEvent('handleChange', {
                    key: 'idcard',
                    value: ''
                });
            } else {
                this.triggerEvent('handleChange', {
                    key,
                    value: e.detail
                });
            }
        },
        // 展示弹出层
        _handleShowPopup(e) {
            if (this.data.isCheck) {
                return false;
            }
            let type = e.currentTarget.dataset.type;
            let title = e.currentTarget.dataset.title;
            let selectData = [];
            if (type === 'location') {
                let selectOption = JSON.parse(JSON.stringify(this.location));
                let indexArr = $$.getLocationIndex(selectOption, this.data.submitData);
                selectData = [{
                        values: selectOption,
                        defaultIndex: indexArr[0]
                    },
                    {
                        values: selectOption[indexArr[0]].children,
                        defaultIndex: indexArr[1]
                    },
                    {
                        values: selectOption[indexArr[0]].children[indexArr[1]].children || [],
                        defaultIndex: indexArr[2]
                    },
                    {
                        values: selectOption[indexArr[0]].children[indexArr[1]].children[indexArr[2]].children || [],
                        defaultIndex: indexArr[3]
                    },
                ];
                selectData.forEach((x) => {
                    x.values.forEach((y) => {
                        delete y.children;
                    });
                });
            } else {
                let selectOption = this.select[type];
                selectData = selectOption;
            }
            this.triggerEvent('handleShowPopup', {
                visible: true,
                title: title,
                type: type,
                selectData: selectData,
            });
        },
        // 获取手机号码
        _handleGetPhoneNumber(e) {
            this.triggerEvent('handleGetPhoneNumber', e.detail.code);
        },
        // 获取个人信息
        async _getUserInfo() {
            console.log('个人信息')
            console.log(app.globalData.access_token, 'app.globalData.access_token1111111')
            // const res = await getUserInfoApi();
            // $$.hideLoading();
            // if (res.type) {
            //     this.triggerEvent('getUserInfo', res.data);
            // }
            const res = await getUserInfoApi();
            $$.hideLoading();
            if (res.type) {
                if(res.data.trueName !== null)
                this.triggerEvent('getUserInfo', res.data);
            }
            if (app.globalData.access_token && res.data.trueName === null) {
                let actoken = app.globalData.access_token;
                wx.request({
                    url: 'https://xcx.pinganbaiyun.cn/p_060_cs_intf/api_001/sv_002_get_paby_login_info', //仅为示例,并非真实的接口地址
                    data: {
                        "access_token": '测试token',
                        "app_id": "测试",
                        "secret": "测试"
                    },
                    method: 'post',
                    success: (res1) => {
                        $$.hideLoading();
                        this.triggerEvent('getUserInfo', {
                            ...res1.data[0],
                            trueName: res1.data[0].XM,
                            idcard: res1.data[0].ZJHM,
                            mobile: res1.data[0].LXDH
                        });
                    }
                })
            }
        },
        // 请求下拉框资源
        async _getSelectOptionData() {
            const res = await $$.commonRequest({
                url: `${$$.url.assets}selectOption.json`,
                type: 'get'
            });
            if (res) {
                this.select = {
                    cardType: [],
                    sex: [],
                };
                this.select.cardType = res.data.cardType || [];
                this.select.sex = res.data.sex || [];
            }
        },
        // 获取省市区等地理资源
        async _getLocationData() {
            $$.showLoading();
            const res = await $$.commonRequest({
                url: `${$$.url.assets}locationSelect.json`,
                type: 'get'
            });
            $$.hideLoading();
            if (res) {
                let location = [];
                $$.province.forEach((x) => {
                    location.push(res[x][0]);
                });
                this.location = location;
            }
        },
    isCheck: {
      type: Boolean,
      value: false,
    },
    isImproveData: {
      type: Boolean,
      value: false,
    },
  },
  /**
   * 组件的初始数据
   */
  select: {}, // 下拉框资源
  location: [],
  data: {},
  pageLifetimes: {
    show() {
      $$.showLoading();
      this._getSelectOptionData();
      this._getLocationData();
      this._getUserInfo();
    },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //
    _handleChange(e) {
      let key = e.currentTarget.dataset.key;
      if (key === 'clearidcard') {
        this.triggerEvent('handleChange', {
          key: 'idcard',
          value: ''
        });
      } else {
        this.triggerEvent('handleChange', {
          key,
          value: e.detail
        });
      }
    },
    // 展示弹出层
    _handleShowPopup(e) {
      if (this.data.isCheck) {
        return false;
      }
      let type = e.currentTarget.dataset.type;
      let title = e.currentTarget.dataset.title;
      let selectData = [];
      if (type === 'location') {
        let selectOption = JSON.parse(JSON.stringify(this.location));
        let indexArr = $$.getLocationIndex(selectOption, this.data.submitData);
        selectData = [{
            values: selectOption,
            defaultIndex: indexArr[0]
          },
          {
            values: selectOption[indexArr[0]].children,
            defaultIndex: indexArr[1]
          },
          {
            values: selectOption[indexArr[0]].children[indexArr[1]].children || [],
            defaultIndex: indexArr[2]
          },
        ];
        selectData.forEach((x) => {
          x.values.forEach((y) => {
            delete y.children;
          });
        });
      } else {
        let selectOption = this.select[type];
        selectData = selectOption;
      }
      this.triggerEvent('handleShowPopup', {
        visible: true,
        title: title,
        type: type,
        selectData: selectData,
      });
    },
    // 获取手机号码
    _handleGetPhoneNumber(e) {
      console.log('eeeee', e);
      this.triggerEvent('handleGetPhoneNumber', e.detail.code);
    },
    // 获取个人信息
    async _getUserInfo() {
      console.log('个人信息')
      console.log(app.globalData.access_token, 'app.globalData.access_token1111111')
      const res = await getUserInfoApi();
      $$.hideLoading();
      if (res.type) {
        if (res.data.trueName !== null)
          this.triggerEvent('getUserInfo', res.data);
        wx.setStorage({
          key: 'userInfo',
          data: res.data
        });
      }
    },
    // 请求下拉框资源
    async _getSelectOptionData() {
      const res = await $$.commonRequest({
        url: `${$$.url.assets}selectOption.json`,
        type: 'get'
      });
      if (res) {
        this.select = {
          cardType: [],
          sex: [],
        };
        this.select.cardType = res.data.cardType || [];
        this.select.sex = res.data.sex || [];
      }
    },
    // 获取省市区等地理资源
    async _getLocationData() {
      $$.showLoading();
      const res = await $$.commonRequest({
        url: `${$$.url.assets}locationSelect.json`,
        type: 'get'
      });
      $$.hideLoading();
      if (res) {
        let location = [];
        $$.province.forEach((x) => {
          location.push(res[x][0]);
        });
        this.location = location;
      }
    },
  },
});