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

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

      <div class="top-hang">
        <div class="d-s">
          <el-select v-model="queryParams.cardAmount"  clearable style="margin-right: 10px" placeholder="请选择面值">
            <el-option
              v-for="item in jglist"
              :key="item.cardAmount"
              :label="item.cardAmount"
              :value="item.cardAmount">
            </el-option>
          </el-select>
          <el-select v-model="queryParams.activateStatus" clearable style="margin-right: 10px" placeholder="请选择激活状态">
            <el-option
              v-for="item in option"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
          <el-select v-model="queryParams.sailStatus" clearable style="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" icon="el-icon-search" >下载模板</el-button>
          <el-button type="primary" @click="addCertificate" >新增优惠券</el-button>
<!--          <el-upload-->

<!--            class=""-->
<!--            v-loading="uploading"-->
<!--            action="/fuint-application/business/marketingActivity/cardGift/exchangeImport"-->
<!--            :headers="headers"-->
<!--            :limit="1"-->
<!--            :on-change="handleChange"-->
<!--            style="margin-left: 15px"-->
<!--            :file-list="fileList">-->
<!--            <el-button  type="primary" icon="el-icon-upload">点击上传</el-button>-->
<!--          </el-upload>-->
        </div>
      </div>
      <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="cardAmount"
          label="优惠券名称"
        >
        </el-table-column>
        <el-table-column
          prop="useTime"
          label="优惠券类型"
        >
        </el-table-column>
        <el-table-column
          prop="sailTime"
          label="投放类型"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="优惠内容"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="有效期"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="已领/投放数量"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="已核销"
        >
        </el-table-column>
        <el-table-column
          prop="sailStatus"
          label="状态"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.sailStatus  == 1">已售</span>
            <span v-if="scope.row.sailStatus  != 1">未售</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="createBy"
          label="创建人"
        >
        </el-table-column>
        <el-table-column
          prop="createBy"
          label="创建时间"
        >
        </el-table-column>
        <el-table-column
          prop="address"
          label="操作">
          <template slot-scope="scope">
            <div style="display: flex;">
              <el-button
                type="text"
                @click="grounding"
              >修改</el-button>
              <el-button
                type="text"
                @click=""
              >下架</el-button>
              <el-button
                type="text"
                @click="remindOpen()"
              >删除</el-button>
            </div>
          </template>
        </el-table-column>
        <!--          <el-table-column
                    prop="remark"
                    label="备注信息"
                    width="280">
                  </el-table-column>-->
      </el-table>
      <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="优惠券编号" prop="name" style="width: 30%;">
            <el-input v-model="ruleForm.name" placeholder="请输入优惠券编号" style="width: 300px"></el-input>
          </el-form-item>
          <el-form-item label="优惠券名称" prop="name" style="width: 30%;">
            <el-input v-model="ruleForm.name" placeholder="请输入优惠券名称" style="width: 300px"></el-input>
          </el-form-item>
          <el-form-item label="投放类型" prop="name" style="width: 30%;">
            <el-select v-model="ruleForm.region" placeholder="请选择投放类型" style="width: 300px">
              <el-option label="类型一" value="shanghai"></el-option>
              <el-option label="类型二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
        </div>
        <div class="d-s" style="justify-content: space-between">

          <el-form-item label="投放类型" prop="name" style="width: 30%;">
            <el-select v-model="ruleForm.region" placeholder="请选择投放类型" style="width: 300px">
              <el-option label="类型一" value="shanghai"></el-option>
              <el-option label="类型二" value="beijing"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="消费条件" prop="name" style="width: 30%;">
              <div class="d-s">
                <el-select v-model="ruleForm.region" placeholder="请选择金额" >
                  <el-option label="金额一" value="shanghai"></el-option>
                  <el-option label="金额二" value="beijing"></el-option>
                </el-select>
                  <div style="margin: 0px 5px;">满</div>
                <el-input placeholder="" v-model="ruleForm.input2" style="width: 140px">
                  <template slot="append">元</template>
                </el-input>
                <div style="width: 60px;text-align: center">优惠</div>
                <el-input placeholder="" v-model="ruleForm.input2"  style="width: 140px">
                  <template slot="append">元</template>
                </el-input>
              </div>
          </el-form-item>
