<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" :copyId.sync="copyId"
                  :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: '推送数据导出', 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="推送数据类型:" field="dataType">
                  <template v-slot>
                    <el-input v-model="formData.dataType" size="small" clearable/>
                  </template>
                </vxe-form-item>
                <vxe-form-item title="推送组织编码:" field="pushCompanyCode">
                  <template v-slot>
                    <el-input v-model="formData.pushCompanyCode" size="small" clearable/>
                  </template>
                </vxe-form-item>
                <vxe-form-item title="是否启用:" field="enabled">
                  <template v-slot>
                    <el-select v-model="formData.enabled" clearable>
                      <el-option :value="true" label="启用"></el-option>
                      <el-option :value="false" label="禁用"></el-option>
                    </el-select>
                  </template>
                </vxe-form-item>
                <vxe-form-item title="推送类型:" field="pushType">
                  <template v-slot>
                    <el-select v-model="formData.pushType" clearable>
                      <el-option :value="0" label="异步推送"></el-option>
                      <el-option :value="1" label="同步调用"></el-option>
                    </el-select>
                  </template>
                </vxe-form-item>
                <vxe-form-item title="脚本:" field="script">
                  <template v-slot>
                    <el-input v-model="formData.script" size="small" clearable/>
                  </template>
                </vxe-form-item>
                <vxe-form-item title="脚本备注:" field="remark" class-name="block">
                  <template v-slot>
                    <el-input v-model="formData.remark" size="small" clearable/>
                  </template>
                </vxe-form-item>
              </vxe-form>
            </template>
          </vxe-grid>
        </div>
      </el-tab-pane>
    </el-tabs>
    <!--    <advancedSearchDialog v-if="showAdvancedSearch" :visiable.sync="showAdvancedSearch" :formData.sync="advancedFormData" @confirm="searchEvent">-->
    <!--      <template #form>-->
    <!--        <vxe-form :model="advancedFormData" title-width="102px" :inline="true" class="adSearchForm">-->
    <!--          <vxe-form-item title="脚本备注:" field="remark" class-name="block">-->
    <!--            <template v-slot>-->
    <!--              <el-input v-model="advancedFormData.remark" size="small" clearable />-->
    <!--            </template>-->
    <!--          </vxe-form-item>-->
    <!--        </vxe-form>-->
    <!--      </template>-->
    <!--    </advancedSearchDialog>-->
  </div>
</template>

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

export default {
  name: 'push_setting:list',
  components: {editView},
  data() {
    return {
      activeName: 'second',
      dataId: 0,
      copyId: 0,
      showEdit: false,
      showAdvancedSearch: false,
      vxeOption: {},
      formData: {},
      advancedFormData: {},
    };
  },
  mounted() {
    this.initTableList();
  },
  methods: {
    searchEvent() {
      this.$refs['table-m1'].commitProxy('reload');
    },
    resetEvent() {
      this.formData = {};
      this.advancedFormData = {};
      this.$refs['table-m1'].commitProxy('reload');
    },
    openEditDialog(id) {
      this.copyId = 0;
      this.dataId = !id || typeof id == 'object' ? 0 : id;
      this.activeName = 'first';
      this.$openEditView('showEdit');
    },
    initTableList() {
      let that = this;
      let pushTypeMap = {0: '异步推送', 1: '同步调用'};
      let tableOption = {
        vue: this,
        tableRef: 'table-m1',
        tableName: 'basic_pushSetting_list-m2',
        path: USER_PREFIX + '/push_setting/listPage',
        param: () => {
          return {
            ...this.formData,
            ...this.advancedFormData
          }
        },
        columns: [
          {type: 'checkbox', width: 48, resizable: false, fixed: 'left'},
          {
            title: '推送数据类型',
            field: 'dataType',
            width: 150,
            fixed: 'left'
          },
          {
            title: '推送组织编码',
            field: 'pushCompanyCode',
            width: 150
          },
          {
            title: '推送类型',
            field: 'pushType',
            width: 150,
            slots: {
              default: ({row}) => {
                return pushTypeMap[row.pushType] || '';
              }
            }
          },
          {
            title: '调度任务编码',
            field: 'taskCode',
            width: 150
          },
          {
            title: 'Api请求编码',
            field: 'apiReqCode',
            width: 150
          },
          {
            title: '脚本备注',
            field: 'remark',
            width: 250
          },
          {
            field: 'enabled',
            title: this.$t1('是否启用'),
            width: 150,
            slots: {
              default: ({row}) => {
                if (row.enabled) {
                  return [
                    <div class="txt-status">
                      <span>启用</span>
                    </div>
                  ];
                } else {
                  return [
                    <div class="txt-status disable">
                      <span>禁用</span>
                    </div>
                  ];
                }
              }
            }
          },
          {
            field: 'createDate',
            title: this.$t1('创建时间'),
            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>
