<template>
  <div style="width: 100%;">
    <div class="set-background">
      <div class="block">
        <el-form :model="queryCode">
          <div class="set-between">
            <!-- <el-form-item label="创建时间" label-width="70px"><el-date-picker v-model="queryCode.dateQuery" align="left" size="medium" type="datetime" style="width:76%;" placeholder="选择日期" /></el-form-item> -->
            <el-input v-model="queryCode.currentHandler" placeholder="处理人" autocomplete="off" clearable size="medium" style="width:13%;margin-right: 15px;" />
            <el-input v-model="queryCode.creator" placeholder="提交人" autocomplete="off" clearable size="medium" style="width:13%;margin-right: 15px;" />
            <el-input v-model="queryCode.bugName" placeholder="主题" autocomplete="off" clearable size="medium" style="width:13%;margin-right: 15px;" />
            <el-select v-model="queryCode.taskId" size="medium" style="width:15%;margin-right: 15px;" clearable placeholder="任务">
              <el-option v-for="item in taskIdStr" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
            <el-select v-model="queryCode.status" size="medium" style="width:15%;margin-right: 15px;" clearable placeholder="bug状态">
              <el-option v-for="item in bugStatusStr" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
            <el-select v-model="queryCode.priority" size="medium" style="width:15%;margin-right: 15px;" clearable placeholder="级别">
              <el-option v-for="item in bugStatusPriority" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
            <el-select v-model="queryCode.repairResult" size="medium" style="width:15%;margin-right: 10px;" clearable placeholder="修复状态">
              <el-option v-for="item in repairResultStr" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
            <el-button type="primary" size="medium" style="margin-right:10px;" icon="el-icon-plus" circle @click="timeShow = !timeShow, isPlatformShow = !isPlatformShow, queryCode.platformType = '', isBusinessShow === true ? isBusinessShow = false : isBusinessShow = false" />
          </div>
          <div class="set-between">
            <el-button type="primary" size="medium" plain @click="dataQuery(queryCode)">查询</el-button>
            <el-button type="primary" size="medium" plain @click="createdCode()">新增</el-button>
          </div>
        </el-form>
        <el-date-picker
          v-show="timeShow"
          v-model="timeInterval"
          size="medium"
          type="datetimerange"
          range-separator="至"
          start-placeholder="创建开始时间"
          end-placeholder="创建结束时间"
          clearable
        />
        <el-select v-if="isPlatformShow" v-model="queryCode.platformType" size="medium" style="width:17.5%;margin-right: 15px;" clearable placeholder="平台类型" @change="clickChangeBusiness(queryCode.platformType)">
          <el-option v-for="item in platformTypeStr" :key="item.code" :label="item.name" :value="item.code" />
        </el-select>
        <el-select v-if="isBusinessShow" v-model="queryCode.clientType" size="medium" style="width:17.5%;margin-right: 15px;" clearable placeholder="业务模块" @change="clickChangeModule(queryCode.clientType)">
          <el-option v-for="item in businessTypeStr" :key="item.code" :label="item.name" :value="item.code" />
        </el-select>
        <div class="set-locate">
          <el-table
            :data="tableData"
            border
            style="width: 100%"
            size="mini"
          >
            <el-table-column
              prop="id"
              label="ID"
              align="center"
              width="60"
            />
            <el-table-column
              label="主题"
              align="center"
              width="180"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <a href="javascript:void(0)" style="color:#20a0ff" @click="toReportView(scope.row.id)">{{ scope.row.bugName }}</a>
              </template>
            </el-table-column>
            <el-table-column
              prop="priorityName"
              label="级别"
              align="center"
              width="60"
            />
            <el-table-column
              label="状态"
              align="center"
            >
              <template slot-scope="scope">
                <el-tag type="success" size="medium"><span>{{ scope.row.bugStatusName }}</span></el-tag>
              </template>
            </el-table-column>
            <el-table-column
              prop="currentHandlerList"
              label="处理人"
              align="center"
              show-overflow-tooltip
            />
            <el-table-column
              prop="creatorList"
              label="提交人"
              align="center"
              show-overflow-tooltip
            />
            <el-table-column
              prop="assignerList"
              label="责任人"
              align="center"
              show-overflow-tooltip
            />
            <el-table-column
              prop="repairResultName"
              label="修复结果"
              align="center"
              width="70"
              show-overflow-tooltip
            />
            <el-table-column
              prop="gmtCreate"
              label="创建日期"
              align="center"
              show-overflow-tooltip
            />
            <el-table-column
              label="操作"
              align="center"
              width="220"
            >
              <template v-slot="scope">
                <div>
                  <el-button size="mini" type="primary" plain @click="queryPresentation(scope.row)">更新</el-button>
                  <el-button size="mini" type="danger" plain @click="delePresentation(scope.row.id)">删除</el-button>
                  <el-button size="mini" type="info" plain @click="copyArrange(scope.row.id)">复制</el-button>
                </div>
              </template>
            </el-table-column>
          </el-table>
          <div class="set-locate">
            <h4>缺陷分析数据</h4>
            <el-table
              :data="[statistics]"
              border
              style="width: 100%"
              size="mini"
            >
              <el-table-column
                prop="totalBug"
                label="有效Bug总数"
                align="center"
              />
              <el-table-column
                prop="invalidBug"
                label="无效Bug"
                align="center"
              />
              <el-table-column
                prop="fixBug"
                label="已解决"
                align="center"
              />
              <el-table-column
                prop="rateOfFix"
                label="修复率"
                align="center"
              />
              <el-table-column
                prop="remainBug"
                label="遗留"
                align="center"
              />
              <el-table-column
                prop="rateOfReopen"
                label="Reopen率"
                align="center"
              />
              <el-table-column
                prop="overnightRate"
                label="过夜率"
                align="center"
              />
              <el-table-column
                prop="fixTime"
                label="修复时长"
                align="center"
              />
              <el-table-column
                prop="p0"
                label="P0"
                align="center"
              />
              <el-table-column
                prop="p1"
                label="P1"
                align="center"
              />
              <el-table-column
                prop="other"
                label="其他"
                align="center"
              />
            </el-table>
            <el-tooltip effect="dark" placement="bottom">
              <div slot="content"><div>总数: 搜索结果下的所有有效缺陷不包含无效bug和重复bug</div> <div style="margin:5px 0">已解决: 状态为已完成并且修复结果为已修复或不修复的bug</div><div style="margin:5px 0">遗留bug: 状态不是已完成状态的bug</div><div style="margin:5px 0">reopen率: reopen次数/bug总数</div><div style="margin:5px 0">过夜: 创建时间-修复时间 >24h/bug总数</div><div style="margin:5px 0">修复时长: 创建时间-修复时间，不包含节假日</div><div style="margin:5px 0">其他: 除p0，p1级之外的bug</div><div>无效bug: 修复结果为无效 或者重复的bug</div></div>
              <span class="titleDescription">统计规则说明<i class="el-icon-question" /> </span>
            </el-tooltip>
          </div>
          <el-pagination style="margin-top:30px;" align="center" :current-page="curIndex" :page-sizes="[5, 10, 20]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </div>
      </div>
      <el-dialog class="adjustHeight" :title="titName" :visible.sync="dialogFormVisible" width="70%">
        <el-form ref="form" :model="form" :rules="serviceDataRules">
          <div class="set-background">
            <el-form-item label="标题" :label-width="formLabelWidth"><el-input v-model="form.bugName" autocomplete="off" placeholder="普惠质量产品工具平台..." style="width:77.2%;" /></el-form-item>
            <div style="display:flex;">
              <el-form-item style="flex-grow:1" prop="bizId" label="业务线" :label-width="formLabelWidth1">
                <el-select v-model="form.bizId" placeholder="业务线" style="width:54.5%;">
                  <el-option v-for="item in bizOptions" :key="item.value" :label="item.name" :value="item.value" />
                </el-select>
              </el-form-item>
              <el-form-item style="flex-grow:1" label="业务模块" prop="businessType" :label-width="formLabelWidth1">
                <el-select v-model="form.businessType" placeholder="业务模块" style="width:54.5%;">
                  <el-option v-for="item in businessTypeStr" :key="item.name" :label="item.name" :value="item.name" />
                </el-select>
              </el-form-item>
            </div>
            <div style="display:flex;">
              <el-form-item style="flex-grow:1" prop="taskId" label="任务" :label-width="formLabelWidth1">
                <el-select v-model="form.taskId" placeholder="任务" style="width:54.5%;">
                  <el-option v-for="item in taskIdStr" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item>
              <el-form-item style="flex-grow:1" label="平台类型" prop="platformType" :label-width="formLabelWidth1">
                <el-select v-model="form.platformType" placeholder="平台类型" style="width:54.5%;" @change="clickChangeType(form.platformType)">
                  <el-option v-for="item in platformTypeStr" :key="item.name" :label="item.name" :value="item.name" />
                </el-select>
              </el-form-item>
            </div>
            <div style="display:flex;">
              <el-form-item style="flex-grow:1" label="类型" prop="bugType" :label-width="formLabelWidth1">
                <el-select v-model="form.bugType" style="width:54.5%;" placeholder="类型">
                  <el-option v-for="item in bugTypeStr" :key="item.name" :label="item.name" :value="item.name" />
                </el-select>
              </el-form-item>
              <el-form-item style="flex-grow:1" label="发现方式" prop="discoveryMethod" :label-width="formLabelWidth1">
                <el-select v-model="form.discoveryMethod" style="width:54.5%;" placeholder="发现方式">
                  <el-option v-for="item in discoveryMethodStr" :key="item.name" :label="item.name" :value="item.name" />
                </el-select>
              </el-form-item>
            </div>
            <div style="display:flex;">
              <el-form-item style="flex-grow:1" label="级别" prop="priority" :label-width="formLabelWidth1">
                <el-select v-model="form.priority" style="width:54.5%;" placeholder="级别">
                  <el-option v-for="item in bugLevelStr" :key="item.name" :label="item.name" :value="item.name" />
                </el-select>
              </el-form-item>
              <el-form-item style="flex-grow:1" label="问题原因" prop="reason" :label-width="formLabelWidth1">
                <el-select v-model="form.reason" style="width:54.5%;" placeholder="问题原因">
                  <el-option v-for="item in reasonStr" :key="item.name" :label="item.name" :value="item.name" />
                </el-select>
              </el-form-item>
            </div>
            <div style="display:flex;">
              <el-form-item style="flex-grow:1" label="状态" prop="status" :label-width="formLabelWidth1">
                <el-select v-model="form.status" placeholder="状态" style="width:54.5%;" @change="buildShow(form.status)">
                  <el-option v-for="item in bugStatusStr" :key="item.name" :label="item.name" :value="item.name" />
                </el-select>
              </el-form-item>
              <el-form-item style="flex-grow:1" label="所处阶段" prop="stage" :label-width="formLabelWidth1">
                <el-select v-model="form.stage" placeholder="所处阶段" style="width:54.5%;">
                  <el-option v-for="item in stageStr" :key="item.name" :label="item.name" :value="item.name" />
                </el-select>
              </el-form-item>
            </div>
            <el-form-item label="bug描述" prop="bugDescribe" :label-width="formLabelWidth"><el-input v-model="form.bugDescribe" type="textarea" placeholder="bug描述" rows="2" style="width:77.2%;" /></el-form-item>
          </div>
          <div style="display:flex;">
            <el-form-item label="创建人" :label-width="formLabelWidth"><el-input v-model="form.creator" autocomplete="off" style="width:67%;" /></el-form-item>
            <el-form-item label="bug责任人" prop="assigner" :label-width="formLabelWidth"><el-input v-model="form.assigner" autocomplete="off" style="width:67%;" /></el-form-item>
          </div>
          <div style="flex:1">
            <el-form-item v-show="statusShow" label="问题原因和修复方法" :label-width="formLabelWidth"><el-input v-model="form.reasonsAndSolutionForTheProblem" type="textarea" placeholder="问题原因和修复方法" rows="4" style="width:77.2%;" /></el-form-item>
          </div>
          <div style="flex:1">
            <el-form-item label="bug处理人" prop="currentHandler" :label-width="formLabelWidth"><el-input v-model="form.currentHandler" autocomplete="off" style="width:67%;" /></el-form-item>
            <el-form-item label="app版本号" :label-width="formLabelWidth"><el-input v-model="form.appVersion" autocomplete="off" style="width:67%;" /></el-form-item>
            <el-form-item label="地图类型" :label-width="formLabelWidth"><el-input v-model="form.mapType" autocomplete="off" style="width:67%;" /></el-form-item>
            <el-form-item label="地图版本号" :label-width="formLabelWidth"><el-input v-model="form.mapVersion" autocomplete="off" style="width:67%;" /></el-form-item>
            <el-form-item label="SDK版本" :label-width="formLabelWidth"><el-input v-model="form.sdkVersion" autocomplete="off" style="width:67%;" /></el-form-item>
            <el-form-item v-show="repairShow" label="修复结果" :label-width="formLabelWidth">
              <el-select v-model="form.repairResult" placeholder="发现方法">
                <el-option v-for="item in repairResultStr" :key="item.name" :label="item.name" :value="item.name" />
              </el-select>
            </el-form-item>
          </div>
          <el-form-item label="附件" :label-width="formLabelWidth">
            <el-upload
              class="upload-demo"
              multiple
              capture
              accept="image/jpeg, image/png, image/gif, audio/mp4, video/mp4, audio/mpeg, application/vnd.ms-excel"
              :on-change="handleChange"
              :file-list="fileList"
              action="http://page-daily.kuaidadi.com/upload/img.node"
            >
              <!-- action="http://page-daily.kuaidadi.com/upload/img.node" 线下 -->
              <!-- action="http://star.xiaojukeji.com/upload/img.node" 线上 -->
              <!-- action="https://jsonplaceholder.typicode.com/posts/" 原始地址-->
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
          {{ form.accessory }}

          <!-- <el-form-item label="逻辑删" :label-width="formLabelWidth">
            <el-select v-model="form.isDelete" placeholder="发现方法">
              <el-option v-for="item in isDeleteStr" :key="item.value" :label="item.name" :value="item.value" />
            </el-select>
          </el-form-item> -->
          <!-- <el-form-item label="reopen的次数" :label-width="formLabelWidth"> <el-input v-model="form.reopenTimes" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="业务线" prop="bizId" :label-width="formLabelWidth"><el-input v-model="form.bizId" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="模块" :label-width="formLabelWidth"><el-input v-model="form.moduleId" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="项目名" :label-width="formLabelWidth"><el-input v-model="form.projectName" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="项目ID" :label-width="formLabelWidth"><el-input v-model="form.projectId" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="测试计划ID" prop="planId" :label-width="formLabelWidth"><el-input v-model="form.planId" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="caseID" :label-width="formLabelWidth"><el-input v-model="form.caseId" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="bug创建人" :label-width="formLabelWidth"> <el-input v-model="form.creator" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="开始开发时间" :label-width="formLabelWidth"><el-input v-model="form.startDevTime" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="开始等待测试时间" :label-width="formLabelWidth"><el-input v-model="form.waitTestTime" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="创建时间" :label-width="formLabelWidth"><el-input v-model="form.gmtCreate" autocomplete="off" /></el-form-item> -->
          <!-- <el-form-item label="修改时间" :label-width="formLabelWidth"><el-input v-model="form.gmtModify" autocomplete="off" /></el-form-item> -->
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="titName === '新建' ? createFormData(form) : queryFormData(form)">确 定</el-button>
        </div>
      </el-dialog>

      <el-dialog :visible.sync="dialogFormQuery" width="70%">
        <el-form :model="form" size="mini">
          <el-form-item :label-width="formLabelWidth" style="margin-bottom:-10px;"><span style="font-weight:bold;font-size:20px;margin-left:-60px;">主题 : </span>{{ form.bugName }}</el-form-item><hr>
          <div style="display:flex;">
            <div style="flex:1">
              <el-form-item label="任务 : " class="styline" :label-width="formLabelWidth1">{{ form.projectName }}</el-form-item>
              <el-form-item label="级别 : " :label-width="formLabelWidth1">{{ form.priority }}</el-form-item>
              <el-form-item label="reopen的次数 : " :label-width="formLabelWidth1">{{ form.reopenTimes }}</el-form-item>
              <el-form-item label="bug状态 : " :label-width="formLabelWidth1">{{ form.status }}</el-form-item>
              <el-form-item label="bug类型 : " :label-width="formLabelWidth1">{{ form.bugType }}</el-form-item>
              <el-form-item label="bug描述 : " :label-width="formLabelWidth1">{{ form.bugDescribe }}</el-form-item>
              <el-form-item v-show="statusShow" label="问题原因和修复方法" :label-width="formLabelWidth">{{ form.reasonsAndSolutionForTheProblem }}</el-form-item>
              <el-form-item label="问题原因 : " :label-width="formLabelWidth1">{{ form.reason }}</el-form-item>
              <el-form-item label="平台类型 : " :label-width="formLabelWidth1">{{ form.platformType }}</el-form-item>
              <el-form-item label="业务模块 : " :label-width="formLabelWidth1">{{ form.businessType }}</el-form-item>
              <el-form-item label="所处阶段 : " :label-width="formLabelWidth1">{{ form.stage }}</el-form-item>
              <el-form-item label="发现方法 : " :label-width="formLabelWidth1">{{ form.discoveryMethod }}</el-form-item>
              <el-form-item v-show="repairShow" label="修复结果 : " :label-width="formLabelWidth1">{{ form.repairResult }}</el-form-item>
              <el-form-item label="os类型 : " :label-width="formLabelWidth1">{{ form.osType }}</el-form-item>
              <el-form-item label="机型 : " :label-width="formLabelWidth1">{{ form.model }}</el-form-item>
              <el-form-item label="网络类型 : " :label-width="formLabelWidth1">{{ form.networkType }}</el-form-item>
              <el-form-item label="SDK版本 : " :label-width="formLabelWidth1">{{ form.sdkVersion }}</el-form-item>
              <el-form-item label="app版本号 : " :label-width="formLabelWidth1">{{ form.appVersion }}</el-form-item>
              <el-form-item label="地图类型 : " :label-width="formLabelWidth1">{{ form.mapType }}</el-form-item>
              <el-form-item label="地图版本号 : " :label-width="formLabelWidth1">{{ form.mapVersion }}</el-form-item>
              <el-form-item label="附件 : " :label-width="formLabelWidth1">{{ form.accessory }}</el-form-item>
            </div>
            <div style="flex:1; margin-left:30px;">
              <el-form-item label="业务线 : " :label-width="formLabelWidth1">{{ form.bizId }}</el-form-item>
              <el-form-item label="bug责任人 : " :label-width="formLabelWidth1">{{ form.assigner }}</el-form-item>
              <el-form-item label="bug创建人 : " :label-width="formLabelWidth1">{{ form.creator }}</el-form-item>
              <el-form-item label="bug处理人 : " :label-width="formLabelWidth1">{{ form.currentHandler }}</el-form-item>
              <el-form-item label="开始开发时间 : " :label-width="formLabelWidth1">{{ form.startDevTime }}</el-form-item>
              <el-form-item label="开始等待测试时间 : " :label-width="formLabelWidth1">{{ form.waitTestTime }}</el-form-item>
              <el-form-item label="创建时间 : " :label-width="formLabelWidth1">{{ form.gmtCreate }}</el-form-item>
            </div>
          </div>
          <!-- <el-form-item label="caseID" :label-width="formLabelWidth">{{ form.caseId }}</el-form-item> -->
          <!-- <el-form-item label="项目名" :label-width="formLabelWidth">{{ form.projectName }}</el-form-item> -->
          <!-- <el-form-item label="项目ID" :label-width="formLabelWidth">{{ form.projectId }}</el-form-item> -->
          <!-- <el-form-item label="测试计划ID" :label-width="formLabelWidth">{{ form.planId }}</el-form-item> -->
          <!-- <el-form-item label="逻辑删" :label-width="formLabelWidth">{{ form.isDelete }}</el-form-item> -->
          <!-- <el-form-item label="业务线" :label-width="formLabelWidth">{{ form.bizId }}</el-form-item> -->
          <!-- <el-form-item label="模块ID" :label-width="formLabelWidth">{{ form.moduleId }}</el-form-item> -->
          <!-- <el-form-item label="修改时间" :label-width="formLabelWidth">{{ form.gmtModify }}</el-form-item> -->

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="dialogFormQuery = false">关 闭</el-button>
        </div>
      </el-dialog>
    </div>
  </div></template>

