<template>
  <div>
    <base-page
      ref="basePage"
      :searchParams="searchParams"
      :tableParams="tableParams"
      :tableUrl="tableUrl"
      :delUrl="delUrl"
      :delMultipleUrl="delMultipleUrl"
      :delAuth="delAuth"
      :infoUrl="infoUrl"
      :exportUrl="exportUrl"
      :editParams="editParams"
      :editElseRules="editElseRules"
      :editBtnName="(item) => (!item.latitude ? '待完善' : '修改')"
      idName="id"
    >
      <template v-slot:listBtn="{ multipleSelection }">
        <el-button @click="handleSyncMultiple(multipleSelection)" size="small"
          >批量更新</el-button
        >
      </template>

      <template v-slot:listBtnSup="{ item }">
        <el-button type="text" @click="handleSync(item)" size="small"
          >全部更新</el-button
        >
      </template>
    </base-page>
  </div>
</template>

<script>
import basePage from "@/views/modules/cpts/base/index";
import { requestPost } from "@/js/dai/request";

export default {
  props: {},

  data() {
    return {
      searchParams: [
        { field: "姓名", keyName: "name", type: "input" },
        { field: "证件号", keyName: "idCard", type: "input" },
      ],

      tableParams: [
        { field: "选择框", keyName: "", type: "selection" },
        { field: "序号", keyName: "", type: "no" },
        { field: "姓名", keyName: "name", type: "text" },
        { field: "证件号", keyName: "idCard", type: "text" },
        { field: "死亡日期", keyName: "deathDate", type: "text" },
        { field: "现年龄", keyName: "age", type: "text" },
        { field: "家庭住址", keyName: "address", type: "text" },
      ],

      tableUrl: "/epmetuser/dataSyncRecordDeath/page",
      delMultipleUrl: "/epmetuser/dataSyncRecordDeath/delete",

      infoUrl: "/epmetuser/dataSyncRecordDeath/detail/",
      //   delUrl: "/gov/org/icDangerousChemicals/del",
      exportUrl: "/epmetuser/dataSyncRecordDeath/expoprt",

      editParams: [
        { field: "姓名", keyName: "name", type: "input" },
        { field: "证件号", keyName: "idCard", type: "input" },
        { field: "死亡日期", keyName: "deathDate", type: "input" },
        { field: "现年龄", keyName: "age", type: "input" },
        { field: "家庭住址", keyName: "address", type: "input" },
      ],
    };
  },
  components: { basePage },
  computed: {},
  watch: {},

  async mounted() {},

  methods: {
    async handleSync(item) {
      const { data, code, msg } = await requestPost(
        "/epmetuser/dataSyncRecordDeath/batchupdate",
        [item["id"]]
      );

      if (code === 0) {
        this.$message.success("更新成功！");
        this.$refs.basePage.getTableData();
      } else {
        this.$message.error("操作失败！");
      }
    },

    async handleSyncMultiple(multipleSelection) {
      const { data, code, msg } = await requestPost(
        "/epmetuser/dataSyncRecordDeath/batchupdate",
        [...multipleSelection.map((item) => item["id"])]
      );

      if (code === 0) {
        this.$message.success("批量更新成功！");
        this.$refs.basePage.getTableData();
      } else {
        this.$message.error("操作失败！");
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
