<template>
  <a-card :bordered="false">
    <!-- 新建 -->
    <div class="add">
      <a-button type="primary" icon="plus" class="addBtn" @click="openModal()" id="editionSetting-openModal">新增</a-button>
    </div>
    <!-- table列表 -->
    <s-table
      ref="table"
      size="default"
      :rowKey="(row)=> row.id"
      :columns="columns"
      :data="loadData"
      bordered
    >
      <!-- 操作 -->
      <span slot="action" slot-scope="text, record">
        <template>
          <a-icon v-if="currentDate < new Date(record.publicDate).getTime()" type="edit" id="editionSetting-handleEdit" style="font-size: 20px;color: #1890FF;padding: 0 10px;" @click="handleEdit(record)" />
          <span v-if="currentDate > new Date(record.publicDate).getTime()">--</span>
        </template>
      </span>
      <template slot="upgradeContent" slot-scope="text, record">
        <span :title="record.upgradeContent" style="display: inline-block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">{{ record.upgradeContent }}</span>

      </template>
      <span slot="forceUpgrade" slot-scope="text">
        <template>
          <span v-if=" text == '1'">是</span>
          <span v-if=" text == '0'">否</span>
        </template>
      </span>
    </s-table>
  </a-card>
</template>

<script>
import { STable } from '@/components'
import { getEditionSettingList } from '@/api/editionSetting.js'
export default {
  name: 'EditionSetting',
  components: { STable },
  data () {
    return {
      columns: [
        {
          title: '序号',
          dataIndex: 'no',
          width: 60,
          align: 'center'
        },
        {
          title: '创建时间',
          width: 100,
          dataIndex: 'createDate',
          align: 'center'
        },
        {
          title: '版本号',
          width: 100,
          dataIndex: 'version',
          align: 'center'
        },
        {
          title: '强制升级',
          width: 100,
          dataIndex: 'forceUpgrade',
          align: 'center',
          scopedSlots: { customRender: 'forceUpgrade' }
        },
        {
          title: '升级内容',
          width: 100,
          dataIndex: 'upgradeContent',
          align: 'center',
          ellipsis: true, // 内容超过宽度 自动出现省略号
          scopedSlots: { customRender: 'upgradeContent' }

        },
        {
          title: '下载地址',
          width: 100,
          dataIndex: 'downloadUrl',
          align: 'center',
          customRender: (text) => {
            return text || '--'
          }
        },
        {
          title: '更新时间',
          width: 100,
          dataIndex: 'publicDate',
          align: 'center'
        },
        {
          title: '操作',
          // dataIndex: 'action',
          width: 100,
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      applyCode: 'atit',
      applyName: 'IT后台',
      currentDate: new Date().getTime(),	// 当前时间
      // 获取列表数据
      loadData: parameter => {
        return getEditionSettingList(Object.assign(parameter))
          .then(res => {
            const no = (res.data.pageNo - 1) * res.data.pageSize
            for (let i = 0; i < res.data.list.length; i++) {
              const _item = res.data.list[i]
              _item.no = no + i + 1
            }
            return res.data
          })
      },
      id: ''
    }
  },
  methods: {
	 // 新增
    openModal () {
      this.$router.push({ name: 'editionSetting_add' })
    },
    // 编辑
    handleEdit (row) {
      console.log(row)
      this.$router.push({ name: 'editionSetting_edit', query: { id: row.id } })
    }
  }
}
</script>

<style scoped>
  .addBtn{
    margin-bottom: 20px;
  }

</style>
