<template>
  <div style="width: 100%;margin-left: 10px;">
    <div style="margin: 2% 0;">
      <el-form :model="queryCode">
        <!-- <el-select v-model="queryCode.taskId" clearable placeholder="任务" style="width:10%;margin:0 5px;">
          <el-option v-for="item in taskIdStr" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
        <el-select v-model="queryCode.status" clearable placeholder="bug状态" style="width:10%;margin-right:5px;">
          <el-option v-for="item in bugStatusStr" :key="item.code" :label="item.name" :value="item.code" />
        </el-select> -->
        <el-input v-model="queryCode.currentHandler" clearable filterable placeholder="处理人" style="width:12%;margin-right:5px;" />
        <el-input v-model="queryCode.creator" clearable filterable placeholder="创建人" style="width:12%;margin-right:5px;" />
        <el-date-picker v-model="queryCode.gmtCreateBegin" style="width:19%;margin-right:5px;" type="datetime" placeholder="创建时间" />
        <!-- <el-date-picker v-model="queryCode.gmtCreateEnd" style="width:12%;margin-right:5px;" type="datetime" placeholder="截止时间" /> -->
        <el-input v-model="queryCode.bugName" clearable filterable placeholder="主题" style="width:12%;margin-right:5px;" />
        <el-select v-model="queryCode.priority" clearable placeholder="故障级别" style="width:10%;margin-right:5px;">
          <el-option v-for="item in bugStatusPriority" :key="item.code" :label="item.name" :value="item.code" />
        </el-select>
        <el-button type="primary" @click="dataQuery(queryCode)">查询</el-button>
        <el-button type="primary" style="margin: 1% 5px;" @click="createdCode()">新建线上问题</el-button>
      </el-form>
    </div>

    <el-table :data="tableData" fit>
      <el-table-column label="ID" min-width="120" align="center">
        <template slot-scope="scope">{{ scope.row.id }}</template>
      </el-table-column>
      <el-table-column label="主题" min-width="230" align="center">
        <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 label="处理人" min-width="150" align="center">
        <template slot-scope="scope">{{ scope.row.currentHandlerList }}</template>
      </el-table-column>
      <el-table-column label="创建日期" min-width="250" align="center">
        <template slot-scope="scope">{{ scope.row.gmtCreate }}</template>
      </el-table-column>
      <el-table-column label="级别" width="150" align="center">
        <template slot-scope="scope"><span>{{ scope.row.priorityName }}</span></template>
      </el-table-column>
      <el-table-column label="状态" width="150" align="center">
        <template slot-scope="scope"><span>{{ scope.row.bugStatusName }}</span></template>
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="225" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="primary" @click="queryPresentation(scope.row)">更新</el-button>
          <el-button size="mini" type="primary" @click="delePresentation(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <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>
</template>

<script>
import { bugList, bugGet, bugDelete, taskListCreate, bugGetEnum } from '@/api/defectManage'

export default {
  name: 'DefectManagement',
  data() {
    return {
      bugTypeStr: [],
      bugStatusStr: [],
      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: [],
      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: 0,
      total: 0,
      show2: '',
      tableData: [],
      queryCode: {},
      statusShow: false,
      repairShow: false,
      formLabelWidth: '11%',
      formLabelWidth1: '22%',
      serviceTypeEnumList: [],
      clientTypeEnumList: [],
      bizIdEnumList: [],
      objData: '',
      userData: '',
      taskIdStr: '',
      fileList: [],
      fileDbList: []
    }
  },
  created() {
    this.getList()
    this.bugListSelect()
  },
  mounted() {
    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.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 = 0
      this.indexPage.bizId = this.bizJson
      this.indexPage.pageSize = this.pageSize
      this.indexPage.curIndex = this.curIndex
      bugList(this.indexPage).then(res => {
        this.tableData = res.data
        this.total = res.total
      })
    },
    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
      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: '已取消' })
        })
    },
    queryPresentation(ele) {
      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.$router.push({ name: '更新线上问题', params: { formData: this.form }, query: { id: this.form.id }})
      // this.dialogFormVisible = true
    },
    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.pageSize = size
      this.dataQueryInSearch(this.queryCode)
    },
    handleCurrentChange(curIndex) {
      this.curIndex = curIndex
      this.dataQueryInSearch(this.queryCode)
    },
    createdCode() {
      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: '新建线上问题' })
    },
    toReportView(e) {
      // 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: '查看线上问题', 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>

</style>
