
<template>
  <div class="orderManage app-container">
    <div class="search">
      <div>

        <el-input
          v-model="query.noOrGName"
          size="small"
          placeholder="请输入订单编号"
          class="item-width-200 "
        ></el-input>
            <el-date-picker
          v-model="date"
          size="small"
          value-format="timestamp"
          class="item-width-350 ml10"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
         <el-select
          v-model="query.orderType"
          size="small"
          clearable
          class="item-width-200 ml10"
          placeholder="请选择订单状态"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-button
        class="ml10"
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="handleSearch"
      >
        搜索
      </el-button>
      </div>
    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      border
      v-loading="loading"
      style="width: 100%"
    >
      <el-table-column
        align="center"
        label="订单编号"
        prop="orderNo"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="shopName"
        align="center"
        label="商品名"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
        {{formatData(scope.row.goodsModelList).goodsName }}
      </template>
      </el-table-column>
      <!-- <el-table-column
        prop="createTime"
        align="center"
        label="数量"
        show-overflow-tooltip
      >
      </el-table-column> -->
      <el-table-column
        prop="goodsAmount"
        align="center"
        label="售价"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
        {{formatData(scope.row.goodsModelList).price }}

      </template>
      </el-table-column>
      <el-table-column
        prop="payAmount"
        align="center"
        label="订单金额"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="createTime"
        align="center"
        label="状态"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
        {{scope.row.goodsModelList[0] | filterType}}
      </template>
      </el-table-column>
      <el-table-column
        prop="shopName"
        align="center"
        label="店铺名称"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
        {{scope.row.shopInfo.shopName }}
      </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        align="center"
        label="下单时间"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
        {{ timeFormat(scope.row.createTime) }}
      </template>
      </el-table-column>
       <el-table-column prop="address" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="query.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="query.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
  
  <script>
  import {debounce} from '@/utils/index'
  import {getOrderList} from '@/api/order'
  import {timeFormat} from '@/utils/index'

