<template>
  <div class="app-container calendar-list-container">
    <div>
      <div class="filter-container" ref="filter-container">
        <el-form ref="queryForm" :inline="inline" :model="listQuery" label-width="80px">
          <el-row>
            <el-form-item label="所属公司">
              <el-select v-model="listQuery.corporationId" placeholder="请选择">
                <el-option label="全部" :key="undefined" :value="undefined"></el-option>
                <el-option
                  v-for="val in companys_list"
                  :key="val.id"
                  :label="val.name"
                  :value="val.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="所属门店">
              <el-select
                class="filter-item"
                v-model="listQuery.companyId"
                clearable
                placeholder="请选择"
              >
                <el-option label="全部" :key="undefined" :value="undefined"></el-option>
                <el-option
                  v-for="val in branchCompany_list"
                  :key="val.id"
                  :label="val.name"
                  :value="val.id"
                ></el-option>
              </el-select>
            </el-form-item>

            <el-button
              class="filter-item"
              type="primary"
              v-waves
              icon="el-icon-search"
              @click="handleFilter"
            >搜索</el-button>
            <el-button class="filter-item" @click="clear_handleFilter">清除搜索</el-button>
          </el-row>
        </el-form>
        <div class="label_box">
          <div class="label_item top_color_bule">
            <p class="money_p">
              <span>￥</span>1,000,000.00
            </p>
            <p class="money_label">总营收金额</p>
          </div>
          <div class="label_item top_color_bule2">
            <p class="money_p">
              <span>￥</span>1,000,000.00
            </p>
            <p class="money_label">订单&服务营收</p>
          </div>
          <div class="label_item top_color_origin">
            <p class="money_p">
              <span>￥</span>1,000,000.00
            </p>
            <p class="money_label">额外赔偿(违约金等)</p>
          </div>
          <div class="label_item top_color_yellow">
            <p class="money_p">
              <span>￥</span>1,000,000.00
            </p>
            <p class="money_label">已提现金额</p>
          </div>
          <div class="label_item top_color_red">
            <p class="money_p">
              <span>￥</span>1,000,000.00
            </p>
            <p class="money_label">
              可提现金额，
              <a>立即提现 ></a>
            </p>
          </div>
        </div>
        <div class="label_filter">
          <div>收支明细</div>
          <div>
            <el-form>
              <el-form-item style="margin-bottom:0" label="时间筛选">
                <el-date-picker
                  type="date"
                  placeholder="开始时间"
                  v-model="listQuery.daystart"
                  style="width: 40%;"
                ></el-date-picker>&nbsp;—
                <el-date-picker
                  type="date"
                  placeholder="结束时间"
                  v-model="listQuery.dayend"
                  style="width: 40%;"
                ></el-date-picker>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
      <el-table :key="tableKey" :data="list" border fit highlight-current-row style="width: 100%;">
        <el-table-column align="center" label="公司名称" prop="name"></el-table-column>
        <el-table-column align="center" label="联系人/电话">
          <template slot-scope="{row}">
            <span>{{row.contact}}/{{row.mobile}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="法人姓名" prop="legalPerson"></el-table-column>
        <el-table-column align="center" label="法人身份证" prop="legalIdNumber"></el-table-column>

        <el-table-column align="center" label="操作">
          <template slot-scope="{row}">
            <el-button type="text" @click="withdraw(row)">提现</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div v-show="!listLoading" class="pagination-container">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="listQuery.page"
          :page-sizes="[10,20,30,40,50]"
          :page-size="listQuery.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { formatDate } from "utils/dateFormattor";

import {
  toEast8Date,
  deepCopyDate,
  newEast8Date,
  convertDate2Str,
  timestamp2Date,
} from "utils/dateUtils";

import { mapGetters } from "vuex";

import {
  company_list,
  add_company,
  del_company,
  upd_company,
} from "api/company";
import { getAllZone } from "api/base_info/constant/";
import Element1 from "../admin/menu/components/element";
import ElRow from "element-ui/packages/row/src/row";
import ElCol from "element-ui/packages/col/src/col";
import { getToken } from "utils/auth";
import { company_all_list, branchCompany_all_list } from "api/company.js";

export default {
  name: "carApplyList",
  components: {
    ElCol,
    ElRow,
    Element1,
  },
  data() {
    return {
      title_text: "",
      BASE_API: process.env.BASE_API,
      add_edit_dialog: false,
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 10,
        companyId: undefined,
        corporationId: undefined,
        daystart: "",
        dayend: "",
      },
      inline: true,
      tableKey: 0,
      btn_disable: null,
      companys_list: [],
      branchCompany_list: [],
    };
  },
  created() {
    this.getList();
    this.get_all_companys();
    this.get_all_branchCompany();
  },
  computed: {
    ...mapGetters(["elements"]),
    getHeaderWithToken() {
      return { Authorization: getToken() };
    },
  },
  methods: {
    //所有公司
    get_all_companys() {
      company_all_list().then((res) => {
        if (res.status == 200) {
          this.companys_list = res.data;
        }
      });
    },
    //所有门店
    get_all_branchCompany() {
      branchCompany_all_list({ state: 1 }).then((res) => {
        if (res.status == 200) {
          this.branchCompany_list = res.data;
        }
      });
    },
    handleAvatarSuccess(res, file) {
      this.company_form.businessLicense = res.data;
    },

    /**
     * 获取列表
     * */
    getList() {
      this.listLoading = true;
      company_list(this.listQuery).then((response) => {
        console.log(response);
        let totalCountRs = undefined;
        let listRs = undefined;
        if (
          !this.$utils.isEmpty(response.data.data) &&
          this.$utils.isInteger(response.data.totalCount)
        ) {
          listRs = response.data.data;
          totalCountRs = response.data.totalCount;
        }
        this.listLoading = false;
        this.list = listRs;
        this.total = totalCountRs;
      });
    },
    handleFilter() {
      this.listQuery.page = 1;
      this.$refs.queryForm.validate((valid) => {
        if (valid) {
          this.getList();
        } else {
          return false;
        }
      });
    },
    clear_handleFilter() {
      this.listQuery = {
        page: 1,
        limit: 10,
        companyId: undefined,
        corporationId: undefined,
        daystart: "",
        dayend: "",
      };
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped>
.top_btn {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}
.form_box {
  width: 80%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.customWidth1 {
  width: 35%;
}
.label_box {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}
.label_item {
  width: 260px;
  height: 130px;
  margin-right: 20px;
  margin-bottom: 20px;
  box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.top_color_bule {
  border-top: 12px solid #3d5afe;
}
.top_color_bule2 {
  border-top: 12px solid #00b0ff;
}
.top_color_origin {
  border-top: 12px solid #ff9100;
}
.top_color_yellow {
  border-top: 12px solid #ffea00;
}
.top_color_red {
  border-top: 12px solid #ff3d00;
}
.money_p {
  margin: 0;
  color: rgba(66, 66, 66, 1);
  font-size: 18px;
  font-weight: 600;
  span {
    &:first-child {
      color: rgba(97, 97, 97, 1);
      font-size: 14px;
    }
  }
}
.money_label {
  margin: 0;
  color: rgba(189, 189, 189, 1);
  font-size: 14px;
  a {
    &:first-child {
      color: blue;
    }
  }
}
.label_filter {
  div {
    &:first-child {
      margin-left: 10px;
      color: #101010;
      font-size: 15px;
      font-weight: 600;
    }
  }
  display: flex;
  justify-content: space-between;
  border-left: 5px solid #101010;
  align-items: center;
  height: fit-content;
}
</style>
