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

          <el-input
            v-model="query.noOrGName"
            size="small"
            placeholder="请输入订单编号或商品名称"
            class="item-width-200 "
          ></el-input>
           <el-input
            v-model="query.phone"
            size="small"
            placeholder="请输入手机号"
            class="item-width-200 ml10"
          ></el-input>
           <el-input
            v-model="query.userId"
            size="small"
            placeholder="请输入用户ID"
            class="item-width-200 ml10"
          ></el-input>
            <el-select
            v-model="query.shopId"
            size="small"
            clearable
            class="item-width-200 ml10"
            placeholder="请输入搜索店铺名称"
            filterable
            remote
            reserve-keyword
            :remote-method="getShopList"
          >
            <el-option
              v-for="item in options1"
              :key="item.shopId"
              :label="item.shopName"
              :value="item.shopId"
            >
            </el-option>
          </el-select>
              <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-select
            v-model="query.platInter"
            size="small"
            clearable
            class="item-width-200 ml10"
            placeholder="是否客服介入"
          >
            <el-option
              v-for="item in options2"
              :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">
        <img :src="formatType(scope.row).icon" alt="" class="icon">

        <!-- <img src="@/assets/recharge.png" v-if="scope.row.goodsModelList[0].jobFlowMap == 'video2'" alt="" class="icon">
        <img v-else :src="scope.row.goodsModelList[0].goodsInfo.activityCover||scope.row.goodsModelList[0].goodsInfo.goodsPath" alt="" class="icon"> -->
      </template>
      </el-table-column>
      <el-table-column
        prop="shopName"
        align="center"
        label="商品名"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
        <!-- {{scope.row.goodsModelList[0].goodsInfo.activityName||scope.row.goodsModelList[0].goodsInfo.goodsName }} -->
        {{ formatType(scope.row).goodsName}}
      </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        align="center"
        label="商品类型"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
        {{goodsTypeObj[scope.row.goodsModelList[0].goodsInfo.goodsType] || formatType(scope.row).type }}
      </template>
      </el-table-column>
    
      <el-table-column
        prop="payAmount"
        align="center"
        label="订单金额"
        show-overflow-tooltip
      >
       <template slot-scope="scope">
        {{scope.row.goodsModelList[0].payAmount}}
      </template>
      </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="createTime"
        align="center"
        label="申请介入"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
        {{scope.row.goodsModelList[0].refundLog | filterApply}}
      </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,'detail')">详情</el-button>
          <!-- 拒绝退款和申请退款都显示 -->
          <el-button type="text" size="small" v-if="(scope.row.goodsModelList[0].refundLog&&scope.row.goodsModelList[0].refundLog.refund == 'REFUSAL_REFUND')||scope.row.goodsModelList[0].goodsState == 'APPLY_REFUND'&&scope.row.goodsModelList[0].jobFlowMap!='XiaoJu'" @click="handleDetail(scope.row,'refund')">介入处理</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'
import { getList } from "@/api/shop";

