<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>
              <div class="clearfix screen-btns">
                <div class="fl">
                </div>
                <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 ref="form" class="screen-box" title-width="92px" title-align="right" :data="formData"
                        @submit="searchEvent" @reset="searchEvent">
                <vxe-form-item :title="$t1('表单分类路径')+':'" field="treePathName">
                  <template v-slot>
                    <el-input v-model="formData.treePathName" size="small" clearable/>
                  </template>
                </vxe-form-item>
                <vxe-form-item :title="$t1('日志类型')+':'" field="logType">
                  <template v-slot>
                    <el-input v-model="formData.logType" size="small" clearable/>
                  </template>
                </vxe-form-item>
                <vxe-form-item :title="$t1('日志对象')+':'" field="logObj">
                  <template v-slot>
                    <el-input v-model="formData.logObj" size="small" clearable/>
                  </template>
                </vxe-form-item>
                <vxe-form-item :title="$t1('结果')+':'" field="impReturnType">
                  <template v-slot>
                    <el-select v-model="formData.impReturnType" size="small" clearable>
                      <el-option value="success" label="成功"></el-option>
                      <el-option value="fail" label="失败"></el-option>
                    </el-select>
                  </template>
                </vxe-form-item>
                <vxe-form-item title="导入时间:" field="date1">
                  <template #default="{ data }">
                    <el-date-picker
                      v-model="formData.startImpDate"
                      type="datetime"
                      placeholder=""
                      size="small"
                      clearable
                      value-format="yyyy-MM-dd HH:mm:ss"
                      :picker-options="$baseStartPickerOptions(formData.endImpDate)"
                    ></el-date-picker>
                    <span>-</span>
                    <el-date-picker
                      v-model="formData.endImpDate"
                      type="datetime"
                      placeholder=""
                      size="small"
                      clearable
                      value-format="yyyy-MM-dd HH:mm:ss"
                      default-time="23:59:59"
                      :picker-options="$baseEndPickerOptions(formData.startImpDate)"
                    ></el-date-picker>
                  </template>
                </vxe-form-item>
              </vxe-form>
            </template>
          </vxe-grid>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import editView from './edit.vue';

export default {
  name: 'form_import_log:list',
  components: {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 impReturnTypeMap = {
        success: this.$t1('成功'),
        fail: this.$t1('失败')
      }
      let tableOption = {
        aes: true,
        vue: this,
        tableRef: 'table-m1',
        tableName: 'user_form_import_log_list-m1',
        path: USER_PREFIX + '/form_import_log/listPage',
        param: () => {
          return this.formData;
        },
        columns: [
          {type: 'checkbox', width: 48, resizable: false, fixed: 'left'},
          {
            title: this.$t1('表单分类路径'),
            field: 'treePathName',
            width: 250,
            fixed: 'left'
          },
          {
            field: 'logType',
            title: this.$t1('日志类型'),
            width: 150
          },
          {
            field: 'version',
            title: this.$t1('版本号'),
            width: 150
          },
          {
            field: 'logObj',
            title: this.$t1('日志对象'),
            width: 250,
            slots: {
              default: ({row}) => {
                return `[${row.abc}] ${row.logObj}`;
              }
            }
          },
          {
            field: 'impReturnType',
            title: this.$t1('结果'),
            width: 150,
            slots: {
              default: ({row}) => {
                return impReturnTypeMap[row.impReturnType];
              }
            }
          },
          {
            field: 'impReturnMsg',
            title: this.$t1('失败描述'),
            width: 250
          },
          {
            field: 'impDate',
            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>
