<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="输入流程标题"></el-input>
            </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-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">
        <el-table-column label="申请类型">
          <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="流程标题"></el-table-column>
        <el-table-column label="流程状态" width="150">
          <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>
          </template>
        </el-table-column>
        <el-table-column prop="createTime" label="发起时间"></el-table-column>
        <el-table-column prop="endTime" label="结束时间"></el-table-column>
        <el-table-column label="操作" width="100" >
          <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="75%" :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="90%"
      :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,
        path: 'views/workflowList/addWorkflow/',
        code: '',
        data: undefined,
        // 日期范围
        dateRange: [],
        pageSizes: [10,20,50,100],
        // 总条数
        total: 0,
        // 查询参数
        queryParams: {
          pageNumber: 1,
          pageSize: 10,
          procTitle: "",
          recordStatus: "",
        },
        applyDetail: {},
        applyToolDetail: {},
        tableData1: [
          {
            prop1: '使用申请',
            prop2: '进行中',
            prop3: '直接领导审核',
            prop4: '赵宇',
            prop5: '2024/02/09 12:00',
            prop6: '2024/02/09 12:00',
          },
          {
            prop1: '使用申请',
            prop2: '已办结',
            prop3: '直接领导审核',
            prop4: '钱多多',
            prop5: '2024/02/09 12:00',
            prop6: '2024/02/09 12:00',
          },
          {
            prop1: '使用申请',
            prop2: '进行中',
            prop3: '直接领导审核',
            prop4: '赵宇',
            prop5: '2024/02/09 12:00',
            prop6: '2024/02/09 12:00',
          },
          {
            prop1: '使用申请',
            prop2: '已办结',
            prop3: '直接领导审核',
            prop4: '钱多多',
            prop5: '2024/02/09 12:00',
            prop6: '2024/02/09 12:00',
          },
          {
            prop1: '使用申请',
            prop2: '进行中',
            prop3: '直接领导审核',
            prop4: '赵宇',
            prop5: '2024/02/09 12:00',
            prop6: '2024/02/09 12:00',
          },
          {
            prop1: '使用申请',
            prop2: '已办结',
            prop3: '直接领导审核',
            prop4: '钱多多',
            prop5: '2024/02/09 12:00',
            prop6: '2024/02/09 12:00',
          },
          {
            prop1: '使用申请',
            prop2: '进行中',
            prop3: '直接领导审核',
            prop4: '赵宇',
            prop5: '2024/02/09 12:00',
            prop6: '2024/02/09 12:00',
          },
          {
            prop1: '使用申请',
            prop2: '已办结',
            prop3: '直接领导审核',
            prop4: '钱多多',
            prop5: '2024/02/09 12:00',
            prop6: '2024/02/09 12:00',
          },
          {
            prop1: '使用申请',
            prop2: '进行中',
            prop3: '直接领导审核',
            prop4: '赵宇',
            prop5: '2024/02/09 12:00',
            prop6: '2024/02/09 12:00',
          },
          {
            prop1: '使用申请',
            prop2: '已办结',
            prop3: '直接领导审核',
            prop4: '钱多多',
            prop5: '2024/02/09 12:00',
            prop6: '2024/02/09 12:00',
          }
        ],
        tableData2: [
          {
            prop1: '0021',
            prop2: '工具名称1',
            prop3: '人力资源部/培训组',
            prop4: '赵宇',
            prop5: '网络工具',
          },
          {
            prop1: '0022',
            prop2: '工具名称2',
            prop3: '人力资源部/招聘组',
            prop4: '钱多多',
            prop5: '网络工具',
          },
          {
            prop1: '0023',
            prop2: '工具名称3',
            prop3: '人力资源部/薪资组',
            prop4: '孙瑶',
            prop5: '网络工具',
          }
        ],
        tableData3: [
          {
            prop1: '部门领导审核',
            prop2: '张宇',
            prop3: '管理员审核 ',
            prop4: '赵定',
            prop5: '同意',
            prop6: '2024/02/09 12:00',
            prop7: '2024/02/09 12:03',
            prop8: '耗时0天',
            prop9: '已完成',
          },
          {
            prop1: '管理员审核',
            prop2: '赵定',
            prop3: '直接领导审核 ',
            prop4: '钱多多',
            prop5: '同意',
            prop6: '2024/02/09 12:00',
            prop7: '2024/02/09 12:03',
            prop8: '耗时0天',
            prop9: '已完成',
          }
        ],
        tableData4: [
          {
            prop1: '部门领导审核',
            prop2: '张宇',
            prop3: '管理员审核 ',
            prop4: '赵定',
            prop5: '同意',
            prop6: '2024/02/09 12:00',
            prop7: '2024/02/09 12:03',
            prop8: '耗时0天',
            prop9: '已完成',
          },
          {
            prop1: '管理员审核',
            prop2: '赵定',
            prop3: '直接领导审核 ',
            prop4: '钱多多',
            prop5: '同意',
            prop6: '2024/02/09 12:00',
            prop7: '2024/02/09 12:03',
            prop8: '耗时0天',
            prop9: '已完成',
          }
        ],
      }
    },
    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>
