<!--
 * @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.memberCode"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'会员姓名'">
                <el-input
                  v-model="select.memberName"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'联系方式'">
                <el-input
                  v-model="select.phone"
                  clearable
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'会员等级'" prop="teamCode">
                <el-select v-model="select.pkGrade" clearable :placeholder="'请选择'">
                  <el-option
                    v-for="item,index in gradeRangList"
                    :key="index"
                    :label="item.gradeName"
                    :value="item.pkId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
                <el-form-item :label="'真实奖衔'" prop="pkAwards">
                <el-select clearable v-model="select.pkAwards">
                  <el-option
                    v-for="item in awardsChioseList"
                    :key="item.pkId"
                    :label="item.awardsName"
                    :value="item.pkId"
                  ></el-option>
                </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="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
           size="small"
           class="thebtn2"
           v-hasButtons="['PlantDetailListExport']"
           @click="handleExport"
         > {{ '导出' }}</el-button>
       </div>

        <div class="maintable">
          <el-table
            :summary-method="getSummaries"
            show-summary
            :data="tableData"
            v-loading="loading"
            style="width: 100%"
            height="78vh"
            :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="'会员编号'"
            />
            <el-table-column
              align="center"
              prop="memberName"
              :label="'会员姓名'"
            />
            <el-table-column
              align="center"
              prop="phone"
              :label="'联系方式'"
            />
            <el-table-column
              align="center"
              prop="orderCode"
              :label="'订单编号'"
            />
            <el-table-column
              align="center"
              prop="settleGradeStr"
              :label="'会员等级'"
            />
            <el-table-column
              align="center"
              prop="awardsStr"
              :label="'真实奖衔'"
            />
            <el-table-column
              align="center"
              prop="quantity"
              :label="'购买数量'"
            />
            <el-table-column
              align="center"
              prop="price"
              label="价格(¥)"
            />
            <el-table-column
              align="center"
              prop="orderAmount"
              :label="'金额'+'(￥)'"
            />
<!--            <el-table-column-->
<!--              align="center"-->
<!--              prop="creationTime"-->
<!--              :label="'创建日期'"-->
<!--              width="200"-->
<!--            />-->
<!--            <el-table-column-->
<!--              align="center"-->
<!--              prop="modifiedTime"-->
<!--              :label="'修改日期'"-->
<!--              width="200"-->
<!--            />-->
            <el-table-column
              align="center"
              prop="payTime"
              :label="'购买日期'"
              width="200"
            />

<!--            <el-table-column-->
<!--              align="center"-->
<!--              prop="time"-->
<!--              :label="'操作'"-->
<!--              fixed="right"-->
<!--            >-->
<!--              <template slot-scope="scope">-->
<!--                <el-button-->
<!--                  type="text"-->
<!--                  style="color: #F3A900;"-->
<!--                  v-hasButtons="['cardUpdata']"-->
<!--                  size="small"-->
<!--                  @click="toFixed(scope.row.pkId, 2)"-->
<!--                >-->
<!--                  修改-->
<!--                </el-button>-->
<!--              </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 {tgtype, treerulePickList} from "@/api/giftGoods.js";
import {getPickList} from "@/api/manage";
import {getAwardsListChiose, getgradeRanglist} from "@/api/level";
export default {
  name: 'Bzpz',
  components: {
    topBar
  },
  filters: {
 isAgree(val) {
      if (!val) {
        return '允许';
      } else {
        return '禁止';
      }
    }
  },
  data() {
    return {
      creationTime: [],
      creationTime1: [],
      creationTime2: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      addOrEdit: '',
      total: 0,
      dialogVisible: false,
      tableData: [],
      loading:false,
      moren: 'plantDetailList',
      topList: [
        {
          name: '种植公益明细',
          path: 'plantDetailList'
        }
      ],
      form: {
        name: ''
      },
      rules: {
        name: [{ required: true, message: '请输入规格类型', trigger: 'blur' }]
      },
      actStatus: [],
      gradeRangList: [],
      awardsChioseList: [],
    }
  },
  mounted() {
    // 获取下拉
    this.getData()
    // 获取列表
    this.getDataList()
  },
  methods: {
    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 4) {
          sums[index] = '合计'
          return
        }
        if (index === 0) {
          sums[index] = ''
          return
        }
        if (index === 1) {
          sums[index] = ''
          return
        }
        if (index === 2) {
          sums[index] = ''
          return
        }
        if (index === 3) {
          sums[index] = ''
          return
        }
        if (index === 6) {
          sums[index] = ''
          return
        }
        if (index === 8) {
          sums[index] = ''
          return
        }
        const values = data.map((item) => Number(item[column.property]))
        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          // sums[index] += ' 元'
        } else {
          sums[index] = ''
        }
      })

      return sums
    },
    // 重置
    reset() {
      this.creationTime = []
      this.select = {
        pageNum: 1,
        pageSize: 50
      }
      this.getDataList()
    },
    getData() {
      getgradeRanglist().then((res) => {
        this.gradeRangList = res.data
      })
      getAwardsListChiose().then((res) => {
        this.awardsChioseList = res.rows;
      });
    },
    changeTime(val) {
      if(val){
        this.select.startPayDate = val[0]
        this.select.endPayDate = val[1]
      }
    },
    changeTime1(val) {
      // this.select.endActStartDate = val[0]
      // this.select.endActEndDate = val[1]
    },
    changeTime2(val) {
      // this.select.startCreationTime = val[0]
      // this.select.endCreationTime = val[1]
    },
    // 点击修改
    toFixed(id, index) {
      // this.addOrEdit = false
      // this.dialogVisible = true
      this.$router.push({
        name: 'addRechargeCard',
        query: {
          pkId: id,
          type: 2
          // functionType:this.select.functionType
        }
      })
    },
    // 删除
    handleDelete(id) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api.activityRemove(id).then((res) => {
          this.getDataList()
        })
      })
    },
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = ''
          if (this.addOrEdit == true) {
            url = classifySave
          } else {
            url = classifyUpdate
          }
          url(this.form).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: 'success'
              })
              this.dialogVisible = false
              // 充值数据
              this.$refs[formName].resetFields()
              // 获取列表
              this.getDataList()
            }
          })
        } else {
          return false
        }
      })
    },
    handleClose() {
      this.dialogVisible = false
      this.$refs['form'].clearValidate()
      this.$refs['form'].resetFields()
    },
    openDig() {
      this.$router.push({
        name: 'addRechargeCard',
        query: {
          type: 1
        }
      })
    },

    // 获取列表
    getDataList() {
      this.loading = true
      if (this.creationTime == '' || this.creationTime == null) {
        this.select.startPayDate = ''
        this.select.endPayDate = ''
      }
      treerulePickList(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/member-info-list-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">
.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  //padding: 15px 0;
  height: 44px;
  background: #FFFFFF;
  box-shadow: 0px 2px 20px 0px rgba(204,204,204,0.5);
  border-radius: 0px 0px 8px 8px;
  opacity: 1;
  width: 100%;
  bottom: 0;
}
.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: 20px;
  background: #fff;
}
</style>
