<template>
  <div class="content-container">
    <el-row class="tool-bar">
      <el-col :span="12" class="left">
        <div class="content-title">
          {{ title }}
        </div>
      </el-col>

      <el-col :span="12" class="right">
        <el-input v-model="conditions.keywords" style="width: 200px;" class="filter-item" prefix-icon="el-icon-search" size="mini" placeholder="请输入内容" @keyup.enter.native="getData" />
        <el-button class="filter-item" style="margin-left: 10px;" type="primary" size="mini" icon="el-icon-search" @click="getData">查询</el-button>

        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">添加</el-button>
      </el-col>
    </el-row>

    <el-row class="content-body">
      <el-table v-loading="listLoading" class="page-table" border :data="dataList" size="mini" height="calc(100vh - 218px)">
        <el-table-column type="index" label="序号" header-align="center" align="center" width="80" />

        <el-table-column prop="checklistTitle" label="评价清单" header-align="left" align="left" width="260">
          <template v-slot="{row}">
            <span><i class="el-icon-tickets" /> {{ row.checklistTitle }}</span>
          </template>
        </el-table-column>

        <el-table-column prop="checklistCatTitle" label="类别" header-align="center" align="center" width="200">
          <template v-slot="{row}">
            <span><el-tag effect="plain" color="rgb(38 69 90)">{{ row.checklistCatTitle }}</el-tag></span>
          </template>
        </el-table-column>

        <el-table-column prop="checklistDesc" label="说明" header-align="left" align="left">
          <template v-slot="{row}">
            <span>{{ row.checklistDesc }}</span>
          </template>
        </el-table-column>

        <el-table-column prop="issuedAt" label="变更人" header-align="center" align="center" width="200">
          <template v-slot="{row}">
            <i class="el-icon-user-solid" />
            <span> {{ row.issuedAccountName }}</span>
          </template>
        </el-table-column>

        <el-table-column prop="issuedAt" label="变更时间" header-align="center" align="center" width="200">
          <template v-slot="{row}">
            <i class="el-icon-time" />
            <span> {{ row.issuedAt | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" header-align="center" align="center" width="180">
          <template v-slot="{row}">
            <el-button size="mini" icon="el-icon-view" type="primary" @click="handleDetails(row)">详情</el-button>
            <el-button v-if="row.isFixed !== 1" size="mini" icon="el-icon-delete" type="danger" @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination-wrap">
        <pagination v-show="total>0" :total="total" :page.sync="conditions.page" :limit.sync="conditions.limit" @pagination="getData" />
      </div>
    </el-row>

    <checklist ref="AddChecklist" title="新增" @formSuccess="formSuccess" />
    <checklist-details ref="ChecklistDetails" title="详情" @formSuccess="getData" />
  </div>
</template>

<script>
import Checklist from './components/Checklist'
import ChecklistDetails from './components/Details'
import { deleteChecklistById, getChecklistByPage } from '@/api/system/checklistApi'
import { Pagination } from '@/components'

export default {
  name: 'ChecklistIndex',
  components: {
    Pagination,
    Checklist,
    ChecklistDetails
  },
  data() {
    return {
      title: '清单管理',
      listLoading: false,
      total: 0,
      dataList: [],
      conditions: {
        page: 1,
        limit: 10,
        checklistTypeId: 3, // 同story ID
        keywords: ''
      }
    }
  },

  mounted() {
    this.getData()
  },

  methods: {
    // 请求数据
    getData() {
      this.listLoading = true
      getChecklistByPage(this.conditions).then((resp) => {
        this.listLoading = false
        const { data, total } = resp
        this.dataList = data
        this.total = total
      }).catch((error) => {
        console.log(error)
      })
    },

    // 新增
    handleAdd() {
      this.$refs['AddChecklist'].showAddModel()
    },

    // 详情
    handleDetails(data) {
      const { checklistId } = data
      this.$refs['ChecklistDetails'].showModel(checklistId)
    },

    // Delete Handling
    handleDelete(data) {
      const { checklistId, checklistTitle } = data
      this.$confirm(`此操作将删除该数据${checklistTitle}, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteChecklistById(checklistId).then((resp) => {
          const { msg } = resp
          this.getData()
          this.$message.success(msg)
        }).catch((error) => {
          console.log(error)
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消删除' })
      })
    },

    // 更新
    formSuccess(data) {
      this.getData()
    }

  }
}
</script>
<style lang="scss">
</style>
<style lang="scss" scoped>

</style>

