<template>
  <div class="policy-selector">
    <div class="policy-selector-content">
      <div style="border: 1px solid #E5E5E5;padding: 1px" id="huodong">
        <div
          style="padding: 10px 13px;font-size: 14px;border-bottom: 1px solid #E5E5E5;display: flex;justify-content: space-between;">
          <div style="line-height:200%">选择策略</div>
          <div style="display: flex">
            <el-select v-model="zytype" placeholder="请选择" style="width: 40%;margin-right: 15px" @change="changzytype">
                <el-option label="商铺" :value="'1'"></el-option>
                <el-option label="广告" :value="'2'"></el-option>
                <el-option label="场地" :value="'3'"></el-option>
            </el-select>
            <el-input placeholder="请输入" suffix-icon="el-icon-search" style="margin-right:15px;width: 40%;"
              v-model="name">
            </el-input>
            <el-button @click="onSearch" style="background-color: #3F9B6A;color: #fff">查询
            </el-button>
            <el-button @click="resetting" class="buttonHover"
              style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;">重置
            </el-button>
          </div>
        </div>
        <div style="padding: 15px;">
          <div style="padding: 0px 20px 0px 0px;max-height:40vh;overflow-y: auto;">
            <el-table ref="multipleTable" :data="listData" tooltip-effect="dark"
              @selection-change="handleSelectionChange"
              :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}">
              <el-table-column label="选择" type="selection" width="55">
              </el-table-column>
              <el-table-column label="序号">
                <template slot-scope="scope">
                  {{scope.$index +1 }}
                </template>
              </el-table-column>
              <el-table-column label="编号" prop="id"></el-table-column>
              <el-table-column label="资源名称">
                <template slot-scope="scope">
                  {{scope.row.shopName ? scope.row.shopName :  scope.row.advertisingName?scope.row.advertisingName:scope.row.venueName}}
                </template>
              </el-table-column>
              <el-table-column label="资源类型">
                <template slot-scope="scope">
                  {{scope.row.shopName ? '商铺' : scope.row.advertisingType?scope.row.advertisingType:'场地'}}
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
    </div>
    <div style="display: flex;justify-content: space-between;margin: 20px 0;" class="bom">
      <div style="font-size: 14px;">共 <span style="color: #3F9B6A;">{{total}}</span> 项数据</div>
      <el-pagination :current-page="pageindex.pageNumber+1" :page-sizes="[5,10, 20, 50, 100]"
        :page-size="pageindex.pageSize" background small layout="prev, pager, next" :total="total"
        @size-change="handleSizeChange" @current-change="handleCurrentChange">
      </el-pagination>
    </div>
    <div class="policy-selector-footer" style="display: flex; justify-content: flex-end; align-items: center;">
      <el-button @click="confirm" style="background-color: #3F9B6A;color: #fff;">确定</el-button>
      <el-button @click="cancel" class="buttonHover"
        style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;">取消</el-button>
    </div>
  </div>
</template>

<script>
    import {
    cereResourceStrategylist
  } from '@/api/newly.js'
  import {
    ceGetAll
  } from '@/api/sam.js'
  import {
    getAlls,
    changAlls
  } from '@/api/information.js'
  import {
    getAlls as map1
  } from '@/api/map1.js'
  export default {
    data() {
      return {
        name:'',
        zytype:'1',
        total: 0,
        pageindex: {
          pageNumber: 0,
          pageSize: 5,
          // publishStatus:'0'
        },
        selectedRows: [],
        listData: [],
      };
    },
    async created() {

      await this.getAll()
    },
    props: {
      publishStatus: {
        type: String,
        default: function () {
          return '0'
        }
      },
      maxSelection: {
        type: Number,
        default: function () {
          return 20
        }
      },
    },
    methods: {
      changzytype() {
        this.onSearch()
      },
      async getAll() {
        let list = []
        if(this.zytype == '1') {
          list = await getAlls({shopName: this.name,...this.pageindex,publishStatus:this.publishStatus})
        } else if(this.zytype == '2') {
          list = await map1({advertisingName: this.name,...this.pageindex,publishStatus:this.publishStatus})
        } else if(this.zytype == '3') {
          list = await changAlls({venueName: this.name,...this.pageindex,publishStatus:this.publishStatus})
        }
        this.listData = list.data.content
        this.total = list.data.totalElements

      },
      async handleCurrentChange(val) {
        this.pageindex.pageNumber = val - 1
        await this.getAll()
      },
      handleSizeChange(val) {
        this.pageindex.pageSize = val
        this.getAll()
      },
      onSearch() {
        this.pageindex.pageNumber = 0
        this.getAll()
      },
      resetting() {
        this.pageindex = {
          pageNumber: 0,
          pageSize: 5,
        }
        this.name = ''
        this.getAll()
      },
      handleSelectionChange(selection) {
        if (selection.length > this.maxSelection) {
          this.$message.warning(`最多只能选择 ${this.maxSelection} 项`);
          this.$refs.multipleTable.clearSelection();
          selection.slice(0, this.maxSelection).forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row, true);
          });
        } else {
          this.selectedRows = selection;
        }
      },
      confirm() {

        this.$emit('minSev',this.selectedRows);
      },
      cancel() {
        this.$emit('mingClose');
      }
    }
  };
</script>

<style scoped>
  .policy-selector {
    padding: 20px;
    /* padding: 20px;
    width: 100%;
    margin: 0 auto;
    border: 1px solid #ddd; */
    /* border-radius: 4px; */
    /* box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); */
  }

  .policy-selector-header {
    text-align: left;
    margin-bottom: 20px;
  }

  .policy-selector-header h3 {
    margin: 0;
    font-size: 18px;
    color: #303133;
  }

  .policy-selector-content {
    margin-bottom: 20px;
  }

  .policy-selector-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
  ::v-deep .el-dialog__body {
    padding: 0 0 !important;
  }
</style>