<!--          -->
          <el-form-item label="适用油品油号" prop="name" style="width: 30%;">
            <div class="d-s">
              <div class="icon-type" v-for="(item,index) in oilTypelist" :key="index"
                   :class="{ 'acvtive' : index === tindex }" @click="Typeindex(index)">
                <img src="../../../assets/images/wx.png" style="width: 20px;height: 20px" v-if="index != tindex">
                <img src="../../../assets/images/xz.png" style="width: 20px;height: 20px" v-if="index == tindex">
                {{ item }}
              </div>
              <el-select v-model="ruleForm.value1" multiple placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </div>

          </el-form-item>

        </div>
        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="适用会员等级" prop="name" style="width: 30%;">
            <el-select v-model="ruleForm.value1" multiple placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="生效日期设置" prop="name" style="width: 30%;">
            <div class="d-s">
              <div class="icon-type" v-for="(item,index) in timelist" :key="index"
                   :class="{ 'acvtive' : index === tindex }" @click="Typeindex(index)">
                <img src="../../../assets/images/wx.png" style="width: 20px;height: 20px" v-if="index != tindex">
                <img src="../../../assets/images/xz.png" style="width: 20px;height: 20px" v-if="index == tindex">
                {{ item }}
              </div>
              <el-input v-model="ruleForm.input" placeholder="" style="width: 80px" ></el-input>
              <div>天内有效</div>
            </div>
          </el-form-item>
          <el-form-item label="生效日期" prop="name" style="width: 30%;">
            <el-date-picker
              v-model="ruleForm.value1"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期">
            </el-date-picker>
          </el-form-item>
        </div>
        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="是否与其他优惠同时使用" label-width="180px" prop="name" style="width: 30%;">
            <div class="d-s">
              <div class="icon-type" v-for="(item,index) in whetherlist" :key="index"
                   :class="{ 'acvtive' : index === tindex }" @click="Typeindex(index)">
                <img src="../../../assets/images/wx.png" style="width: 20px;height: 20px" v-if="index != tindex">
                <img src="../../../assets/images/xz.png" style="width: 20px;height: 20px" v-if="index == tindex">
                {{ item }}
              </div>
              <el-select v-model="ruleForm.value1" multiple placeholder="请选择优惠券类型">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </div>
          </el-form-item>
          <el-form-item label="使用次数限制" prop="name" style="width: 30%;">
            <div class="d-s">
              <div style="margin: 0px 5px;">每</div>
              <el-input placeholder="" v-model="ruleForm.input2" style="width: 140px">
                <template slot="append">天</template>
              </el-input>
              <div style="margin: 0px 5px;">限制使用</div>
              <el-input placeholder="" v-model="ruleForm.input2"  style="width: 140px">
                <template slot="append">次</template>
              </el-input>
            </div>
          </el-form-item>
          <el-form-item label="每人领券限制" prop="name" style="width: 30%;">
            <el-input v-model="ruleForm.input" placeholder="请输入内容"></el-input>

          </el-form-item>
        </div>

        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="是否允许收银台送券" label-width="160px" prop="name" style="width: 30%;">
            <div class="d-s">
              <div class="icon-type" v-for="(item,index) in whetherlist" :key="index"
                   :class="{ 'acvtive' : index === tindex }" @click="Typeindex(index)">
                <img src="../../../assets/images/wx.png" style="width: 20px;height: 20px" v-if="index != tindex">
                <img src="../../../assets/images/xz.png" style="width: 20px;height: 20px" v-if="index == tindex">
                {{ item }}
              </div>
            </div>
          </el-form-item>
          <el-form-item label="每日领券限制" prop="name" style="width: 30%;">
            <el-input v-model="ruleForm.input" placeholder="请输入内容"></el-input>
          </el-form-item>
          <el-form-item label="投放总数" prop="name" style="width: 30%;">
            <el-input v-model="ruleForm.input" placeholder="请输入内容"></el-input>
          </el-form-item>
        </div>
        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="使用条件"  style="width: 30%;">
            <el-input type="textarea" v-model="ruleForm.desc"></el-input>

          </el-form-item>
          <el-form-item label="适用时间段" prop="name" style="width: 30%;">
            <div class="d-s" style="margin-bottom: 10px">
              <img src="../../../assets/images/xz.png" style="width: 20px;height: 20px" >
              <div class="malou">每周</div>
              <el-select v-model="ruleForm.value1" multiple 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" style="margin-bottom: 10px">
              <img src="../../../assets/images/xz.png" style="width: 20px;height: 20px" >
              <div class="malou">每月</div>

              <el-select v-model="ruleForm.value1" multiple 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">
              <div class="malou">时间段</div>
              <el-date-picker
                v-model="ruleForm.value1"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </div>

          </el-form-item>
          <el-form-item label="不可适用时间段" prop="name" style="width: 30%;">
            <div class="d-s" style="margin-bottom: 10px">
              <img src="../../../assets/images/xz.png" style="width: 20px;height: 20px" >
              <div class="malou">每周</div>
              <el-select v-model="ruleForm.value1" multiple 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" style="margin-bottom: 10px">
              <img src="../../../assets/images/xz.png" style="width: 20px;height: 20px" >
              <div class="malou">每月</div>

              <el-select v-model="ruleForm.value1" multiple 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">
              <div class="malou">时间段</div>
              <el-date-picker
                v-model="ruleForm.value1"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </div>

          </el-form-item>

        </div>
        <div class="d-s" style="justify-content: space-between">
          <el-form-item label="背景图" prop="name" style="width: 30%;">
            <imgUpload   :limit="1" @input="ruleForm.getImgUrl"></imgUpload>
          </el-form-item>
          <el-form-item label="备注" prop="name" style="width: 30%;">
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="ruleForm.textarea">
            </el-input>
          </el-form-item>

        </div>


      </el-form>
      <span slot="footer" class="dialog-footer">
            <el-button @click="centerDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="addBlock()">创建</el-button>
          </span>
    </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";
