<template>
  <div class="balanceBudget">
    <div class="el-card__header">
      <span>余额收支</span>
      <div style="display: flex;flex-direction: row;align-items: center">
        <el-button type="primary" class="el-button--small" @click="dialogVisible=true">导出全部</el-button>
      </div>
    </div>

    <div class="content">
      <div style="display: flex;flex-direction: row;align-items: center">
        <div class="block">
          <el-date-picker
            style="padding: 3px 10px;width: 380px;height: 32px"
            v-model="value"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            @change="change"
            align="right">
          </el-date-picker>
          <div class="searchInput" style="width:250px">
            <el-input style="display:inline-block;width:225px;height:30px"
                      placeholder="请输入昵称搜索"
                      v-model="msg.MemberName"
                      @clear="msg.pageIndex=1,getList()"
                      @keyup.enter.native="msg.pageIndex=1,getList()"
                      size="small"
                      clearable>
            </el-input>
            <span @click="msg.pageIndex=1,getList()" class="el-icon-search" style="color:#979dad;font-size:14px;position:relative;top:1px"></span>
          </div>
        </div>
      </div>
    </div>

    <div style="padding: 20px;background: #fff;margin-top: 10px">
      <el-table
        :data="tableData"
        header-cell-class-name="headClass"
        style="width: 100%;"
        border
      >

        <el-table-column
          prop="Id"
          label="ID"
          width="80">
        </el-table-column>
        <el-table-column
          prop="MemberName"
          label="昵称">
        </el-table-column>
        <el-table-column
          label="收支情况(元)"
          width="180">
          <template slot-scope="scope">
            {{scope.row.RecordTypeStr}}{{scope.row.Balance}}
          </template>
        </el-table-column>
        <el-table-column
          prop="Description"
          label="说明"
          width="500">
        </el-table-column>
        <el-table-column
          prop="Remarks"
          label="备注">
        </el-table-column>

        <el-table-column
          prop="CreateDate"
          label="充值时间"
          width="180"
        >
        </el-table-column>
      </el-table>
      <el-pagination style="text-align:right"
            background
            @current-change="handleCurrentChange"
            :page-size="msg.pageSize"
            layout="prev, pager, next"
            :current-page.sync="msg.pageIndex"
            :total="count">
      </el-pagination>
    </div>
    <!-- 选择导出信息 -->
    <el-dialog
      title="选择导出信息"
      :visible.sync="dialogVisible"
      width="960px">
      <el-form style="border: 1px solid #F0F2F7;" :model="addMsg" ref="addMsg" label-width="100px">
        <div style="box-sizing: border-box;background-color: #F3F5F6;width: 100%;padding-left: 20px;height: 50px;line-height: 50px;">
          <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
        </div>
        <div style="margin: 15px 0;"></div>
        <div style="padding: 10px 25px 20px;">
          <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
            <el-checkbox style="margin-bottom:10px" v-for="city in cities" :label="city.Id" :key="city.Name">{{city.Name}}</el-checkbox>
          </el-checkbox-group>
        </div>

      </el-form>
      <div style="text-align:right;margin-top:20px">
        <el-button size="small" type="primary" @click="Export">导出</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
    export default {
        name: "balanceBudget",
      data(){
          return{
            value:'',
            msg:{
              pageIndex:1,
              pageSize:20,
              MemberName:'',
              StartDate:'',
              EndDate:'',
            },
            tableData:[],
            count:0,
            loading:false,
            dialogVisible:false,
            checkAll: false,
            checkedCities: [],
            isIndeterminate: true,
            cities: [],
            cityOptions: [],
            addMsg:{},

          }
      },
      created(){
          this.getDateList()
          this.getDown();

      },
      methods:{
        getDateList(){
          if(this.value!='' && this.value!=null){
            this.msg.StartDate = this.value[0];
            this.msg.EndDate = this.value[1];
          }else{
            this.msg.StartDate = '';
            this.msg.EndDate = '';
          }
          this.loading=true;
          this.apipost("/api/Recharge/GetMemberBalancePageList", this.msg, res => {
            this.loading=false;
            if(res.data.resultCode==1){
              this.tableData = res.data.data.pageData;
              this.count = res.data.data.count;
            }else {
              this.Info(res.data.message);
            }

          })
        },
        getDown(){
          this.cityOptions=[];
          this.apipost("/api/Recharge/GetBalanceExportEnumList",{}, res => {
            this.cities=res.data.data;
            let data=res.data.data;
            data.forEach(item=>{
              this.cityOptions.push(item.Id)
            })

          })
        },
        Export(){
          let msg = {
            MemberName:this.msg.MemberName,
            StartDate :this.msg.StartDate ,
            EndDate :this.msg.EndDate,
            ExcelEnumIds:this.checkedCities
          }
          msg = JSON.parse(JSON.stringify(msg));
          this.GetLocalFile(
            "/api/Recharge/GetDistributorRemitListToExcel",
            msg,
            "余额收支.xls"
          );
        },
        handleCurrentChange(val) {
          this.msg.pageIndex = val;
          this.getDateList();
        },
        change(val){
          if(val == null ){
            this.value='';
            this.msg.StartDate='';
            this.msg.EndDate='';

          }
          this.msg.pageIndex =1 
          this.getDateList();

        },
        handleCheckAllChange(val) {
          this.checkedCities = val ? this.cityOptions : [];
          this.isIndeterminate = false;
        },
        handleCheckedCitiesChange(value) {
          let checkedCount = value.length;
          this.checkAll = checkedCount === this.cities.length;
          this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length;
        },
        getList(){
          this.getDateList();

        }

      }
    }
</script>

<style >
  .balanceBudget .el-card__header{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: #fff;
    padding: 18px 20px;
  }
  .balanceBudget .el-button--small{
    padding: 9px 15px;
  }
  .balanceBudget .content .searchInput{
    border: 1px solid #DCDFE6;
    border-radius: 4px;
    margin-left: 20px;
  }
  .balanceBudget .content .searchInput .el-input__inner{
    border:none;outline:none;
    height: 30px;
    line-height: 30px;
  }
  .balanceBudget .content .searchInput{
    line-height: normal;
    display: inline-table;
    border-collapse: separate;
    border-spacing: 0;
    width:250px;
    margin-right: 20px;
  }
  .balanceBudget .content{
    background: #fff;
    margin-top:10px;
    padding: 15px;
    box-sizing: border-box;
  }
  .balanceBudget .el-icon-date{
    line-height: 24px;
  }
  .balanceBudget .el-range-separator{
    line-height: 24px;
  }
  .balanceBudget .el-input__icon {
    line-height: 24px;
  }
</style>
