<template>
  <div class="financeManage app-container">
   
    <div class="search">
      <div>
          <el-input
            v-model="query.noOrGName"
            size="small"
            placeholder="请输入订单编号"
            class="item-width-200 "
          ></el-input>
          <el-select
          v-model="query.channel"
          size="small"
          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-date-picker
            size="small"
          v-model="date"
          value-format="timestamp"
          class="item-width-400 ml10"
          type="daterange"
          :default-time="['00:00:00','23:59:59']"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          align="right">
      </el-date-picker>
      </div>
     <el-button
        class="ml10"
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="handleSearch"
      >
        搜索
      </el-button>
    </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="payTime"
        align="center"
        label="订单时间"
        show-overflow-tooltip
      >
      </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="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.platform}}
        </template>
      </el-table-column>
       <el-table-column
        prop="createTime"
        align="center"
        label="购买店铺分账金额"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
          {{scope.row.buyShop}}
        </template>
      </el-table-column>
       <el-table-column
        prop="createTime"
        align="center"
        label="核销店铺分账金额"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
          {{scope.row.useShop}}
        </template>
      </el-table-column>
       <el-table-column
        prop="createTime"
        align="center"
        label="状态"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
        <span :class="[scope.row.transfer?'green':'red']"> {{scope.row.transfer ?'分账成功':'未分账'}}</span>
        </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 {getTransferList} from '@/api/payment'
  import {debounce,timeFormat} from '@/utils/index'
export default {
  name: "financeManage",
  data() {
    return {
      options: [
        {
          value: "ZhongShu",
          label: "中数未来",
        },
        {
          value: "GuiDa",
          label: "印象贵大",
        }
      ],
      date:'',
      tableData: [],
      loading: false,
      query: {
        noOrGName: "",
        startTime: "",
        endTime: "",
        channel:"ZhongShu",
        page: 1,
        size: 10,
      },
      total: 0,
      pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
    };
  },
 watch: {
    // query: {
    //   handler: debounce(function(val) {
    //     this.getTransferList()
    //   }),
    //   deep:true
    // },
    date(val){
      if(val){
        this.query.startTime = val[0]
        this.query.endTime = val[1]
      }else{
        this.query.startTime = ''
        this.query.endTime = ''
      }
    }
  },
  methods: {
     handleSearch(){
      this.query.page = 1
      this.getTransferList();

    },
    timeFormat(val){
      return timeFormat(val)
    },
    handleSizeChange(val) {
      this.query.page = 1;
      this.query.size = val;
      this.getTransferList();

    },
    handleCurrentChange(val) {
      this.query.page = val;
      this.getTransferList();

    },
    getTransferList(){
      this.loading = true
      let obj = JSON.parse(JSON.stringify(this.query))
      --obj.page
      getTransferList(obj).then(res=>{
        this.loading = false
        if(res.state == 'Success'){
          this.tableData = res.content.content
          this.total = res.content.totalElements
        }
      })
    }
  },
  created() {
   this.getTransferList()
  },
};
</script>
  
<style lang="scss" scoped>
.financeManage {

  
}

</style>
  