<template>
  <div class="app-containers">
    <!--      礼品卡-->

    <div class="card-box" style="margin-bottom: 20px">

      <div class="top-hang">
        <div class="d-s">
          <el-input v-model="queryParams.name" clearable style=" width: 250px; margin-right: 10px"
                    placeholder="请输入优惠券名称"></el-input>
          <el-select v-model="queryParams.type" clearable style=" width: 250px; margin-right: 10px"
                     placeholder="请选择优惠类型">
            <el-option v-for="dict in dict.type.CardCoupon_type" :key="dict.value" :label="dict.label"
                       :value="dict.value"/>
          </el-select>
          <el-select v-model="queryParams.status" clearable style=" width: 250px; margin-right: 10px"
                     placeholder="请选择状态">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div class="d-s">
          <el-button type="primary" icon="el-icon-search" @click="getlist">查询</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
          <el-button type="primary" @click="addCertificate">新增优惠券</el-button>
        </div>
      </div>
      <div style="height: 69vh;overflow: auto">
        <el-table border :data="tableData" style="width: 100%">
          <el-table-column label="序号" type="index"></el-table-column>
          <el-table-column prop="number" label="优惠券编号"></el-table-column>
          <el-table-column prop="name" label="优惠券名称"></el-table-column>
          <el-table-column prop="type" label="优惠券类型">
            <template slot-scope="scope">
              <span v-if="scope.row.type==1">代金券</span>
              <span v-if="scope.row.type==2">兑换券</span>
              <span v-if="scope.row.type==3">折扣券</span>
              <span v-if="scope.row.type==4">油品立减券</span>
              <span v-if="scope.row.type==5">单品代金券</span>
            </template>
          </el-table-column>
          <el-table-column prop="putType" label="投放类型">
            <template slot-scope="scope">
              <span v-if="scope.row.putType==1">营销投放</span>
              <span v-if="scope.row.putType==2">免费领取</span>
              <span v-if="scope.row.putType==3">积分兑换</span>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="优惠内容">
            <template slot-scope="scope">
              <span>{{ scope.row.remark }}</span>
            </template>

          </el-table-column>
          <el-table-column prop="createTime" label="有效期">
            <template slot-scope="scope">
              <span>{{ scope.row.effectiveDateStart }}~{{ scope.row.effectiveDateEnd }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="tfGetNum" label="已领/投放数量">
            <template slot-scope="scope">
              <span>{{ scope.row.tfGetNum || 0 }}/{{ scope.row.tfTotal || 0 }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="已核销"></el-table-column>
          <el-table-column prop="status" label="状态">
            <template slot-scope="scope">
              <span v-if="scope.row.status == 1" style="color: #0DC291">上架</span>
              <span v-if="scope.row.status != 1" style="color: #F44522">下架</span>
            </template>
          </el-table-column>
          <el-table-column prop="createBy" label="创建人"></el-table-column>
          <el-table-column prop="createTime" label="创建时间"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <div style="display: flex;">
                <el-button type="text" @click="updetenCardCoupon(scope.row.id)">修改</el-button>
                <el-button type="text" @click="sxCoupon(scope.row.id)">
                  <span v-if="scope.row.status == 0">上架</span>
                  <span v-if="scope.row.status == 1">下架</span>
                </el-button>
                <el-button type="text" @click="deletId(scope.row.id)">删除</el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination v-show="total > 0" :total="total" :page.sync="pageNo" :limit.sync="pageSize" @pagination="getlist"/>
    </div>
    <el-drawer title="订单记录" :visible.sync="orderShow" size="55%" :before-close="handleClose" center>
      <div class="box-der">
        <div class="d-b">
          <div class="d-s">
            <el-input v-model="input" style="width: 200px;margin-right: 10px" placeholder="请输入订单号"></el-input>
            <el-select v-model="value" placeholder="请选择" style="width: 200px;margin-right: 10px">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
            <el-date-picker v-model="value1" type="daterange" range-separator="至" start-placeholder="开始日期"
                            end-placeholder="结束日期">
            </el-date-picker>
          </div>
          <el-button type="primary" icon="el-icon-search">搜索</el-button>
        </div>
        <el-table :data="orderData" border style="width: 100%">
          <el-table-column label="序号" type="index"></el-table-column>
          <el-table-column prop="date" label="订单号"></el-table-column>
          <el-table-column prop="date" label="会员手机号"></el-table-column>
          <el-table-column prop="date" label="礼品卡面值（元）"></el-table-column>
          <el-table-column prop="date" label="数量"></el-table-column>
          <el-table-column prop="date" label="礼品卡金额"></el-table-column>
          <el-table-column prop="date" label="实收金额"></el-table-column>
          <el-table-column prop="date" label="订单状态"></el-table-column>
          <el-table-column prop="date" label="订单完成时间"></el-table-column>
        </el-table>
      </div>
    </el-drawer>

    <el-dialog title="新增/编辑优惠券" :visible.sync="centerDialogVisible" width="90%">
      <!--          表-->
      <el-form :model="ruleForm" :rules="rules" :label-position="labelPosition" ref="ruleForm" label-width="120px"
               class="demo-ruleForm">
        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="优惠券编号" required style="width: 45%;">
            <el-input v-model="ruleForm.number" :disabled="ruleForm.id" placeholder="请输入优惠券编号"></el-input>
          </el-form-item>
          <el-form-item label="优惠券名称" required style="width: 50%;">
            <el-input v-model="ruleForm.name" :disabled="ruleForm.id" placeholder="请输入优惠券名称"></el-input>
          </el-form-item>

        </div>
        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="投放类型" required style="width: 45%;">
            <el-select v-model="ruleForm.putType" placeholder="请选择投放类型" style="width: 100%">
              <el-option v-for="dict in dict.type.putType_type" :key="dict.value" :label="dict.label"
                         :value="dict.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="优惠券类型" required style="width: 50%;">
            <el-select v-model="ruleForm.type" placeholder="请选择优惠券类型" style="width: 100%" :disabled="ruleForm.id">
              <el-option v-for="dict in dict.type.CardCoupon_type" :key="dict.value" :label="dict.label"
                         :value="dict.value"/>
            </el-select>
          </el-form-item>
        </div>
        <div class="d-s" style="justify-content: space-between">


          <el-form-item label="消费条件" required style="width: 45%;"
                        v-if="ruleForm.type=='1' || ruleForm.type=='5'">
            <div class="d-s">
              <el-select v-model="ruleForm.useType" :disabled="ruleForm.id" placeholder="请选择金额">
                <el-option label="订单金额" value="1"/>
                <el-option label="实收金额" value="2"/>
                <el-option label="兑换券" value="3"/>
                <el-option label="折扣券" value="4"/>
                <el-option label="油品立减券" value="5"/>
                <el-option label="单品代金券" value="6"/>
              </el-select>
              <div style="margin: 0px 5px;">满</div>
              <el-input placeholder="" v-model="ruleForm.reachAmount" :disabled="ruleForm.id" style="width: 140px">
                <template slot="append">元</template>
              </el-input>
              <div style="width: 60px;text-align: center">优惠</div>
              <el-input placeholder="" v-model="ruleForm.reduceAmount" :disabled="ruleForm.id" style="width: 140px">
                <template slot="append">元</template>
              </el-input>
            </div>
          </el-form-item>

          <el-form-item label="兑换内容" required style="width: 45%;" v-if="ruleForm.type=='2'">
            <el-input placeholder="" v-model="ruleForm.exchangeContent" :disabled="ruleForm.id"></el-input>
          </el-form-item>

          <el-form-item label="优惠条件" required style="width: 45%;" v-if="ruleForm.type=='3'">
            <div class="d-s">
              <el-select v-model="ruleForm.useType" placeholder="请选择" style="width: 110px" :disabled="ruleForm.id">
                <el-option label="订单金额" value="1"/>
                <el-option label="实收金额" value="2"/>
                <el-option label="兑换券" value="3"/>
                <el-option label="折扣券" value="4"/>
                <el-option label="油品立减券" value="5"/>
                <el-option label="单品代金券" value="6"/>
              </el-select>
              <div style="width: 50px;text-align: center">范围</div>
              <el-input placeholder="" v-model="ruleForm.zkStartAmount" :disabled="ruleForm.id" style="width: 130px">
                <template slot="append">元</template>
              </el-input>
              <div style="margin: 0px 5px;">~</div>
              <el-input placeholder="" v-model="ruleForm.zkEndAmount" :disabled="ruleForm.id" style="width: 130px">
                <template slot="append">元</template>
              </el-input>
              <div style="width: 50px;text-align: center">优惠</div>
              <el-input placeholder="" v-model="ruleForm.zkData" :disabled="ruleForm.id" style="width: 130px">
                <template slot="append">折</template>
              </el-input>
            </div>
          </el-form-item>

          <el-form-item label="消费条件" required style="width: 45%;" v-if="ruleForm.type=='4'">
            <div class="d-s">
              <el-select v-model="ruleForm.useType" :disabled="ruleForm.id" placeholder="请选择金额">
                <el-option label="订单金额" value="1"/>
                <el-option label="实收金额" value="2"/>
                <el-option label="兑换券" value="3"/>
                <el-option label="折扣券" value="4"/>
                <el-option label="油品立减券" value="5"/>
                <el-option label="单品代金券" value="6"/>
              </el-select>
              <div style="margin: 0px 5px;">满</div>
              <el-input placeholder="" v-model="ruleForm.reachAmount" :disabled="ruleForm.id" style="width: 160px">
                <template slot="append">元</template>
              </el-input>
              <div style="width: 40px;text-align: center">每</div>
              <el-input placeholder="" v-model="ruleForm.ljOilNum" :disabled="ruleForm.id" style="width: 160px">
                <template slot="append">L</template>
              </el-input>
              <div style="width: 40px;text-align: center">减</div>
              <el-input placeholder="" v-model="ruleForm.ljOilAmount" :disabled="ruleForm.id" style="width: 160px">
                <template slot="append">元</template>
              </el-input>
            </div>
          </el-form-item>

          <!--  适用油品油号      oilNumber  -->
          <el-form-item label="适用油品油号" required style="width: 50%;">
            <div class="d-s">
              <el-radio-group v-model="ruleForm.oilLimit">
                <el-radio :label="'1'">不限</el-radio>
                <el-radio :label="'2'">自定义</el-radio>
              </el-radio-group>
              <el-select v-model="ruleForm.oilNumber" multiple placeholder="请选择" style="margin-left: 5px">
                <el-option v-for="(item,index) in oilNumberList" :key="index"
                           :label="getOilNamess(oilNameList,item.oilName)" :value="item.oilName"></el-option>
              </el-select>
            </div>
          </el-form-item>
        </div>

        <div class="d-s" style="justify-content: space-between" v-if="ruleForm.type=='3'">
          <el-form-item label="最大优惠金额" required style="width: 45%;">
            <el-input placeholder="" v-model="ruleForm.zkMaxAmount">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
        </div>

        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="适用会员等级" required style="width: 45%;">
            <el-select v-model="ruleForm.membershipLevel" multiple placeholder="请选择" style="width: 100%">

              <el-option
                v-for="(item,index) in membership"
                :label="item.name"
                :value="item.id.toString()"
                :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否允许收银台送券" label-width="160px" required style="width: 50%;">

            <el-radio-group v-model="ruleForm.sySend">
              <el-radio :label="'0'">否</el-radio>
              <el-radio :label="'1'">是</el-radio>

            </el-radio-group>

          </el-form-item>
        </div>
        <div class="d-s" style="justify-content: space-between">

          <!-- 生效日期设置 timeType 字段 -->
          <el-form-item label="生效日期设置" required style="width: 45%;">
            <div class="d-s">
              <el-radio-group v-model="ruleForm.timeType">
                <el-radio :label="'1'">领取
                  <el-input v-model="ruleForm.validityDay" placeholder=""
                            style="width: 80px;margin: 0px 10px"></el-input>
                  <span>天内有效</span></el-radio>
                <el-radio :label="'2'">指定使用日期</el-radio>

              </el-radio-group>

            </div>
          </el-form-item>
          <!-- 生效日期  effectiveDateStart 字段 -->
          <el-form-item label="生效日期" required style="width: 50%;" v-if="ruleForm.timeType=='2'">
            <el-date-picker
              v-model="ruleForm.effectiveDateStart"
              style="width: 160px"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="开始日期">
            </el-date-picker>
            <span style="margin: 0 5px">至</span>
            <el-date-picker
              v-model="ruleForm.effectiveDateEnd"
              style="width: 160px"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
        </div>
        <!-- 是否与其他优惠同时使用 useWithOther -->
        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="是否与其他优惠同时使用" label-width="180px" required style="width: 45%;">

            <el-radio-group v-model="ruleForm.useWithOther">
              <el-radio :label="'0'">不可以</el-radio>
              <el-radio :label="'1'">可以</el-radio>

            </el-radio-group>

          </el-form-item>
          <el-form-item label="使用次数限制" required style="width: 50%;">
            <div class="d-s">
              <div style="margin: 0px 5px;">每</div>
              <el-input placeholder="" v-model="ruleForm.limitTotalDay" style="width: 140px">
                <template slot="append">天</template>
              </el-input>
              <div style="margin: 0px 5px;">限制使用</div>
              <el-input placeholder="" v-model="ruleForm.limitTotalNum" style="width: 140px">
                <template slot="append">次</template>
              </el-input>
            </div>
          </el-form-item>
          <!-- 每人领卷限制 getNumLimit -->

        </div>
        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="适用时间段" style="width: 45%;">
            <el-radio-group v-model="ruleForm.availableType">
              <el-radio :label="'1'" style="margin-bottom: 15px">每周
                <el-select v-model="ruleForm.availableWeek" multiple placeholder="请选择周日期">
                  <el-option v-for="item in weekList" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-radio>
              <el-radio :label="'2'" style="margin-bottom: 15px">每月
                <el-select v-model="ruleForm.availableDay" multiple placeholder="请选择每月固定日期">
                  <el-option v-for="item in monthList" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-select>
              </el-radio>

            </el-radio-group>

            <div class="d-s">
              <div class="malou">时间段</div>
              <el-time-select
                style="margin-right: 10px"
                placeholder="起始时间"
                v-model="ruleForm.availablePeriodStart"
                :picker-options="{
                  start: '00:00',
                  step: '00:15',
                  end: '24:00'
                  }">
              </el-time-select>
              <el-time-select
                placeholder="结束时间"
                v-model="ruleForm.availablePeriodEnd"
                :picker-options="{
                     start: '00:00',
                  step: '00:15',
                  end: '24:00',
                minTime: ruleForm.availablePeriodStart
              }">
              </el-time-select>
            </div>

          </el-form-item>
          <el-form-item label="不适用时间段" style="width: 50%;">
            <el-radio-group v-model="ruleForm.unAvailableType">
              <div>
                <el-radio label="1" style="margin-bottom: 15px">每周
                  <el-select v-model="ruleForm.unAvailableWeek" multiple placeholder="请选择周日期">
                    <el-option v-for="item in weekList" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-radio>
              </div>
              <div>
                <el-radio label="2" style="margin-bottom: 15px">每月
                  <el-select v-model="ruleForm.unAvailableDay" multiple placeholder="请选择每月固定日期">
                    <el-option v-for="item in monthList" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-radio>
              </div>
            </el-radio-group>

            <div class="d-s">
              <div class="malou">时间段</div>
              <el-time-select
                style="margin-right: 10px"
                placeholder="起始时间"
                v-model="ruleForm.unAvailablePeriodStart"
                :picker-options="{
                  start: '00:00',
                  step: '00:15',
                  end: '24:00'
                  }">
              </el-time-select>
              <el-time-select
                placeholder="结束时间"
                v-model="ruleForm.unAvailablePeriodEnd"
                :picker-options="{
                     start: '00:00',
                  step: '00:15',
                  end: '24:00',
                minTime: ruleForm.availablePeriodStart
              }">
              </el-time-select>
            </div>

          </el-form-item>
        </div>
        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="每人领券限制" required style="width: 45%;">
            <el-input v-model="ruleForm.getNumLimit" placeholder="请输入内容"></el-input>
          </el-form-item>
          <el-form-item label="每日领券限制" required style="width: 50%;">
            <el-input v-model="ruleForm.dayGetLimit" placeholder="请输入内容"></el-input>
          </el-form-item>
        </div>

        <div class="d-s" style="justify-content: space-between">

          <!-- 每日领卷限制 dayGetLimit -->

          <el-form-item label="投放总数" required style="width: 45%;">
            <el-input v-model="ruleForm.tfTotal" placeholder="请输入内容"></el-input>
          </el-form-item>
          <el-form-item label="使用条件" style="width: 50%;">
            <el-input type="textarea" v-model="ruleForm.useCondition"></el-input>
          </el-form-item>
        </div>
        <!-- 使用条件  useCondition -->
        <div class="d-s" style="justify-content: space-between">
        </div>
        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="背景图" required style="width: 45%;">
            <imgUpload :limit="1" v-model="ruleForm.backgroundImage"></imgUpload>
          </el-form-item>
          <el-form-item label="备注"  style="width: 50%;">
            <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="ruleForm.remark">
            </el-input>
          </el-form-item>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addBlock(ruleForm)">保存</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  getList,
  getListtj,
  addList,
  eitList,
  deleteList,
  oilDepotConfiguration,
  getdownload,
  getselectGiftValue,
  getyi,
  getwei,
  getqb,
  getsk
} from "@/api/EventMarketing/giftBlock";
import imgUpload from "@/components/ImageUpload/index.vue"
import {getToken} from "@/utils/auth";
import imgUpload1 from "@/components/map/imgUpload.vue";
import {Row} from "element-ui";
import {
  addCardCoupon,
  listCardCoupon,
  getCardCoupon,
  getCoupon,
  CardCouponDelete,
  editCardCoupon
} from "@/api/EventMarketing/cardCoupon";
import {getOilNameList, oilNumberList} from "@/api/order/oilnumgun";
import {listUserGrade} from "@/api/staff/user/usergrade";

