<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>
          <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">
            <vxe-form-item :title="$t1('数据源名称')+':'" field="dsName">
              <template v-slot>
                <el-input v-model="formData.dsName" size="small" clearable/>
              </template>
            </vxe-form-item>
            <vxe-form-item :title="$t1('数据源Url')+':'" field="dsUrl">
              <template v-slot>
                <el-input v-model="formData.dsUrl" size="small" clearable/>
              </template>
            </vxe-form-item>
            <vxe-form-item :title="$t1('数据源类型')+':'" field="dsType">
              <template v-slot>
                <el-select v-model="formData.dsType" clearable>
                  <el-option :value="0" label="mysql"></el-option>
                  <el-option :value="1" label="oracle"></el-option>
						      <el-option :value="2" label="doris"></el-option>
                </el-select>
              </template>
            </vxe-form-item>
          </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.dsName }}</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';

export default {
  name: 'areaDialog',
  props: ['visiable', 'multi', 'rows'],
  mixins: [selectDialogMixins],
  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 tableOption = {
        vue: this,
        tableRef: 'table-m1',
        tableName: 'report_datasource_dialog-m1',
        path: USER_PREFIX + '/extend_datasource/listPage',
        aes: true,
        param: () => {
          return {
            enabled: true,
            ...this.formData
          };
        },
        config: {
          checkboxConfig: {
            checkStrictly: true,
            showHeader: this.selectMulti,
            trigger: 'row'
          }
        },
        columns: [
          {type: 'checkbox', width: 48, resizable: false, fixed: 'left'},
          {
            title: this.$t1('数据源名称'),
            field: 'dsName',
            width: 150,
            fixed: 'left'
          },
          {
            title: this.$t1('数据源编码'),
            field: 'dsCode',
            width: 150
          },
          {
            title: this.$t1('数据源类型'),
            field: 'dsType',
            width: 150,
            slots: {
              default: ({row}) => {
                if (row.dsType === 0) {
                  return 'mysql';
                } else if (row.dsType === 1) {
                  return 'oracle';
                } else if (row.dsType === 2) {
                  return 'doris';
                }
              }
            }
          },
          {
            title: this.$t1('数据源对应驱动ClassName'),
            field: 'driverClassName',
            width: 150
          },
          {
            title: this.$t1('链接数据源Url'),
            field: 'dsUrl',
            width: 150
          },
          {
            title: this.$t1('数据源用户名'),
            field: 'dsUserName',
            width: 150
          },
          {
            title: this.$t1('数据源密码'),
            field: 'dsPassWord',
            width: 150
          },
          {
            field: 'enabled',
            title: this.$t1('是否启用'),
            width: 150,
            slots: {
              default: ({row}) => {
                if (row.enabled) {
                  return [
                    <div class="txt-status">
                      <span>{this.$t1('启用')}</span>
                    </div>
                  ];
                } else {
                  return [
                    <div class="txt-status disable">
                      <span>{this.$t1('禁用')}</span>
                    </div>
                  ];
                }
              }
            }
          },
          {
            field: 'remark',
            title: this.$t1('备注'),
            width: 250
          },
          {
            field: 'createDate',
            title: this.$t1('创建时间'),
            width: 150
          },
          {
            width: 47,
            fixed: 'right',
            title: '',
            sortable: false,
            slots: {
              default: ({row}) => {
                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>
                ];
              }
            }
          }
        ]
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then(opts => {
        this.vxeOption = opts;
      });
    }
  }
};
</script>
