"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_api = require("../../utils/api.js");
const utils_des = require("../../utils/des.js");
if (!Array) {
  const _easycom_uni_segmented_control2 = common_vendor.resolveComponent("uni-segmented-control");
  const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
  (_easycom_uni_segmented_control2 + _easycom_uni_icons2 + _easycom_uni_popup2)();
}
const _easycom_uni_segmented_control = () => "../../uni_modules/uni-segmented-control/components/uni-segmented-control/uni-segmented-control.js";
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
if (!Math) {
  (_easycom_uni_segmented_control + _easycom_uni_icons + NoData + _easycom_uni_popup + Tabber)();
}
const Tabber = () => "../../components/tabber.js";
const NoData = () => "../../components/noData.js";
const _sfc_main = {
  __name: "backlog",
  setup(__props) {
    const activeCurrent = common_vendor.ref(0);
    const currentPage = common_vendor.ref(1);
    const total = common_vendor.ref(0);
    const controlList = ["待审核", "已拒绝", "进校核销", "出校核销", "已完成"];
    const list = common_vendor.ref([]);
    const popup = common_vendor.ref(null);
    const popObj = common_vendor.ref({});
    const showSet = common_vendor.ref(false);
    const configInfo = common_vendor.ref({});
    common_vendor.onLoad(() => {
      getConfig();
      getData();
    });
    common_vendor.onReachBottom(() => {
      if (total.value > list.value.length) {
        currentPage.value++;
        getData();
      } else {
        common_vendor.index.showToast({
          title: "没有更多数据了",
          icon: "none"
        });
      }
    });
    const getConfig = async () => {
      const res = await utils_api.myRequest({
        url: "/wanzai/api/smartVisitorParentsConfig/getUserId",
        data: {
          userId: common_vendor.index.getStorageSync("userInfo").id
        }
      });
      if (res.code == 200) {
        showSet.value = true;
        const result = JSON.parse(utils_des.decryptDes(res.data));
        configInfo.value = result;
      }
    };
    const getData = async () => {
      let type;
      if (activeCurrent.value == 0) {
        type = 1;
      } else if (activeCurrent.value == 1) {
        type = 2;
      } else if (activeCurrent.value == 2) {
        type = 7;
      } else if (activeCurrent.value == 3) {
        type = 8;
      } else if (activeCurrent.value == 4) {
        type = 9;
      }
      const res = await utils_api.myRequest({
        url: "/wanzai/api/smartVisitor/visitingAgencys",
        data: {
          currentPage: currentPage.value,
          pageCount: 6,
          userId: common_vendor.index.getStorageSync("userInfo").id,
          type
        }
      });
      const result = res.data;
      total.value = result.totalCount;
      list.value = [...list.value, ...result.list || []];
    };
    const onClickItem = (e) => {
      if (activeCurrent.value != e.currentIndex) {
        activeCurrent.value = e.currentIndex;
        currentPage.value = 1;
        list.value = [];
        getData();
      }
    };
    const handleClick = (item) => {
      popObj.value = item;
      popup.value.open();
    };
    const handleReject = (info) => {
      handleExamine(info, 2);
    };
    const handleAgree = (info) => {
      handleExamine(info, 4);
    };
    const handleExamine = (info, type) => {
      common_vendor.index.showModal({
        title: "提示",
        content: type == 4 ? "确定同意吗？" : "确定拒绝吗？",
        success: (res) => {
          if (res.confirm) {
            if (info.visitorType == 1) {
              handleExamineReq(info.id, type);
            } else {
              handleExamineReq_other(info.id, type);
            }
          }
        }
      });
    };
    const handleExamineReq = async (id, type) => {
      await utils_api.myRequest({
        url: "/wanzai/api/smartVisitor/parentsAudit",
        data: {
          id,
          type
        }
      });
      common_vendor.index.showToast({
        title: type == 4 ? "已同意该审核" : "已拒绝该审核",
        icon: "success",
        duration: 2e3
      });
      setTimeout(() => {
        list.value = [];
        currentPage.value = 1;
        getData();
      }, 2e3);
    };
    const handleExamineReq_other = async (id, type) => {
      await utils_api.myRequest({
        url: "/wanzai/api/smartVisitor/restsAudit",
        data: {
          id,
          type
        }
      });
      common_vendor.index.showToast({
        title: type == 4 ? "已同意该审核" : "已拒绝该审核",
        icon: "success",
        duration: 2e3
      });
      setTimeout(() => {
        list.value = [];
        currentPage.value = 1;
        getData();
      }, 2e3);
    };
    const closePop = () => {
      popup.value.close();
    };
    const handleClickSet = () => {
      let info = JSON.stringify(configInfo.value);
      common_vendor.index.navigateTo({
        url: `/pagesReservation/set/set?info=${info}`
      });
    };
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o(onClickItem),
        b: common_vendor.p({
          current: activeCurrent.value,
          values: controlList,
          styleType: "text",
          activeColor: "#0061FF"
        }),
        c: common_vendor.f(list.value, (item, k0, i0) => {
          return common_vendor.e({
            a: common_vendor.t(item.userName),
            b: common_vendor.t(item.createTime),
            c: item.statuStr == "待审核"
          }, item.statuStr == "待审核" ? {
            d: common_vendor.t(item.statuStr)
          } : {}, {
            e: item.statuStr == "已拒绝"
          }, item.statuStr == "已拒绝" ? {
            f: common_vendor.t(item.statuStr)
          } : {}, {
            g: item.statuStr == "已推送"
          }, item.statuStr == "已推送" ? {
            h: common_vendor.t(item.statuStr)
          } : {}, {
            i: common_vendor.t(item.visitorType === 1 ? "学生家长预约" : "其他访客预约"),
            j: common_vendor.t(item.visitorTime),
            k: common_vendor.t(item.visitReason),
            l: common_vendor.t(item.visitorType === 1 ? "受访学生" : "受访人"),
            m: common_vendor.t(item.respondentName),
            n: item.statuStr == "待审核"
          }, item.statuStr == "待审核" ? {
            o: common_vendor.o(($event) => handleReject(item), item.id),
            p: common_vendor.o(($event) => handleAgree(item), item.id)
          } : {}, {
            q: item.id,
            r: common_vendor.o(($event) => handleClick(item), item.id)
          });
        }),
        d: showSet.value
      }, showSet.value ? {
        e: common_vendor.p({
          type: "gear-filled",
          size: "18"
        }),
        f: common_vendor.o(handleClickSet)
      } : {}, {
        g: !list.value.length
      }, !list.value.length ? {} : {}, {
        h: common_vendor.o(closePop),
        i: popObj.value.statuStr == "待审核"
      }, popObj.value.statuStr == "待审核" ? {
        j: common_vendor.t(popObj.value.statuStr)
      } : {}, {
        k: popObj.value.statuStr == "已拒绝"
      }, popObj.value.statuStr == "已拒绝" ? {
        l: common_vendor.t(popObj.value.statuStr)
      } : {}, {
        m: popObj.value.statuStr == "已推送"
      }, popObj.value.statuStr == "已推送" ? {
        n: common_vendor.t(popObj.value.statuStr)
      } : {}, {
        o: common_vendor.t(popObj.value.visitorType === 1 ? "学生家长预约" : "其他访客预约"),
        p: common_vendor.t(popObj.value.userName),
        q: common_vendor.t(popObj.value.userPhone),
        r: common_vendor.t(popObj.value.visitorTime),
        s: common_vendor.t(popObj.value.userNumber),
        t: common_vendor.t(popObj.value.visitReason),
        v: common_vendor.t(popObj.value.carNum ? popObj.value.carNum : "无"),
        w: common_vendor.t(popObj.value.peerNum ? popObj.value.carNum : "无"),
        x: common_vendor.t(popObj.value.visitorType === 1 ? "受访学生" : "受访人"),
        y: common_vendor.t(popObj.value.respondentName),
        z: common_vendor.t(popObj.value.responcode || popObj.value.respondentPhone),
        A: popObj.value.statuStr == "待审核"
      }, popObj.value.statuStr == "待审核" ? {
        B: common_vendor.o(($event) => handleReject(popObj.value)),
        C: common_vendor.o(($event) => handleAgree(popObj.value))
      } : {}, {
        D: common_vendor.sr(popup, "a46ecdc3-3", {
          "k": "popup"
        }),
        E: common_vendor.p({
          type: "center",
          ["is-mask-click"]: false
        })
      });
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-a46ecdc3"], ["__file", "E:/workSpace/WanZai_School_app/pagesReservation/backlog/backlog.vue"]]);
wx.createPage(MiniProgramPage);