export default {
  name: 'index',
  dicts: ['CardCoupon_type', 'putType_type', 'oilNumber_type'],
  data() {
    return {
      oilTypelist: [
        "不限",
        "自定义"
      ],
      oilTypelistL: [
        "每周",
        "每月"
      ],
      timelist: [
        "指定具体使用日期",
        "领取后",
      ],
      whetherlist: [
        "否",
        "是",
      ],

      tindex: 0,
      timeType: 0,
      //是否可与其他优惠一起使用1可以0不可以
      useWithOther: 0,
      validityDay: 30,
      jglist: [],
      onelist: [],
      twolist: [],
      threelist: [],
      orderShow: false,
      weekList: [
        {
          label: "周一",
          value: "1"
        },
        {
          label: "周二",
          value: "2"
        },
        {
          label: "周三",
          value: "3"
        },
        {
          label: "周四",
          value: "4"
        },
        {
          label: "周五",
          value: "5"
        }, {
          label: "周六",
          value: "6"
        }, {
          label: "周天",
          value: "7"
        }

      ],
      monthList: [
        {
          label: "每月1号",
          value: "01"
        },
        {
          label: "每月2号",
          value: "02"
        },
        {
          label: "每月3号",
          value: "03"
        },
        {
          label: "每月4号",
          value: "04"
        },
        {
          label: "每月5号",
          value: "05"
        }, {
          label: "每月6号",
          value: "06"
        }, {
          label: "每月7号",
          value: "07"
        }, {
          label: "每月8号",
          value: "08"
        }, {
          label: "每月9号",
          value: "09"
        }, {
          label: "每月10号",
          value: "10"
        }, {
          label: "每月11号",
          value: "11"
        }, {
          label: "每月12号",
          value: "12"
        }, {
          label: "每月13号",
          value: "13"
        }, {
          label: "每月14号",
          value: "14"
        }, {
          label: "每月15号",
          value: "15"
        }, {
          label: "每月16号",
          value: "16"
        }, {
          label: "每月17号",
          value: "17"
        }, {
          label: "每月18号",
          value: "18"
        }, {
          label: "每月19号",
          value: "19"
        }, {
          label: "每月20号",
          value: "20"
        }, {
          label: "每月21号",
          value: "21"
        }, {
          label: "每月22号",
          value: "22"
        }, {
          label: "每月23号",
          value: "23"
        }, {
          label: "每月24号",
          value: "24"
        }, {
          label: "每月25号",
          value: "25"
        }, {
          label: "每月26号",
          value: "26"
        }, {
          label: "每月27号",
          value: "27"
        }, {
          label: "每月28号",
          value: "28"
        }, {
          label: "每月29号",
          value: "29"
        }
        , {
          label: "每月30号",
          value: "30"
        }
        , {
          label: "每月31号",
          value: "31"
        }

      ],
      orderData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      },],
      headers: {
        'Access-Token': getToken(),
      },
      uploading: false,
      fileList: [],
      labelPosition: 'right',
      queryParams: {
        number: '',
        remark: '',
        activateStatus: null,
        status: '',
        pageNo: 1,
        pageSize: 10
      },
      centerDialogVisible: false,
      input: '',
      total: 0,
      pageNo: 1,
      effectiveDateStart: '',
      pageSize: 10,
      option: [
        {
          value: '0',
          label: '已激活'
        }, {
          value: '1',
          label: '未激活'
        },],
      value1: '',
      options: [
        {
          value: '1',
          label: '上架'
        }, {
          value: '0',
          label: '下架'
        },],
      value: '',
      tjdata: {},
      tableData: [
        {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1517 弄'
        }, {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1519 弄'
        }, {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }],
      oilNumberList: [],
      oilNameList: [],
      ruleForm: {
        oilLimit: '',
        sySend: '',
        timeType: '',
        useWithOther: '',
        availableType: '',
        unAvailableType: '',
        name: '',
        number: '',
        status: '',
        quantity: '',
        cardAmount: '',
        remark: '',
        putType: '',
        oilNumber: '',
        region: '',
        membershipLevel: '',
        //限制多少天内可使用几次的 天字段
        limitTotalDay: '',
        //限制多少天内可使用几次的 次字段
        ruleForm: '',
        tfTotal: 0,
        dayGetLimit: 0,
        getNumLimit: 0,
        useCondition: "",
        validityDay: 30

      },
      membership: [],
      rules: {
        name: [
          {required: true, message: '此为必填项', trigger: 'blur'},
        ],


      }

    }
  },

  created() {
    this.getOilList()
    this.getlist()
    this.gettj()

  },
  components: {
    imgUpload1,
    imgUpload,
  },
  methods: {
    sxCoupon(id) {
      getCoupon(id).then(res => {
        if (res.code == 200) {
          this.$message({
            message: '操作成功',
            type: 'success'
          });
          this.getlist()
        } else {
          this.$message({
            message: res.msg,
            type: 'error'
          });
        }
      })
    },
    listUserGrade() {
      listUserGrade({page: 1, pageSize: 1000}).then(res => {
        if (res.code == 200) {
          this.membership = res.data.records
        }
      })
    },
    getOilList() {
      getOilNameList().then(response => {
        this.oilNameList = response.data;
      })
      oilNumberList().then(response => {
        this.oilNumberList = response.data.records;
      })
    },
    getOilNamess(list, id) {
      let name = ""
      if (list != null && list != "") {
        list.forEach(item => {
          if (item.id == id) {
            name = item.oilName;
          }
        })
      }
      return name;
    },
    handleClose(done) {
      // this.$confirm('确认关闭？')
      //   .then(_ => {
      done();
      // })
      // .catch(_ => {});
    },
    Typeindex(index) {
      this.tindex = index
    },
    TypeindexSet(index) {
      this.timeType = index
    },
    TypeindexOther(index) {
      this.useWithOther = index;
    },

    updetenCardCoupon(id) {
      this.listUserGrade()
      this.centerDialogVisible = !this.centerDialogVisible
      getCardCoupon(id).then(res => {
        this.ruleForm = res.data
        if (res.data.unAvailableWeek) {
          this.ruleForm.unAvailableWeek = res.data.unAvailableWeek.split(",")
        }
        if (res.data.unAvailableDay) {
          this.ruleForm.unAvailableDay = res.data.unAvailableDay.split(",")
        }
        if (res.data.availableWeek) {
          this.ruleForm.availableWeek = res.data.availableWeek.split(",")
        }
        if (res.data.availableDay) {
          this.ruleForm.availableDay = res.data.availableDay.split(",")
        }
        if (res.data.membershipLevel) {
          this.ruleForm.membershipLevel = res.data.membershipLevel.split(",")
        }
        if (res.data.oilNumber) {
          this.ruleForm.oilNumber = res.data.oilNumber.split(",")
        }

      })
    },
    addCertificate() {
      this.ruleForm = {
        oilLimit: '',
        sySend: '',
        timeType: '',
        useWithOther: '',
        availableType: '',
        unAvailableType: '',
        name: '',
        number: '',
        quantity: '',
        cardAmount: '',
        remark: '',
        putType: '',
        oilNumber: '',
        region: '',
        membershipLevel: '',
        limitTotalDay: '',
        ruleForm: '',
        tfTotal: 0,
        dayGetLimit: 0,
        getNumLimit: 0,
        useCondition: "",
        validityDay: 30

      }
      this.centerDialogVisible = !this.centerDialogVisible
      //   新增优惠券
      this.listUserGrade()
    },
    getwysk(row) {
      if (row.sailStatus == 1) {
        this.$message.error("此卡已经售出过了呦")
        return
      }
      if (row.activateStatus == 1) {
        this.$message.error("此卡还未激活呦")
        return
      }
      let data = {
        id: row.id,
        sailStatus: 1
      }
      getsk(data).then(res => {
        this.getlist()
        console.log(res)
        this.$message.success("售卡成功")
      })
    },

    // 下载
    handleChange(file, fileList) {
      this.uploading = true;
      console.log(file)
      if (file.status === 'success') {
        this.uploading = false;
        this.openUpload = false;
        this.openUser = false;

        this.fileList.splice(0, 1)
        this.result = file.response.data
        this.getlist()
      }
    },
    putStatus(id) {
      let data = {
        id: 1,
        exchangeStatus: id,
      }
      oilDepotConfiguration(data).then(res => {
        if (res.code == 200) {
          this.$message.success("操作成功")
          this.gettj()
        }
      })

    },
    // 重置按钮操作
    resetQuery() {
      this.queryParams = {
        number: '',
        remark: '',
        activateStatus: null,
        status: '',
        pageNo: 1,
        pageSize: 10
      }
      this.getlist();
    },
    getlist() {
      getselectGiftValue().then(res => {
        console.log(res)
        this.jglist = res.data
      })
      getqb().then(res => {

        this.onelist = res.data
        console.log(this.onelist)
      })
      getyi().then(res => {
        this.twolist = res.data
      })
      getwei().then(res => {
        this.threelist = res.data
      })
      this.queryParams.pageNo = this.pageNo
      this.queryParams.pageSize = this.pageSize
      listCardCoupon(this.queryParams).then(res => {
        this.tableData = res.data.records
        this.total = res.data.total;
      })
      // getList(this.queryParams).then(res => {
      //   this.tableData = res.data.records
      //   this.total = res.data.total;
      // })
    },
    // 删除
    deletId(id) {

      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        CardCouponDelete(id).then(res => {
          if (res.code == 200) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.getlist()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });


    },

    updateTableData(deletedRow) {
      // 更新表格数据，例如移除已删除的行
      this.tableData = this.tableData.filter(item => item.id !== deletedRow.id);
    },
    grounding() {
      this.$confirm('是否上架本条数据', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '上架成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消上架'
        });
      });
    },
    Offshelf() {
      this.$confirm('是否下架本条数据', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    posteid(data) {
      eitList(data).then(res => {
        if (res.code == 200) {
          this.$message.success('操作成功！');
        } else {
          this.$message.error('修改失败请稍后再试');
        }
      })
    },
    gettj() {
      getListtj().then(res => {
        this.tjdata = res.data
      })
    },
    daking() {
      this.centerDialogVisible = true
      this.ruleForm = {
        activateStatus: '0',
        quantity: '1',
        cardAmount: '1',
        remark: '',
      }
    },
    addBlock() {

      if (this.ruleForm.unAvailableWeek) {
        this.ruleForm.unAvailableWeek = this.ruleForm.unAvailableWeek.toString()
      }
      if (this.ruleForm.unAvailableDay) {
        this.ruleForm.unAvailableDay = this.ruleForm.unAvailableDay.toString()
      }
      if (this.ruleForm.availableWeek) {
        this.ruleForm.availableWeek = this.ruleForm.availableWeek.toString()
      }
      if (this.ruleForm.availableDay) {
        this.ruleForm.availableDay = this.ruleForm.availableDay.toString()
      }
      if (this.ruleForm.membershipLevel) {
        this.ruleForm.membershipLevel = this.ruleForm.membershipLevel.toString()
      }
      if (this.ruleForm.oilNumber) {
        this.ruleForm.oilNumber = this.ruleForm.oilNumber.toString()
      }


      if (!this.ruleForm.id) {

        addCardCoupon(this.ruleForm).then(res => {
          if (res.code == 200) {
            this.$message.success('添加成功');
            this.gettj()
            this.getlist()
          } else {
            this.$message.error('操作失败请稍后再试');
          }
        }).catch().catch(error => {
          this.$message.error('操作失败请稍后再试');
        });
      } else {
        editCardCoupon(this.ruleForm).then(res => {
          if (res.code == 200) {
            this.$message.success('修改成功');
            this.gettj()
            this.getlist()
          } else {
            this.$message.error('操作失败请稍后再试');
          }
        }).catch().catch(error => {
          this.$message.error('操作失败请稍后再试');
        });
      }


      this.centerDialogVisible = false
    }
  }
}
</script>

