<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="thetopbox">
      <el-form  label-width="100px">
      <el-row>
        <el-col :span="4">
          <el-form-item :label="'标题'" style="margin-left: -30px">

<!--          <div class="searchbox">-->
<!--            <div class="searchtitle">标题</div>-->
            <div><el-input clearable  v-model="queryParams.protocolTitle"></el-input></div>
<!--          </div>-->
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="'创建日期'">
          <el-date-picker
                v-model="cjsj"
                type="daterange"
                range-separator="——"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item :label="'生效日期'">
          <el-date-picker
                v-model="sxsj"
                type="daterange"
                range-separator="——"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd"
                :unlink-panels="true"
              >
              </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <div class="searchbox">
            <el-button class="my_search" @click="getDataList"> {{ '搜索' }}</el-button>
            <el-button class="my_reset" @click="reChongzhi"> {{ '重置' }}</el-button>
          </div>
        </el-col>
      </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="small" class="thebtn1" @click="findRow"
            >{{'添加'}}</el-button
          >
          <el-button size="small" class="thebtn2"> {{ '导出' }}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          height="660px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column align="center" prop="title" :label="'标题'" width="180">
          </el-table-column>
          <el-table-column align="center" prop="content" :label="'内容'">
          </el-table-column>
          <el-table-column
            align="center"
            prop="creationTime"
            :label="'创建日期'"

          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="effectiveDate"
            :label="'生效日期'"
            width="180"
          >
          </el-table-column>
          <el-table-column   width="200" align="center" prop="time" :label="'操作'" fixed="right" >
            <template slot-scope="scope">
              <el-button
                @click.native.prevent="findRow(scope.row)"
                type="text"
                size="small"
              >
                {{ '查看' }}
              </el-button>
              <el-button
                @click.native.prevent="deleteRow(scope.row)"
                type="text"
                size="small"
                style="color: #c73030"
              >
                {{'删除'}}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getDataList" />
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import { getAgreementList,deleteAgreement } from "@/api/configManage";
export default {
  name: "Protocol",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "protocol",
      topList: [
        {
          name: '协议配置',
          path: "protocol",
        },
      ],
      tableData: [],
      loading:false,
      total:0,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        protocolTitle: "", //标题
        startDate: "",
        endDate: "",
        effectiveStartDate: "",
        effectiveEndDate: "",
      },
      cjsj: "",
      sxsj: "",
      multipleSelection: [],
    };
  },
  created() {
    this.getDataList();
  },
  methods: {
    findRow(item) {
      if (item.pkId) {
        this.$router.push({
          path: "xyxq",
          query: { id: item.pkId },
        });
      } else {
        this.$router.push({
          path: "xyxq",
        });
      }
    },

    //删除
    deleteRow(row) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        deleteAgreement(row.pkId).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: "success",
            });
          }
          this.getDataList();
        });
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
        protocolTitle: "", //标题
        startDate: "",
        endDate: "",
        effectiveStartDate: "",
        effectiveEndDate: "",
      }
      this.cjsj = ""
      this.sxsj = ""
    },
    getDataList() {
      this.loading = true
      if (this.cjsj) {
        this.queryParams.startDate = this.cjsj[0];
        this.queryParams.endDate = this.cjsj[1];
      }else{
        this.queryParams.startDate =""
        this.queryParams.endDate = ""
      }
      if (this.sxsj) {
        this.queryParams.effectiveStartDate = this.sxsj[0];
        this.queryParams.effectiveEndDate = this.sxsj[1];
      }else{
        this.queryParams.effectiveStartDate = "";
        this.queryParams.effectiveEndDate = "";
      }
      getAgreementList(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.total = res.total
        this.loading = false
        this.tableData.forEach(item=>{
          if(item.content.length>20){
            item.content = item.content.substring(0,20) + '...'
          }
        })
      });
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-range-editor.el-input__inner{
  width: 100%;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}
.page {
  padding:  20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 15px 20px 15px 0;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      margin-left: 40px;
    }
    .searchtitle {
      margin-right: 10px;
    }
    .searchbtn {
      background: #08143f;
      color: #ffffff;
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #48B2FD;
          width: 68px;
          height: 32px;
        }
        .thebtn2 {
          color: #ffffff;
          background: #ffad41;
          width: 68px;
          height: 32px;
        }
      }
    }
  }
}
</style>
