<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="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入投标项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="招标业主" prop="partyA">
        <el-input
          v-model="queryParams.partyA"
          placeholder="请输入招标业主"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业主联系人" prop="aPerson">
        <el-input
          v-model="queryParams.aPerson"
          placeholder="请输入业主联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业主联系电话" prop="aPhone">
        <el-input
          v-model="queryParams.aPhone"
          placeholder="请输入业主联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="招标代理" prop="agent">
        <el-input
          v-model="queryParams.agent"
          placeholder="请输入招标代理"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理联系人" prop="agentPerson">
        <el-input
          v-model="queryParams.agentPerson"
          placeholder="请输入代理联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理联系电话" prop="agentPhone">
        <el-input
          v-model="queryParams.agentPhone"
          placeholder="请输入代理联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="招标地点" prop="place">
        <el-input
          v-model="queryParams.place"
          placeholder="请输入招标地点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="投标部门" prop="dept">
        <el-input
          v-model="queryParams.dept"
          placeholder="请输入投标部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="投标委托人" prop="trustee">
        <el-input
          v-model="queryParams.trustee"
          placeholder="请输入投标委托人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业主预算" prop="budget">
        <el-input
          v-model="queryParams.budget"
          placeholder="请输入业主预算"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="拟报价金额" prop="quote">
        <el-input
          v-model="queryParams.quote"
          placeholder="请输入拟报价金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保证金" prop="deposit">
        <el-input
          v-model="queryParams.deposit"
          placeholder="请输入保证金"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="投标时间" prop="tenderTime">
        <el-date-picker clearable
          v-model="queryParams.tenderTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择投标时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="标书购买截止时间" prop="bidBuyDeadline">
        <el-date-picker clearable
          v-model="queryParams.bidBuyDeadline"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择标书购买截止时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="招标信息网址" prop="bidWebsite">
        <el-input
          v-model="queryParams.bidWebsite"
          placeholder="请输入招标信息网址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="招标文件" prop="bidDocument">
        <el-input
          v-model="queryParams.bidDocument"
          placeholder="请输入招标文件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目内容简述" prop="projectBriefly">
        <el-input
          v-model="queryParams.projectBriefly"
          placeholder="请输入项目内容简述"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商务标书编写人" prop="businessWriter">
        <el-input
          v-model="queryParams.businessWriter"
          placeholder="请输入商务标书编写人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商务标书要求提交时间" prop="businessDeadline">
        <el-date-picker clearable
          v-model="queryParams.businessDeadline"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择商务标书要求提交时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="技术标书编写人" prop="techWriter">
        <el-input
          v-model="queryParams.techWriter"
          placeholder="请输入技术标书编写人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技术标书要求提交时间" prop="techDeadline">
        <el-date-picker clearable
          v-model="queryParams.techDeadline"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择技术标书要求提交时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="标书合稿人" prop="tenderCombiner">
        <el-input
          v-model="queryParams.tenderCombiner"
          placeholder="请输入标书合稿人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标书检查人" prop="tenderChecker">
        <el-input
          v-model="queryParams.tenderChecker"
          placeholder="请输入标书检查人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标书打印装订人" prop="tenderPrinter">
        <el-input
          v-model="queryParams.tenderPrinter"
          placeholder="请输入标书打印装订人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标书文件" prop="tenderDocument">
        <el-input
          v-model="queryParams.tenderDocument"
          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>
    </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="['oa:tender:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['oa:tender:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['oa:tender:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['oa:tender:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tenderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="投标id" align="center" prop="tenderId" />
      <el-table-column label="投标项目名称" align="center" prop="projectName" />
      <el-table-column label="招标业主" align="center" prop="partyA" />
      <el-table-column label="业主联系人" align="center" prop="aPerson" />
      <el-table-column label="业主联系电话" align="center" prop="aPhone" />
      <el-table-column label="招标代理" align="center" prop="agent" />
      <el-table-column label="代理联系人" align="center" prop="agentPerson" />
      <el-table-column label="代理联系电话" align="center" prop="agentPhone" />
      <el-table-column label="招标地点" align="center" prop="place" />
      <el-table-column label="投标部门" align="center" prop="dept" />
      <el-table-column label="投标委托人" align="center" prop="trustee" />
      <el-table-column label="业主预算" align="center" prop="budget" />
      <el-table-column label="拟报价金额" align="center" prop="quote" />
      <el-table-column label="保证金" align="center" prop="deposit" />
      <el-table-column label="投标时间" align="center" prop="tenderTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tenderTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="标书购买截止时间" align="center" prop="bidBuyDeadline" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.bidBuyDeadline, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="招标信息网址" align="center" prop="bidWebsite" />
      <el-table-column label="招标文件" align="center" prop="bidDocument" />
      <el-table-column label="项目内容简述" align="center" prop="projectBriefly" />
      <el-table-column label="商务标书编写人" align="center" prop="businessWriter" />
      <el-table-column label="商务标书要求提交时间" align="center" prop="businessDeadline" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.businessDeadline, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="技术标书编写人" align="center" prop="techWriter" />
      <el-table-column label="技术标书要求提交时间" align="center" prop="techDeadline" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.techDeadline, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="标书合稿人" align="center" prop="tenderCombiner" />
      <el-table-column label="标书检查人" align="center" prop="tenderChecker" />
      <el-table-column label="标书打印装订人" align="center" prop="tenderPrinter" />
      <el-table-column label="标书文件" align="center" prop="tenderDocument" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['oa:tender:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['oa:tender:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改投标管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="投标项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入投标项目名称" />
        </el-form-item>
        <el-form-item label="招标业主" prop="partyA">
          <el-input v-model="form.partyA" placeholder="请输入招标业主" />
        </el-form-item>
        <el-form-item label="业主联系人" prop="aPerson">
          <el-input v-model="form.aPerson" placeholder="请输入业主联系人" />
        </el-form-item>
        <el-form-item label="业主联系电话" prop="aPhone">
          <el-input v-model="form.aPhone" placeholder="请输入业主联系电话" />
        </el-form-item>
        <el-form-item label="招标代理" prop="agent">
          <el-input v-model="form.agent" placeholder="请输入招标代理" />
        </el-form-item>
        <el-form-item label="代理联系人" prop="agentPerson">
          <el-input v-model="form.agentPerson" placeholder="请输入代理联系人" />
        </el-form-item>
        <el-form-item label="代理联系电话" prop="agentPhone">
          <el-input v-model="form.agentPhone" placeholder="请输入代理联系电话" />
        </el-form-item>
        <el-form-item label="招标地点" prop="place">
          <el-input v-model="form.place" placeholder="请输入招标地点" />
        </el-form-item>
        <el-form-item label="投标部门" prop="dept">
          <el-input v-model="form.dept" placeholder="请输入投标部门" />
        </el-form-item>
        <el-form-item label="投标委托人" prop="trustee">
          <el-input v-model="form.trustee" placeholder="请输入投标委托人" />
        </el-form-item>
        <el-form-item label="业主预算" prop="budget">
          <el-input v-model="form.budget" placeholder="请输入业主预算" />
        </el-form-item>
        <el-form-item label="拟报价金额" prop="quote">
          <el-input v-model="form.quote" placeholder="请输入拟报价金额" />
        </el-form-item>
        <el-form-item label="保证金" prop="deposit">
          <el-input v-model="form.deposit" placeholder="请输入保证金" />
        </el-form-item>
        <el-form-item label="投标时间" prop="tenderTime">
          <el-date-picker clearable
            v-model="form.tenderTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择投标时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="标书购买截止时间" prop="bidBuyDeadline">
          <el-date-picker clearable
            v-model="form.bidBuyDeadline"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择标书购买截止时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="招标信息网址" prop="bidWebsite">
          <el-input v-model="form.bidWebsite" placeholder="请输入招标信息网址" />
        </el-form-item>
        <el-form-item label="招标文件" prop="bidDocument">
          <el-input v-model="form.bidDocument" placeholder="请输入招标文件" />
        </el-form-item>
        <el-form-item label="项目内容简述" prop="projectBriefly">
          <el-input v-model="form.projectBriefly" placeholder="请输入项目内容简述" />
        </el-form-item>
        <el-form-item label="商务标书编写人" prop="businessWriter">
          <el-input v-model="form.businessWriter" placeholder="请输入商务标书编写人" />
        </el-form-item>
        <el-form-item label="商务标书要求提交时间" prop="businessDeadline">
          <el-date-picker clearable
            v-model="form.businessDeadline"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择商务标书要求提交时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="技术标书编写人" prop="techWriter">
          <el-input v-model="form.techWriter" placeholder="请输入技术标书编写人" />
        </el-form-item>
        <el-form-item label="技术标书要求提交时间" prop="techDeadline">
          <el-date-picker clearable
            v-model="form.techDeadline"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择技术标书要求提交时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="标书合稿人" prop="tenderCombiner">
          <el-input v-model="form.tenderCombiner" placeholder="请输入标书合稿人" />
        </el-form-item>
        <el-form-item label="标书检查人" prop="tenderChecker">
          <el-input v-model="form.tenderChecker" placeholder="请输入标书检查人" />
        </el-form-item>
        <el-form-item label="标书打印装订人" prop="tenderPrinter">
          <el-input v-model="form.tenderPrinter" placeholder="请输入标书打印装订人" />
        </el-form-item>
        <el-form-item label="标书文件" prop="tenderDocument">
          <el-input v-model="form.tenderDocument" placeholder="请输入标书文件" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTender, getTender, delTender, addTender, updateTender } from "@/api/oa/tender/tender";

