<!--会员充值订单-->
<template>
  <div class="app-container">
<!--    条件查询-->
    <el-card class="box-card">
<!--      <div style="display: flex;">-->
<!--        <div class="top-app-sou">-->
<!--          <el-form :label-position="labelPosition" label-width="40px" :model="formLabelAlign">-->
<!--            <el-form-item label="名称">-->
<!--              <el-input v-model="formLabelAlign.name" placeholder="请输入要搜索的内容"></el-input>-->
<!--            </el-form-item>-->
<!--          </el-form>-->
<!--        </div>-->
<!--        <div style="margin-left: 10px">-->
<!--          <el-button type="primary" icon="el-icon-search">搜索</el-button>-->
<!--        </div>-->
<!--      </div>-->
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
        <el-form-item label="交易员工" prop="staffId">
          <el-select
            v-model="queryParams.mtStaffId"
            clearable
            placeholder="全部"
          >
            <el-option v-for="item in staffList" :key="item.id" :label="item.realName" :value="item.id">
              <span style="float: left">{{ item.realName }}</span>
              <span style="float: right; color: #8492a6; font-size: 13px">{{ item.mobile }}</span>
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付类型" prop="paymentType">
          <el-select
            v-model="queryParams.paymentType"
            clearable
            placeholder="全部"
          >
            <el-option v-for="item in payList"
                       :key="item.id"
                       :label="item.dictLabel"
                       :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="queryParams.mobile" placeholder="请输入会员手机号"></el-input>
        </el-form-item>
<!--        <el-form-item label="交易时间">-->
<!--          <el-date-picker-->
<!--            v-model="dateRange"-->
<!--            style="width: 240px"-->
<!--            size="medium"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            type="daterange"-->
<!--            range-separator="-"-->
<!--            start-placeholder="开始日期"-->
<!--            end-placeholder="结束日期"-->
<!--          ></el-date-picker>-->
<!--        </el-form-item>-->
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
<!--    统计-->
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>会员充值统计</span>
      </div>
      <div class="box-gang">
        <div class="box" v-for="(item,index) in 7" :key="index">
          <div class="size-hui">订单总数</div>
          <div class="size-bole">55</div>
        </div>

      </div>
    </el-card>
