<template>
  <el-dialog
    :title="title || $t1('组织列表')"
    :append-to-body="true"
    :modal-append-to-body="true"
    :close-on-click-modal="falseValue"
    :visible.sync="showDialog"
    :modal="falseValue"
    custom-class="dialog-style list-dialog dialog-checkbox pd_0"
    width="1200px"
    :before-close="handleBeforeClose"
    @close="dialogClose"
    v-el-drag-dialog
    v-el-dialog-center
  >
    <div class="cont" style="height: 65vh">
      <vxe-grid
        class="is-pointer"
        ref="table-m1"
        v-bind="vxeOption"
        @resizable-change="$vxeTableUtil.onColumnWitchChange"
        @custom="$vxeTableUtil.customHandle"
        @checkbox-change="addDataTable"
        @checkbox-all="checkAll"
        @cell-dblclick="checkWithSubmit"
      >
        <template #form>
          <div class="clearfix screen-btns">
            <div class="fr">
              <vxe-button
                icon="el-icon-brush"
                class="button-sty"
                @click="resetEvent"
                type="text"
                status="primary"
                plain
                >{{ $t1("重置") }}
              </vxe-button>
              <vxe-button
                status="warning"
                icon="el-icon-search"
                class="button-sty"
                @click="searchEvent"
              >
                {{ $t1("搜索") }}
              </vxe-button>
            </div>
          </div>
          <vxe-form
            class="screen-box"
            title-width="92px"
            title-align="right"
            :data="formData"
            @submit="searchEvent"
            @reset="resetEvent"
            v-if="!allCompany"
          >
            <vxe-form-item :title="$t1('组织名称') + ':'" field="companyName">
              <template v-slot>
                <el-input v-model="formData.companyName" size="small" clearable />
              </template>
            </vxe-form-item>
            <vxe-button type="submit" @click="searchEvent" v-show="false"></vxe-button>
          </vxe-form>
        </template>
      </vxe-grid>
    </div>
    <label id="labBtn" class="transverse">
      <div class="icon">
        <i class="el-icon-more"></i>
        <i class="el-icon-more"></i>
      </div>
    </label>
    <div class="multipleChoice">
      <el-tooltip
        :enterable="false"
        effect="dark"
        :content="$t1('全部删除')"
        placement="top"
        ><a class="allDel icon-quanbushanchu" @click="clearChecked()"></a
      ></el-tooltip>
      <div class="list">
        <div class="item" v-for="(checkRow, index) in checkRows" :key="index">
          <p>{{ checkRow.companyName }}</p>
          <a class="el-icon-close" @click="clearTable1Select(index)"></a>
        </div>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <span class="fl tips" v-if="!selectMulti">{{
        $t1("注：双击确认选择（单选）")
      }}</span>
      <el-button type="primary" plain class="button-sty" @click="dialogCancel">
        <i class="el-icon-close el-icon"></i>
        {{ $t1("取 消") }}
      </el-button>
      <el-button type="primary" @click="dialogPrimary" class="button-sty">
        <i class="el-icon-check el-icon"></i>
        {{ $t1("确 定") }}
      </el-button>
    </span>
  </el-dialog>
</template>

<script>
import { selectDialogMixins } from "@base/mixins/selectDialog/index.js";

export default {
  name: "company_info_dialog",
  props: ["title", "visiable", "multi", "rows", "param", "firstEnabled", "allCompany"],
  mixins: [selectDialogMixins],
  created() {
    if (this.$attrs.fieldKey) this.fieldKey = this.$attrs.fieldKey;
    this.initSetting();
  },
  mounted() {
    this.initTableM1();
  },
  data() {
    return {
      showDialog: true,
      falseValue: false,
      selectMulti: true,
      formData: {},
      vxeOption: {},
    };
  },
  methods: {
    initTableM1() {
      let that = this;
      let path = USER_PREFIX + "/user_company_info/getCurrentList";
      let treeNodeUrl = USER_PREFIX + "/user_company_info/getChildren";
      if (this.allCompany) {
        path = USER_PREFIX + "/company_info/getRoot";
        treeNodeUrl = USER_PREFIX + "/company_info/getChildren";
      }
      let tableOption = {
        vue: that,
        tableRef: "table-m1",
        tableName: "basic_ompany_info_dialog_list",
        path: path,
        treeNodeUrl: treeNodeUrl,
        treeNodeParam: function (row) {
          return { enabled: true, parentCompanyCode: row.companyCode };
        },
        param: () => {
          return {
            enabled: true,
            ...this.formData,
          };
        },
        columns: [
          { type: "checkbox", width: 48, resizable: false, fixed: "left" },
          {
            title: this.$t1("组织名称"),
            field: "companyName",
            width: 250,
            fixed: "left",
            treeNode: true,
          },
          { title: this.$t1("组织编码"), field: "companyCode", width: 200 },
          {
            width: 47,
            fixed: "right",
            title: "",
            sortable: false,
          },
        ],
        config: {
          checkboxConfig: {
            checkStrictly: true,
            showHeader: this.selectMulti,
            trigger: "row",
            checkMethod: ({ row }) => {
              if (this.firstEnabled === "true" || this.firstEnabled === true) {
                return true;
              } else {
                if (!row.parentCompanyCode) {
                  return false;
                } else {
                  return true;
                }
              }
            },
          },
        },
      };

      this.$vxeTableUtil.initVxeTable(tableOption).then((opts) => {
        that.vxeOption = opts;
      });
    },
  },
};
</script>
