<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="main">
      <div class="form_all">
        <el-form
          ref="select"
          :model="select"
          label-width="auto"
        >
          <el-row :gutter="40">
            <!-- 一层 -->
            <el-col :span="4">
              <el-form-item :label="'活动名称'">
                <el-input
                  v-model="select.actName"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'活动状态'">
                <el-select
                  v-model="select.activityStatus"
                  clearable
                  :placeholder="'请选择'"
                >
                  <el-option
                    v-for="item in actStatus"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'开始日期'">
                <el-date-picker
                  v-model="creationTime"
                  value-format="yyyy-MM-dd"
                  type="datetimerange"
                  format="yyyy-MM-dd"
                  :range-separator="'至'"
                  :start-placeholder="'开始日期'"
                  :end-placeholder="'结束日期'"
                  @change="changeTime"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'结束日期'">
                <el-date-picker
                  v-model="creationTime1"
                  value-format="yyyy-MM-dd"
                  format="yyyy-MM-dd"
                  type="datetimerange"
                  :range-separator="'至'"
                  :start-placeholder="'开始日期'"
                  :end-placeholder="'结束日期'"
                  @change="changeTime1"
                />
              </el-form-item>
            </el-col>
<!--            <el-col :span="8">-->
<!--              <el-form-item :label="'购买日期'">-->
<!--                <el-date-picker-->
<!--                  v-model="select.receiveTime"-->
<!--                  value-format="yyyy-MM-dd"-->
<!--                  format="yyyy-MM-dd"-->
<!--                  type="datetimerange"-->
<!--                  :range-separator="'至'"-->
<!--                  :start-placeholder="'开始日期'"-->
<!--                  :end-placeholder="'结束日期'"-->
<!--                  @change="changeTime2"-->
<!--                />-->
<!--              </el-form-item>-->
<!--            </el-col>-->
            <el-col :span="4">
              <el-button
                class="my_search"
                type="primary"
                @click="getDataList"
              > {{ '搜索' }}</el-button>
              <el-button
                class="my_reset"
                @click="reset"
              > {{ '重置' }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="main_a">
        <div class="mainbtn">
          <el-button
            v-hasButtons="['addPlant']"
            size="small"
            class="addBtn"
            @click="openDig"
          >{{'添加'}}</el-button>
          <el-button
            v-hasButtons="['plantExport']"
            size="small"
            class="thebtn2"
            @click="handleExport"
          > {{ '导出' }}</el-button>
        </div>
        <div class="maintable">
          <el-table
            :data="tableData"
            v-loading="loading"
            style="width: 100%"
            height="690px"
            :header-cell-style="{ background: '#EEEEEE' }"
            :row-class-name="tableRowClassName"
            @selection-change="handleSelectionChange"
          >
            <el-table-column
              type="selection"
              width="55"
            />
            <el-table-column
              align="center"
              prop="memberCode"
              :label="'活动图片'"
              width="150"
            >
              <template slot-scope="scope">
                <img :src="scope.row.actCover" style="width: 44px;height: 44px;border-radius: 8px" />
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="actName"
              :label="'活动名称'"
              width="150"
            />
            <el-table-column
              align="center"
              prop="actStartDate"
              :label="'开始日期'"
              width="300"
            />
            <el-table-column
              align="center"
              prop="actEndDate"
              :label="'结束日期'"
              width="300"
            />
            <el-table-column
              align="center"
              prop="status"
              :label="'活动状态'"
            >
<!--              <template slot-scope="scope">-->
<!--                  <div v-if="scope.row.status=='即将开始'" style="color: #1F1F1F">{{scope.row.status}}</div>-->
<!--                  <div v-if="scope.row.status=='进行中'" style="color: #009B58">{{scope.row.status}}</div>-->
<!--                  <div v-if="scope.row.status=='已结束'" style="color: #C8161D">{{scope.row.status}}</div>-->
<!--              </template>-->

            </el-table-column>
            <el-table-column
              align="center"
              prop="creationTime"
              :label="'创建日期'"
              width="auto"
            />
            <el-table-column
              align="center"
              prop="time"
              :label="'操作'"
              fixed="right"
            >
              <template slot-scope="scope">
                <div>
                  <el-button
                    v-has-buttons="['updatePlant']"
                    style="color: #FFAD41"
                    class="button"
                    type="text"
                    size="small"
                    @click.native.prevent="updateDig(scope.row,2)"
                  >
                    {{ '修改' }}
                  </el-button>
                  <el-button
                    v-has-buttons="['checkPlant']"
                    style="color: #E70DEC"
                    class="button"
                    type="text"
                    size="small"
                    @click.native.prevent="updateDig(scope.row,4)"
                  >
                    {{ '查看' }}
                  </el-button>
                  <el-button
                    v-has-buttons="['delPlant']"
                    class="button"
                    type="text"
                    size="small"
                    style="color: #C8161D"
                    @click.native.prevent="updateDig(scope.row,3)"
                  >
                    {{ '删除' }}
                  </el-button>
                </div>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as api from '@/api/giftGoods.js'
import {consumptionlist, tgtype, treeRulePickDel} from '@/api/giftGoods.js'
import { getPickList } from '@/api/manage'
import * as ons from '@/api/notice'
import { deleteVertex } from '@/api/systemconfiguration'
import {getActiveStatus} from "@/api/newgift";
export default {
  name: 'Bzpz',
  components: {
    topBar
  },
  filters: {
 isAgree(val) {
      if (!val) {
        return '允许';
      } else {
        return '禁止';
      }
    }
  },
  data() {
    return {
      creationTime: [],
      creationTime1: [],
      creationTime2: [],
      select: {
        actType:19
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      addOrEdit: '',
      total: 0,
      dialogVisible: false,
      tableData: [],
      loading:false,
      moren: 'plantCommonwealList',
      topList: [
        {
          name: '种植公益配置',
          path: 'plantCommonwealList'
        }
      ],
      form: {
        name: ''
      },
      rules: {
        name: [{ required: true, message: '请输入规格类型', trigger: 'blur' }]
      },
      actStatus: []
    }
  },
  mounted() {
    // 获取下拉
    this.getData()
    // 获取列表
    this.getDataList()
  },
  methods: {
    // 重置
    reset() {
      this.select = {
        pageNum: 1,
        pageSize: 50
      }
      this.getDataList()
    },
    getData() {
      getActiveStatus().then((res) => {
        this.actStatus = res.data
      })
    },
    changeTime(val) {
      if(val){
        this.select.startActStartDate = val[0]
        this.select.endActStartDate = val[1]
      }
    },
    changeTime1(val) {
      if(val){
        this.select.startActEndDate = val[0]
        this.select.endActEndDate = val[1]
      }
    },
    handleClose() {
      this.dialogVisible = false
      this.$refs['form'].clearValidate()
      this.$refs['form'].resetFields()
    },
    openDig() {
      this.$router.push({
        name: 'AddPlantCommonwealList',
        query: {
          controlType: 1,
        },
      })
    },
    updateDig(data, index) {
      this.$router.push({
        name: 'AddPlantCommonwealList',
        query: {
          pkId: data.pkId,
          controlType: index,
        }
      })
    },
    // 获取列表
    getDataList() {
      this.loading = true
      if (this.creationTime == '' || this.creationTime == null) {
        this.select.startActStartDate = ''
        this.select.endActStartDate = ''
      }
      if (this.creationTime1 == '' || this.creationTime1 == null) {
        this.select.startActEndDate = ''
        this.select.endActEndDate = ''
      }
      consumptionlist(this.select)
        .then((res) => {
          this.tableData = res.rows
          this.total = res.total
          this.loading = false
        })
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm( '是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          'activity/manage/tree-rule-pick/export',
          Object.assign({}, 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 ''
    }
  }
}
</script>
<style scoped lang="scss">
.button{
  padding: 5px 3px;
}
.thebtn2 {
  background: #ffad41;
  color: #ffffff;
  height: 32px;
}
::v-deep .el-range-editor{
  width: 100%!important;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    // background: #ffffff;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    .main_a {
      background: #fff;
      border-radius: 8px;
      justify-content: space-between;
      align-items: center;
      box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    }
    .mainbtn {
      padding: 0px 20px;
    }
    .maintable {
      flex: 1;
    }
  }
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto;
}
.form_all {
  padding: 3px 20px 0 20px;
  margin-bottom: 0px;
  background: #fff;
}
</style>
