<template>
<div>
  <div class="container normal-panel normal-margin">
    <slot name="add"></slot>
  </div>
  <div class="container normal-panel">
    <el-form size="small" inline label-position="right" :model="params.content.where">
      <el-form-item label="搜索">
        <el-input v-model="params.content.where.condition" prefix-icon="el-icon-search" placeholder="活动名称" @keyup.native.enter="listData(params.content.pageNumber = 1)" @clear="listData(params.content.pageNumber = 1)" clearable></el-input>
      </el-form-item>&emsp;
      <el-form-item label="活动类型">
        <el-select v-model="params.content.where.type" placeholder="请选择" clearable @change="listData(params.content.pageNumber = 1)">
          <el-option
            v-for="item in campaigntypeList"
            :key="item.index"
            :label="item.value"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>&emsp;
      <el-form-item label="状态">
        <el-select v-model="params.content.where.status" placeholder="请选择" clearable @change="listData(params.content.pageNumber = 1)">
          <el-option
            v-for="item in sys_options"
            :key="item.index"
            :label="item.value"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <tableLayout :layout="tablecols" :data="list" :custom="true" height="calc(100vh - 254px)">
      <template v-slot:customcol="scope">
        <div v-if="scope.column.columnname === 'status'">
          <span :style="scope.column.data.status === '发布'?'color:#52C419':scope.column.data.status === '结束'?'color:#999999':''">{{scope.column.data.status}}</span>
        </div>
        <p v-else>{{scope.column.data[scope.column.columnname]}}</p>
      </template>
      <template v-slot:opreation="scope">
        <slot name="detail" :data="scope.data"></slot>
        <slot name="edit" :data="scope.data"></slot>
        <slot name="relase" :data="scope.data"></slot>
        <slot name="finish" :data="scope.data"></slot>
      </template>
    </tableLayout>
    <div style="margin-top:16px;text-align:right">
      <el-pagination
        background
        small
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="params.content.pageSize"
        layout="total, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</div>
</template>

<script>
import {mapGetters} from 'vuex'

export default {
  props:['campaigntypeList'],
  data () {
    return {
      params:{
        "classname":"webmanage.saletool.orderclue.ordercluecampaign",
        "method": "queryCampaignList",
        "content": {
          "isAll":false,
          "pageNumber": 1,
          "pageSize": 20,
          "where": {
              "condition": "",
              "status": ""
          }
        }
      },
      tablecols:[],
      sys_options2:[],
      list:[],
      total:0,
      currentPage:0
    }
  },
  computed:{
    ...mapGetters({
      sys_options:'sys_options'
    })
  },
  methods:{
    async listData() {
      const res = await this.$api.requested(this.params)
      this.list = res.data
      this.total = res.total
      this.currentPage = res.pageNumber
      this.$store.dispatch('optiontypeselect','activitystatus')
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.params.content.pageSize = val
      this.listData()
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.params.content.pageNumber = val
      this.listData()
    },
    async queryOption () {
      let obj = {
          "classname": "sysmanage.develop.optiontype.optiontype",
          "method": "optiontypeselect",
          "content": {
              "pageNumber": 1,
              "pageSize": 1000,
              "typename": 'campaigntype',
              "parameter": {
              }
          }
        }
        const res = await this.$api.requested(obj)
        this.sys_options2 = res.data
    },
  },
  mounted () {
    this.listData()
    this.queryOption()
  },
  created () {
    this.tablecols = this.tool.tabelCol(this.$route.name)['activitylist'].tablecols
  }
}

</script>
<style>
</style>