<template>
  <div class="subPage">
    <div class="system-table-search">
      <div class="flex-h">
        <div class="flex-item flex-h">
          <el-button size="mini" type="success" @click="addCoupon('drink')">新增饮品优惠券</el-button>
          <el-button size="mini" type="success" @click="addCoupon('course')">新增课程优惠券</el-button>
        </div>
        <ul>
          <li>
            <!-- <span>选择案场：</span> -->
            <el-select v-model="CaseId" placeholder="请选择案场">
              <el-option
                v-for="item in cases"
                :key="item.CaseId"
                :label="item.CaseName"
                :value="item.CaseId">
              </el-option>
            </el-select>
          </li>
        </ul>
        <el-button
          size="mini"
          type="primary" @click="search">搜索</el-button>
      </div>
      <div class="moreFilter"></div>
    </div>
    <div class="system-table-box">
      <el-table
        :data="currentList"
        stripe
        style="width: 100%">
        <el-table-column
          prop="xxx"
          label="券名称">
        </el-table-column>
        <el-table-column
          prop="xxx"
          label="券类型">
        </el-table-column>
        <el-table-column
          prop="xxx"
          label="券价格">
        </el-table-column>
        <el-table-column
          prop="xxx"
          label="有效期">
        </el-table-column>
        <el-table-column
          prop="xxx"
          label="发放类型">
        </el-table-column>
        <el-table-column
          prop="xxx"
          label="总数量">
        </el-table-column>
        <el-table-column
          prop="xxx"
          label="已发">
        </el-table-column>
        <el-table-column
          prop="xxx"
          label="实际使用">
        </el-table-column>
        <el-table-column
          prop="xxx"
          label="状态">
        </el-table-column>
        <el-table-column label="操作" fixed='right' width="350">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="warning"
              @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="sendCoupon(scope.$index, scope.row)">赠送客户</el-button>
            <el-button
              size="mini"
              type="success"
              @click="handleDelete(scope.$index, scope.row)">点击复制链接</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page.sync="postData.page"
      :page-size="postData.pagesize"
      layout="prev, pager, next, jumper"
      :total="total">
    </el-pagination>
    <el-dialog
      title="选择赠送客户"
      :visible.sync="centerDialogVisible"
      width="800px"
      center>
      <div>
        <ul class="dialogSearchList flex-h" style="margin-bottom:10px;">
          <li class="flex-item">
            <el-input
              placeholder="请输入用户名"
              v-model="dialogPostData.username"
              clearable>
            </el-input>
          </li>
          <li class="flex-item">
            <el-input
              placeholder="请输入手机号"
              v-model="dialogPostData.phone"
              clearable>
            </el-input>
          </li>
          <li class="flex-item">
            <el-input
              placeholder="请输入推荐人"
              v-model="dialogPostData.referrer"
              clearable>
            </el-input>
          </li>
          <li>
            <el-button type="primary" @click="dialogSearch">搜索</el-button>
          </li>
        </ul>
        <ul class="dialogSearchList flex-h">
          <li class="flex-item">
            <el-date-picker
              v-model="dialogPostData.startdate"
              type="date"
              placeholder="选择起始日期">
            </el-date-picker>
            <el-date-picker
              v-model="dialogPostData.enddate"
              type="date"
              placeholder="选择截止日期">
            </el-date-picker>
          </li>
        </ul>
      </div>
      <div>
        <el-table
          ref="multipleTable"
          :data="customerList"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection">
          </el-table-column>
          <el-table-column
            prop="Name"
            label="姓名">
          </el-table-column>
          <el-table-column
            prop="NickName"
            label="微信昵称">
          </el-table-column>
          <el-table-column
            prop="Phone"
            label="手机号">
          </el-table-column>
          <el-table-column
            prop="CreatDate"
            label="创建时间">
          </el-table-column>
          <el-table-column
            prop="Referrer"
            label="推荐人">
          </el-table-column>
        </el-table>
      </div>
      <div>
        <el-pagination
          @current-change="handleCurrentChangeDialog"
          :current-page.sync="dialogPostData.page"
          :page-size="dialogPostData.pagesize"
          layout="prev, pager, next, jumper"
          :total="dialogTotal">
        </el-pagination>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: '',
  data () {
    return {
      dialogTotal: 0,
      dialogPostData: {
        caseid: '', // 案场id
        page: 1, // 当前页码
        pagesize: 10, // 请求数据量
      },
      customerList: [],
      centerDialogVisible: false,
      total: 0,
      postData: { // 表格搜索条件
        caseid: '', // 案场id
        page: 1, // 当前页码
        pagesize: 10, // 请求数据量
      },
      currentList: [{
        xxx: 'xxx'
      }]
    }
  },
  mounted () {
    this.$nextTick(function () {
      this.getList()
    })
  },
  computed: {
    ...mapState({
      cases: x => x.app.cases.list,
      defaultCaseId: x => x.app.cases.default
    }),
    CaseId: {
      get () {
        return this.postData.caseid || this.defaultCaseId
      },
      set (val) {
        this.postData.caseid = val
      }
    }
  },
  methods: {
    dialogSearch () { // 赠送客户搜索
      // 1
    },
    handleCurrentChangeDialog (val) {
      // 1
    },
    handleSelectionChange (val) {
      // 1
    },
    sendCoupon (index, row) { // 赠送优惠券
      this.centerDialogVisible = true
    },
    search () { // 搜索
      this.postData.page = 1
      this.currentList = []
      this.getList()
    },
    getList () { // 获取列表
      this.$ajax(this.$api.channelManager.getChannelList.url, {
        method: this.$api.channelManager.getChannelList.method,
        queryData: { ...this.postData, caseid: this.CaseId }
      }).then(res => {
        this.currentList = res.list
        this.postData.page = res.page
        this.total = res.pagenum
      })
    },
    handleCurrentChange (val) { // 跳转到分页
      this.getList()
    },
    handleEdit (index, row) { // 编辑
      this.$router.push({ name: 'editChannel', query: { id: row.ChannelId } })
    },
    handleDelete (index, row) { // 删除
      let name = '确认删除渠道“' + row.ChannelName + '”?'
      this.$confirm(name, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$ajax(this.$api.channelManager.deleteChannel.url, {
          method: this.$api.channelManager.deleteChannel.method,
          urlData: { channelId: row.ChannelId }
        }).then(res => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          this.search()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    addCoupon (val) {
      this.$router.push({ name: 'editCoupon', query: { type: val } })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
@import "page.scss";
.dialogSearchList {
  align-items: center;
  > li {
    font-size: 0;
    margin-left: 10px;
    &:first-child {
      margin-left: 0;
    }
    > *:nth-child(2) {
      margin-left: 10px;
    }
  }
}
</style>
