"use strict";
const common_vendor = require("../../common/vendor.js");
const api_xuncha = require("../../api/xuncha.js");
if (!Array) {
  const _easycom_up_th2 = common_vendor.resolveComponent("up-th");
  const _easycom_up_tr2 = common_vendor.resolveComponent("up-tr");
  const _easycom_up_table2 = common_vendor.resolveComponent("up-table");
  (_easycom_up_th2 + _easycom_up_tr2 + _easycom_up_table2)();
}
const _easycom_up_th = () => "../../node-modules/uview-plus/components/u-th/u-th.js";
const _easycom_up_tr = () => "../../node-modules/uview-plus/components/u-tr/u-tr.js";
const _easycom_up_table = () => "../../node-modules/uview-plus/components/u-table/u-table.js";
if (!Math) {
  (TableTitle + _easycom_up_th + SsInput + Td + _easycom_up_tr + _easycom_up_table + Form + SsBottom)();
}
const Form = () => "../../components/Form/index.js";
const Td = () => "../../components/Td/index.js";
const SsInput = () => "../../components/SsInput/index.js";
const TableTitle = () => "../../components/SsTableTitle/index.js";
const SsBottom = () => "../../components/SsBottom/index.js";
const _sfc_main = {
  __name: "mp_excelRcXcdjl_edit",
  setup(__props) {
    const rcid = common_vendor.ref(0);
    const xunchaList = common_vendor.ref([]);
    const formData = common_vendor.ref({});
    const loadXunchaData = async () => {
      try {
        const res = await api_xuncha.xunchaApi.initZxxzEdit({ rcid: rcid.value });
        common_vendor.index.__f__("log", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:55", "返回数据:", res);
        if (res.data && res.data) {
          xunchaList.value = res.data;
          common_vendor.index.__f__("log", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:60", "巡查点数据:", xunchaList.value);
        } else {
          common_vendor.index.__f__("warn", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:62", "未找到 xcdjlList 数据");
          xunchaList.value = [];
        }
        generateFieldConfigs();
      } catch (error) {
        common_vendor.index.__f__("error", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:70", "加载巡查数据失败:", error);
        common_vendor.index.showToast({
          title: "加载数据失败",
          icon: "none"
        });
      }
    };
    const fieldConfigs = common_vendor.ref({});
    const generateFieldConfigs = () => {
      const newFormData = {};
      const newFieldConfigs = {};
      xunchaList.value.forEach((item, index) => {
        const areaKey = `xcd_${index}`;
        newFormData[areaKey] = {
          qkms: item.qkms || "",
          clms: item.clms || "",
          zrr: item.zrr || ""
        };
        newFieldConfigs[`${areaKey}.qkms`] = {
          rules: [{ required: true, message: `${item.xcdmc}的情况描述不能为空` }]
        };
        newFieldConfigs[`${areaKey}.clms`] = {
          rules: [{ required: true, message: `${item.xcdmc}的处理描述不能为空` }]
        };
        newFieldConfigs[`${areaKey}.zrr`] = {
          rules: [{ required: true, message: `${item.xcdmc}的责任人不能为空` }]
        };
      });
      formData.value = newFormData;
      fieldConfigs.value = newFieldConfigs;
      common_vendor.index.__f__("log", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:110", "初始化完成:", {
        formData: formData.value,
        fieldConfigs: fieldConfigs.value
      });
    };
    const formRef = common_vendor.ref(null);
    const submitting = common_vendor.ref(false);
    const bottomButtons = [
      { text: "取消", action: "cancel" },
      { text: "保存并提交", action: "submit" }
    ];
    const handleBottomAction = (data) => {
      common_vendor.index.__f__("log", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:130", "底部按钮操作:", data);
      switch (data.action) {
        case "cancel":
          common_vendor.index.navigateBack();
          break;
        case "submit":
          handleSubmit();
          break;
      }
    };
    const handleSubmit = async () => {
      if (formRef.value) {
        try {
          submitting.value = true;
          const isValid = formRef.value.validateForm(formData.value, fieldConfigs.value);
          common_vendor.index.__f__("log", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:150", "校验结果:", isValid);
          if (isValid) {
            const formSubmitData = {
              // 隐藏字段
              rcid: rcid.value,
              // 巡查点数据 - 使用JSP中的字段名格式
              xcdid: [],
              xcdjlid: [],
              qkms: [],
              clms: [],
              zrr: []
            };
            xunchaList.value.forEach((item, index) => {
              formSubmitData.xcdid.push(item.xcdid);
              formSubmitData.xcdjlid.push(item.xcdjlid || "null");
              formSubmitData.qkms.push(formData.value[`xcd_${index}`].qkms);
              formSubmitData.clms.push(formData.value[`xcd_${index}`].clms);
              formSubmitData.zrr.push(formData.value[`xcd_${index}`].zrr);
            });
            common_vendor.index.__f__("log", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:175", "提交数据（JSP格式）:", formSubmitData);
            const res = await api_xuncha.xunchaApi.submZxxzEdit(formSubmitData);
            common_vendor.index.__f__("log", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:177", "提交结果:", res);
            common_vendor.index.showToast({
              title: "提交成功",
              icon: "success"
            });
            setTimeout(() => {
              common_vendor.index.navigateBack();
            }, 1500);
          } else {
            common_vendor.index.showToast({
              title: "请检查表单信息",
              icon: "none"
            });
          }
        } catch (error) {
          common_vendor.index.__f__("error", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:195", "提交失败:", error);
          common_vendor.index.showToast({
            title: "提交失败",
            icon: "error"
          });
        } finally {
          submitting.value = false;
        }
      }
    };
    common_vendor.onLoad((options) => {
      common_vendor.index.__f__("log", "at pages/xuncha/mp_excelRcXcdjl_edit.vue:206", "onLoad", options);
      rcid.value = options.rcid || 521185;
      loadXunchaData();
    });
    return (_ctx, _cache) => {
      return {
        a: common_vendor.f(xunchaList.value, (item, index, i0) => {
          return {
            a: common_vendor.t(item.xcdmc),
            b: "134710e1-1-" + i0 + ",134710e1-0",
            c: "134710e1-4-" + i0 + "," + ("134710e1-3-" + i0),
            d: "134710e1-6-" + i0 + "," + ("134710e1-5-" + i0),
            e: common_vendor.o(($event) => formData.value[`xcd_${index}`].qkms = $event, item.xcdid),
            f: common_vendor.p({
              placeholder: "请输入情况描述",
              modelValue: formData.value[`xcd_${index}`].qkms
            }),
            g: "134710e1-5-" + i0 + "," + ("134710e1-3-" + i0),
            h: common_vendor.p({
              field: `xcd_${index}.qkms`
            }),
            i: "134710e1-3-" + i0 + "," + ("134710e1-2-" + i0),
            j: "134710e1-8-" + i0 + "," + ("134710e1-7-" + i0),
            k: "134710e1-10-" + i0 + "," + ("134710e1-9-" + i0),
            l: common_vendor.o(($event) => formData.value[`xcd_${index}`].clms = $event, item.xcdid),
            m: common_vendor.p({
              placeholder: "请输入处理描述",
              modelValue: formData.value[`xcd_${index}`].clms
            }),
            n: "134710e1-9-" + i0 + "," + ("134710e1-7-" + i0),
            o: common_vendor.p({
              field: `xcd_${index}.clms`
            }),
            p: "134710e1-7-" + i0 + "," + ("134710e1-2-" + i0),
            q: "134710e1-12-" + i0 + "," + ("134710e1-11-" + i0),
            r: "134710e1-14-" + i0 + "," + ("134710e1-13-" + i0),
            s: common_vendor.o(($event) => formData.value[`xcd_${index}`].zrr = $event, item.xcdid),
            t: common_vendor.p({
              placeholder: "请输入责任人",
              modelValue: formData.value[`xcd_${index}`].zrr
            }),
            v: "134710e1-13-" + i0 + "," + ("134710e1-11-" + i0),
            w: common_vendor.p({
              field: `xcd_${index}.zrr`
            }),
            x: "134710e1-11-" + i0 + "," + ("134710e1-2-" + i0),
            y: "134710e1-2-" + i0 + ",134710e1-0",
            z: item.xcdid
          };
        }),
        b: common_vendor.sr(formRef, "134710e1-0", {
          "k": "formRef"
        }),
        c: common_vendor.o(($event) => formData.value = $event),
        d: common_vendor.p({
          rules: fieldConfigs.value,
          modelValue: formData.value
        }),
        e: common_vendor.o(handleBottomAction),
        f: common_vendor.p({
          buttons: bottomButtons
        })
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-134710e1"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/xuncha/mp_excelRcXcdjl_edit.js.map
