<template>
  <div class="app-container">
    <el-form :model="queryParams" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单编号" >
        <el-input v-model="queryParams.orderNo" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" style="width:230px"/>
      </el-form-item>
      <el-form-item label="顺序号" >
        <el-input v-model="queryParams.orderNum" placeholder="请输入顺序号" clearable @keyup.enter.native="handleQuery" style="width:230px"/>
      </el-form-item>
      <el-form-item label="用户昵称">
        <el-input v-model="queryParams.userName" placeholder="请输入用户昵称" clearable @keyup.enter.native="handleQuery" style="width:230px"/>
      </el-form-item>
      <el-form-item label="店铺" >
        <el-select v-model="queryParams.shopId" placeholder="请选择店铺" clearable style="width:230px">
          <el-option
            v-for="item in shopList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="付款时间">
        <el-date-picker v-model="payTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" style="width:230px"></el-date-picker>
      </el-form-item>
      <el-form-item label="订单状态">
        <el-select v-model="queryParams.state" placeholder="请选择订单状态" clearable style="width:230px">
          <el-option v-for="item in stateList"  :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" v-hasPermi="['system:refund:query']">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>   
    <el-table :data="refundList">
      <el-table-column label="退款编号" align="center">
        <template slot-scope="scope">
          <a @click="handleDetial(scope.row)" style="color: blue">{{ scope.row.refundNo }}</a>
        </template>
      </el-table-column>
      <el-table-column label="订单编号" align="center" prop="orderNo"/>
      <el-table-column label="商品数量" align="center" prop="order.goodsNum" />
      <el-table-column label="金额" align="center" prop="refundAmount" />
      <el-table-column label="店铺" align="center" prop="order.shop.name" />      
      <el-table-column label="用户名称" align="center" prop="order.userName" />
      <el-table-column label="付款时间" align="center" prop="order.payTime"/>  
      <el-table-column label="订单状态" align="center" >
        <template slot-scope="scope">{{formatterState(scope.row.order.state)}}</template>
      </el-table-column> 
      <el-table-column label="申请退款时间" align="center" prop="createdAt"/>
      <el-table-column label="到账时间" align="center" prop="updatedAt"/>
      <el-table-column label="退款状态" align="center" prop="state">
        <template slot-scope="scope">
          <span v-if="scope.row.state=='1'">退款中</span>
          <span v-if="scope.row.state=='2'">退款成功</span>
          <span v-if="scope.row.state=='3'">退款失败</span>
        </template>
      </el-table-column>
      <el-table-column label="发起人" align="center" prop="createUserName"/>   
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 详情对话框 -->
    <RefundDetial ref="refundDetial" ></RefundDetial>

  </div>
</template>

<script>
import { listRefund } from "@/api/system/refund";
import { listShop} from "@/api/system/shop";
import piovince from '@/utils/piovince';
import RefundDetial from '@/components/order/refundDetial.vue';
export default {
  name: "Order",  
  components: { RefundDetial},
  data() {
    return {
      payTime:[],   
      shopList:[
        {value: '',label: '全部'},
      ],
      stateList:[
        {value:null,label:"全部"},
        {value:"0",label:"创建未校验"},
        {value:"1",label:"未支付"},
        {value:"2",label:"已支付"},
        {value:"3",label:"支付制作中"},
        {value:"4",label:"制作完成未取"},
        {value:"5",label:"取餐中"},
        {value:"6",label:"正常完成"},
        {value:"7",label:"待取超时"},
        {value:"8",label:"未支付取消"},
        {value:"9",label:"支付后制作前取消"},
        {value:"10",label:"制作中取消"},
        {value:"11",label:"制作完成取消"},
        {value:"12",label:"退款中"},        
        {value:"13",label:"退款失败"},
        {value:"14",label:"部分退款"},
        {value:"15",label:"已退款"},
        {value:"50",label:"其他人工干预状态"},
      ],  
      piovince,
      // 遮罩层
      //loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      refundList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        orderNum: null,
        userName: null,
        shopId: null,
        createAtStart: null,
        createAtEnd:null,
        payAtStart:null,
        payAtEnd: null,
        state: null
      },     
      // 表单参数
      form: {}      
    };
  },
  created() {
    this.getList();
    this.getShopList();
  },
  methods: {
    getProvince(province){
      let list=this.piovince;
      for(let i=0;i<list.length;i++){
        if(list[i].children.length>0){
          let childrenList=list[i].children;
          for(let j=0;j<childrenList.length;j++){
            if(childrenList[j].value == province){
              return childrenList[j].name;
            } 
          }
        }       
      }
    },    
    formatterState(state){
      if(state == 0){
        return "创建未校验（创建未校验）";
      }else if(state == 1){
        return "未支付（待付款）";
      }else if(state == 2){
        return "已支付（待制作）";
      }else if(state == 3){
        return "支付制作中（制作中）";
      }else if(state == 4){
        return "制作完成未取（待取餐）";
      }else if(state == 5){
        return "取餐中（取餐中）";
      }else if(state == 6){
        return "正常完成（已完成）";
      }else if(state == 7){
       return "待取超时（已完成）";
      }else if(state == 8){
       return "未支付取消（已取消）";
      }else if(state == 9){
        return "支付后制作前取消（已取消）";
      }else if(state == 10){
        return "制作中取消（已取消）";        
      }else if(state == 11){
        return "制作完成取消（已取消）";  
      }else if(state == 12){
        return "退款中（退款中）";  
      }else if(state == 13){
        return "退款失败（退款失败）";  
      }else if(state == 14){
        return "部分退款（部分退款）";  
      }else if(state == 15){
        return "已退款（已退款）";  
      }else if(state == 50){
        return "其他人工干预状态（其他人工干预状态）";  
      }
    },    
    /** 查询订单列表 */
    getList() {
      listRefund(this.queryParams).then(response => {
        if(response.code=="200"){
          this.refundList = response.rows;
          this.total = response.total;
        }
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.payAtStart=null;
      this.queryParams.payAtEnd= null;
      if(this.payTime!=null &&  this.payTime.length>0 ){
        this.queryParams.payAtStart=this.payTime[0];
        this.queryParams.payAtEnd=this.payTime[1];
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.pageNum = 1;   
      this.queryParams.orderNo=null;
      this.queryParams.orderNum=null;
      this.queryParams.userName=null;
      this.queryParams.shopId=null;      
      this.payTime=[];
      this.queryParams.payAtStart=null,
      this.queryParams.payAtEnd= null,
      this.queryParams.state=null;   
      this.handleQuery();
    },
    /** 详情按钮操作 */
    handleDetial(row) {
      this.$refs.refundDetial.getDetial(row);
    },
    /** 店铺列表 */
    getShopList() {
      listShop({pageNum:1,pageSize:10000}).then(response => {
        if(response.code=="200"){
          this.shopList=[];
          if(response.rows.length>0){
            for(let i=0;i<response.rows.length;i++){              
              this.shopList.push({value:response.rows[i].id,label: response.rows[i].name},)
            }
          }
        }
      });
    }
    
  }
};
</script>