export default {
  name: "orderManage",
  data() {
    return {
      date:'',//时间
      options: [
        {
          value: "APPLY_REFUND",
          label: "申请退款",
        },
        {
          value: "CLOSE",
          label: "关闭订单",
        },
        {
          value: "REFUNDED",
          label: "已退款",
        },
        {
          value: "APPLY_REFUNDING",
          label: "退款中",
        },
        {
          value: "REFUSAL_REFUND",
          label: "拒绝退款",
        },
        {
          value: "USED",
          label: "已使用",
        },
        {
          value: "WAIT_PAYMENT",
          label: "待付款",
        },
        {
          value: "WAIT_USE ",
          label: "待使用",
        },
      ],
      tableData: [],
      loading: false,
      query: {
        "endTime": '',
        "noOrGName": '',
        "orderType": "",
        "page": 1,
        "size": 10,
        "sort": "",
        "startTime": ''
      },
      title: "",
      total: 0,
    };
  },
 watch: {
    // query: {
    //   handler: debounce(function(val) {
    //     this.getList()
        
    //   }),
    //   deep:true
    // },
    date(val){
      if(val){
        this.query.startTime = val[0]
        this.query.endTime = val[1]
      }else{
        this.query.startTime = ''
        this.query.endTime = ''
      }
    }
  },
  filters: {
    filterType: function(val) {
				if(val.refundLog&&val.refundLog.refund == 'REFUSAL_REFUND'&&!val.change){
					return '拒绝退款'
				}
                else if(val.jobFlowMap == 'Hotel'&&val.extend.orderInfo){
					return val.extend.orderInfo.orderStatus
				}
				else if(val.goodsState == 'APPLY_REFUND'){
					return '退款审核中'
				}else if(val.goodsState == 'CLOSE'){
					return '关闭订单'
				}else if(val.goodsState == 'REFUNDED'){
					return '已退款'
				}else if(val.goodsState == 'REFUSAL_REFUND'){
					return '拒绝退款'
				}else if(val.goodsState == 'APPLY_REFUNDING'){
					return '退款中'
				}else if(val.goodsState == 'USED'){
          if(val.jobFlowMap == 'YPP'){
						return '已出票'
					}else{
						return '订单已完成'
					}
				}else if(val.goodsState == 'WAIT_PAYMENT'){
					return '待付款'
				}else if(val.goodsState == 'WAIT_USE'){
          if(val.jobFlowMap == 'YPP'){
						return '出票中'
					}else{
						return '待使用'
					}
				}else{
					return ''
				}
			},
   
  },
  methods: {
    formatData(goodsModelList){
        if(goodsModelList[0].jobFlowMap == 'XiaoJu'){
          return {
            goodsName:goodsModelList[0].goodsInfo.goodsName,
            price:goodsModelList[0].goodsInfo.storePrice
          }
        }else if(goodsModelList[0].jobFlowMap == 'Activity'){
          return {
            goodsName:goodsModelList[0].goodsInfo.activityName,
            price:goodsModelList[0].goodsInfo.price
          }
        }else if(goodsModelList[0].jobFlowMap == 'Ticket'){
          return {
            goodsName:goodsModelList[0].goodsInfo.goodsName,
            // price:goodsModelList[0].payAmount
            price:goodsModelList[0].goodsInfo.salePrice
          }
        }else if(goodsModelList[0].jobFlowMap == 'Hotel'){
          return {
            goodsName:goodsModelList[0].goodsInfo.goodsName,
            price:goodsModelList[0].goodsInfo.totalPrice
          }
        }else if(goodsModelList[0].jobFlowMap == 'YPP'){
          return {
            goodsName:goodsModelList[0].goodsInfo.goodsName,
            price:goodsModelList[0].goodsInfo.originPrice
          }
        }else if(goodsModelList[0].jobFlowMap == 'video2'){
          return {
            goodsName:goodsModelList[0].goodsInfo.goodsName,
            price:goodsModelList[0].goodsInfo.originPrice
          }
        }else if(goodsModelList[0].jobFlowMap == 'QiuXiang'){
          return {
            goodsName:goodsModelList[0].goodsInfo.goodsName,
            price:goodsModelList[0].goodsInfo.originPrice
          }
        }
        else if(goodsModelList[0].jobFlowMap == 'Kfc'){
          return {
            goodsName:goodsModelList[0].goodsInfo.goodsName,
            price:goodsModelList[0].goodsInfo.products[0].sellPrice
          }
        }else{
          return {
            goodsName:goodsModelList[0].goodsInfo.goodsName,
            price:goodsModelList[0].goodsInfo.realPrice
          }
        }
    },
     handleSearch(){
      this.query.page = 1
      this.getList();

    },
    timeFormat(val){
      return timeFormat(val)
    },
    handleDetail(row){
      // localStorage.setItem('orderItem',JSON.stringify(row))
      this.$router.push({
        path:'/operationManage/orderManage/payDetail',
        query:{
           orderNo:row.orderNo,
        }
      })
    },
    handleSizeChange(val) {
      this.query.page = 1;
      this.query.size = val;
   this.getList()
    },
    handleCurrentChange(val) {
      this.query.page = val;
   this.getList()
    },

    search() {
      this.query.page = 1;
   this.getList()
    },
    getList(){
      this.loading = true
      let obj = JSON.parse(JSON.stringify(this.query)) 
      obj.page = obj.page -1
      if(!obj.orderType){
        delete obj.orderType
      }
      getOrderList(obj).then(res=>{
        this.loading = false
        if(res.state == 'Success'){
          this.tableData = res.content.content
          console.log(this.tableData);
          this.total = res.content.totalElements
        }
      })
    }
  },
  created() {
   this.getList()
  },
};
</script>
  
<style lang="scss" >
.orderManage {
  
}

</style>
  