<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="报价单号" prop="number">
        <el-input v-model="queryParams.number" placeholder="请输入报价单号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>

      <el-form-item label="订单编号" prop="orderNo">
        <el-input v-model="queryParams.orderNo" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['ecw:offer:create']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
                   v-hasPermi="['ecw:offer:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="报价单号" align="left" prop="number" width="200px" />
      <el-table-column label="订单编号" align="left" prop="orderNo" />
      <el-table-column label="客户名称" align="left" prop="relationName" />
      <el-table-column label="目的地" align="center" prop="objectiveName" />
      <el-table-column label="销售阶段" align="left" width="180">
        <template slot-scope="{row}">
          <dict-tag :type="DICT_TYPE.ECW_OFFER_STATUS" :value="row.status" />
        </template>
      </el-table-column>
      <el-table-column label="预计结束时间" align="left">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.stopTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="运输方式" align="left">
        <template slot-scope="scope" v-if="scope.row.transportIds" >
          <span v-for="(item, index) in scope.row.transportIds.split(',')" :key="index">
            <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="item" />
          </span>
        </template>
      </el-table-column>
      <el-table-column label="业务员" align="left">
        <template slot-scope="scope">
          暂无
        </template>
      </el-table-column>

      <el-table-column label="预计销售额" align="center" prop="estCost">
        <template slot-scope="{row}">
          <div class="" v-if="row.estCostVO.clearanceNGN || row.estCostVO.clearanceRMB || row.estCostVO.clearanceUSD">
            清关费：
            <span v-if="row.estCostVO.clearanceNGN">{{row.estCostVO.clearanceNGN}}N</span>
            <span v-if="row.estCostVO.clearanceRMB">{{row.estCostVO.clearanceRMB}}￥</span>
            <span v-if="row.estCostVO.clearanceUSD">{{row.estCostVO.clearanceUSD}}$</span>
          </div>
          <div class="" v-if="row.estCostVO.seaNGN || row.estCostVO.seaRMB || row.estCostVO.seaUSD">
            运费：
            <span v-if="row.estCostVO.seaNGN">{{row.estCostVO.seaNGN}}N</span>
            <span v-if="row.estCostVO.seaRMB">{{row.estCostVO.seaRMB}}￥</span>
            <span v-if="row.estCostVO.seaUSD">{{row.estCostVO.seaUSD}}$</span>
          </div>

        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <template v-if="[1,2].indexOf(scope.row.status) > -1">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="$router.push('detail?offerId=' + scope.row.offerId)"
                    v-hasPermi="['ecw:offer:update']">详情</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" @click="$router.push('edit?id=' + scope.row.offerId)"
                      v-hasPermi="['ecw:offer:update']">编辑</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" @click="$router.push('logList?offerId=' + scope.row.offerId)"
                      v-hasPermi="['ecw:offer:update']">跟进</el-button>
          </template>
          <template v-if="scope.row.status == 2">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="$router.push('detail?offerId=' + scope.row.offerId)"
                      v-hasPermi="['ecw:offer:update']">详情</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" @click="$router.push(`result?offerId=${scope.row.offerId}&number=${scope.row.number}`)"
                      v-hasPermi="['ecw:offer:update']">结果</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" @click="$router.push('/offer/special/' + scope.row.offerId)"
                      v-hasPermi="['ecw:offer:update']">特价</el-button>

            <el-button size="mini" type="text" icon="el-icon-edit"
                      v-hasPermi="['ecw:offer:update']">取消</el-button>

            <el-button size="mini" type="text" icon="el-icon-edit"
                      v-hasPermi="['ecw:offer:update']">恢复</el-button>
          </template>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="$router.push('detail?offerId=' + scope.row.offerId)"
                    v-hasPermi="['ecw:offer:update']">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete"
                     v-hasPermi="['ecw:offer:delete']">删除</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 { createOffer, updateOffer, deleteOffer, getOffer, getOfferPage, exportOfferExcel } from "@/api/ecw/offer";

export default {
  name: "Offer",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报价单管理列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      dateRangeStopTime: [],
      dateRangeStartTime: [],
      dateRangeEndTime: [],
      dateRangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        number: null,
        orderIds: null,
        orderNo: null,
        consignorId: null,
        consigneeId: null,
        marks: null,
        customsType: null,
        departureId: null,
        departure: null,
        objectiveId: null,
        objective: null,
        control: null,
        competitor: null,
        importance: null,
        tradeType: null,
        tradeAdress: null,
        remarks: null,
        status: null,
        oldStatus: null,
        relation: null,
        relationId: null,
        commissionType: null,
        warehousingType: null,
        reason: null,
        estCost: null,
        sendstatus: null,
      },


    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 处理查询参数
      let params = {...this.queryParams};
      this.addBeginAndEndTime(params, this.dateRangeStopTime, 'stopTime');
      this.addBeginAndEndTime(params, this.dateRangeStartTime, 'startTime');
      this.addBeginAndEndTime(params, this.dateRangeEndTime, 'endTime');
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行查询
      getOfferPage(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.dateRangeStopTime = [];
      this.dateRangeStartTime = [];
      this.dateRangeEndTime = [];
      this.dateRangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      return this.$router.push('edit')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      return this.$router.push('edit?id=' + row.offerId)
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const offerId = row.offerId;
      this.$modal.confirm('是否确认删除报价单管理编号为"' + offerId + '"的数据项?').then(function() {
          return deleteOffer(offerId);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = {...this.queryParams};
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.addBeginAndEndTime(params, this.dateRangeStopTime, 'stopTime');
      this.addBeginAndEndTime(params, this.dateRangeStartTime, 'startTime');
      this.addBeginAndEndTime(params, this.dateRangeEndTime, 'endTime');
      this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime');
      // 执行导出
      this.$modal.confirm('是否确认导出所有报价单管理数据项?').then(() => {
          this.exportLoading = true;
          return exportOfferExcel(params);
        }).then(response => {
          this.$download.excel(response, '${table.classComment}.xls');
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
