<!-- 申购审核 -->
<template>
  <div class="app-container purchaseExamine">
    <div class="page-container purchaseExaminePage" v-if="pageType === 1">
      <div class="page-form-title-box">
        <el-form :model="queryParams" class="form-box" ref="queryForm"
                 :inline="true" style="width:100%;">
          <el-form-item label="" prop="deptId">
            <el-select v-model="queryParams.deptId" placeholder="请选择学院" style="width: 130px">
              <el-option
                v-for="item in deptOptions"
                :key="item.deptId"
                :label="item.deptName"
                :value="item.deptId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="applyStatus">
            <el-select v-model="queryParams.applyStatus" placeholder="请选择状态" style="width: 200px">
              <el-option
                v-for="dict in optionList"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="state">
            <el-date-picker
              :clearable="false"
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="" prop="queryParamsData1">
            <el-input
              maxLength="30"
              v-model="queryParams.searchValue"
              placeholder="化学品名/CAS/实验室/申购人/课题组/课题组成员"
              style="width: 340px"
            />
          </el-form-item>
          <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
          <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
        </el-form>
      </div>
      <div class="page-content-box">
        <div class="page-content-button">
          <p :class="queryParams.auditStatus == 1?'check-p':''" @click="checkButton(1)">待审核</p>
          <p :class="queryParams.auditStatus == 2?'check-p':''" @click="checkButton(2)">已审核</p>
        </div>
        <el-table class="table-box" v-loading="loading" border :data="dataList">
          <el-table-column label="申请时间" prop="applyTime" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.applyTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="申购人" prop="applyUserName" width="140" show-overflow-tooltip/>
          <el-table-column label="实验室" prop="subName" width="200" show-overflow-tooltip/>
          <el-table-column label="学院" prop="deptName" width="250" show-overflow-tooltip/>
          <el-table-column label="楼栋楼层" prop="name" width="250" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{scope.row.buildName}}-{{scope.row.floorName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="审核时间" prop="completeTime" width="180"
                           v-if="queryParams.auditStatus==2" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.completeTime,"{y}-{m}-{d} {h}:{i}") }}</span>
            </template>
          </el-table-column>
          <el-table-column label="申购状态" prop="auditNode" width="150" show-overflow-tooltip/>
          <el-table-column label="操作" width="130" show-overflow-tooltip v-if="tableButtonType">
            <template slot-scope="scope">
              <div class="table-button-box">
                <p class="table-button-null"></p>
                <p class="table-button-p"
                   @click="tableButton(2,scope.row)"
                   v-hasPermiRouter="['apply:audit:detail']"
                >详情</p>
                <p class="table-button-p"
                   @click="tableButton(3,scope.row)"
                   v-hasPermiRouter="['apply:audit:edit']"
                   v-if="scope.row.auditFlag && scope.row.applyStatus==4"
                >审核</p>
                <p class="table-button-null"></p>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <pagination :page-sizes="[20, 30, 40, 50]"
                    v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.page"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList"
        />
      </div>
    </div>
    <info-page :propsData="propsData" v-if="pageType === 2"></info-page>
  </div>
</template>
<script>
  import infoPage from "./infoPage.vue";
  import { chemicalApplyApproveList, chemicalApplyDetail } from '@/api/chemicalManage'
  import { getDeptDropList } from '@/api/commonality/permission'
  export default {
    name: 'index',
    components: {
     infoPage
    },
    data () {
      return {
        tableButtonType:this.hasPermiDom(['apply:audit:detail','apply:audit:edit']),
        //页面状态
        pageType:1,
        //页面遮罩
        loading:false,
        deptOptions:[],
        //下拉列表数据
        optionList:[{label:'保存草稿',value:2},{label:'撤销',value:3},{label:'审核中',value:4},{label:'已完成',value:5},{label:'驳回',value:6}],
        //查询条件
        queryParams:{
          page:1,
          pageSize:20,
          deptId:"",
          applyStatus :'',
          searchValue :"",
          auditStatus:1,//1是待审核，2是已审核
        },
        //时间数据
        dateRange:[],
        //列表数据
        dataList:[{}],
        //数据数量
        total:0,
        //组件传参
        propsData:{},
      }
    },
    created () {

    },
    mounted () {
      this.getList();
      this.getDeptDropList();
    },
    methods: {
      //切换
      checkButton(type){
        this.$set(this.queryParams,'auditStatus',type);
        this.getList();
      },
      //查询按钮
      handleQuery(){
        this.$set(this.queryParams,'page',1);
        this.getList();
      },
      //重置按钮
      resetQuery(){
        this.$set(this,'dateRange',[])
        this.$set(this,'queryParams',{
          page:1,
          pageSize:20,
          deptId:"",
          applyStatus :'',
          searchValue :"",
          auditStatus:1,//1是待审核，2是已审核
        });
        this.getList();
      },
      //查询学院列表
      getDeptDropList(){
        getDeptDropList({deptName:"",level:2,deptType:1}).then(response => {
          this.$set(this, 'deptOptions', response.data)
        });
      },
      //获取数据列表
      getList(){
        this.$set(this,'loading',true);
        let obj = JSON.parse(JSON.stringify(this.queryParams))
        if(this.dateRange[0]){
          obj.startApplyTime = this.dateRange[0]+'T00:00:00'
          obj.endApplyTime = this.dateRange[1]+'T23:59:59'
        }else{
          obj.startApplyTime = "";
          obj.endApplyTime = "";
        }
        chemicalApplyApproveList(obj).then(response => {
          this.$set(this,'loading',false);
          this.$set(this,'dataList',response.data.records);
          this.$set(this,'total',response.data.total);
        });
      },
      //操作按钮
      tableButton(type,row){
        let self = this;
        if(type == 1){
          //新增
          this.$set(this,'pageType',2);
          this.$set(this,'propsData',{});
        }else if(type == 2){
          //详情
          chemicalApplyDetail({applyId:row.applyId}).then(response => {
            this.$set(this,'propsData',response.data);
            this.propsData.showType = false;
            this.$set(this,'pageType',2);
          });
        }else if(type == 3){
          //审核
          chemicalApplyDetail({applyId:row.applyId}).then(response => {
            this.$set(this,'propsData',response.data);
            this.propsData.showType = true;
            this.$set(this,'pageType',2);
          });
        }else if(type == 'out'){
          //返回并刷新
          this.$set(this,'pageType',1);
          this.getList();
        }
      },
    },
  }
</script>
<style scoped lang="scss">
  .purchaseExamine{
    .purchaseExaminePage{
      .page-content-box{
        .page-content-button{
          display: flex;
          p{
            width:100px;
            line-height:40px;
            text-align: center;
            border-top-right-radius: 4px;
            border-top-left-radius: 4px;
            border:1px solid #dedede;
            border-bottom:none;
            color:#333;
            margin-right:10px;
            cursor: pointer;
            font-size:14px;
          }
          .check-p{
            border:1px solid #0045AF;
            background-color: #0045AF;
            color:#fff;
          }
        }
      }
    }
  }
</style>
