
<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">
        {{scope.row.goodsModelList[0].goodsInfo.activityName||scope.row.goodsModelList[0].goodsInfo.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">
        {{scope.row.goodsModelList[0].goodsInfo.price||scope.row.goodsModelList[0].goodsInfo.realPrice}}
      </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].goodsState | 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 {getList} 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: "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 == 'APPLY_REFUND'){
          return "申请退款"
      }else if(val == 'CLOSE'){
          return "关闭订单"
        
      }else if(val == 'REFUNDED'){
          return "已退款"
        
      }else if(val == 'REFUSAL_REFUND'){
          return "拒绝退款"
        
      }else if(val == 'USED'){
          return "已使用"
        
      }else if(val == 'WAIT_PAYMENT'){
          return "待付款"
        
      }else{
          return "待使用"
      }
    }
  },
  methods: {
     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
      }
      getList(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>
  