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

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">

      <el-form-item :label="$t('运输方式')" prop="transportType">
        <dict-selector :type="DICT_TYPE.ECW_TRANSPORT_TYPE" v-model="queryParams.transportType" formatter="number"
                       clearable/>
      </el-form-item>
      <el-form-item>
        <el-form-item :label="$t('始发仓')" prop="startWarehouseId">
          <el-select multiple v-model="queryParams.startWarehouseIdList" :placeholder="$t('请选择始发仓')" clearable>
            <el-option v-for="item in exportWarehouseList" :label="$l(item, 'title')" :value="item.id"
                       :key="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('目的仓')" prop="destWarehouseIdArr">
          <el-select multiple v-model="queryParams.destWarehouseIdList" multiple
                     :placeholder="$t('请选择目的仓')" clearable>
            <el-option v-for="item in importWarehouseList" :label="$l(item, 'title')" :value="item.id"
                       :key="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('出货渠道')" prop="shippingChannel">
          <el-select v-model="queryParams.channelId" :placeholder="$t('请选择出货渠道')" clearable>
            <el-option v-for="item in channelList" :label="item.nameZh" :value="item.channelId"
                       :key="item.channelId"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label-width="200" label="目的仓国家">
          <el-select style="width: 100%" filterable clearable v-model="queryParams.destCountryId" :placeholder="$t('请选择国家')">
            <el-option v-for="dict in countryList"
                       :key="dict.id" :label="$l(dict,'title')" :value="parseInt(dict.id)"/>
          </el-select>
        </el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('搜索') }}</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column :label="$t('序号')" align="center" type="index"/>
      <el-table-column :label="$t('始发仓')" align="center">
        <template slot-scope="{row}">
          {{ $l(row, 'startWarehouseTitle') }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('目的仓')" align="center">
        <template slot-scope="{row}">
          {{ $l(row, 'destWarehouseTitle') }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('运输方式')" align="center">
        <template slot-scope="{row}">
          <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="row.transportType"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column :label="$t('目的仓国家')" align="center">
        <template slot-scope="{row}">
      {{$l(row, 'destCountryName')}}
        </template>
      </el-table-column>
      <el-table-column :label="$t('出货渠道')" align="center">
        <template slot-scope="{row}">
          {{ row.channelIds ? $l(row, 'channelNames') : '/' }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center">
        <template slot-scope="{row}">
          <el-button v-if="row.transportType === 3" type="text" @click="$router.push({
          path:'/offer/channel-route?id='+ row.id,
          query:{
            startWarehouseTitle:$l(row,'startWarehouseTitle'),
            destWarehouseTitle: $l(row, 'destWarehouseTitle'),
            destCountryName:$l(row,'destCountryName')
          }
          })">空运渠道包装清关费
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.rows"
                @pagination="getList"/>
  </div>
</template>

<script>
import {
  createDeptTarget,
  updateDeptTarget,
  deleteDeptTarget,
  getDeptTarget,
  getDeptTargetPage,
  exportDeptTargetExcel,
  getCreateInitData,
  getPersonTargetPage,
  myAchievementByPage
} from "@/api/ecw/deptTarget";
import {listSimpleDepts} from "@/api/system/dept";
import {getChannelList} from '@/api/ecw/channel';
import dayjs from "dayjs";
import {listServiceUser} from "@/api/system/user";
import {getWarehouseList} from '@/api/ecw/warehouse'
import {DICT_TYPE} from "@/utils/dict";
import {warehouseLinePage} from "@/api/ecw/customerContacts";
import {getTradeCountryList} from "@/api/ecw/region";

export default {
  name: "EcwOfferAll-routes-list",
  components: {},
  data() {
    return {
      countryList:[],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      list: [],
      // 是否显示弹出层
      open: false,
      tableOpen: false,
      channelList: [],
      // 查询参数
      queryParams: {
        page: 1,
        rows: 10,
      },

      // 表单校验
      myAchievementData: {},
      warehouseList: []
    };
  },
  computed: {
    DICT_TYPE() {
      return DICT_TYPE
    },
    exportWarehouseList() {
      /* tradeType 1 进口，2出口，3进出口 */
      return this.warehouseList.filter(item => item.tradeType == 2 || item.tradeType == 3)
    },
    importWarehouseList() {
      return this.warehouseList.filter(item => item.tradeType == 1 || item.tradeType == 3)
    },
  },
  activated() {
    this.getChannelList();
    this.getList();
  },
  created() {
    getTradeCountryList().then(r => {
      this.countryList = r.data
    })
    this.getChannelList();
    this.getList();
    listServiceUser().then(r => {
      this.customerServiceList = r.data;
    })
    getWarehouseList().then(res => {
      this.warehouseList = res.data
    })
  },
  methods: {
    getChannelList() {
      getChannelList().then(res => this.channelList = res.data)
    },
    customerServiceFn(val) {
      if (this.customerServiceList.length > 0) {
        let index = this.customerServiceList.findIndex(item => item.id === val.userId);
        return index !== -1 ? this.customerServiceList[index]?.nickname : ''
      } else {
        return ''
      }
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      const params = {...this.queryParams}
      // 执行查询
      warehouseLinePage(params).then(r => {
        this.loading = false;
        this.list = r.data.list;
        this.total = r.data.total
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
  }
};
</script>


<style scoped>
.total_num {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 20px 0;
  font-size: 15px;
}

.total_num span {
  margin: 0 8px;
}
</style>

