<template>
  <ai-list class="notice">
    <template slot="title">
      <ai-title title="学习统计" isShowBottomBorder isShowArea v-model="search.areaId" :instance="instance"></ai-title>
    </template>
    <template slot="content">
      <ai-search-bar class="search-bar">
        <template #left>
        </template>
        <template #right>
          <el-input
            v-model="search.title"
            class="search-input"
            size="small"
            v-throttle="() => { search.current = 1, getList() }"
            placeholder="请输入标题"
            clearable
            @clear="search.current = 1, getList()"
            suffix-icon="iconfont iconSearch">
          </el-input>
        </template>
      </ai-search-bar>
      <ai-table
        :tableData="tableData"
        :col-configs="colConfigs"
        :total="total"
        style="margin-top: 6px;"
        :current.sync="search.current"
        :size.sync="search.size"
        @getList="getList">
        <el-table-column slot="options" width="120px" fixed="right" label="操作" align="center">
          <template slot-scope="{ row }">
            <div class="table-options">
              <el-button type="text" @click="toAdd(row.id)">编辑</el-button>
              <el-button type="text" @click="remove(row.id)">删除</el-button>
            </div>
          </template>
        </el-table-column>
      </ai-table>
    </template>
  </ai-list>
</template>

<script>
  import {mapState} from 'vuex'
  export default {
    name: 'AppLearningStatistics',
    label: '学习统计',

    props: {
      instance: Function,
      dict: Object
    },

    data () {
      return {
        search: {
          current: 1,
          size: 10,
          title: '',
          areaId: ''
        },
        total: 10,
        colConfigs: [
          { prop: 'title',  label: '题目', align: 'left' },
          { prop: 'createUserName',  label: '证书名称', align: 'center' },
          { prop: 'createUserName',  label: '类型', align: 'center' },
          { prop: 'createUserName',  label: '已颁发数量', align: 'center' },
          { prop: 'createUserName',  label: '累积学习时（分钟）', align: 'center' },
          { prop: 'createUserName',  label: '通过考试', align: 'center' }
        ],
        tableData: []
      }
    },

    computed: {
      ...mapState(['user'])
    },

    mounted() {
      this.search.areaId = this.user.info.areaId
      this.getList()
    },

    methods: {
      getList() {
        this.instance.post(`/app/appmarketingactivityinfo/list`, null, {
          params: {
            ...this.search
          }
        }).then(res => {
          if (res.code == 0) {
            this.tableData = res.data.records
            this.total = res.data.total
          }
        })
      },

      remove (id) {
        this.$confirm('确定删除该活动？').then(() => {
          this.instance.post(`/app/appmarketingactivityinfo/delete?id=${id}`).then(res => {
            if (res.code == 0) {
              this.$message.success('删除成功！')
              this.getList()
            }
          })
        })
      },

      toDetail (id) {
        this.$emit('change', {
          type: 'Detail',
          params: {
            id: id || ''
          }
        })
      },

      toAdd(id) {
        this.$emit('change', {
          type: 'Add',
          params: {
            id: id || ''
          }
        })
      }
    }
  }
</script>

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