"use strict";
const common_vendor = require("../../../../common/vendor.js");
const common_js_validator = require("../../../../common/js/validator.js");
const common_js_net_UserApi = require("../../../../common/js/net/UserApi.js");
const _sfc_main = {
  data() {
    return {
      userInfo: {
        userInfoName: "",
        contactPhone: ""
      },
      showInfo: false,
      msgType: "success",
      msgTxt: ""
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "个人信息"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      // 必写项，字体颜色仅支持#ffffff和#000000
      backgroundColor: "#F0F0F0",
      // 传递的颜色值，仅支持十六进制颜色
      animation: {
        // 可选项
        duration: 500,
        timingFunc: "linear"
      }
    });
    this.doGetMineInfo();
  },
  methods: {
    //输入姓名
    inputName(e) {
      common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineInfo/mineInfo.vue:60", e);
      this.userInfo.userInfoName = e.detail.value;
    },
    //输入电话号码
    inputPhone(e) {
      common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineInfo/mineInfo.vue:65", e);
      this.userInfo.contactPhone = e.detail.value;
    },
    //校验参数
    checkParams() {
      if (this.userInfo.userInfoName == "") {
        this.msgTxt = "请输入姓名";
        this.msgType = "error";
        this.$refs.msg.open();
        return false;
      }
      if (this.userInfo.contactPhone == "" || !common_js_validator.isValidPhone(this.userInfo.contactPhone)) {
        this.msgTxt = "请输入正确的联系电话";
        this.msgType = "error";
        this.$refs.msg.open();
        return false;
      }
      return true;
    },
    //修改信息
    doUpdateInfo() {
      const _self = this;
      const isLegal = _self.checkParams();
      if (isLegal) {
        common_vendor.index.showLoading({
          title: "保存中..."
        });
        const data = {
          userInfoName: _self.userInfo.userInfoName,
          contactPhone: _self.userInfo.contactPhone,
          idCardType: "ID_CARD",
          userInfoType: "PERSONAL"
        };
        common_js_net_UserApi.UserApi.doUpdateUserInfo(data).then((res) => {
          common_vendor.index.hideLoading();
          common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineInfo/mineInfo.vue:101", res);
          _self.msgTxt = "个人信息修改成功";
          _self.msgType = "success";
          _self.$refs.msg.open();
        }).catch((err) => {
          common_vendor.index.hideLoading();
          _self.msgTxt = err.msg ? err.msg : "信息修改失败,请稍后重试";
          _self.msgType = "error";
          _self.$refs.msg.open();
        });
      }
    },
    //获取个人信息
    doGetMineInfo() {
      const _self = this;
      common_vendor.index.showLoading({
        title: "加载中..."
      });
      common_js_net_UserApi.UserApi.doGetUserInfo().then((res) => {
        common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineInfo/mineInfo.vue:122", res);
        common_vendor.index.hideLoading();
        _self.userInfo = res;
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgTxt = err.msg ? err.msg : "个人信息获取过程中出现异常，建议您稍作等待后再次尝试。";
        _self.msgType = "error";
        setTimeout(() => {
          common_vendor.index.navigateBack();
        }, 1500);
      });
    }
  }
};
if (!Array) {
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_uni_popup_message2 + _easycom_uni_popup2)();
}
const _easycom_uni_popup_message = () => "../../../../uni_modules/uni-popup/components/uni-popup-message/uni-popup-message.js";
const _easycom_uni_popup = () => "../../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (_easycom_uni_popup_message + _easycom_uni_popup)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: $data.userInfo.userInfoName,
    b: common_vendor.o((...args) => $options.inputName && $options.inputName(...args)),
    c: $data.userInfo.contactPhone,
    d: common_vendor.o((...args) => $options.inputPhone && $options.inputPhone(...args)),
    e: common_vendor.o((...args) => $options.doUpdateInfo && $options.doUpdateInfo(...args)),
    f: common_vendor.p({
      type: $data.msgType,
      message: $data.msgTxt,
      duration: 2e3
    }),
    g: common_vendor.sr("msg", "5aa3a145-0"),
    h: common_vendor.p({
      type: "message"
    })
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-5aa3a145"]]);
tt.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../../.sourcemap/mp-toutiao/pages/mine/mineAccount/mineInfo/mineInfo.js.map
