"use strict";
const common_vendor = require("../../../../common/vendor.js");
const common_js_net_UserApi = require("../../../../common/js/net/UserApi.js");
const common_js_validator = require("../../../../common/js/validator.js");
const ContainerLoading = () => "../../../../components/container-loading.js";
const _sfc_main = {
  components: {
    ContainerLoading
  },
  data() {
    return {
      contactList: [],
      //联系人列表
      pageData: {
        page: 1,
        rows: 10,
        keywords: ""
      },
      //检索参数
      loadingState: "loading",
      //加载状态
      listRefreshTrig: false,
      //list刷新状态
      isLoadMore: false,
      //加载更多的状态
      hasMore: true,
      //是否有更多数据
      keywords: "",
      //搜索关键字
      showCreateContact: false,
      //创建联系人
      contactCompany: "",
      //公司名称
      contactEmail: "",
      //联系邮箱
      contactName: "",
      //名字
      contactPhone: "",
      //联系电话
      showError: false,
      errorHint: "",
      showSuccess: false,
      successHint: "",
      csaNo: "",
      //客服号
      title: "创建联系人",
      btnTxt: "保存",
      isCreate: true,
      //创建还是编辑
      tempContact: null,
      //修改的联系人
      loadMore: "more",
      alertMsg: "",
      msgType: "info",
      msgTxt: ""
    };
  },
  onLoad(options) {
    common_vendor.index.setNavigationBarTitle({
      title: "产权联系人"
    });
    common_vendor.index.setNavigationBarColor({
      frontColor: "#000000",
      // 必写项，字体颜色仅支持#ffffff和#000000
      backgroundColor: "#F0F0F0",
      // 传递的颜色值，仅支持十六进制颜色
      animation: {
        duration: 500,
        timingFunc: "linear"
      }
    });
    this.doGetCsaNo();
    this.doGetMineContactList();
  },
  onPullDownRefresh() {
    this.doRefreshList();
    common_vendor.index.stopPullDownRefresh();
  },
  methods: {
    inputKeywords(e) {
      this.keywords = e.detail.value;
    },
    inputContactName(e) {
      this.contactName = e.detail.value;
    },
    inputContactPhone(e) {
      this.contactPhone = e.detail.value;
    },
    inputContactEmail(e) {
      this.contactEmail = e.detail.value;
    },
    inputContactCompany(e) {
      this.contactCompany = e.detail.value;
    },
    //关闭弹窗
    closePopup() {
      this.$refs.popup.close();
    },
    //显示创建联系人
    showCreateDialog() {
      this.title = "创建联系人";
      this.isCreate = true;
      this.$refs.popup.open();
    },
    //创建联系人
    doSaveContact() {
      const _self = this;
      if (_self.contactName == "") {
        _self.msgTxt = "请输入联系人姓名";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return;
      }
      if (_self.contactPhone == "" || !common_js_validator.isValidPhone(_self.contactPhone)) {
        _self.msgTxt = "请输入正确的联系电话";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return;
      }
      if (_self.contactEmail != "") {
        if (!common_js_validator.isValidEmail(_self.contactEmail)) {
          _self.msgTxt = "请输入正确的邮箱";
          _self.msgType = "error";
          _self.$refs.msg.open();
          return;
        }
      }
      common_vendor.index.showLoading({
        title: "创建中..."
      });
      _self.$refs.popup.close();
      const data = {
        company: _self.contactCompany,
        csaNo: _self.csaNo,
        name: _self.contactName,
        phone: _self.contactPhone,
        email: _self.contactEmail
      };
      common_js_net_UserApi.UserApi.doCreateContact(data).then((res) => {
        common_vendor.index.hideLoading();
        _self.msgTxt = "新建成功";
        _self.msgType = "success";
        _self.$refs.msg.open();
        _self.contactEmail = "";
        _self.contactPhone = "";
        _self.contactName = "";
        _self.contactCompany = "";
        _self.doRefreshList();
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgTxt = err.msg ? err.msg : "新建失败,请稍后重试";
        _self.msgType = "error";
        _self.$refs.msg.open();
      });
    },
    //显示编辑联系人
    showEditDialog(e) {
      this.tempContact = e.currentTarget.dataset.value;
      this.title = "编辑";
      this.isCreate = false;
      this.contactCompany = this.tempContact.company;
      this.contactName = this.tempContact.name;
      this.contactEmail = this.tempContact.email;
      this.contactPhone = this.tempContact.phone;
      this.$refs.popup.open();
    },
    //保存修改联系人
    doEditContact() {
      const _self = this;
      if (_self.contactName == "") {
        _self.msgTxt = "请输入联系人姓名";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return;
      }
      if (_self.contactPhone == "" || !common_js_validator.isValidPhone(_self.contactPhone)) {
        _self.msgTxt = "请输入正确的联系电话";
        _self.msgType = "error";
        _self.$refs.msg.open();
        return;
      }
      if (_self.contactEmail != "") {
        if (!common_js_validator.isValidEmail(_self.contactEmail)) {
          _self.msgTxt = "请输入正确的邮箱";
          _self.msgType = "error";
          _self.$refs.msg.open();
          return;
        }
      }
      common_vendor.index.showLoading({
        title: "保存中..."
      });
      const data = {
        company: _self.contactCompany,
        csaNo: _self.tempContact.csaNo,
        name: _self.contactName,
        phone: _self.contactPhone,
        email: _self.contactEmail
      };
      common_js_net_UserApi.UserApi.doUpdateContactList(_self.tempContact.projContactId, data).then((res) => {
        common_vendor.index.hideLoading();
        _self.$refs.popup.close();
        _self.msgTxt = "修改成功";
        _self.msgType = "success";
        _self.contactEmail = "";
        _self.contactPhone = "";
        _self.contactName = "";
        _self.contactCompany = "";
        _self.tempContact = null;
        _self.doRefreshList();
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.$refs.popup.close();
        _self.msgTxt = err.msg ? err.msg : "新建失败,请稍后重试";
        _self.msgType = "error";
        _self.$refs.msg.open();
      });
    },
    //显示删除
    showDelDialog(e) {
      this.tempContact = e.currentTarget.dataset.value;
      this.alertMsg = "一旦删除，该联系人信息将无法恢复，你仍要删除吗？";
      this.$refs.confirmDialog.open();
    },
    //删除联系人
    doDelContact() {
      const _self = this;
      const id = _self.tempContact.projContactId;
      common_vendor.index.showLoading({
        title: "删除中..."
      });
      common_js_net_UserApi.UserApi.doDelContact(id).then((res) => {
        common_vendor.index.hideLoading();
        _self.msgTxt = "删除成功";
        _self.msgType = "success";
        _self.$refs.msg.open();
        _self.doRefreshList();
      }).catch((err) => {
        common_vendor.index.hideLoading();
        _self.msgTxt = err.msg ? err.msg : "删除失败,请稍后重试";
        _self.msgType = "error";
        _self.$refs.msg.open();
      });
    },
    //获取客服NO
    doGetCsaNo(isShow) {
      const _self = this;
      common_js_net_UserApi.UserApi.doGetCsaNo().then((res) => {
        common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineContact/mineContact.vue:335", res);
        _self.csaNo = res.csaNo;
        _self.isShowContact = isShow;
      }, (err) => {
        common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineContact/mineContact.vue:339", err);
      });
    },
    //获取我的联系人列表 isRefresh false 加载更多  true 刷新
    doGetMineContactList(isRefresh) {
      const _self = this;
      _self.contactList = isRefresh ? [] : _self.contactList;
      _self.loadingState = isRefresh ? "loading" : "";
      common_js_net_UserApi.UserApi.doGetMineContactList(_self.pageData).then((res) => {
        common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineContact/mineContact.vue:349", res);
        var status = "success";
        status = res.rows && res.rows.length > 0 ? "success" : "empty";
        _self.loadingState = isRefresh ? status : "";
        _self.contactList = _self.contactList.concat(res.rows);
        _self.listRefreshTrig = false;
        _self.isLoadMore = false;
        _self.hasMore = _self.contactList.length < res.total;
        _self.loadMore = _self.hasMore ? "more" : "noMore";
      }).catch((err) => {
        _self.loadingState = "error";
        _self.listRefreshTrig = false;
        _self.isLoadMore = false;
        _self.hasMore = true;
        _self.loadMore = "more";
      });
    },
    //清除搜索内容
    clearSearch() {
      const _self = this;
      _self.keywords = "";
      _self.doRefreshList();
    },
    //发起搜索
    doSearchKeyWord() {
      const _self = this;
      _self.doRefreshList();
    },
    //刷新列表
    doRefreshList() {
      common_vendor.index.__f__("log", "at pages/mine/mineAccount/mineContact/mineContact.vue:380", "正在刷新...");
      const _self = this;
      _self.listRefreshTrig = true;
      _self.loadingState = "loading";
      _self.hasMore = true;
      _self.pageData.page = 1;
      _self.pageData.keywords = _self.keywords;
      _self.isLoadMore = false;
      _self.loadMore = "more";
      _self.doGetMineContactList(true);
    },
    //加载更多
    doLoadMore() {
      const _self = this;
      if (_self.isLoadMore || _self.loadMore == "noMore") {
        return;
      }
      _self.isLoadMore = true;
      _self.loadMore = "loading";
      _self.pageData.page = ++_self.pageData.page;
      _self.keywords = _self.keywords;
      _self.doGetMineContactList(false);
    }
  }
};
if (!Array) {
  const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  const _component_ContainerLoading = common_vendor.resolveComponent("ContainerLoading");
  const _easycom_uni_popup_dialog2 = common_vendor.resolveComponent("uni-popup-dialog");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  const _easycom_uni_popup_message2 = common_vendor.resolveComponent("uni-popup-message");
  (_easycom_uni_load_more2 + _component_ContainerLoading + _easycom_uni_popup_dialog2 + _easycom_uni_popup2 + _easycom_uni_popup_message2)();
}
const _easycom_uni_load_more = () => "../../../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
const _easycom_uni_popup_dialog = () => "../../../../uni_modules/uni-popup/components/uni-popup-dialog/uni-popup-dialog.js";
const _easycom_uni_popup = () => "../../../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
const _easycom_uni_popup_message = () => "../../../../uni_modules/uni-popup/components/uni-popup-message/uni-popup-message.js";
if (!Math) {
  (_easycom_uni_load_more + _easycom_uni_popup_dialog + _easycom_uni_popup + _easycom_uni_popup_message)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return common_vendor.e({
    a: $data.keywords,
    b: common_vendor.o((...args) => $options.inputKeywords && $options.inputKeywords(...args)),
    c: common_vendor.o((...args) => $options.doSearchKeyWord && $options.doSearchKeyWord(...args)),
    d: $data.keywords != ""
  }, $data.keywords != "" ? {
    e: common_vendor.o((...args) => $options.clearSearch && $options.clearSearch(...args))
  } : {}, {
    f: common_vendor.o((...args) => $options.showCreateDialog && $options.showCreateDialog(...args)),
    g: common_vendor.f($data.contactList, (item, index, i0) => {
      return {
        a: common_vendor.t(item.name),
        b: common_vendor.t(item.phone),
        c: item,
        d: item,
        e: common_vendor.t(item.company),
        f: common_vendor.t(item.csaNo),
        g: index
      };
    }),
    h: common_vendor.o((...args) => $options.showEditDialog && $options.showEditDialog(...args)),
    i: common_vendor.o((...args) => $options.showDelDialog && $options.showDelDialog(...args)),
    j: common_vendor.p({
      status: $data.loadMore
    }),
    k: common_vendor.o((...args) => $options.doLoadMore && $options.doLoadMore(...args)),
    l: common_vendor.o($options.doRefreshList),
    m: common_vendor.p({
      loadingVisible: $data.loadingState
    }),
    n: common_vendor.o($options.doDelContact),
    o: common_vendor.p({
      type: "warning",
      cancelText: "取消",
      confirmText: "删除",
      title: "警告",
      content: $data.alertMsg
    }),
    p: common_vendor.sr("confirmDialog", "c8b76c9a-2"),
    q: common_vendor.p({
      type: "dialog"
    }),
    r: common_vendor.o((...args) => $options.closePopup && $options.closePopup(...args)),
    s: common_vendor.t($data.title),
    t: $data.contactName,
    v: common_vendor.o((...args) => $options.inputContactName && $options.inputContactName(...args)),
    w: $data.contactPhone,
    x: common_vendor.o((...args) => $options.inputContactPhone && $options.inputContactPhone(...args)),
    y: $data.contactEmail,
    z: common_vendor.o((...args) => $options.inputContactEmail && $options.inputContactEmail(...args)),
    A: $data.contactCompany,
    B: common_vendor.o((...args) => $options.inputContactCompany && $options.inputContactCompany(...args)),
    C: $data.isCreate
  }, $data.isCreate ? {
    D: common_vendor.t($data.btnTxt),
    E: common_vendor.o((...args) => $options.doSaveContact && $options.doSaveContact(...args))
  } : {}, {
    F: !$data.isCreate
  }, !$data.isCreate ? {
    G: common_vendor.t($data.btnTxt),
    H: common_vendor.o((...args) => $options.doEditContact && $options.doEditContact(...args))
  } : {}, {
    I: common_vendor.sr("popup", "c8b76c9a-4"),
    J: common_vendor.p({
      type: "bottom",
      ["background-color"]: "#fff",
      ["border-radius"]: "15rpx 15rpx 0rpx 0rpx"
    }),
    K: common_vendor.p({
      type: $data.msgType,
      message: $data.msgTxt,
      duration: 2e3
    }),
    L: common_vendor.sr("msg", "c8b76c9a-5"),
    M: common_vendor.p({
      type: "message"
    })
  });
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
tt.createPage(MiniProgramPage);
//# sourceMappingURL=../../../../../.sourcemap/mp-toutiao/pages/mine/mineAccount/mineContact/mineContact.js.map
