<template>
   <div class="app-container calendar-list-container" v-loading.body="showLoadingBody">
    <div>
      <div class="filter-container" ref="filter-container">
        <el-form ref="queryForm" :inline="inline" :model="listQuery" label-width="100px">
          <el-row>
            <el-col :span="8">
              <el-form-item label="标题">
                <el-input v-model.number="listQuery.title" placeholder="请输入姓名"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="状态" prop="type">
                <el-select class="filter-item" v-model="listQuery.state" placeholder="请输入状态">
                  <el-option v-for="(item,index) in typeOptions" :key="index" :label="item.name" :value="item.val"> </el-option>
                </el-select>
              </el-form-item>
            </el-col>
             <el-button class="filter-item" type="primary" v-waves icon="search" @click="handleFilter">搜索</el-button>
             <el-button class="filter-item" type="primary" @click="addCunpon" style="float: right;">+ 添加优惠券</el-button>
          </el-row>
        </el-form>
      </div>
      <el-table :key='tableKey' :data="list" border fit highlight-current-row
                style="width: 100%;">
        <el-table-column type="index" width="100" align="center" label="ID">
          <template scope="scope">
            <span>{{scope.row.id}}</span>
          </template>
        </el-table-column>

        <el-table-column width="200" align="center" label="优惠券标题">
          <template scope="scope">
            <span>{{scope.row.title}}</span>
          </template>
        </el-table-column>

        <el-table-column width="200" align="center" label="已领取">
          <template scope="scope">
            <span>{{scope.row.get}}</span>
          </template>
        </el-table-column>

        <el-table-column width="200" align="center" label="已使用">
          <template scope="scope">
            <span>{{scope.row.used}}</span>
          </template>
        </el-table-column>

        <el-table-column width="200" align="center" label="申请时间">
          <template scope="scope">
            <span>{{scope.row.time}}</span>
          </template>
        </el-table-column>
        <el-table-column width="200" align="center" label="操作">
          <template scope="scope">
            <el-button size="small" type="success" @click="handleUpdate(scope.row)">编辑</el-button>
            <el-popover
                ref="popover1"
                placement="top"
                width="160"
                v-model="scope.row.visible2">
                <p>确定删除吗？</p>
                <div style="text-align: right; margin: 0">
                <el-button size="mini" type="text" @click="scope.row.visible2 = false">取消</el-button>
                <el-button type="primary" size="mini" @click="deleteHandler(scope.row)">确定</el-button>
                </div>
            </el-popover>
          <el-button type="danger" size="small" v-popover:popover1>删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div v-show="!listLoading" class="pagination-container">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                       :current-page.sync="listQuery.page" :page-sizes="[10,20,30,40,50]" :page-size="listQuery.limit"
                       layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
      </div>
    </div>

    <!-- 优惠券编辑 -->
	<el-dialog title="优惠券编辑" :visible.sync="editDialogVisible">
		<el-form :model="formdata" :rules="rules" ref="form" label-width="90px">
            <div style="font-weight: bold;">基础设置</div>
            <hr style="background-color:#e5e5e5;height:1px;border:none;margin:10px 0">
			<el-row>
                <el-col :span="12">
                    <el-form-item label="优惠券标题" prop="name">
                        <el-input v-model="formdata.title" placeholder="请输入优惠券标题"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="适用人群">
                        
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="优惠金额" prop="name">
                        <el-input v-model="formdata.title" placeholder="请输入优惠金额"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="优惠方式">
                        <el-select class="filter-item" v-model="formdata.endDate" placeholder="请选择" style="width:100px">
                            <el-option v-for="(item,index) in cunponType " :key="item.id" :label="item.val"
                                    :value="item.id"></el-option>
                        </el-select>
                        <span>满</span>
                        <el-input v-model="formdata.title" placeholder="请输入金额" style="width:50px"></el-input>
                        <span>可用</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="有效期" prop="name">
                        <span>领取后</span>
                        <el-input v-model="formdata.title" placeholder="请输入金额" style="width:50px"></el-input>
                        <span>天有效</span>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="是否可转赠" prop="name">
                        
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="跳转链接">
                        <el-input v-model="formdata.title" placeholder="请输入跳转链接"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
            <el-form-item label="图标" :style="{display:'block'}">
              <el-upload
                class="upload-demo"
                :headers="getHeaderWithToken"
                action="https://xxtest.upyuns.com/api/universal/file/app/unauth/admin/upload"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                list-type="picture">
                <!--<img v-if="$utils.isString(add.icon) && !$utils.isEmpty(add.icon)" :src="add.icon"
                     style="width:300px;max-height:300px;">-->
                <!--<i v-else class="el-icon-plus avatar-uploader-icon"
                   style="lineHeight:100px;width:300px;height: 100px;border: 1px dashed #ccc;"></i>-->
                   <i class="el-icon-plus avatar-uploader-icon"
                   style="lineHeight:100px;width:300px;height: 100px;border: 1px dashed #ccc;"></i>
              </el-upload>
            </el-form-item>
          </el-row>
          <div style="font-weight: bold;">高级设置</div>
           <hr style="background-color:#e5e5e5;height:1px;border:none;margin:10px 0">
           <el-row>
                <el-col :span="12">
                    <el-form-item label="优惠券类别" prop="name">
                        <el-select class="filter-item" v-model="formdata.endDate" placeholder="请选择">
                            <el-option v-for="(item,index) in cunponType " :key="item.id" :label="item.val"
                                    :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="适用范围" prop="name">
                        <el-select class="filter-item" v-model="formdata.endDate" placeholder="请选择">
                            <el-option v-for="(item,index) in cunponType " :key="item.id" :label="item.val"
                                    :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="开始发放时间" prop="name">
                        <el-select class="filter-item" v-model="formdata.endDate" placeholder="请选择">
                            <el-option v-for="(item,index) in cunponType " :key="item.id" :label="item.val"
                                    :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="结束发放时间" prop="name">
                        <el-select class="filter-item" v-model="formdata.endDate" placeholder="请选择">
                            <el-option v-for="(item,index) in cunponType " :key="item.id" :label="item.val"
                                    :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label="最多发放数量" prop="name">
                        <el-select class="filter-item" v-model="formdata.endDate" placeholder="请选择">
                            <el-option v-for="(item,index) in cunponType " :key="item.id" :label="item.val"
                                    :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="每人限领次数" prop="name">
                        <el-input v-model="formdata.title" placeholder="请输入限领次数"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
		</el-form>
        <div slot="footer"  class="dialog-footer">
          <el-button  @click="">取消</el-button>
          <el-button type="primary" @click="">确定</el-button>
        </div>
	</el-dialog>
  </div>