export default {
  name: 'index',
  data() {
    return {
      oilTypelist:[
        "不限",
        "自定义"
      ],
      timelist:[
        "指定具体使用日期",
        "领取后",
      ],
      whetherlist:[
        "否",
        "是",
          ],

      tindex:0,
      jglist:[],
      onelist:[],
      twolist:[],
      threelist:[],
      orderShow:false,
      orderData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, ],
      headers: {
        'Access-Token': getToken(),
      },
      uploading: false,
      fileList: [],
      labelPosition:'left',
      queryParams: {
        number:'',
        remark:'',
        activateStatus:null,
        status:'',
        pageNo:1,
        pageSize:10
      },
      centerDialogVisible:false,
      input:'',
      total:0,
      pageNo:1,
      pageSize:10,
      option: [
        {
          value: '0',
          label: '已激活'
        }, {
          value: '1',
          label: '未激活'
        },],
      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 弄'
        }],
      ruleForm: {
        status:'1',
        quantity:'1',
        cardAmount:'1',
        remark:''

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


      }

    }
  },
  mounted() {
    this.getlist()
    this.gettj()
  },
  components:{
    imgUpload1,
    imgUpload,
  },
  methods:{
    Typeindex(index){
      this.tindex = index
    },
    addCertificate(){
      this.centerDialogVisible =! this.centerDialogVisible
    //   新增优惠券
    },
    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
      getList(this.queryParams).then(res=>{
        this.tableData = res.data.records
        this.total = res.data.total;
      })
    },
    remindOpen() {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          message: '删除成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    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.quantity == '' ||this.ruleForm.cardAmount == '' ||this.ruleForm.status == '' ){
        this.$message.error('必填项不能有空')
        return
      }
      let data = this.ruleForm
      addList(data).then(res=>{
        if(res.code == 200){
          this.$message.success('添加成功');
          this.gettj()
          this.getlist()
        }else {
          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 #409eff;
  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>