export default {
  name: "Tender",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 投标管理表格数据
      tenderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        partyA: null,
        aPerson: null,
        aPhone: null,
        agent: null,
        agentPerson: null,
        agentPhone: null,
        place: null,
        dept: null,
        trustee: null,
        budget: null,
        quote: null,
        deposit: null,
        tenderTime: null,
        bidBuyDeadline: null,
        bidWebsite: null,
        bidDocument: null,
        projectBriefly: null,
        businessWriter: null,
        businessDeadline: null,
        techWriter: null,
        techDeadline: null,
        tenderCombiner: null,
        tenderChecker: null,
        tenderPrinter: null,
        tenderDocument: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询投标管理列表 */
    getList() {
      this.loading = true;
      listTender(this.queryParams).then(response => {
        this.tenderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        tenderId: null,
        projectName: null,
        partyA: null,
        aPerson: null,
        aPhone: null,
        agent: null,
        agentPerson: null,
        agentPhone: null,
        place: null,
        dept: null,
        trustee: null,
        budget: null,
        quote: null,
        deposit: null,
        tenderTime: null,
        bidBuyDeadline: null,
        bidWebsite: null,
        bidDocument: null,
        projectBriefly: null,
        businessWriter: null,
        businessDeadline: null,
        techWriter: null,
        techDeadline: null,
        tenderCombiner: null,
        tenderChecker: null,
        tenderPrinter: null,
        tenderDocument: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.tenderId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加投标管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const tenderId = row.tenderId || this.ids
      getTender(tenderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改投标管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.tenderId != null) {
            updateTender(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTender(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const tenderIds = row.tenderId || this.ids;
      this.$modal.confirm('是否确认删除投标管理编号为"' + tenderIds + '"的数据项？').then(function() {
        return delTender(tenderIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('oa/tender/export', {
        ...this.queryParams
      }, `tender_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