</template>

<script>
  import {
    formatDate
  } from 'utils/dateFormattor';

  import {
    toEast8Date,
    deepCopyDate,
    newEast8Date,
    convertDate2Str,
    timestamp2Date
  } from 'utils/dateUtils';

  import {mapGetters} from 'vuex';
  import {
    getToken
  } from 'utils/auth';
  import {
    cunponManagementList
  } from 'api/cunponManagements';
  import Element1 from "../admin/menu/components/element";
  import ElRow from "element-ui/packages/row/src/row";
  import ElCol from "element-ui/packages/col/src/col";

  export default {
    name: 'discountRecord',
    components: {
      ElCol,
      ElRow,
      Element1,
    },
    data() {
      return {
        typeOptions: [
          {
            "name":'类型',
            "val":''
          },
          {
            "name":'未到账',
            "val":'0'
          },
          {
            "name":'已到账',
            "val":'1'
          },
        ],
        cunponType:[
            {
                id:'1',
                val:'满减'
            }
        ],
        BASE_API: process.env.BASE_API,
        showLoadingBody: false,
        // list: null,
        total: null,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          title: '',//手机号
          state:'',//状态
        },
        inline: true,
        tableKey: 0,
        editDialogVisible:false,
        formdata:{},
        rules:{
            name: [
                {
                    type: 'string',
                    required: true,
                    message: '请输入消息内容',
                    trigger: 'blur'
                },
                {
                    min: 0,
                    max: 50,
                    message: '长度小于50个字符',
                    trigger: 'blur'
                }
            ],
        },
        list:[
            {
                "id":'1',
                "title":"123",
                "get":'1',
                "used":'1',
                "time":'2018-01-01',
                "visible2":false
            }
        ]
      }
    },
    created() {
      this.getList();
    },
    computed: {
      ...mapGetters([
        'elements'
      ])
    },
    methods: {
      /**
       * 获取提现列表
       * */
      getList() {
        // this.listLoading = true;
        // cunponManagementList(this.listQuery).then(response => {
        //   let totalCountRs = undefined;
        //   let listRs = undefined;
        //   if (!this.$utils.isEmpty(response.data.data) && this.$utils.isInteger(response.data.totalCount)) {
        //     listRs = response.data.data;
        //     totalCountRs = response.data.totalCount;
        //     listRs.map(function(item){
        //       item.crtTimeStr = timestamp2Date(item.crtTime);
        //       item.finishTimeStr = timestamp2Date(item.finishTime);
        //     });
        //   }
        //   this.listLoading = false;
        //   this.list = listRs;
        //   this.total = totalCountRs;
        // })

      },
      handleFilter() {
        this.listQuery.page = 1;
        this.$refs.queryForm.validate(valid => {
          if (valid) {
            this.getList();
          } else {
            return false;
          }
        });
      },
      handleSizeChange(val) {
        this.listQuery.limit = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.page = val;
        this.getList();
      },
      handleUpdate(item){
          var that = this;
          that.editDialogVisible = true;
          console.log(item)
          that.formdata = item
      },
      addCunpon(){
            
      },
      deleteHandler(item){
          item.visible2 = false
          
      },
    }
  }
</script>
 
<style lang="" scope>
    
</style>