<!--
 * @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-select
                  v-model="select.pickType"
                  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="select.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="select.modifiedTime"
                  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="['cardAdd']"
            size="small"
            class="addBtn"
            @click="openDig"
          >{{ '添加' }}</el-button>
          <el-button
            v-hasButtons="['cardExport']"
            size="small"
            class="thebtn2"
            @click="handleExport"
          > 导出</el-button>
        </div>
        <div class="maintable">
          <el-table
            v-loading="loading"
            :data="tableData"
            style="width: 100%"
            height="73vh"
            :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="140"
            />
            <el-table-column
              align="center"
              prop="memberName"
              :label="'会员姓名'"
            />
            <el-table-column
              align="center"
              prop=""
              :label="'产品名称(规格)'"
              min-width="130"
            >
              <template slot-scope="scope">
                <div v-for="item in scope.row.detailList">
                  {{ item.productName }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="memberName"
              :label="'产品数量'"
              width="100"
            >
              <template slot-scope="scope">
                <div v-for="item in scope.row.detailList">
                  {{ item.quantity }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              prop="pickTypeVal"
              :label="'提货来源'"
              width="100"
            />
            <el-table-column
              align="center"
              prop="actName"
              :label="'活动名称'"
            />
            <el-table-column
              align="center"
              prop="usableQuantity"
              :label="'可用兑换数量'"
              width="120"
            />
            <el-table-column
              align="center"
              prop="usedQuantity"
              :label="'已用兑换数量'"
              width="120"
            />
            <el-table-column
              align="center"
              prop="creationTime"
              :label="'创建日期'"
              width="160"
            />
            <el-table-column
              align="center"
              prop="modifiedTime"
              :label="'修改日期'"
              width="160"
            />
            <el-table-column
              align="center"
              prop="receiveTime"
              :label="'截止日期'"
              width="160"
            />
            <el-table-column
              align="center"
              prop="time"
              :label="'操作'"
              fixed="right"
              width="120"
            >
              <template slot-scope="scope">

                <div class="btnHeng">
                  <div

                    v-hasButtons="['cardUpdata']"
                    type="text"
                    style="color:#F3A900"
                    size="small"
                    @click="toFixed(scope.row.pkId,2)"
                  >
                    {{ '修改' }}
                  </div>
                  <div
                    v-hasButtons="['cardDel']"
                    type="text"
                    size="small"
                    style="color: #C8161D"
                    @click="toDel(scope.row.pkId)"
                  >
                    {{ '删除' }}
                  </div>
                </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 { tgtype } from '@/api/giftGoods.js'
import { getPickList } from '@/api/manage'
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: 'RechargeCardList',
      topList: [
        {
          name: '充值提货卡',
          path: 'RechargeCardList'
        }
      ],
      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() {
      api.tgtype().then((res) => {
        this.actStatus = res.data
      })
    },
    changeTime(val) {
      // this.select.startActStartDate = val[0]
      // this.select.startActEndDate = 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
        }
      })
    },
    toDel(id) {
      this.$router.push({
        name: 'addRechargeCard',
        query: {
          pkId: id,
          type: 3
          // 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
      getPickList(Object.assign({}, this.queryParams, 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/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">
.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: 0 20px;
    }
    .maintable {
      flex: 1;
    }
  }
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto;
}
.form_all {
  padding: 0 20px 0 20px;
  margin-bottom: 3px;
  background: #fff;
}
.btnHeng {
  display: flex;
  justify-content: space-around;
  font-size: 12px;
  cursor: pointer;
  font-weight: 600;
}
</style>