export default {
  name: "list",
  data() {
    return {
      date:'',//时间
      options: [
        {
          value: "APPLY_REFUND",
          label: "申请退款",
        },
        {
          value: "CLOSE",
          label: "关闭订单",
        },
        {
          value: "REFUNDED",
          label: "已退款",
        },
        {
          value: "REFUSAL_REFUND",
          label: "拒绝退款",
        },
        {
          value: "APPLY_REFUNDING",
          label: "退款中",
        },
        {
          value: "USED",
          label: "已使用",
        },
        {
          value: "WAIT_PAYMENT",
          label: "待付款",
        },
        {
          value: "WAIT_USE ",
          label: "待使用",
        },
      ],
      options1:[],
      options2:[
        {
          label:'是',
          value:true
        },
        {
          label:'否',
          value:false
        }
      ],
      tableData: [],
      goodsTypeObj:{},
      loading: false,
      query: {
        userId:'',
        phone:'',
        shopId:'',
        "endTime": '',
        "noOrGName": '',
        "orderType": "",
        "page": 1,
        "size": 10,
        "sort": "",
        "startTime": '',
        "platInter":''
      },
      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 ''
				}
			},
    filterApply: function(val) {
      if(val){
        if(val.platInter){
          return '是'
        }else{
          return '否'
        }
      }else{
        return '否'
      }
    }
  },
  methods: {
    formatType(row){
        if(row.goodsModelList[0].jobFlowMap == 'XiaoJu'){

            return {
                icon:row.goodsModelList[0].goodsInfo.goodsPath,
                type:'加油充电',
                goodsName:row.goodsModelList[0].goodsInfo.goodsName
              }
        }else if(row.goodsModelList[0].jobFlowMap == 'Activity'){
            return {
                icon:row.goodsModelList[0].goodsInfo.activityCover,
                type:'活动报名',
                goodsName:row.goodsModelList[0].goodsInfo.activityName
              }
        }else if(row.goodsModelList[0].jobFlowMap == 'Ticket'){
             return {
                icon:row.goodsModelList[0].goodsInfo.goodsPath,
                type:'景区门票',
                goodsName:row.goodsModelList[0].goodsInfo.goodsName
              }
        }else if(row.goodsModelList[0].jobFlowMap == 'Hotel'){
            return {
                icon:row.goodsModelList[0].goodsInfo.goodsPath,
                type:'酒店住宿',
                goodsName:row.goodsModelList[0].goodsInfo.goodsName
              }
        }else if(row.goodsModelList[0].jobFlowMap == 'YPP'){
             return {
                icon:row.goodsModelList[0].goodsInfo.goodsPath,
                type:'电影票',
                goodsName:row.goodsModelList[0].goodsInfo.goodsName
              }
        }else if(row.goodsModelList[0].jobFlowMap == 'video2'){
             return {
                icon:require('@/assets/recharge.png'),
                type:'视频会员',
                goodsName:row.goodsModelList[0].goodsInfo.goodsName
              }
        }else if(row.goodsModelList[0].jobFlowMap == 'QiuXiang'){
             return {
                icon:row.goodsModelList[0].goodsInfo.goodsPath,
                type:'秋香代驾',
                goodsName:row.goodsModelList[0].goodsInfo.goodsName
              }
        }else if(row.goodsModelList[0].jobFlowMap == 'Kfc'){
             return {
                icon:row.goodsModelList[0].goodsInfo.products[0].imageUrl,
                type:'大牌点餐',
                goodsName:row.goodsModelList[0].goodsInfo.goodsName
              }
        }else{
           return {
                icon:row.goodsModelList[0].goodsInfo.goodsPath,
                type:'-',
                goodsName:row.goodsModelList[0].goodsInfo.goodsName
              }
        }
    },
    handleSearch(){
      this.query.page = 1
      this.getList();

    },
    timeFormat(val){
      return timeFormat(val)
    },
    handleDetail(row,mode){
      localStorage.setItem('orderItem',JSON.stringify(row))
      this.$router.push({
        path:'/operationManage/orderManage/orderDetail',
        query:{
          mode,
          orderNo:row.orderNo,
          id:row.goodsModelList[0].id
        }
      })
    },
   
    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
      }
      if(obj.platInter === ''){
        obj.platInter = null
      }
      getOrderList(obj).then(res=>{
        this.loading = false
        if(res.state == 'Success'){
          this.tableData = res.content.content
          this.total = res.content.totalElements
        }
      })
    },
    getShopList(shopNameOrPhoneNum) {
      if(shopNameOrPhoneNum){
          this.loading = true;
          getList({
              shopNameOrPhoneNum,
              currentPage: 1,
              pageSize: 10
          }).then((res) => {
            this.loading = false;
            if (res.state == "Success") {
              this.options1 = res.content.records;
            }
          });
      }else{
        this.options1 = []
      }
    },
  },
  created() {
    this.goodsTypeObj = JSON.parse(sessionStorage.getItem('goodsTypeObj'))
   this.getList()
  },
};
</script>
  
<style lang="scss" >
.list {
.icon{
    width: 80px;
}
}

</style>
  