<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">
                  <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"
                  />
                </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="etCode">
                  <template v-slot>
                    <el-input
                      v-model="formData.etCode"
                      size="small"
                      clearable
                    />
                  </template>
                </vxe-form-item>
                <vxe-form-item :title="$t1('输出类型')+':'" field="etType">
                  <template v-slot>
                    <el-select v-model="formData.etType" clearable>
                      <el-option :value="0" :label="etTypeMap[0]"></el-option>
                      <el-option :value="1" :label="etTypeMap[1]"></el-option>
                      <el-option :value="2" :label="etTypeMap[2]"></el-option>
                      <el-option :value="3" :label="etTypeMap[3]"></el-option>
                      <el-option :value="4" :label="etTypeMap[4]"></el-option>
                      <el-option :value="5" :label="etTypeMap[5]"></el-option>
                      <el-option :value="6" :label="etTypeMap[6]"></el-option>
                      <el-option :value="7" :label="etTypeMap[7]"></el-option>
                      <el-option :value="8" :label="etTypeMap[8]"></el-option>
                      <el-option :value="9" :label="etTypeMap[9]"></el-option>
                    </el-select>
                  </template>
                </vxe-form-item>
                <vxe-form-item :title="$t1('组织编码')+':'" field="etCompanyCode">
                  <template v-slot>
                    <el-input
                      v-model="formData.etCompanyCode"
                      size="small"
                      clearable
                    />
                  </template>
                </vxe-form-item>
                <vxe-form-item :title="$t1('是否启用')+':'" field="enabled">
                  <template v-slot>
                    <el-select v-model="formData.enabled" clearable>
                      <el-option value="true" :label="$t1('启用')"></el-option>
                      <el-option value="false" :label="$t1('禁用')"></el-option>
                    </el-select>
                  </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: "export_template:list",
  components: {editView},
  data() {
    return {
      activeName: "second",
      dataId: 0,
      showEdit: false,
      vxeOption: {},
      formData: {},
      etTypeMap: {
        0: this.$t1('输出excel格式文件，使用excel格式模版'),
        1: this.$t1('输出pdf格式文件，使用excel格式模版'),
        2: this.$t1('菜鸟打印'),
        3: this.$t1('网页打印'),
        4: this.$t1('上传存储自定义文件，使用自定义格式模版'),
        5: this.$t1('输出自定义文件，使用自定义格式模版'),
        6: this.$t1('京东打印'),
        7: this.$t1('拼多多打印'),
        8: this.$t1('唯品会打印'),
        9: this.$t1('小红书打印')
      }
    };
  },
  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_exportTemplate_list-m2",
        path: USER_PREFIX + "/export_template/listPage",
        param: () => {
          return this.formData;
        },
        columns: [
          {type: "checkbox", width: 48, resizable: false, fixed: "left"},
          {
            title: this.$t1('输出模板编码'),
            field: "etCode",
            width: 150,
            fixed: "left",
          },
          {
            title: this.$t1('输出模板名称'),
            field: "etName",
            width: 150,
          },
          {
            title: this.$t1('输出类型'),
            field: "etType",
            width: 250,
            slots: {
              default: ({row}) => {
                return this.etTypeMap[row.etType] || "";
              },
            },
          },
          {
            field: "enabled",
            title: this.$t1('是否启用'),
            width: 150,
            slots: {
              default: ({row}) => {
                if (row.enabled) {
                  return [<div class="txt-status">{this.$t1('启用')}</div>];
                } else {
                  return [<div class="txt-status s-3">{this.$t1('禁用')}</div>];
                }
              },
            },
          },
          {
            title: this.$t1('组织编码'),
            field: "etCompanyCode",
            width: 150,
          },
          {
            title: this.$t1('备注'),
            field: "remark",
            width: 150,
          },
          {
            title: this.$t1('创建时间'),
            field: "createDate",
            width: 150,
          },
          {title: this.$t1('更新时间'), field: "modifyDate", 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>
