<template>
  <div v-loading="loading">
    <div class="heior_box">
      <el-button size="small" type="primary" icon="el-icon-sold-out" @click="showDialog=true">认领</el-button>
      <div class="search-box">       
        <el-date-picker
          size="small"
          v-model="dateRange"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
        <el-input
          v-model="searchModel.keyWord"
          placeholder="销售员"
          clearable
          size="small"
        >
          <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
        </el-input>
      </div>
    </div>
    <el-table :data="retData.Data" row-key="Id" border size="medium" :height="$getHeight(100)">
      <el-table-column prop="Channel" label="销售员" ></el-table-column>
      <el-table-column prop="Amount" label="充值金额"></el-table-column>     
    </el-table>
    <div class="block">
      <el-pagination
        v-if="retData.Data.length>0"
        @current-change="get"
        :current-page.sync="searchModel.PageIndex"
        :page-size="50"
        layout="total,prev, pager, next"
        :total="retData.TotalCount"
      ></el-pagination>
    </div>
      <el-dialog title="认领订单" :visible.sync="showDialog" width="300px">
      <el-form :model="takeModel" ref="inputForm" label-width="80px">
        <el-form-item prop="phone" label="手机号">
          <el-input v-model="takeModel.phone" size="small"></el-input>
        </el-form-item>
        <el-form-item prop="amount" label="订单金额">
          <el-input v-model="takeModel.amount" size="small" type="number"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="resetForm('inputForm')">取 消</el-button>
        <el-button type="primary" @click="take()">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "treeTable",
  components: {
    cutTip: () => import("@/components/common/cutTip"),
    phoneHide: () => import("@/components/common/phonehide")
  },
  data() {
    return {
      loading: false,
      options: [],
      showDialog:false,
      retData: { TotalCount: 0, Data: [] },
      dateRange: [],
      takeModel:{
        phone:'',
        amount:''
      },
      searchModel: {
        PageIndex: 1,     
        keyWord: "",  
        Btime: "",
        Etime: "",      
      }
    };
  },
  created() {
    this.$store.commit("setCurrentNav", "订单管理>>充值订单");
    this.get();  
  },
  methods: {
    search() {
      this.searchModel.PageIndex = 1;
      this.get();
    },
    get() {
      if (this.dateRange && this.dateRange.length == 2) {
        this.searchModel.Btime = this.dateRange[0];
        this.searchModel.Etime = this.dateRange[1];
      }
      this.$api.get(this.$api.phpURL + 'order/ChargeOrder/getList', this.searchModel).then(res => {
        this.retData = res;
      });
    }, 
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.showDialog = false;    
    },
    take(){
       this.$api.get(this.$api.phpURL + "order/ChargeOrder/takeCharge", this.takeModel).then(res => {
        this.resetForm('inputForm')
        this.get();
      });      
    },
    dataExport() {
      this.$api.getDownloadFile("/baseinfo/v1/chargeorder/ExportOrder", this.searchModel);
    }
  }
};
</script>
<style scoped>
</style>
