<template>
  <div id="containt">
    <el-tabs v-model="activeName" class="tab-box">
      <el-tab-pane :label="$t1('常规')" name="first">
        <editView v-if="showEdit" visible-key="showEdit" :_dataId.sync="dataId" :parent-target="_self"
                  @reload="$reloadHandle"></editView>
      </el-tab-pane>
      <el-tab-pane :label="$t1('列表')" name="second">
        <div class="grid-height">
          <vxe-grid ref="table-m1" v-bind="vxeOption" @resizable-change="$vxeTableUtil.onColumnWitchChange"
                    @custom="$vxeTableUtil.customHandle">
            <template #form>
              <tableForm :formData.sync="formData" @searchEvent="searchEvent" @resetEvent="resetEvent">
                <template #buttonLeft>
                  <vxe-button status="primary" class="button-sty" icon="el-icon-plus" @click="openEditDialog">
                    {{ $t1('新增') }}
                  </vxe-button>
                  <base-table-export :option="{ title: $t1('项目标签导出'), targetRef: 'table-m1'}"
                                     :parent-target="_self"/>
                </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>
                <template #tag>
                  <vxe-form-item :title="$t1('项目标签')+':'" field="tag">
                    <template v-slot>
                      <el-input
                        class="search-input"
                        max="200"
                        :value="getTabNames()"
                        @clear="
                            checkTags = [];
                          "
                        v-el-readonly
                        clearable
                      >
                        <i slot="suffix" class="el-input__icon el-icon-search" @click="openProjectTagDialog3"></i>
                      </el-input>
                    </template>
                  </vxe-form-item>
                </template>
              </tableForm>
            </template>
          </vxe-grid>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import editView from './edit.vue';
import tableForm from "@base/components/table/tableForm.vue";

export default {
  name: 'project_tag:list',
  components: {tableForm, editView},
  data() {
    return {
      activeName: 'second',
      dataId: 0,
      showEdit: false,
      vxeOption: {},
      formData: {}
    };
  },
  mounted() {
    this.initTableList();
  },
  methods: {
    searchEvent() {
      this.$refs['table-m1'].commitProxy('reload');
    },
    resetEvent() {
      this.formData = {};
      this.$refs['table-m1'].commitProxy('reload');
    },
    openEditDialog(id) {
      this.dataId = !id || typeof id == 'object' ? 0 : id;
      this.activeName = 'first';
      this.$openEditView('showEdit');
    },
    initTableList() {
      let that = this;
      let tableOption = {
        vue: this,
        tableRef: 'table-m1',
        tableName: 'user_projectTag_list-m1',
        path: USER_PREFIX + '/projectTag/listPage',
        param: () => {
          return this.formData;
        },
        columns: [
          {type: 'checkbox', width: 48, resizable: false, fixed: 'left'},
          {
            title: this.$t1('标签名称'),
            field: 'tagName',
            width: 150,
            fixed: 'left'
          },
          {
            title: this.$t1('标签编码'),
            field: 'tagCode',
            width: 150
          },
          {
            title: this.$t1('标签说明'),
            field: 'tagRemark',
            width: 250
          },
          {
            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 [
                  <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: [
          {title: this.$t1('标签名称'), field: "tagName", type: "input", common: true},
          {title: this.$t1('标签编码'), field: "tagCode", type: "input", common: true},
          {title: this.$t1('标签说明'), field: "tagRemark", type: "input", common: true}
        ]
      };
      this.$vxeTableUtil.initVxeTable(tableOption).then(opts => {
        this.vxeOption = opts;
      });
    }
  }
};
</script>
