<template>
  <div class="app-container">
    <a-card :bordered="false">
      <SearchForm ref="searchForm" @reloadData="reloadData"/>
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :scroll="{ x: 3300 }"
        :columns="columns"
        :data="loadData"
        :alert="options.alert"
        :rowSelection="options.rowSelection"
        showPagination="true"
      >

        <span slot="summary" slot-scope="text">
          <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
        </span>

        <span slot="video" slot-scope="text">
          <video :src="text" style="width: 25%" controls></video>
        </span>

        <span slot="avatar" slot-scope="text">
          <template>
            <avatar-list size="large"><avatar-list-item :src="text"/></avatar-list>
          </template>
        </span>

        <span slot="videoAccountName" slot-scope="text, record">
          <ellipsis :length="10" :tips="record.finderUin" tooltip>{{ text }}</ellipsis>
        </span>

        <span slot="createTime" slot-scope="text">
          {{ text | dayjs }}
        </span>

      </s-table>

      <CreateAuthorForm
        :formType="formType"
        :visible="visible"
        ref="createAuthorForm"
        @resetData="resetData"
        @refreshTable="refreshTable"
      />
    </a-card>
  </div>
</template>

<script>
import { fetchFeedList, deleteAuthorVideo } from '@/api/author'
import { STable, Ellipsis } from '@/components'
import CreateAuthorForm from './modules/CreateForm'
import SearchForm from './modules/SearchForm'
import { filters, table } from './putFeed-constants'
import AvatarList from '@/components/AvatarList'
const AvatarListItem = AvatarList.AvatarItem

export default {
  name: 'PutFeedList',
  components: {
    STable,
    Ellipsis,
    CreateAuthorForm,
    SearchForm,
    AvatarList,
    AvatarListItem
  },
  filters: filters,
  data () {
    return {
      queryParam: {
        status: 1,
        size: 10000
      },
      loadData: parameter => {
        console.log('loadData.parameter', parameter)
        return fetchFeedList(Object.assign(parameter, this.queryParam)).then(res => {
          return res
        })
      },
      options: {
        alert: {
          show: true,
          clear: () => {
            this.selectedRowKeys = []
          }
        },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      },
      columns: table.columns,
      visible: false,
      formType: 'create'
    }
  },
  created () {
  },
  methods: {
    createHandler () {
      this.formType = 'create'
      this.visible = true
      this.$refs.createAuthorForm.resetForm()
    },
    handleEdit (record) {
      this.$refs.createAuthorForm.handleEdit(record)
      this.formType = 'edit'
      this.visible = true
    },
    resetData (flag) {
      this.visible = flag
      this.record = null
    },
    refreshTable () {
      this.$refs.table.refresh()
    },
    reloadData (queryParam) {
      this.queryParam = queryParam
      this.refreshTable()
    },
    handleDelete (row) {
      deleteAuthorVideo(row.id).then(res => {
        this.$notification.success({
          message: '删除成功'
        })
        this.$refs.table.refresh()
      })
    },
    cancel () {
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}

.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}

.ant-upload-select-picture-card i {
  font-size: 32px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}
</style>
