<!-- 安全生产管理列表 -->
<template>
  <div class="app-container">
    <!--筛选条件-->
    <div class="search-div">
      <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container">
        <el-row>
          <el-form-item class="selectForm-container-item">
            <el-input v-model.trim="listQuery.signName" placeholder="签署用户" clearable/>
          </el-form-item>
          <el-form-item class="selectForm-container-item">
            <el-select v-model="listQuery.projectId" filterable placeholder="所属项目" clearable value="" >
              <el-option
                v-for="item in projectList"
                :key="item.id"
                :label="item.projectName"
                :value="item.id"/>
            </el-select>
          </el-form-item>
          <el-form-item class="selectForm-container-item" width="370">
            <el-date-picker
              v-model="daterange"
              type="daterange"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="签署开始日期"
              end-placeholder="签署结束日期"/>
          </el-form-item>
          <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">查询</el-button>
        </el-row>
      </el-form>
    </div>
    <!--查询结果Table显示-->
    <div>
      <el-row class="table-title">
        <el-col :span="15"><div class="title-header"><i class="el-icon-menu"/>数据列表</div></el-col>
      </el-row>
      <el-table v-loading="listLoading" :data="list" class="table" border>
        <el-table-column :index="indexMethod" align="center" type="index" label="序号" width="55"/>
        <el-table-column v-for="column in columns" :key="column.value" :label="column.text" :width="column.width" :align="column.align">
          <template slot-scope="scope">
            <div v-if="column.text === '签名图片'" class="demo-image__preview" >
              <el-image
                :src="scope.row.signImage"
                :preview-src-list="[scope.row.signImage]"
                style="width: 100px;height: 100px"
              />
            </div>
            <span v-else :class="column.class">{{ scope.row[column.value] }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column property="img" label="签名图片" align="center">
          <template scope="scope">

          </template>
        </el-table-column> -->
        <el-table-column label="操作" align="center" width="80">
          <template slot-scope="scope">
            <el-button type="text" @click="detail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--分页-->
    <div class="pagination-container">
      <el-pagination
        :current-page="listQuery.offset"
        :page-sizes="[10,20,30]"
        :page-size="listQuery.limit"
        :total="total"
        align="center"
        layout="total, sizes, prev, pager, next"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
    <SafeBookDialog v-show="dialogFormVisible" ref="safeBookDialogRef" @watchChild="fetchData"/>
  </div>
</template>

<script>
import { getSafeManageList } from '@/api/factoryManager/safeManage'
import { getProjectListUnpageSegment } from '@/api/factoryManager/project'
import DownloadTemplate from '@/components/DownloadTemplate/index'
import SafeBookDialog from '../components/safeBookDialog.vue'
export default {
  name: 'ListQuality',
  components: { DownloadTemplate, SafeBookDialog },
  data() {
    return {
      dialogFormVisible: false,
      daterange: [], // 签署日期范围
      projectList: [], // 项目列表
      listQuery: {
        signName: '', // 签署用户
        startTime: '', // 签署开始日期
        endTime: '', // 签署结束日期
        projectId: '', // 所属项目
        offset: 1,
        limit: 10
      }, // 筛选条件
      columns: [
        {
          text: '所属项目',
          value: 'projectName',
          align: 'center'
        },
        {
          text: '签署用户',
          value: 'signName',
          align: 'center'
        },
        {
          text: '签名图片',
          value: 'signImage',
          align: 'center'
        },
        {
          text: '签署日期',
          value: 'signTime',
          align: 'center'
        }
      ], // 显示列
      list: [], // 列表数据
      total: 0, // 数据总数
      multipleSelection: [], // 多选
      listLoading: true, // 加载动画
      fullscreenLoading: false // 全屏加载动画
    }
  },
  watch: {
    daterange(val) {
      if (val && val.length > 0) {
        this.listQuery.beginTime = val[0]
        this.listQuery.endTime = val[1]
      } else {
        this.listQuery.beginTime = ''
        this.listQuery.endTime = ''
      }
    }
  },
  created() {
    this.fetchProjectListUnpageSegment() // 获取项目列表
    this.fetchData()// 获取数据
  },
  activated() {
    this.fetchData()// 获取数据
  },
  methods: {
    // 查询数据
    search() {
      this.fetchData(false)
    },
    // 获取项目列表
    fetchProjectListUnpageSegment() {
      getProjectListUnpageSegment().then(response => {
        this.projectList = response.data
      })
    },
    // 获取数据
    fetchData(isNowPage = true) {
      this.listLoading = true
      if (!isNowPage) { // 是否显示当前页，否则跳转第一页
        this.listQuery.offset = 1
      }
      getSafeManageList(this.listQuery).then(response => {
        this.list = response.data.rows
        this.total = parseInt(response.data.total)
        this.listLoading = false
      }).catch(res => {
        this.listLoading = false
        this.$message.error(res.message)
      })
    },
    // 制作表格序号
    indexMethod(index) {
      return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
    },
    // 改变页容量
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.fetchData()
    },
    // 改变当前页
    handleCurrentChange(val) {
      this.listQuery.offset = val
      this.fetchData()
    },
    // 点击详情
    detail(row) {
      this.dialogFormVisible = true
      this.$refs.safeBookDialogRef.initDialog('detail', this.dialogFormVisible, row)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  $tableTitleHeight:46px;
  .table{
    margin-bottom: 20px;
  }
  .pagination-container{
    margin-bottom: 50px;
  }
  .table-title{
    background-color:rgba(243, 243, 243, 1);
    height: $tableTitleHeight;
    .title-header{
      line-height:$tableTitleHeight;
      color: #606266;
      font-size: 15px;
      i{
        margin-left: 5px;
        margin-right: 5px;
      }
    }
  }
  .edit_btns{
    .edit_btn{
      float:right;
      margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
    }
  }
  .upload-btn{
    display: inline;
  }
</style>