<script>
import { bugList, bugGet, bugDelete, bugUpdate, bugCreate, bugCopy, taskListCreate, bugGetEnum } from '@/api/defectManage'
import { projectGetTypeMap } from '@/api/projectPage.js'

export default {
  name: 'DefectManage',
  data() {
    return {
      isPlatformShow: false,
      isBusinessShow: false,
      bugTypeStr: [],
      bugStatusStr: [],
      bizOptionsRR: [],
      bizOptions: [{ name: '万象', value: 101 }, { name: '企业级', value: 100 }, { name: '滴滴代驾', value: 261 }, { name: 'prado', value: 330 }, { name: 'carbo', value: 331 }, { name: '海马', value: 309 }],
      bugLevelStr: [{ name: 'p0', value: 0 }, { name: 'p1', value: 1 }, { name: 'p2', value: 2 }, { name: 'p3', value: 3 }],
      reasonStr: [],
      platformTypeStr: [],
      stageStr: [],
      discoveryMethodStr: [],
      businessTypeStr: [],
      bugStatusPriority: [],
      repairResultStr: [],
      statistics: [],
      isDeleteStr: [{ name: '保留', value: 0 }, { name: '删除', value: 1 }],
      serviceDataRules: {
        bizId: [{ required: true, message: '业务线不能为空', trigger: 'change' }],
        // bugName: [{ required: true, message: '主题不能为空', trigger: 'change' }],
        taskId: [{ required: true, message: '任务不能为空', trigger: 'change' }],
        // projectId: [{ required: true, message: '项目ID不能为空', trigger: 'change' }],
        bugType: [{ required: true, message: 'bug类型不能为空', trigger: 'change' }],
        discoveryMethod: [{ required: true, message: '发现方式不能为空', trigger: 'change' }],
        reason: [{ required: true, message: '问题原因不能为空', trigger: 'change' }],
        priority: [{ required: true, message: '级别不能为空', trigger: 'change' }],
        status: [{ required: true, message: '状态不能为空', trigger: 'change' }],
        platformType: [{ required: true, message: '平台类型不能为空', trigger: 'change' }],
        stage: [{ required: true, message: '所处阶段不能为空', trigger: 'change' }],
        assigner: [{ required: true, message: 'bug责任人不能为空', trigger: 'change' }],
        currentHandler: [{ required: true, message: 'bug处理人不能为空', trigger: 'change' }],
        bugDescribe: [{ required: true, message: 'bug描述不能为空', trigger: 'change' }],
        businessType: [{ required: true, message: '业务模块不能为空', trigger: 'change' }]
      },
      userInformation: localStorage.getItem('username'),
      userNames: localStorage.getItem('realname'),
      bizJson: localStorage.getItem('key'),
      pageSize: 20,
      curIndex: 1,
      total: 0,
      show2: '',
      form: {
        id: ''
      },
      tableData: [],
      queryCode: {},
      statusShow: false,
      repairShow: false,
      timeShow: false,
      dialogFormVisible: false,
      dialogFormQuery: false,
      formLabelWidth: '11%',
      formLabelWidth1: '22%',
      serviceTypeEnumList: [],
      clientTypeEnumList: [],
      bizIdEnumList: [],
      objData: '',
      userData: '',
      titName: '',
      taskIdStr: '',
      timeInterval: [],
      fileList: [],
      fileDbList: []
    }
  },
  created() {
    this.getList()
    this.forkDown()
    this.bugListSelect()
  },
  mounted() {
    document.getElementsByClassName('app-main')[0].style.cssText = 'overflow:auto'
    this.getQueryData()
  },
  methods: {
    getList() {
      this.bizJson = localStorage.getItem('key')
      this.indexPage = {
        bizId: this.bizJson,
        pageSize: this.pageSize,
        curIndex: this.curIndex
      }
      bugList(this.indexPage).then(res => {
        this.statistics = res.query
        this.tableData = res.data
        this.total = res.total
      })
    },
    bugListSelect() {
      bugGetEnum().then(res => {
        this.bugStatusStr = res.data.bugEnumList
        this.bugStatusPriority = res.data.priorityEnumList
        this.stageStr = res.data.bugStageEnumList
        this.reasonStr = res.data.reasonEnumList
        this.platformTypeStr = res.data.platformTypeEnumList
        this.bugTypeStr = res.data.bugTypeEnumList
        this.bugLevelStr = res.data.priorityEnumList
        this.discoveryMethodStr = res.data.discoveryMethodEnumList
        this.repairResultStr = res.data.repairResultEnumList
        this.clientTypeEnumList = res.data.clientTypeEnumList
        this.serviceTypeEnumList = res.data.serviceTypeEnumList
        this.bizIdEnumList = res.data.bizIdEnumList
      })
    },
    clickChangeType(e) {
      // console.log(this.form.businessType)
      // this.form.businessType = ''
      if (e === '服务端') {
        this.businessTypeStr = this.serviceTypeEnumList
      } else {
        this.businessTypeStr = this.clientTypeEnumList
      }
    },
    dataQuery(e) {
      this.bizJson = localStorage.getItem('key')
      this.indexPage = e
      this.curIndex = 1
      this.indexPage.bizId = this.bizJson
      this.indexPage.pageSize = this.pageSize
      this.indexPage.curIndex = this.curIndex
      if (this.timeShow) {
        this.indexPage.gmtCreateBegin = this.timeInterval[0]
        this.indexPage.gmtCreateEnd = this.timeInterval[1]
      } else {
        this.indexPage.gmtCreateBegin = ''
        this.indexPage.gmtCreateEnd = ''
      }
      bugList(this.indexPage).then(res => {
        this.tableData = res.data
        this.total = res.total
        this.statistics = res.query
      })
    },
    // 业务线数据获取
    forkDown() {
      projectGetTypeMap().then(res => {
        if (res.code === 200) {
          this.bizOptionsRR = res.data
          if (this.bizJson) {
            this.platformTypeStr = this.bizOptionsRR.filter(value => value.code === parseInt(this.bizJson))[0].child
            this.$set(this.queryCode, 'platformType', '')
            this.$set(this.queryCode, 'clientType', '')
          } else {
            this.isPlatformShow = false
            this.isBusinessShow = false
          }
        } else {
          this.errorFun('业务线数据获取失败')
        }
      })
    },
    // 业务线取子数据
    clickChangeBusiness(e) {
      if (e && this.platformTypeStr.filter(value => value.code === e)[0].child) {
        this.isBusinessShow = true
        this.businessTypeStr = this.platformTypeStr.filter(value => value.code === e)[0].child
        this.$set(this.queryCode, 'clientType', '')
      } else {
        this.isBusinessShow = false
      }
    },
    clickChangeModule(e) {
      if (!e) {
        this.isBusinessShow = false
      }
    },
    dataQueryInSearch(e) {
      this.bizJson = localStorage.getItem('key')
      this.indexPage = e
      this.indexPage.bizId = this.bizJson
      this.indexPage.pageSize = this.pageSize
      this.indexPage.curIndex = this.curIndex
      if (this.timeShow) {
        this.indexPage.gmtCreateBegin = this.timeInterval[0]
        this.indexPage.gmtCreateEnd = this.timeInterval[1]
      } else {
        this.indexPage.gmtCreateBegin = ''
        this.indexPage.gmtCreateEnd = ''
      }
      bugList(this.indexPage).then(res => {
        this.tableData = res.data
        this.total = res.total
      })
    },
    // // 删除报告
    delePresentation(e) {
      this.$confirm('是否确认删除', '确认信息', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      })
        .then(() => {
          this.userData = { id: '', ename: this.userInformation, name: this.userNames }
          bugDelete(this.userData, e).then(res => {
            this.getList()
          })
          this.$message({ type: 'success', message: '已删除' })
        })
        .catch(action => {
          this.$message({ type: 'success', message: '已取消' })
        })
    },
    copyArrange(e) {
      this.userData = { id: e, ename: this.userInformation, name: this.userNames }
      bugCopy(this.userData, e).then(res => {
        this.getList()
        this.successFun()
      })
    },
    queryPresentation(ele) {
      this.titName = '编辑'
      this.form = ele
      for (var a of this.bizOptions) {
        if (ele.bizId === a.value) {
          this.bizId = a.name
        }
      }
      // this.bizId = ele.bizId
      this.form.taskId = ele.taskId
      this.buildShow(ele)
      this.$router.push({ name: '更新Bug', params: { formData: this.form }, query: { id: this.form.id }})
      // this.dialogFormVisible = true
    },
    buildShow(ele) {
      if (ele.status === '待回归' || ele === 2) {
        this.statusShow = true
      }
      if (ele.repairResult === '已修复' || ele === 3) {
        this.repairShow = true
      }
    },
    queryFormData(form) {
      this.userData = { id: '', ename: this.userInformation, name: this.userNames }
      this.objData = { bugBaseInfo: this.form, user: this.userData }
      bugUpdate(this.objData).then(res => {
        res.code === 200 ? this.successFun() : this.errorFun()
        this.dialogFormVisible = false
        this.getList()
      })
    },
    getQueryData() {
      this.$route.query.code === 4 ? this.queryCode.taskId = this.$route.query.id : ''
      this.bizJson = localStorage.getItem('key')
      taskListCreate({ bizId: this.bizJson }).then(res => {
        this.taskIdStr = res.data
      })
    },
    handleSizeChange(size) {
      this.curIndex = 1
      this.pageSize = size
      this.dataQueryInSearch(this.queryCode)
    },
    handleCurrentChange(curIndex) {
      this.curIndex = curIndex
      this.dataQueryInSearch(this.queryCode)
    },
    createdCode() {
      // this.titName = '新建'
      // this.dialogFormVisible = true
      this.form = {}
      // this.$route.query.code === 4 ? this.form.taskId = this.$route.query.id : ''
      // if (this.$refs['form'] !== undefined) {
      //   this.$refs['form'].resetFields()
      // }
      this.$router.push({ name: '新建Bug' })
    },
    createFormData(form) {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          // form.bizId = this.bizJson
          this.userData = { id: '', ename: this.userInformation, name: this.userNames }
          this.objData = { bugBaseInfo: form, user: this.userData }
          bugCreate(this.objData).then(res => {
            this.dialogFormVisible = false
            this.getList()
            res.code === 200 ? this.successFun() : this.errorFun()
          })
        }
      })
    },
    toReportView(e) {
      // this.dialogFormQuery = true
      // this.buildShow(e)
      bugGet(e).then(res => {
        this.form = res.data
        for (var a of this.bizIdEnumList) {
          res.data.bizId === a.code ? this.form.bizId = a.name : ''
        }
        this.$router.push({ name: '查看Bug', query: { id: this.form.id }})
      })
    },

    handleChange(file, fileList) {
      this.fileDbList = []
      this.fileList = fileList.slice(-3)
      for (var a of this.fileList) {
        this.fileDbList.push({ name: a.name, url: 'http' + a.response.url })
      }
      var arr = []
      for (var el of this.fileDbList) {
        arr.push({ 'name': el.name, 'url': el.response.url })
      }
    },

    successFun() {
      this.$notify({ title: 'Success', message: 'Created Successfully', type: 'success', duration: 2000 })
    },
    errorFun() {
      this.$notify({ title: 'Failed', message: 'Created Failed', type: 'error', duration: 2000 })
    }
  }
}
</script>

<style lang="stylus" scoped>
  .set-background
    background-color #F2F3F6
    display flex
    justify-content center
    min-width 900px
    .block
      background-color rgba(255,255,255,1)
      box-shadow 0px 0px 11px 0px rgba(238,240,245,1)
      border-radius 7px
      width 96%
      margin 20px 0
      padding 20px
      min-height calc(100vh - 100px)
    .block >>> .el-form
      display flex
      justify-content space-between
      margin 10px 0px 15px 0px
    .block >>> .el-form-item__content
      margin-left 0 !important
    .block >>> th
      background-color #F0F2F4 !important
    .block >>> .el-range-separator
      padding 0
    .set-between
      display flex
    .set-between >>> .el-button
      height 36px
    .set-between >>> .el-form-item
      display flex
      margin-right -35px
    .set-locate
      margin-top 25px
      .titleDescription
        font-size 12px
        color rgba(244,121,121,1)
        margin 30px 0px
        display inline-block
</style>
