<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>

      <a-dropdown v-if="selectedRowKeys.length > 0">
<!--        <a-menu slot="overlay">-->
<!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
        <a-button @click="batchDel" type="danger" icon="delete">批量删除</a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="logoSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="50px" alt="" style="max-width:100px;font-size: 12px;font-style: italic;"/>
        </template>
        <span slot="status" slot-scope="text,record">
            <a-tag v-if="text == 1" color="green">启用</a-tag>
            <a-tag v-else color="red">禁用</a-tag>
        </span>
        <span slot="type" slot-scope="text,record">
             <a-tag v-if="record.type > 0" color="green">{{text}}</a-tag>
<!--            <a-tag v-if="text == 1" color="green">小程序首页</a-tag>-->
<!--            <a-tag v-else-if="text == 2" color="green">后台登录</a-tag>-->
<!--            <a-tag v-else-if="text == 3" color="green">商城首页</a-tag>-->
        </span>

        <span slot="action" slot-scope="text, record">
            <a-popconfirm
                    placement="top"
                    :title="record.status===1? '确定禁用？':'确定启用？'"
                    @confirm="() => handleStatus(record)">
            <a>{{record.status == 1 ? "禁用":"启用"}}</a>
          </a-popconfirm>
            <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                  <a @click="handleEdit(record)">修改</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <advert-modal ref="modalForm" @ok="modalFormOk"></advert-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import advertModal from './modules/advertModal'

  export default {
    name: 'BusAdvertList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      advertModal
    },
    data () {
      return {
        description: '广告管理管理页面',
        // 表头
        columns: [
          {
            title:'轮播图标题',
            align:"center",
            dataIndex: 'title'
          },
          {
            title:'图片',
            align:"center",
            dataIndex: 'logo',
            scopedSlots: { customRender: 'logoSlot' },
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'status',
            scopedSlots: { customRender: 'status' },
          },
          {
            title:'广告位置',
            align:"center",
            dataIndex: 'type_dictText',
            // dataIndex: 'type',
            scopedSlots: { customRender: 'type' },
          },
          {
            title:'链接',
            align:"center",
            dataIndex: 'src'
          },
          {
            title:'排序',
            align:"center",
            dataIndex: 'orderBy'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/business/busAdvert/list",
          delete: "/business/busAdvert/delete",
          deleteBatch: "/business/busAdvert/deleteBatch",
          exportXlsUrl: "/business/busAdvert/exportXls",
          importExcelUrl: "business/busAdvert/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'tenantId',text:'关联租户'})
        fieldList.push({type:'string',value:'hotelId',text:'关联酒店'})
        fieldList.push({type:'string',value:'title',text:'广告标题'})
        fieldList.push({type:'int',value:'type',text:'投放类型'})
        fieldList.push({type:'string',value:'logo',text:'广告图片'})
        fieldList.push({type:'string',value:'src',text:'链接'})
        fieldList.push({type:'int',value:'orderBy',text:'排序'})
        fieldList.push({type:'int',value:'status',text:'状态(0-禁用；1-启用)'})
        fieldList.push({type:'int',value:'delFlag',text:'删除状态(0-正常,1-已删除)'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
