<script>
import {warehouseLinePage} from "@/api/ecw/customerContacts";
import {getWarehouseList} from "@/api/ecw/warehouse";
import Template from "@/views/cms/template/index.vue";

export default {
  name: "airFreightRouteTemplate",
  components: {Template},
  props:{
    lineId:{
      default:''
    }
  },
  data() {
    return {
      open: false,
      warehouseList: [],
      list: [],
      total: 0,
      form: {},
      queryParams: {
        page: 1,
        rows: 10,
        transportType:3,
        startWarehouseIdList:[],
        destWarehouseIdList: []
      }
    }
  },
  mounted() {
    getWarehouseList().then((r) => {
      this.warehouseList = r.data;
    });
  },
  methods: {
    getList() {
      warehouseLinePage(this.queryParams).then(r => {
        this.list = r.data.list;
        this.total = r.data.total
      })
    },
    copy(value) {
      this.$emit('copy', value)
      this.open = false
    }
  },
  computed: {
    exportWarehouseList() {
      return this.warehouseList.filter(
          (item) => item.tradeType == "2" || item.type == "3"
      );
    },
    importWarehouseList() {
      return this.warehouseList.filter(
          (item) => item.tradeType == "1" || item.type == "3"
      );
    },
  },
  watch: {
    open(value) {
      if (value) {
        this.getList();
      }
    }
  }

}
</script>

<template>
  <div>
    <div @click="open = true;" style="display: inline-block">
      <slot></slot>
    </div>
    <el-dialog :visible.sync="open">
      <el-card>
        <template #header>
          <el-form inline>
            <el-form-item label="始发地">
              <el-select v-model="queryParams.startWarehouseIdList" @change="queryParams.page = 1;getList()"  multiple :placeholder="$t('请选择始发地')">
                <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="destWarehouseId">
              <el-select @change="queryParams.page = 1;getList()"  v-model="queryParams.destWarehouseIdList" multiple :placeholder="$t('请选择目的地')">
                <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>
        </template>
        <el-table border :data="list">
          <el-table-column label="始发仓">
            <template slot-scope="{row}">
              {{ $l(row, 'startWarehouseTitle') }}
            </template>
          </el-table-column>
          <el-table-column label="目的仓">
            <template slot-scope="{row}">
              {{ $l(row, 'destWarehouseTitle') }}
            </template>
          </el-table-column>
          <el-table-column label="渠道数">
            <template slot-scope="{row}">
              {{ row.channelIds ? row.channelIds.split(',').length : 0 }}
            </template>
          </el-table-column>
          <el-table-column>
            <template slot-scope="{row}">
              <el-button type="text" v-if="lineId !== row.id" @click="copy(row)">复制</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"/>
      </el-card>
    </el-dialog>
  </div>
</template>

<style scoped lang="scss">

</style>
