<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item :label="$t('名称')" prop="nameZh">
        <el-input v-model="queryParams.nameZh" :placeholder="$t('请输入名称')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <!-- <el-form-item label="名称-英文" prop="nameEn">
        <el-input v-model="queryParams.nameEn" placeholder="请输入名称-英文" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item> -->
      <el-form-item :label="$t('内部名称')" prop="internalNameZh">
        <el-input v-model="queryParams.internalNameZh" :placeholder="$t('请输入内部名称')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <!-- <el-form-item label="内部名称-英文" prop="internalNameEn">
        <el-input v-model="queryParams.internalNameEn" placeholder="请输入内部名称-英文" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item> -->
      <el-form-item :label="$t('类型编码')" prop="typeNumber">
        <el-input v-model="queryParams.typeNumber" :placeholder="$t('请输入类型编码')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <!-- <el-form-item label="仓库ID字符串" prop="warehouseIds">
        <el-input v-model="queryParams.warehouseIds" placeholder="请输入仓库ID字符串" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item> -->
      <!-- <el-form-item :label="$t('排序')" prop="sort">
        <el-input v-model="queryParams.sort" :placeholder="$t('请输入排序')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item> -->
      <el-form-item :label="$t('快递ID')" prop="expressId">
        <el-input v-model="queryParams.expressId" :placeholder="$t('请输入快递ID')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item :label="$t('预计时间')">
          <el-input v-model="queryParams.etaTime" :placeholder="$t('预计到达天数')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item :label="$t('渠道代理')" prop="channelAgent">
        <el-input v-model="queryParams.channelAgent" :placeholder="$t('请输入渠道代理')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item :label="$t('备注')" prop="remarksZh">
        <el-input v-model="queryParams.remarksZh" :placeholder="$t('请输入备注-中文')" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <!-- <el-form-item label="备注-英文" prop="remarksEn">
        <el-input v-model="queryParams.remarksEn" placeholder="请输入备注-英文" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item> -->
      <!-- <el-form-item label="状态(0:禁用 1:启用)" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态(0:禁用 1:启用)" clearable size="small">
          <el-option :label="$t('请选择字典生成')" value="" />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item :label="$t('创建时间')">
        <el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd"
                        type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>


    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column :label="$t('渠道ID')" align="center" prop="channelId" />
      <el-table-column :label="$t('名称')" align="center" prop="nameZh">
        <template slot-scope="{row}">{{$l(row, 'name')}}</template>
      </el-table-column>
      <el-table-column :label="$t('内部名称')" align="center" prop="internalNameZh">
        <template slot-scope="{row}">{{$l(row, 'internalName')}}</template>
      </el-table-column>
      <el-table-column :label="$t('包装数量')" prop="packagingCount">

      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="text"  @click="copyFn(scope.row)">
            复制
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>

  </div>
</template>

<script>
import {getChannelPage, exportChannelExcel } from "@/api/ecw/channel";

export default {
  name: "EcwChannelIndex",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 渠道管理列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeEtaTime: [],
      dateRangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {

      }
    };
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    copyFn(val){
      this.$emit('copyFn',val.channelId)
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
      // 执行查询
      getChannelPage(params).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNo: 1,
        pageSize: 10
      }
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      return this.$router.push('create_channel')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      return this.$router.push('edit_channel?id=' + row.channelId)
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const channelId = row.channelId;
      this.$modal.confirm(this.$t('是否确认删除渠道管理编号为{channelId}的数据项?'),{channelId} ).then(function() {
          return deleteChannel(channelId);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.addBeginAndEndTime(params, this.dateRangeEtaTime, 'etaTime');
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行导出
      this.$modal.confirm('是否确认导出所有渠道管理数据项?').then(() => {
          this.exportLoading = true;
          return exportChannelExcel(params);
        }).then(response => {
          this.$download.excel(response, '渠道列表.xls');
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>

<style lang="scss">

  .left {

    .el-tag {
            background-color: #e6f6fd;
            border: 1px solid #ccecfb;
            display: inline-block;
            height:auto;
            padding: 0 10px;
            line-height: 30px;
            font-size: 12px;
            color: #02a1e9;
            border-radius: 4px;
            box-sizing: border-box;
            white-space: nowrap;

        }

   }

</style>
