<template>
  <div>
    <base-page
      :searchParams="searchParams"
      :tableParams="tableParams"
      :tableUrl="tableUrl"
      :addUrl="addUrl"
      :editUrl="editUrl"
      :delUrl="delUrl"
      :infoUrl="infoUrl"
      :editAuth="editAuth"
      :delAuth="delAuth"
      :exportUrl="exportUrl"
      :importUrl="importUrl"
      :mubanUrl="mubanUrl"
      :editParams="editParams"
      :editElseRules="editElseRules"
      :editFixedParams="editFixedParams"
      :editParamsDiv="5"
      :editBtnName="(item) => (!item.latitude ? '待完善' : '修改')"
      :formBtnFixed="false"
      idName="enterpriseId"
    >
      <template v-slot:editElse="{ id, formType, info }">
        <record
          v-if="formType != 'add' && id"
          :formType="formType"
          :enterpriseId="id"
          :enterpriseInfo="info"
        ></record>
      </template>
    </base-page>
  </div>
</template>

<script>
import basePage from "@/views/modules/cpts/base/index";
import record from "./cpts/record";

export default {
  components: { basePage, record },
  props: {},

  data() {
    return {
      searchParams: [
        { field: "场所名称", keyName: "placeOrgName", type: "input" },
        { field: "联系电话", keyName: "mobile", type: "input" },
        {
          field: "场所区域",
          keyName: "gridId",
          type: "select",
          optionUrl: "/gov/org/customergrid/gridoption",
          optionUrlParams: {
            agencyId: this.$store.state.user.agencyId,
            purpose: "query",
          },
          optionList: [],
        },
        {
          field: "场所类型",
          keyName: "placeType",
          type: "select",
          optionUrl: "/gov/org/coverage/dict-select-list/enterprise_patrol",
          optionUrlParams: {},
          optionList: [],
        },
        {
          field: "规模",
          keyName: "scale",
          type: "select",
          optionUrl: "/sys/dict/data/dictlist",
          optionUrlParams: {
            dictType: "scale",
          },
          optionList: [],
        },
        {
          field: "巡查结果",
          keyName: "result",
          type: "select",
          optionUrl: "",
          optionUrlParams: {},
          optionList: [
            {
              value: "0",
              label: "合格",
            },
            {
              value: "1",
              label: "不合格",
            },
          ],
        },
        { field: "隐患明细", keyName: "detailed", type: "input" },
      ],

      tableParams: [
        { field: "序号", keyName: "", type: "no" },
        { field: "场所名称", keyName: "placeOrgName", type: "text" },
        { field: "场所地址", keyName: "address", type: "text" },
        { field: "场所类型", keyName: "placeTypeName", type: "text" },
        { field: "规模", keyName: "scaleName", type: "text" },
        { field: "负责人", keyName: "personInCharge", type: "text" },
        { field: "联系电话", keyName: "mobile", type: "text" },
        { field: "最新检查时间", keyName: "latestPatrolTime", type: "text" },
        { field: "最新结果", keyName: "latestResultName", type: "text" },
      ],
      tableUrl: "/gov/org/enterprise/list",
      mubanUrl: "/gov/org/enterprise/download-tem",
      importUrl: "/gov/org/enterprise/import",
      exportUrl: "/gov/org/enterprise/export",

      addUrl: "/gov/org/enterprise/addOrUpdate",
      editUrl: "/gov/org/enterprise/addOrUpdate",
      infoUrl: "/gov/org/enterprise/detail/",
      delUrl: "/gov/org/enterprise/delete/",
      editAuth(item) {
        return item.agencyId == this.$store.state.user.agencyId;
      },
      delAuth(item) {
        return item.agencyId == this.$store.state.user.agencyId;
      },

      editParams: [
        {
          field: "场所类型",
          keyName: "placeType",
          type: "select",
          optionUrl: "/gov/org/coverage/dict-select-list/enterprise_patrol",
          optionUrlParams: {
            // dictType: "ic_service_type",
          },
          optionList: [],
          editDisabled: true,
          rules: [
            { required: true, message: "场所类型不能为空", trigger: "blur" },
          ],
        },
        {
          field: "场所区域",
          keyName: "gridId",
          type: "select",
          optionUrl: "/gov/org/customergrid/gridoption",
          optionUrlParams: {
            agencyId: this.$store.state.user.agencyId,
            purpose: "addorupdate",
          },
          optionList: [],
          editDisabled: true,
          rules: [
            { required: true, message: "场所区域不能为空", trigger: "blur" },
          ],
        },
        {
          field: "场所名称",
          keyName: "placeOrgName",
          type: "input",
          maxlength: 50,
          editDisabled: true,
          rules: [
            {
              required: true,
              message: "场所名称不能为空",
              trigger: "blur",
            },
          ],
        },
        {
          field: "规模",
          keyName: "scale",
          type: "select",
          optionUrl: "/sys/dict/data/dictlist",
          optionUrlParams: {
            dictType: "scale",
          },
          optionList: [],
          editDisabled: false,
          rules: [
            {
              required: true,
              message: "规模不能为空",
              trigger: "blur",
            },
          ],
        },
        {
          field: "负责人",
          keyName: "personInCharge",
          type: "input",

          rules: [
            {
              required: true,
              message: "负责人不能为空",
              trigger: "blur",
            },
          ],
        },
        {
          field: "联系电话",
          keyName: "mobile",
          maxlength: 50,
          type: "input",
          rules: [
            {
              required: true,
              message: "联系电话不能为空",
              trigger: "blur",
            },
          ],
        },
        {
          field: "场所地址",
          keyName: "address",
          type: "address",
          maxlength: 50,
          supKeys: ["longitude", "latitude"],
          supValues: ["", ""],
          rules: [
            {
              required: true,
              message: "场所地址坐标不能为空",
              trigger: "blur",
            },
          ],
        },
      ],
      editFixedParams: {
        agencyId: this.$store.state.user.agencyId,
      },
      editElseRules: {
        longitude: {
          type: "number",
          required: true,
          message: "请拖动地图选择坐标点",
        },
      },
    };
  },
  computed: {},
  watch: {},

  async mounted() {},

  methods: {},
};
</script>

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