<!--    表格-->
    <el-card class="box-card">
      <div class="wgang">
        <div>会员充值列表</div>
       <div style="display: flex ">

         <el-button type="primary" size="mini" icon="el-icon-plus" @click="exportExcelVip()">导出订单</el-button>
       </div>
      </div>
      <div class="table-box">
        <el-table
          :data="list"
          style="width: 100%">
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" class="demo-table-expand" style="margin-left: 20px">
                <el-form-item label="会员名称">
                  <span>{{ props.row.name }}</span>
                </el-form-item>
                <el-form-item label="会员手机号">
                  <span>{{ props.row.mobile }}</span>
                </el-form-item>
                <el-form-item label="操作人">
                  <span>{{ props.row.realName }}</span>
                </el-form-item>
                <el-form-item label="操作人手机号">
                  <span>{{ props.row.staffMobile }}</span>
                </el-form-item>
                <el-form-item label="储值优惠">
                  <span>充值满{{ props.row.rechargeBalance }}元赠送{{ props.row.giftBalance }}元</span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="会员名称"> </el-table-column>
          <el-table-column prop="bidBalance" label="储值卡面值"> </el-table-column>
          <el-table-column prop="rechargeBalance" label="储值卡实售金额"> </el-table-column>
          <el-table-column prop="giftBalance" label="储值卡赠送金额"></el-table-column>
          <el-table-column prop="paymentType" label="支付方式">
            <template slot-scope="scope">
              <span>{{getType(payList,scope.row.paymentType)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="payStatus" label="支付状态">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.payStatus == 'unpaid'">未支付</el-tag>
              <el-tag type="success" v-else-if="scope.row.payStatus == 'paid'">已支付</el-tag>
              <el-tag type="danger" v-else>支付失败</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="realName" label="交易员工"></el-table-column>
          <el-table-column prop="remark" label="充值备注">
            <template slot-scope="scope">
              <span>{{ scope.row.remark ? scope.row.remark:"--" }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="fringeBenefit" label="附加福利">
            <template slot-scope="scope">
              <span>{{ scope.row.fringeBenefit ? scope.row.fringeBenefit:"--" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
<!--              <el-button size="mini" type="text" icon="el-icon-edit">更多操作</el-button>-->
              <el-button style="width: 60px" size="mini"
                         @click="patchwork(scope.row)"
                         type="primary" plain round>补打</el-button>
              <el-button style="width: 60px" size="mini"
                         @click="handleRefund(scope.row.id)"
                         type="danger" plain round>退款</el-button>
            </template>
          </el-table-column>

        </el-table>
      </div>
      <div class="pagination-box">
        <el-pagination
          background
          v-show="total>0"
          layout="prev, pager, next"
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @current-change="getList">
        </el-pagination>
      </div>


    </el-card>

<!--    订单退款-->
    <el-dialog
      title="订单退款"
      width="25%"
      :visible.sync="dialogRefund">
      <div style="text-align: center;font-weight: bold">
        ￥<span style="font-size: 35px">{{ oilOrder.rechargeBalance }}</span>
      </div>
      <div class="tk">退款金额</div>
      <div class="tk">会员手机号：{{ oilOrder.mobile }}</div>
      <div style="margin: 10px 0">
        退款原因<br/>
        <el-radio-group v-model="radio1" style="margin: 10px 0">
          <el-radio-button label="充值类型选错"></el-radio-button>
          <el-radio-button label="充值金额错误"></el-radio-button>
          <el-radio-button label="其他原因"></el-radio-button>
        </el-radio-group>
      </div>
      <div>
        <el-input placeholder="请输入密码" v-model="password" show-password></el-input>
        <br/>
        <span style="color: grey;font-size: 12px">退款仅支持全额退款,退款金额将按照支付信息原路退回、优惠券、储值卡等原路退回处理</span>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogRefund = false">取 消</el-button>
        <el-button type="primary" @click="dialogRefund = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {cardValueRecordInfo, listCardValueRecord} from "@/api/order/cardvaluerecord";
import {getDicts} from "@/api/order/data";
import {queryStaffs} from "@/api/order/staff";
import { exportExcelVipApi } from "@/api/order/exportExcel";


export default {
  name: "order_Cashier",
  data(){
    return{
      // 员工列表
      staffList:[],
      // 日期范围
      dateRange: [],
      oilOrder:{},
      // 退款密码
      password:"",
      radio1:"充值类型选错",
      dialogRefund:false,
      // 支付方式列表
      payList:[],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
      },
      // 列表信息
      list:[],
      // 总条数
      total:0,

      labelPosition: 'right',
      formLabelAlign: {
        name: '',
      },
      // tableData: [{
      //   date: '2016-05-03',
      //   name: '王小狼',
      //   province: '上海',
      //   city: '普陀区',
      //   address: '上海市普陀区金沙江路 1518 弄',
      //   zip: 200333
      // }, {
      //   date: '2016-05-02',
      //   name: '王小虎',
      //   province: '上海',
      //   city: '普陀区',
      //   address: '上海市普陀区金沙江路 1518 弄',
      //   zip: 200333
      // }, {
      //   date: '2016-05-04',
      //   name: '王小虎',
      //   province: '上海',
      //   city: '普陀区',
      //   address: '上海市普陀区金沙江路 1518 弄',
      //   zip: 200333
      // }, {
      //   date: '2016-05-01',
      //   name: '王小虎',
      //   province: '上海',
      //   city: '普陀区',
      //   address: '上海市普陀区金沙江路 1518 弄',
      //   zip: 200333
      // }, {
      //   date: '2016-05-08',
      //   name: '王小虎',
      //   province: '上海',
      //   city: '普陀区',
      //   address: '上海市普陀区金沙江路 1518 弄',
      //   zip: 200333
      // }, {
      //   date: '2016-05-06',
      //   name: '王小虎',
      //   province: '上海',
      //   city: '普陀区',
      //   address: '上海市普陀区金沙江路 1518 弄',
      //   zip: 200333
      // }, {
      //   date: '2016-05-07',
      //   name: '王小虎',
      //   province: '上海',
      //   city: '普陀区',
      //   address: '上海市普陀区金沙江路 1518 弄',
      //   zip: 200333
      // }]
    }
  },
  created() {
    this.getList();
    this.getPayList();
  },
  methods:{
    exportExcelVip() {
      exportExcelVipApi(this.queryParams).then(res=>{
          const blob = new Blob([res], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
          this.$download.saveAs(blob,'商品订单统计.xLsx')
        })
    },
    // 补打
    patchwork(data){
      const orderNo = data.name
      this.$modal.confirm('确定您要补打当前订单吗？当前会员[' + orderNo + '],请确保云打印机正在运行中').then(function() {
        // return delUser(row.id);
      }).then(() => {
        this.$modal.msgSuccess("打印指令已发送打印机,请查看打印结果");
      }).catch(() => {});
    },
    // 退款
    handleRefund(id){
      this.dialogRefund = true;
      cardValueRecordInfo(id).then( response => {
        this.oilOrder = response.data
      })
    },
    getType(list,val){
      let name = "";
      list.forEach(item => {
        if (item.dictValue == val){
          name = item.dictLabel
        }
      })
      return name;
    },
    // 获取支付列表信息
    getPayList(){
      getDicts("payment_type").then( response => {
        this.payList = response.data;
      })
      queryStaffs().then( response => {
        this.staffList = response.data;
      })
    },
    // 搜索按钮操作
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    // 重置按钮操作
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {
        pageNo: 1,
        pageSize: 10,
      }
      // this.resetForm("queryForm");
      this.handleQuery();
    },
    // 获取列表信息
    getList(val){
      if (val!=undefined){
        this.queryParams.pageNo = val
      }
      listCardValueRecord(this.queryParams).then( response => {
        this.list = response.data.records;
        this.total = response.data.total;
      })
    },
  }
}
</script>

<style scoped>

.app-container{
    width: 100%;
    height: 100%;
    background: #f6f8f9;
  }
  .app-top{
    width: 100%;

    height: 60px;
    box-sizing: border-box;
    padding: 10px;
  }
  .clearfix{
    width: 100%;

  }
  .box-card{
    width: 100%;
    margin-bottom: 15px;
  }
  .box-gang{
    width: 100%;
    display: flex;
    align-items: center;
  }
  .box{
    width: 200px;
    box-sizing: border-box;
    padding: 10px;
    background: #f9f9f9;
    height: 86px;
    margin-right: 10px;
  }
  .size-hui{
    font-size: 14px;
    margin-bottom: 10px;
    margin-top: 10px;
  }
  .size-bole{
    font-weight: bold;
  }
  .wgang{
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;

  }
  .table-box{
    width: 100%;
  }
  .pagination-box{
    width: 100%;
    margin: 10px auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .top-app-sou{
    width: 20%;
  }
  .tk{
    text-align: center;
    color: grey;
    margin: 10px 0;
  }

</style>
