<template>
  <section class="TaskList">
    <ai-list>
      <ai-title slot="title" title="任务列表" isShowBack isShowBottomBorder @onBackClick="cancel(true)"/>
      <template #content>
        <ai-search-bar bottomBorder>
          <template slot="right">
            <el-input v-model="search.keyword" size="small" placeholder="融资名称/创建人" clearable
                      v-throttle="() => {page.current = 1, getList()}"
                      @clear=";(page.current = 1), (search.keyword = ''), getList()" suffix-icon="iconfont iconSearch"/>
          </template>
        </ai-search-bar>
        <ai-table :tableData="tableData" :col-configs="colConfigs" :total="total" ref="aitableex"
                  :current.sync="page.current" :size.sync="page.size" @getList="getList"
                  @selection-change="(v) => (ids = v.map((e) => e.id))">
          <el-table-column slot="options" label="操作" align="center" width="280" fixed="right">
            <template slot-scope="{ row }">
              <el-button type="text" @click="close(row.id)">撤回任务</el-button>
            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-list>
  </section>
</template>

<script>
export default {
  name: 'TaskList',
  components: {},
  props: {
    dict: Object,
    instance: Function,
    params: Object,
  },
  data() {
    return {
      page: {
        current: 1,
        size: 10,
      },
      total: 0,
      search: {
        bind: '',
        keyword: '',
      },
      tableData: [],
      colConfigs: [
        {
          prop: 'deviceName',
          label: '任务名称',
        },
        {
          prop: 'areaName',
          label: '媒资类型',
          align: 'center',
        },
        {
          prop: 'serialNo',
          label: '级别',
          align: 'center',
        },
        {
          prop: 'devStatus',
          label: '播发方式',
          width: '100',
          align: 'center',
          render: (h, {row}) => {
            return h('span', null, this.dict.getLabel('dlbDevStatus', row.devStatus))
          },
        },
        {
          prop: 'bind',
          label: '开始时间',
          width: '120',
          align: 'center',
          render: (h, {row}) => {
            return h('span', null, this.dict.getLabel('yesOrNo', row.bind))
          },
        },
        {
          prop: 'serialNo',
          label: '状态',
          align: 'center',
        },
        {
          prop: 'serialNo',
          label: '创建人',
          align: 'center',
        },
        {
          slot: 'options',
          label: '操作',
          align: 'center',
        },
      ],
    }
  },
  create() {

  },

  methods: {
    getList() {},

    close(id) {
      this.$confirm('确定停播该设备?').then(() => {
        this.instance.post(`/app/appdlbquipment/stop?deviceId=${id}`).then((res) => {
          if (res.code == 0) {
            this.$message.success('停播成功！')
            this.getList()
          }
        })
      })
    },
    cancel(isRefresh) {
      this.$emit('change', {
        type: 'list',
        isRefresh: !!isRefresh,
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.TaskList {
  height: 100%;
}
</style>