<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="supplierCompanyId">
              <el-select v-model="queryParams.supplierCompanyId" placeholder="请选择" clearable size="small">
                <el-option v-for="dict in spList" :key="dict.id" :label="dict.companyAme" :value="dict.id" />
              </el-select>
            </el-form-item>
            <el-form-item label="类别" prop="purchasingCategoriesId">
              <el-select v-model="queryParams.purchasingCategoriesId" placeholder="请选择" clearable size="small">
                <el-option v-for="dict in this.getDictDatas(DICT_TYPE.BS_MATERIAL_TYPE)" :key="dict.value" :label="dict.label" :value="dict.value" />
              </el-select>
            </el-form-item>
            <el-form-item label="产品名称" prop="productName">
              <el-input v-model="queryParams.productName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
            </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">
        <el-table-column label="报价编号" align="center" prop="number" />
        <el-table-column label="中标供应商名称" align="center" prop="biddingSupplierName" />
        <el-table-column label="类别" align="center" prop="purchasingCategoriesId">
          <template v-slot="scope">
            <dict-tag :type="DICT_TYPE.BS_MATERIAL_TYPE" :value="scope.row.purchasingCategoriesId" />
          </template>
        </el-table-column>
        <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="projectName" />
        <el-table-column label="中标审批状态" align="center" prop="biddingStatus">
          <template v-slot="scope">
            <dict-tag :type="DICT_TYPE.BS_EXPENSE_APPLY_STATUS" :value="scope.row.biddingStatus" />
          </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" 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-bidding:show']">查看详情</el-button>
            <el-button size="mini" type="text" icon="el-icon-refresh-left" :disabled="scope.row.isWin==3" @click="handleRelease(scope.row)" v-hasPermi="['bs:quotation-sheet:releaseFlag']">流标</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>

    <!-- 流标信息 -->
    <el-dialog title="你确定要流标吗?" :visible.sync="dialogVisible" width="600px" @close="dialogVisible = false">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="流标备注">
          <el-input type="textarea" v-model="form.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { createQuotationSheetBidding, updateQuotationSheetBidding, deleteQuotationSheetBidding, getQuotationSheetBidding, getQuotationSheetBiddingPage, exportQuotationSheetBiddingExcel, updateQuotationReleaseFlag } from "@/api/bs/quotationSheetBidding";
import { getSupplierCompanyPage } from "@/api/procurement/supplierMsg";
import { listData } from "@/api/system/dict/data";
export default {
  name: "QuotationSheetBidding",
  components: {
  },
  data() {
    return {
      form: {
        remark: ""
      },
      dialogVisible: false,
      quotationList: [],
      spList: [],
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 报价单物料中标列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        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: {
    handleRelease(row) {
      // this.form.remark = null
      // this.dialogVisible = true
      this.$confirm("你确认要流标吗", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: 'warning'
      }).then(() => {
        updateQuotationReleaseFlag({ id: row.id }).then((res) => {
          this.$modal.msgSuccess("流标成功！");
          this.getList()
        })
      })
    },
    handleShow(row) {
      this.$router.push({ path: "/bs/quotationSheetBidding/in", query: { id: row.id, flag: 'show', title: '报销中标审批详情', typeStr: 'in' } });
    },
    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;
      // 执行查询
      getQuotationSheetBiddingPage(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 = {
        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();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加报价单物料中标";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      getQuotationSheetBidding(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改报价单物料中标";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateQuotationSheetBidding(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createQuotationSheetBidding(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除报价单物料中标编号为"' + id + '"的数据项?').then(function () {
        return deleteQuotationSheetBidding(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal.confirm('是否确认导出所有报价单物料中标数据项?').then(() => {
        this.exportLoading = true;
        return exportQuotationSheetBiddingExcel(params);
      }).then(response => {
        this.$download.excel(response, '报价单物料中标.xls');
        this.exportLoading = false;
      }).catch(() => { });
    }
  }
};
</script>


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

