<template>
  <el-dialog
    :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"
    @close="dialogClose"
    v-el-drag-dialog
    v-el-dialog-center
  >
    <div class="cont" style="height:450px">
      <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>
          <tableForm :formData.sync="formData" @searchEvent="searchEvent" @resetEvent="resetEvent">
            <template #buttonLeft>
            </template>
            <template #buttonRight>
              <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>
            </template>
          </tableForm>
        </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>{{ getCheckLabel(checkRow, 'name') }}</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="dialogClose">
				<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';
import tableForm from "@base/components/table/tableForm.vue";

export default {
  name: 'positionDialog',
  props: ['visiable', 'multi', 'rows', 'param'],
  mixins: [selectDialogMixins],
  components: {
    tableForm
  },
  created() {
    this.initSetting();
  },
  mounted() {
    this.initTableM1();
  },
  data() {
    var that = this;
    return {
      showDialog: true,
      falseValue: false,
      selectMulti: true,
      formData: {},
      vxeOption: {}
    };
  },
  methods: {
    initTableM1() {
      let that = this;
      let bdServiceMap = {"dev": this.$t1("测试"), "uat": this.$t1("UAT"), "prod": this.$t1("正式")};
      let url = USER_PREFIX + '/bd_company_env/listPage';
      let tableOption = {
        vue: that,
        tableRef: 'table-m1',
        tableName: 'basic_position_dialog-m1',
        path: url,
        param: () => {
          return {
            ...this.formData
          }
        },
        columns: [
          {type: 'checkbox', fixed: 'left', width: 48, resizable: false},
          {
            title: this.$t1('服务'),
            field: 'bdService',
            width: 150,
            fixed: 'left',
            slots: {
              default: ({row}) => {
                return bdServiceMap[row.bdService] || "";
              }
            }
          },
          {
            title: this.$t1('组织编码'),
            field: 'bdCompanyCode',
            width: 150,
          },
          {
            title: this.$t1('组织备注'),
            field: 'bdCompanyRemark',
            width: 150,
          },
          {
            width: 47,
            fixed: 'right',
            title: '',
            sortable: false
          }
        ],
        searchColumns: [
          {
            title: this.$t1('服务'), field: "bdService", type: "select", common: true, itemOption: [
              {label: this.$t1("测试"), value: "dev"},
              {label: this.$t1("UAT"), value: "uat"},
              {label: this.$t1("正式"), value: "prod"}
            ]
          },
          {
            title: this.$t1("组织编码"),
            field: "bdCompanyCode",
            type: "input",
            common: true,
          }
        ],
        config: {
          checkboxConfig: {
            checkStrictly: true,
            showHeader: this.selectMulti,
            trigger: 'row'
          }
        }
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then(opts => {
        that.vxeOption = opts;
      });
    }
  }
};
</script>