<style scoped lang="scss">
.tj {
  width: 100%;
  display: flex;
  justify-content: space-between;

}

.box-der {
  box-sizing: border-box;
  padding: 15px;
}

.kar {
  width: 100%;
  background: #FFFFFF;
  margin-bottom: 10px;

}

.d-b {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 10px;
}

.one-size {
  font-size: 20px;
  font-weight: bold;
  color: #000;
}

.two-size {
  font-size: 20px;
  font-weight: bold;
  color: #78b0fb;
}

.three-size {
  font-size: 20px;
  font-weight: bold;
  color: #f73f3f;
}

.ds {
  width: 100%;
  display: flex;
  align-items: center;
  background: #f4f4f4;
  border-radius: 6px;
  margin-bottom: 15px;
  box-sizing: border-box;
  padding: 15px 5px;
}

.tj-text {
  font-size: 18px;
  font-weight: bold;
}

.tj-num {
  margin: 5px auto;
  //font-size: 28px;
  color: #666;
  text-align: center;
}

.tj-siez {
  margin: 5px auto;
  color: #909399;
  font-size: 14px;
  text-align: center;
}

.top-hang {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 15px;
}

.d-s {
  display: flex;
  align-items: center;
}

.butoon {
  box-sizing: border-box;
  padding: 6px 10px;
  border: 1px solid #fe8c4a;
  border-radius: 6px;
  font-size: 16px;
  margin-left: 15px;
}

.sshi {
  width: 33%;
  background: #FFFFFF;
  box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
  box-sizing: border-box;
  padding: 15px;
  border-radius: 6px;
  //background: #f9f9f9;
}

.tjaocuo {
  width: 100%;
  margin-bottom: 15px;
  display: flex;
  justify-content: space-between;
}

.title_ {
  width: 100%;
  display: flex;
  align-items: center;
  font-size: 20px;
  font-weight: bold;
  justify-content: center;
  margin-bottom: 20px;
}

.card-box {
  width: 100%;
  background: #fff;
  box-sizing: border-box;
  padding: 15px;
  border-radius: 10px;
}

.icon-type {
  display: flex;
  align-items: center;
  font-weight: 400;
  font-size: 14px;
  color: #999999;
  margin-right: 20px;
  cursor: pointer;
}

.acvtive {
  color: #FF770F !important;
}

.malou {
  width: 60px;
}
</style>
