<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" label-width="100px">
        <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="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>
        <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" min-width="100px" />
      <!-- <el-table-column label="投标id" align="center" prop="tenderId" min-width="100px" /> -->
      <el-table-column label="投标项目名称" align="center" prop="projectName" min-width="100px" />
      <el-table-column label="招标业主" align="center" prop="partyA" min-width="100px" />
      <el-table-column label="业主联系人" align="center" prop="aPerson" min-width="100px" />
      <el-table-column label="业主联系电话" align="center" prop="aPhone" min-width="100px" />
      <el-table-column label="招标代理" align="center" prop="agent" min-width="100px" />
      <el-table-column label="代理联系人" align="center" prop="agentPerson" min-width="100px" />
      <el-table-column label="代理联系电话" align="center" prop="agentPhone" min-width="100px" />
      <el-table-column label="招标地点" align="center" prop="place" min-width="100px" />
      <el-table-column label="投标部门" align="center" prop="dept" min-width="100px" />
      <el-table-column label="投标委托人" align="center" prop="trustee" min-width="100px" />
      <el-table-column label="业主预算" align="center" prop="budget" min-width="100px" />
      <el-table-column label="拟报价金额" align="center" prop="quote" min-width="100px" />
      <el-table-column label="保证金" align="center" prop="deposit" min-width="100px" />
      <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="dialogProperty.dialogWidth" append-to-body :close-on-click-modal="false">
      <el-descriptions class="margin-top" :column="dialogProperty.column" border>
        <el-descriptions-item :span="3">
          <template slot="label">
            投标项目名称
          </template>
          <el-input v-model="form.projectName"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            招标业主
          </template>
          <el-input v-model="form.partyA"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            业主联系人
          </template>
          <el-input v-model="form.aPerson"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            业主联系电话
          </template>
          <el-input v-model="form.aPhone"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            招标代理
          </template>
          <el-input v-model="form.agent"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            代理联系人
          </template>
          <el-input v-model="form.agentPerson"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            代理联系电话
          </template>
          <el-input v-model="form.agentPhone"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            招标地点
          </template>
          <el-input v-model="form.place"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            投标部门
          </template>
          <el-input v-model="form.dept"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            投标委托人
          </template>
          <el-input v-model="form.trustee"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            业主预算
          </template>
          <el-input v-model="form.budget">
            <span slot="append">元</span>
          </el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            拟报价金额
          </template>
          <el-input v-model="form.quote">
            <span slot="append">元</span>
          </el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            保证金
          </template>
          <el-input v-model="form.deposit">
            <span slot="append">元</span>
          </el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            投标时间
          </template>
          <el-date-picker clearable v-model="form.tenderTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择投标时间">
          </el-date-picker>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            标书购买截止时间
          </template>
          <el-date-picker clearable v-model="form.bidBuyDeadline" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择标书购买截止时间">
          </el-date-picker>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            招标信息网址
          </template>
          <el-input v-model="form.bidWebsite"></el-input>
        </el-descriptions-item>
        <el-descriptions-item :span="3">
          <template slot="label">
            招标文件
          </template>
          <el-input v-model="form.bidDocument"></el-input>
        </el-descriptions-item>
        <el-descriptions-item :span="3">
          <template slot="label">
            项目内容简述
          </template>
          <el-input v-model="form.projectBriefly"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            商务标书编写人
          </template>
          <el-input v-model="form.businessWriter"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            商务标书要求提交时间
          </template>
          <el-date-picker clearable v-model="form.businessDeadline" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择商务标书要求提交时间">
          </el-date-picker>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            技术标书编写人
          </template>
          <el-input v-model="form.techWriter"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            技术标书要求提交时间
          </template>
          <el-date-picker clearable v-model="form.techDeadline" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择技术标书要求提交时间">
          </el-date-picker>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            标书合稿人
          </template>
          <el-input v-model="form.tenderCombiner"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            标书检查人
          </template>
          <el-input v-model="form.tenderChecker"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            标书打印装订人
          </template>
          <el-input v-model="form.tenderPrinter"></el-input>
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            标书文件
          </template>
          <el-input v-model="form.tenderDocument"></el-input>
        </el-descriptions-item>
      </el-descriptions>

      <!-- <el-form ref="form" :model="form" :rules="rules" label-width="160px" style="padding-right: 50px;">
        <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" style="text-align: center;">
        <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,
      // 对话框属性
      dialogProperty: {
        dialogWidth: '1200px',
        column: 3,
      },
      // 查询参数
      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();
    console.log(this.$store.state.app.device);
    if (this.$store.state.app.device == 'mobile') {
      this.dialogProperty.column = 1
      this.dialogProperty.dialogWidth = '90%'
    }
  },
  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>
<style lang="scss" scoped>
::v-deep .el-descriptions-item__label.is-bordered-label {
  color: #121212;
  // background: rgba($color: #46a6ff, $alpha: 0.1);
  width: 120px;
  text-align: center;
}

::v-deep .el-descriptions .is-bordered .el-descriptions-item__cell {
  border: 1px solid #2d3f62;
}

::v-deep .el-form-item--medium .el-form-item__label {
  font-weight: 500;
}
</style>