<template>
  <div class="app-container new-boxr">
    <el-card>
      <!-- 搜索工作栏 -->
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
        <div class="filter-box">
          <div class="filter-lf">
            <el-form-item label="采购名称" prop="productName">
              <el-input v-model="queryParams.productName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="投标时间" prop="cutoffTime">
              <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="queryParams.cutoffTime" type="date" placeholder="请选择">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="采购状态" prop="procurementSchedule">
              <el-select v-model="queryParams.procurementSchedule" placeholder="请选择" clearable size="small">
                <el-option v-for="dict in this.getDictDatas(DICT_TYPE.BS_PROCUREMENT_TYPE)" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </div>
        </div>
      </el-form>

      <!-- 列表 -->
      <el-table stripe border v-loading="loading" :data="list" v-hasPermi="['bs:quotation-sheet:tendereeQuery']">
        <el-table-column label="采购名称" align="center" prop="productName" />
        <el-table-column label="投标时间" align="center" prop="cutoffTime" width="250">
          <template v-slot="scope">
            <span>{{ parseTime(scope.row.cutoffTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="中标状态" align="center" prop="isWin">
          <template v-slot="scope">
            <dict-tag :type="DICT_TYPE.BS_SUPPLIER_TYPE" :value="scope.row.isWin" />
          </template>
        </el-table-column>
        <el-table-column label="采购预算" align="center" prop="money">
          <template v-slot="scope">
            <!-- {{(scope.row.money || scope.row.money == 0) ? scope.row.money : '-'}} 元 -->
            {{(scope.row.money) ? scope.row.money + '元' : ''}}
          </template>
        </el-table-column>
        <el-table-column label="采购状态" align="center" prop="procurementSchedule">
          <template v-slot="scope">
            <dict-tag :type="DICT_TYPE.BS_PROCUREMENT_TYPE" :value="scope.row.procurementSchedule" />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template v-slot="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleShow(scope.row)" v-hasPermi="['bs:quotation-sheet:query']">查看</el-button>
            <el-button size="mini" type="text" icon="el-icon-refresh-left" @click="handleToCp(scope.row)" v-hasPermi="['bs:quotation-sheet-bidding:create']">去投标</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" />
    </el-card>
    <!-- 新增/编辑 -->
    <EditForm :isOpen="isOpen" :id="id" :tenantName="tenantName" :quotationId="quotationId" @onCancel=" isOpen =false" @onConfirm="handleComfirm" />
  </div>
</template>

<script>
import { getQuotationSheetBiddingSpPage } from "@/api/bs/quotationSheetBidding";
import { getSupplierCompanyPage } from "@/api/procurement/supplierMsg";
import { listData } from "@/api/system/dict/data";
export default {
  name: "supplierAd",
  components: {
    EditForm: () => import('./components/editForm')
  },
  data() {
    return {
      tenantName: null,
      quotationId: null,
      isOpen: false,
      id: null,
      form: {
        remark: ""
      },
      dialogVisible: false,
      quotationList: [],
      spList: [],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报价单物料中标列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        cutoffTime: undefined,
        purchasingCategoriesId: null,
        type: null,
        productName: null,
        supplierCompanyId: null,
        pageNo: 1,
        pageSize: 10,
        status: null,
        remark: null,
        createTime: [],
        quotationDetailId: null,
        materialCode: null,
        materialId: null,
        materialName: null,
        companyId: null,
        companyName: null,
        productPrice: null,
        moldCost: null,
        quotationTime: [],
        isWin: null,
        files: null,
        processInstanceId: null,
      },
    };
  },
  created() {
    this.getList();
    this.handleInitList()
  },
  activated() {
    this.getList();
  },
  methods: {
    handleToCp(row) {
      this.id = null
      this.quotationId = row.id
      this.tenantName = row.tenantName
      this.isOpen = true
    },
    handleComfirm() {
      this.isOpen = false
      this.getList()
    },
    handleShow(row) {
      this.id = row.id
      this.tenantName = row.tenantName
      this.isOpen = true
    },
    handleInitList() {
      listData({
        pageNo: 1,
        pageSize: 50,
        dictType: 'quotation_type',
      }).then((res) => {
        this.quotationList = res.data.list || []
      })
      getSupplierCompanyPage({
        pageNo: 1,
        pageSize: 1000,
      }).then((res) => {
        this.spList = res.data.list || []
      })
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getQuotationSheetBiddingSpPage(this.queryParams).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        productName: undefined,
        cutoffTime: undefined,
        purchasingCategoriesId: undefined,
        id: undefined,
        status: undefined,
        remark: undefined,
        quotationDetailId: undefined,
        materialCode: undefined,
        materialId: undefined,
        materialName: undefined,
        companyId: undefined,
        companyName: undefined,
        productPrice: undefined,
        moldCost: undefined,
        quotationTime: undefined,
        isWin: undefined,
        files: undefined,
        processInstanceId: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

  }
};
</script>


<style lang='scss' scoped>
@import '@/assets/styles/header/index.scss';
@import '@/assets/styles/common/index.scss';
.release-remark {
  font-size: 18px;
}
</style>

