<template>
  <div class="app-container"><!--从这一层开始嵌入页面-->

    <el-card>
      <el-form ref="queryForm" label-width="80px">
        <div class="search">
          <div class="sl">
            <el-form-item label="流程标题">
              <el-input
                v-model="queryParams.procTitle"
                placeholder="输入流程标题"
                clearable
                @clear="handleQuery"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="流程状态">
              <el-select placeholder="请选择" v-model="queryParams.recordStatus" @change="handleQuery">
                <el-option label="全部" value=""></el-option>
                <el-option label="审核中" value="doing"></el-option>
                <el-option label="已审核" value="done"></el-option>
                <el-option label="拟稿" value="draft"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="发起时间">
              <el-date-picker
                v-model="dateRange"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </div>
          <div class="sr">
            <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh-left" @click="resetQuery">重置</el-button>
          </div>
        </div><!--search 搜索-->
      </el-form><!--el-form-->
    </el-card><!--el-card-->

    <el-card>
      <el-table :data="tableData1" style="width: 100%" height="529" v-loading="loading">
        <el-table-column label="序号" width="60" type="index" align="center"></el-table-column>
        <el-table-column label="申请类型" width="110px" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span v-if="scope.row.applyType === 'publish'">发布申请</span>
            <span v-if="scope.row.applyType === 'use'">使用申请</span>
          </template>
        </el-table-column>
        <el-table-column prop="procTitle" label="流程标题" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="流程状态" width="80px">
          <template slot-scope="scope">
              <el-tag v-if="scope.row.recordStatus === 'doing'">审核中</el-tag>
              <el-tag type="success" v-if="scope.row.recordStatus === 'done'">已审核</el-tag>
              <el-tag type="info" v-if="scope.row.recordStatus === 'draft'">拟稿</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="发起时间" width="156px" ></el-table-column>
        <el-table-column prop="endTime" label="结束时间" width="156px"></el-table-column>
        <el-table-column label="操作" width="80px" >
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-info" @click="handleDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table><!--el-table-->
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getListData"
      />
    </el-card><!--el-card-->

    <el-drawer :visible.sync="drawer1" size="80%" :show-close="false">
      <template #title>
        <span>申请使用</span>
        <div class="drawer-head-btn">
          <el-button type="primary" @click="handleMonitor"><i class="el-icon-data-line"></i> 流程监控</el-button>
          <el-button  @click="drawer1 = false"><i class="el-icon-close"></i> 关闭</el-button>
        </div><!--drawer-head-btn 抽屉顶部按钮区域-->
      </template>
      <div class="tboper">
        <div class="tit">基本信息</div>
      </div><!--tboper 标题与操作按钮-->
      <div class="el-form-border">
        <el-form ref="form" label-width="150px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="申请人">{{applyDetail.nickName}}</el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="申请部门">{{applyDetail.deptName}}</el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="申请理由">
                <el-input type="textarea"  maxlength="1000" :placeholder="applyDetail.reason" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form><!--el-form-->
      </div><!--el-form-border 表单-->
      <div class="divide double"></div><!--divide 分隔-->
      <div class="tboper">
        <div class="tit">申请工具</div>
      </div><!--tboper 标题与操作按钮-->
      <div class="el-form-border">
        <el-form ref="form" label-width="150px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="工具编号">{{applyToolDetail.toolCode}}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工具名称">{{applyToolDetail.toolName}}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="负责人">{{applyToolDetail.toolPrincipalsName}}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="归属部门">{{applyToolDetail.toolRespDept}}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工具来源">{{applyToolDetail.toolSource}}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工具用途">{{applyToolDetail.toolUse}}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="工具类别">{{applyToolDetail.toolType}}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="状态">{{applyToolDetail.status}}</el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="测试情况">{{applyToolDetail.testSituation}}</el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="功能描述">{{applyToolDetail.functionDesc}}</el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="适用条件">{{applyToolDetail.applyCondition}}</el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="操作说明">{{applyToolDetail.operateExplain}}</el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注">{{applyToolDetail.remark}}</el-form-item>
            </el-col>
          </el-row>
        </el-form><!--el-form-->
      </div>
      <div class="divide double"></div><!--divide 分隔-->
    </el-drawer><!--el-drawer 申请详情-抽屉-->

    <el-drawer
      :visible.sync="drawerShow"
      direction="rtl"
      size="80%"
      :with-header="false"
      :wrapperClosable="false"
      :show-close="false"
      modal-append-to-body
      :destroy-on-close="true"
    >
      <main-component ref="mainComponent" :code="path + code"  :data="data"  @close="handleClose"></main-component>
    </el-drawer>

    <monitor-drawer
      v-if="drawer2"
      ref="monitorDrawer"
    ></monitor-drawer>
  </div><!--app-container-->
</template>

<script>
  import { listApply } from "@/api/tool/toolApply";
  import { getTool } from "@/api/tool/tool";
  import DealDrawer from '@/components/DealDrawer/index.vue'
  import mainComponent from '@/components/mainComponent/index.vue'
  export default {
    name: 'apply',
    components: { mainComponent, DealDrawer },
    data() {
      return {
        drawer1: false,
        drawer2: false,
        drawerShow: false,
        loading: false,
        tableData1: [],
        path: 'views/workflowList/addWorkflow/',
        code: '',
        data: undefined,
        // 日期范围
        dateRange: [],
        pageSizes: [10,20,50,100],
        // 总条数
        total: 0,
        // 查询参数
        queryParams: {
          pageNumber: 1,
          pageSize: 10,
          procTitle: "",
          recordStatus: "",
        },
        applyDetail: {},
        applyToolDetail: {}
      }
    },
    created() {
      // 初始化获取待办清单
      this.getListData()
    },
    methods: {
      handleDeal(row) {
        this.dealDrawerShow = true;
        let flowUrl = this.buildFlowUrl(row)
        this.$nextTick(() => {
          this.$refs.dealDrawer.init(flowUrl);
        });
      },
      /** 查询列表 */
      getListData() {
        this.loading = true;
        this.tableData1 = [];
        listApply(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
          this.total = response.total;
          this.tableData1 = response.rows;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getListData();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm("queryForm");
        this.queryParams.procTitle = "";
        this.queryParams.recordStatus = "";
        this.handleQuery();
      },
      showDetail(row){
        getTool(row.toolId).then((response) => {
          this.applyToolDetail = response.data;
        });
        this.drawer1 = true;
        this.applyDetail = row;
      },
      handleOpen(row){
        let _this = this
        _this.code = row.type
        _this.data = row
        _this.drawerShow = true
      },
      handleDetail(row) {
        let _this = this
        if(row.applyType === 'use'){
          _this.handleOpen({type:'use_apply', procInstId:row.procInstId, status:'2'})
        } else {
          _this.handleOpen({type:'tool_release', procInstId:row.procInstId, status:'2'})
        }

      },
      handleClose(){
        this.drawerShow = false
      },
      handleMonitor() {
        this.drawer2 = true;
        this.$nextTick(() => {
          this.$refs.monitorDrawer.init(this.applyDetail.procInstId);
        });
      },
    },
  }
</script>

<style scoped>

</style>
