<template>
  <ai-list class="Template">
    <ai-title
      slot="title"
      title="模板管理"
      isShowBottomBorder>
    </ai-title>
    <template slot="content">
      <ai-search-bar>
        <template #left>
          <el-button type="primary" @click="toAdd">添加</el-button>
        </template>
        <template #right>
        </template>
      </ai-search-bar>
      <ai-table
        :tableData="tableData"
        :col-configs="colConfigs"
        :total="total"
        :current.sync="search.current"
        :size.sync="search.size"
        style="margin-top: 8px;"
        @getList="getList">
        <el-table-column slot="options" label="操作" align="center" fixed="right" width="140px">
          <template v-slot="{ row }">
            <div class="table-options">
              <el-button type="text" @click="collection(row.id, row.isFavorite)">{{ row.isFavorite === '0' ? '收藏' : '取消收藏' }}</el-button>
              <el-button type="text" @click="toDetail(row.url)">详情</el-button>
            </div>
          </template>
        </el-table-column>
      </ai-table>
    </template>
  </ai-list>
</template>

<script>
  export default {
    name: 'Template',

    data () {
      return {
        colConfigs: [
          { prop: 'name', label: '模板名称', align: 'left' },
          { prop: 'createTime', label: '绑定SKU数量', align: 'center' },
          { prop: 'createTime', label: '创建时间', align: 'center' },
        ],
        tableData: [],
        total: 0,
        search: {
          current: 1,
          size: 10,
          categoryId: ''
        },
        cateList: [],
        isFavorite: 0
      }
    },

    created () {
      this.getList()
    },

    methods: {
      toAdd () {
        this.$router.push('/addLabelsTemplate')
      },

      getList () {
        this.$http.post('/api/learning/pluginPage', null, {
          params: {
            ...this.search
          }
        }).then(res => {
          if (res.code === 0) {
            this.tableData = res.data.records
            this.total = res.data.total
          }
        })
      }
    }
  }
</script>

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