<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="thetopbox">
      <el-form ref="queryParams" :model="queryParams" label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item :label="'活动名称'" prop="actName" class="el-inputs">
              <el-input clearable v-model="queryParams.actName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item
              :label="'活动状态'"
              prop="activityStatus"
              class="el-inputs"
            >
              <el-select clearable v-model="queryParams.activityStatus">
                <el-option
                  v-for="item in stateList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'开始日期'" prop="enableState">
              <el-date-picker
                @change="changeTime"
                type="datetimerange"
                range-separator="——"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd HH:mm:ss"
                :unlink-panels="true"
                v-model="actTime1"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :label="'结束日期'" prop="enableState">
              <el-date-picker
                @change="changeTime2"
                type="datetimerange"
                range-separator="——"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd HH:mm:ss"
                :unlink-panels="true"
                v-model="actTime2"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item :label="'创建日期'" prop="enableState">
              <el-date-picker
                @change="changeTime3"
                type="datetimerange"
                range-separator="——"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                value-format="yyyy-MM-dd HH:mm:ss"
                :unlink-panels="true"
                v-model="actTime3"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4" style="margin-left: 30px">
            <div class="searchbox">
              <el-button class="my_search" @click="reSearch"> {{ '搜索' }}</el-button>
              <el-button class="my_reset" @click="reChongzhi"> {{ '重置' }}</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="mini" class="thebtn1"
          v-hasButtons="['newAdd']" @click="adddate()"
            >{{'添加'}}</el-button
          >
          <el-button size="mini"
          v-hasButtons="['newExport']"
          @click="handleExport"
                     class="exportBtn"> {{ '导出' }}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          style="width: 100%"
          height="680px"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>

          <el-table-column align="center" prop="actName" :label="'活动名称'">
          </el-table-column>
          <el-table-column align="center" prop="actStartDate" :label="'开始日期'">
          </el-table-column>

          <el-table-column align="center" prop="actEndDate" :label="'结束日期'">
          </el-table-column>
          <el-table-column
            align="center"
            prop="status"
            :label="'活动状态'"
          >
          </el-table-column>
          <el-table-column align="center" prop="creationTime" :label="'创建日期'">
          </el-table-column>
          <el-table-column
            align="center"
            prop="time"
            :label="'操作'"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                class="button-s"
                style="color: #e70dec"
                @click.native.prevent="toFixed(scope.row.pkId, 4)"
                type="text"
                v-hasButtons="['newSee']"
                size="small"
              >
                {{ '查看' }}
              </el-button>
              <el-button
                class="button-s"
                style="color: #48b2fd"
                @click.native.prevent="toFixed(scope.row.pkId, 2)"
                type="text"
                v-hasButtons="['newUpdata']"
                size="small"
              >
                {{'修改'}}
              </el-button>

              <el-button
                class="button-s"
                @click.native.prevent="toFixed(scope.row.pkId, 3)"
                type="text"
                size="small"
                v-hasButtons="['newDel']"
                style="color: #c73030"
              >
                {{ '删除' }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="reSearch"
    />
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import * as api from "@/api/newgift";
export default {
  name: "NewcomerGiftList",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "newcomerGiftList",
      topList: [
        {
          name: '新人礼包',
          path: "newcomerGiftList",
        },
      ],
      total: 0,
      tableData: [],
      loading:false,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        actType: 16,
      },
      multipleSelection: [],
      stateList: [],
      actTime1:"",
      actTime2:"",
      actTime3:""
    };
  },
  created() {
    this.reSearch();
    this.getOther();
  },
  methods: {
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
        actType: 16,
      };
      this.reSearch()
    },
    getOther() {
      api.getActiveStatus().then((res) => {
        this.stateList = res.data;
      });
    },
    reSearch() {
      this.loading = true
      api.getNewPeopleList(this.queryParams).then((res) => {
        this.tableData = res.rows;
        this.total = res.total;
        this.loading = false
      });
    },
    adddate() {
      this.$router.push({
        path: "newgiftInfo",
       query:{
        controlType:1
       }
      });
    },
    // 点击修改
    toFixed(id, index) {
      this.$router.push({
        path: "newgiftInfo",
        query: {
          pkId: id,
          controlType: index,
        },
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
     /** 导出按钮操作 */
     handleExport() {
      this.$confirm( '是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then((_) => {
        this.download(
          'activity/manage/people-service/export',
          Object.assign({},{actType:12}, this.queryParams, this.select),
          `${'新人礼包'}${new Date().getTime()}.xlsx`
        )
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
    changeTime(val) {
      this.queryParams.startActStartDate = val?val[0]:''
      this.queryParams.endActStartDate = val?val[1]:''
    },
    changeTime2(val) {
      this.queryParams.startActEndDate = val?val[0]:''
      this.queryParams.endActEndDate = val?val[1]:''
    },
    changeTime3(val) {
      this.queryParams.startCreationTime = val?val[0]:''
      this.queryParams.endCreationTime = val?val[1]:''
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
.page {
  padding: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 20px 20px 20px;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      .searchtitle {
        margin-right: 10px;
      }
      .searchbtn {
        background: #c8161d;
        color: #ffffff;
      }
    }
  }
  .main {
    background: #f9f9f9;
    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          background: #4391fd;
          color: #ffffff;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
        }
      }
    }
  }
}
</style>
