import editView from "../edit.vue";
import editView1 from "../edit1.vue";
import editView2 from "../edit2.vue";
import tableForm from "@base/components/table/tableForm.vue";
import { getJsxBtnList, getJsxStatus,getJsxBtn } from "@base/views/bd/setting/utils/index";

let modules = {};

modules = {
  props: {
    paramType: {
      type: Number,
      default: 0,
    },
  },
  components: { tableForm, editView, editView1, editView2 },
  data() {
    return {
      activeName: "second",
      dataId: 0,
      showEdit: false,
      vxeOption: {},
      formData: {},
      editViewName:"editView",
    };
  },
  created() {
    this.initEditViewName();
  },
  mounted() {
    this.initTableList();
  },
  methods: {
    initEditViewName(){
      let paramTypeStr = this.paramType ? this.paramType : "";
      this.editViewName = `editView${paramTypeStr}`;

    },
    searchEvent() {
      this.$refs["table-m1"].commitProxy("reload");
    },
    resetEvent() {
      this.formData = {};
      this.advancedFormData = {};
      this.$refs["table-m1"].commitProxy("reload");
    },
    openEditDialog(id) {
      this.copyId = 0;
      this.dataId = !id || typeof id == "object" ? 0 : id;
      this.activeName = "first";
      this.$openEditView("showEdit");
    },
    getColumnInfo0() {
      //逻辑参数
      let columns = [
        {
          title: this.$t1("参数编码"),
          field: "paramCode",
          width: 150,
          fixed: "left",
        },
        {
          title: this.$t1("参数值"),
          field: "paramValue",
          width: 150,
        },
        {
          title: this.$t1("参数备注"),
          field: "remark",
          width: 150,
        },
        {
          title: this.$t1("组织编码"),
          field: "paramCompanyCode",
          width: 150,
        },
        {
          title: this.$t1("是否启用"),
          field: "enabled",
          width: 150,
          slots: {
            default: ({ row }) => {
              if (row.enabled) {
                return getJsxStatus(null, this.$t1("启用"));
              } else {
                return getJsxStatus("s-3", this.$t1("禁用"));
              }
            },
          },
        },
      ];

      let searchColumns = [
        {
          title: this.$t1("参数编码"),
          field: "paramCode",
          type: "input",
          common: true,
        },
        {
          title: this.$t1("参数值"),
          field: "paramValue",
          type: "input",
          common: true,
        },
        {
          title: this.$t1("参数备注"),
          field: "remark",
          type: "input",
          common: true,
        },
        {
          title: this.$t1("组织编码"),
          field: "paramCompanyCode",
          type: "input",
          common: true,
        },
        {
          title: this.$t1("是否启用"),
          field: "enabled",
          type: "select",
          itemOption: [
            {
              label: this.$t1("启用"),
              value: true,
            },
            {
              label: this.$t1("禁用"),
              value: false,
            },
          ],
          common: true,
        },
      ];

      return { columns, searchColumns };
    },
    getColumnInfo1() {
      //操作日志编码
      let columns = [
        {
          title: this.$t1("参数值"),
          field: "paramValue",
          width: 150,
          fixed: "left",
        },
        {
          title: this.$t1("参数备注"),
          field: "remark",
          width: 150,
        },
        {
          title: this.$t1("是否启用"),
          field: "enabled",
          width: 150,
          slots: {
            default: ({ row }) => {
              if (row.enabled) {
                return getJsxStatus(null, this.$t1("启用"));
              } else {
                return getJsxStatus("s-3", this.$t1("禁用"));
              }
            },
          },
        },
      ];

      let searchColumns = [
        {
          title: this.$t1("参数值"),
          field: "paramValue",
          type: "input",
          common: true,
        },
        {
          title: this.$t1("参数备注"),
          field: "remark",
          type: "input",
          common: true,
        },
        {
          title: this.$t1("是否启用"),
          field: "enabled",
          type: "select",
          itemOption: [
            {
              label: this.$t1("启用"),
              value: true,
            },
            {
              label: this.$t1("禁用"),
              value: false,
            },
          ],
          common: true,
        },
      ];

      return { columns, searchColumns };
    },
    getColumnInfo2() {
      //上传文件服务
      let columns = [
        {
          title: this.$t1("参数编码"),
          field: "paramCode",
          width: 150,
          fixed: "left",
        },
        {
          title: this.$t1("参数备注"),
          field: "remark",
          width: 150,
        },
        {
          title: this.$t1("是否启用"),
          field: "enabled",
          width: 150,
          slots: {
            default: ({ row }) => {
              if (row.enabled) {
                return getJsxStatus(null, this.$t1("启用"));
              } else {
                return getJsxStatus("s-3", this.$t1("禁用"));
              }
            },
          },
        },
        {
          title: this.$t1("组织编码"),
          field: "paramCompanyCode",
          width: 150
        },
      ];

      let searchColumns = [
        {
          title: this.$t1("参数编码"),
          field: "paramCode",
          type: "input",
          common: true,
        },
        {
          title: this.$t1("参数值"),
          field: "paramValue",
          type: "input",
          common: true,
        },
        {
          title: this.$t1("参数备注"),
          field: "remark",
          type: "input",
          common: true,
        },
        {
          title: this.$t1("是否启用"),
          field: "enabled",
          type: "select",
          itemOption: [
            {
              label: this.$t1("启用"),
              value: true,
            },
            {
              label: this.$t1("禁用"),
              value: false,
            },
          ],
          common: true,
        },
        {
          title: this.$t1("组织编码"),
          field: "paramCompanyCode",
          type: "input",
          common: true,
        },
      ];

      return { columns, searchColumns };
    },
    getColumnInfo() {
      if (this.paramType === 0) {
        return this.getColumnInfo0();
      } else if (this.paramType === 1) {
        return this.getColumnInfo1();
      } else if (this.paramType === 2) {
        return this.getColumnInfo2();
      }
    },
    initTableList() {
      let that = this;
      let { columns, searchColumns } = this.getColumnInfo();

      let tableOption = {
        vue: this,
        tableRef: "table-m1",
        tableName: "logic_param_list-m" + this.paramType,
        path: USER_PREFIX + "/logic_param/listPage",
        param: () => {
          return {
            ...this.formData,
            paramType: this.paramType,
          };
        },
        columns: [
          { type: "checkbox", width: 48, resizable: false, fixed: "left" },
          ...columns,
          {
            field: "createBy",
            title: this.$t1("创建人"),
            width: 150,
          },
          {
            field: "createDate",
            title: this.$t1("创建时间"),
            width: 150,
          },
          {
            field: "modifyBy",
            title: this.$t1("更新人"),
            width: 150,
          },
          {
            field: "modifyDate",
            title: this.$t1("更新时间"),
            width: 150,
          },
          {
            width: 47,
            fixed: "right",
            title: "",
            sortable: false,
            slots: {
              default: ({ row }) => {
                return getJsxBtn({
                  iconName: "el-icon-edit",
                  content: this.$t1('查看'),
                  onclick: () => {
                    this.openEditDialog(row.id);
                  }
                });
                /* return [
                  <div>
                    <a
                      href="javascript:void(0);"
                      class="a-link"
                      onclick={() => {
                        this.openEditDialog(row.id);
                      }}
                    >
                      <el-tooltip
                        enterable={false}
                        effect="dark"
                        content={this.$t1("查看")}
                        placement="top"
                        popper-class="tooltip-skin"
                      >
                        <i class="el-icon-edit" />
                      </el-tooltip>
                    </a>
                  </div>,
                ]; */
              },
            },
          },
        ],
        searchColumns,
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
        this.vxeOption = opts;
      });
    },
  },
};

export default modules
