<template>
  <ai-list class="form-list" isTabs style="width: 100%">
    <template slot="content">
      <ai-search-bar>
        <template #left>
          <ai-select
            v-model="search.status"
            @change="search.current = 1, getList()"
            placeholder="发布状态"
            :selectList="dict.getDict('questionnaireStatus')">
          </ai-select>
          <el-button type="primary" @click="toEdit('')">添加大屏</el-button>
          <el-button type="primary" @click="toAddData">数据源管理</el-button>
        </template>
        <template #right>
          <el-input
            v-model="search.title"
            size="small"
            placeholder="请输入模板名称或创建人"
            clearable
            @keyup.enter.native="search.current = 1, getList()"
            @clear="search.current = 1, search.title = '', getList()"
            suffix-icon="iconfont iconSearch">
          </el-input>
        </template>
      </ai-search-bar>
      <ai-table
        :tableData="tableData"
        :col-configs="colConfigs"
        :total="total"
        v-loading="loading"
        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="toEdit(row.id)">编辑</el-button>
            </div>
          </template>
        </el-table-column>
      </ai-table>
    </template>
  </ai-list>
</template>

<script>
  export default {
    name: 'FormList',
    props: {
      instance: Function,
      dict: Object,
      areaId: String,
      urlPrefix: String
    },

    data () {
      return {
        search: {
          current: 1,
          status: '',
          size: 10,
          title: ''
        },
        colConfigs: [
          { prop: 'name', label: '模板名称' },
          { prop: 'createUserName', align: 'center', label: '创建人' },
          { prop: 'description', align: 'center', label: '描述' },
          { prop: 'status', align: 'center', label: '状态', formart: v => v === '1' ? '已开启' : '未开启' },
          { prop: 'createTime', align: 'center', label: '创建时间' }
        ],
        tableData: [],
        total: 0,
        loading: false
      }
    },

    created () {
      
      this.dict.load('questionnaireStatus').then(() => {
        this.getList()
      })
    },

    mounted () {
      this.loading = true
    },

    methods: {
      getList () {
        this.instance.post(`${this.urlPrefix}/appdiylargescreen/allLargeScreenProjectByPage`, null, {
          params: {
            ...this.search
          }
        }).then(res => {
          if (res.code == 0) {
            this.tableData = res.data.records
            this.total = res.data.total
            this.loading = false
          } else {
            this.loading = false
          }
        }).catch(() => {
          this.loading = false
        })
      },

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

      toAddData () {
        this.$emit('change', {
          type: 'SourceData'
        })
      },

      onConfirm () {
        this.$emit('change', {
          type: 'add',
          params: {
            id: '',
            templateType: 0,
            type: this.currIndex
          }
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  .form-list {
  }
</style>
