<template>
  <div class="content-main">
    <div class="search-bm-boder">
      <el-form ref="searchForm" :model="searchForm" inline label-width="100px">
        <el-form-item label="合同号:" prop="hth">
          <el-input
            v-model="searchForm.hth"
            placeholder="请输入合同号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="委托单位回复:" prop="ccqyhf">
          <el-select v-model="searchForm.ccqyhf">
            <el-option
              v-for="item in options"
              clearable
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="履约截止日期:" prop="jhwcsj">
          <el-date-picker
            style="width: 240px"
            v-model="searchForm.jhwcsj"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            clearable
          ></el-date-picker>
        </el-form-item>
        <el-form-item label-width="0">
          <div class="line-box">
            <el-button
              type="primary"
              @click="submitForm()"
              icon="el-icon-search"
              >查询</el-button
            >
            <el-button
              type="primary"
              @click="resetForm('searchForm')"
              icon="el-icon-refresh-left"
              >重置</el-button
            >
          </div>
        </el-form-item>
      </el-form>
    </div>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      v-loading="pageInfo.loading"
    >
      <el-table-column align="center" label="序号" width="80">
        <template slot-scope="{ $index }">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="合同号"
        prop="hth"
      ></el-table-column>
      <el-table-column
        align="center"
        label="履约截止日期"
        prop="jhwcrq"
      ></el-table-column>
      <el-table-column
        align="center"
        label="提醒日期"
        prop="txrq"
      ></el-table-column>
      <el-table-column
        align="center"
        label="回复时间"
        prop="hfsj"
      ></el-table-column>
      <el-table-column
        align="center"
        label="委托单位回复"
        prop="ccqyhf"
      ></el-table-column>
      <el-table-column align="center" label="说明" prop="sm"></el-table-column>
      <el-table-column align="center" label="状态">
        <template slot-scope="{ row }">
          <span v-show="row.hfzt == 1">已回复</span>
          <span v-show="row.hfzt == 0">未回复</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="{ row }">
          <el-tooltip
            class="item"
            effect="light"
            content="查看"
            placement="top"
          >
            <el-button
              type="primary"
              @click="writeBack(row)"
              class="operate_show_btn iconfont iconchakan2"
              size="small"
            ></el-button>
          </el-tooltip>
          <!-- <el-tooltip
            class="item"
            effect="light"
            content="回复"
            placement="top"
          >
            <el-button
              type="primary"
              style="margin: 0"
              @click="writeBack(row)"
              v-show="row.hfzt == 0"
              class="operate_show_btn iconfont iconqueren"
              size="small"
            ></el-button>
          </el-tooltip> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageInfo.pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageInfo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageInfo.total"
    >
    </el-pagination>
  </div>
</template>
<script>
import { queryPageList } from "@/api/ReceivingDeposit/index"
import { getParameter } from "@/utils/index";
export default {
  data() {
    return {
      tableData: [],
      pageInfo: {
        loading: true,
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
      pageNum: 1,
      pageSize: 10,
      total: 0,
      searchForm: {
        ccqyhf: "",
        hth: "",
        jhwcsj: [],
      },
      options: [
        {
          value: "按时完成",
          label: "按时完成",
        },
        {
          value: "不能按时完成",
          label: "不能按时完成",
        },
      ],
    };
  },
  created() {
    // this.getTable({ pageNum: 1, pageSize: 10 }, {});
    this.getList("start");
  },
  methods: {
    // 分页 一页几条
    handleSizeChange(val) {
      this.pageInfo.pageNum = 1;
      this.pageInfo.pageSize = val;
      this.getList();
    },
    // 分页 当前页
    handleCurrentChange(val) {
      this.pageInfo.pageNum = val;
      this.getList();
    },
    // 回复 查看
    writeBack(row) {
      this.$router.push({
        name: "TradeAlertWriteBack",
        query: {
          id: row.id,
          apcc: row.apcc,
        },
      });
    },
    // 重置
    resetForm() {
      this.searchForm = {
        hth: "",
        ccqyhf: "",
        jhwcsj: [],
      };
      this.submitForm();
    },
    // 搜索
    submitForm() {
      this.pageInfo.pageNum = 1;
      this.getList();
    },
    // 获取表格数据
    getList(type) {
      let self = this,
        data = {
          pageNum: self.pageInfo.pageNum,
          pageSize: self.pageInfo.pageSize,
          hth: self.searchForm.hth,
          ccqyhf: self.searchForm.ccqyhf,
          jhwcsj: self.searchForm.jhwcsj,
        };
      self.pageInfo.loading = true;
      if (type != "start") {
        //非初始化调用：查询、分页
        sessionStorage.setItem("searchData", JSON.stringify(data));
      } else {
        //初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
        if (JSON.parse(sessionStorage.getItem("searchData"))) {
          //详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
          let searchData = JSON.parse(sessionStorage.getItem("searchData"));
          this.searchForm = getParameter(searchData, [
            "hth",
            "ccqyhf",
            "jhwcsj",
          ]);
          this.pageInfo = getParameter(searchData, ["pageNum", "pageSize"]);
        } else {
          //第一次进去此菜单时，保存上方默认的data
          sessionStorage.setItem("searchData", JSON.stringify(data));
        }
      }
      // let form = JSON.parse(sessionStorage.getItem("searchData"));
      let formData = {
        ...JSON.parse(sessionStorage.getItem("searchData")),
        jhwcsjks: "",
        jhwcsjjs: "",
      };
      let pageData = {
        pageNum: formData.pageNum,
        pageSize: formData.pageSize,
      };
      if (formData.jhwcsj) {
        formData.jhwcsjks = formData.jhwcsj[0];
        formData.jhwcsjjs = formData.jhwcsj[1];
      } else {
        formData.jhwcsjks = "";
        formData.jhwcsjjs = "";
      }
      queryPageList(pageData, formData).then(actionMethod).catch(actionMethod);

      function actionMethod(response) {
        self.pageInfo.loading = false;
        if (response && response.infoCode === 200) {
          self.tableData = response.data.items;
          self.pageInfo.total = response.data.total;
        }
      }
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.line-box {
  border-left: 1px dashed blue;
  padding: 0 10px;
}

.title {
  margin-bottom: 20px;
  text-align: center;
  font-size: 16px;
}

.text {
  text-align: center;
}
</style>
