<template>
  <div class="box">
    <!-- 时间选择器 -->
    <div class="inquire">
      <div class="block">
        <span class="demonstration">日期</span>
        <el-config-provider :locale="zhCn">
          <el-date-picker v-model="inquire.time"
                          type="month"
                          placeholder="选择月">
          </el-date-picker></el-config-provider>
      </div>
    </div>
    <div class="inquire">
      <div class="block">
        <span class="demonstration">会长分区</span>
        <el-select v-model="inquire.partitionId"
                   style="width: 75%"
                   placeholder="请选择">
          <el-option v-for="item in inquire.inquireonInfos"
                     :key="item.id"
                     :label="item.desc"
                     :value="item.id"></el-option>
        </el-select>
      </div>
    </div>

    <!-- 公会 -->
    <div class="inquire">
      <span>会长ID</span>
      <el-input v-model="inquire.nick"
                placeholder=""
                class="input"></el-input>
    </div>
    <!-- 查询按钮 -->
    <el-button class="primary"
               type="primary"
               @click="getData()">查询</el-button>
    <!-- 导出 -->
    <el-button class="primary"
               type="primary"
               @click="deriveFun()">导出</el-button>

    <!-- 表格 -->
    <el-table v-loading="loading"
              :data="tableData"
              border
              style="width: 100%; margin-top: 25px">
      <el-table-column prop="ownerErbanNo"
                       align="center"
                       label="会长ID" />
      <el-table-column prop="name"
                       align="center"
                       label="公会名称" />
      <el-table-column prop="ownerPartitionName"
                       align="center"
                       label="会长分区" />
      <el-table-column prop="enable"
                       align="center"
                       label="是否有效状态">
        <template v-slot="scope">{{ scope.row.enable? '是': '否' }}</template>
      </el-table-column>
      <el-table-column prop="memberNum"
                       align="center"
                       label="成员数" />
      <el-table-column prop="goldIncome"
                       align="center"
                       label="月金币收入(流水)" />
      <el-table-column prop="goldWage"
                       align="center"
                       label="金币工资" />
      <el-table-column prop="agentWage"
                       align="center"
                       label="代理工资" />
      <el-table-column prop="diamondRemain"
                       align="center"
                       label="当前钻石余额">
        <template v-slot="scope">{{ scope.row.diamondRemain }}</template>
      </el-table-column>
      <el-table-column align="center"
                       label="操作"
                       width="260">
        <template v-slot="scope">
          <el-button @click="ediClick(scope.row)"
                     class="primary"
                     type="primary"
                     size="default">查看详情</el-button>
          <el-button @click="deriveFun2(scope.row)"
                     class="primary"
                     type="primary"
                     size="default">导出</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 内嵌单个工会详情 -->
    <el-dialog :title="detailsTitle"
               v-model="detailsDialog">
      <el-table v-loading="loading"
                :data="tableDataDetails"
                border
                style="width: 100%; margin-top: 25px">
        <el-table-column prop="erbanNo"
                         align="center"
                         label="用户平台ID">
          <template v-slot="scope">
            {{
              scope.row.erbanNo == scope.row.familyOwnerErbanNo
                ? scope.row.erbanNo + "(会长)"
                : scope.row.enable
                ? scope.row.erbanNo
                : scope.row.erbanNo + "离开"
            }}
          </template>
        </el-table-column>
        <el-table-column prop="nick"
                         align="center"
                         label="用户昵称" />
        <el-table-column prop="micRemainTime"
                         align="center"
                         label="本月直播时长" />
        <el-table-column prop="micVaildDays"
                         align="center"
                         label="本月有效天数" />
        <el-table-column prop="goldIncome"
                         align="center"
                         label="月金币收入（流水）" />
        <el-table-column prop="goldWage"
                         align="center"
                         label="金币工资" />
        <el-table-column prop="agentWage"
                         align="center"
                         label="代理工资" />
        <el-table-column prop="diamondRemain"
                         align="center"
                         label="当前钻石余额" />
        <el-table-column align="center"
                         label="操作">
          <template v-slot="scope">
            <el-button @click="detailsClick(scope.row)"
                       class="primary"
                       type="primary"
                       size="default">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="detailsDialog = false">关闭</el-button>
          <el-button type="primary"
                     @click="detailsClickOut()">导出</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 内嵌单个成员明细 -->
    <el-dialog :title="detailsTitle2"
               v-model="detailsDialog2">
      <el-table v-loading="loading"
                :data="tableDataDetails2"
                border
                style="width: 100%; margin-top: 25px">
        <el-table-column prop="date"
                         align="center"
                         label="日期" />
        <el-table-column prop="micRemainTime"
                         align="center"
                         label="直播时长" />
        <el-table-column prop="micVaild"
                         align="center"
                         label="是否有效天">
          <template v-slot="scope">
            {{ scope.row.micVaild ? "是" : "否" }}
          </template>
        </el-table-column>
        <el-table-column prop="goldIncome"
                         align="center"
                         label="当日金币收入" />
        <el-table-column prop="savedGoldIncome"
                         align="center"
                         label="月累计金币收入" />
        <el-table-column prop="saveedGoldWage"
                         align="center"
                         label="月金币工资" />
        <el-table-column prop="diamondRemain"
                         align="center"
                         label="当日钻石余额" />
        <!-- <el-table-column align="center" label="操作">
          <template v-slot="scope">
            <el-button
              @click="detailsClick2(scope)"
              class="primary"
              type="text"
              size="default"
              :disabled="!scope.row.enable"
              >查看详情</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="detailsDialog2 = false">关闭</el-button>
          <el-button type="primary"
                     @click="detailsClickOut2()">导出</el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 分页 -->
    <el-pagination style="margin-top: 10px"
                   class="paginationClass"
                   v-model:current-page="currentPage"
                   v-model:page-size="pageSize"
                   :page-sizes="[10, 20, 30, 40, 50, 100, 200, 300, 400, 500, 999999999]"
                   layout="sizes, prev, pager, next"
                   :total="total"
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange" />
  </div>
</template>
<script>
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
import {
  statPageFamily,
  listFamilyMember,
  statExportFamilyMember,
  listFamilyMemberDaily,
  exportFamilyMemberDaily,
  statExportFamily,
} from "@/api/nobleman/nobleman";
// @ts-ignore
import { dateFormat } from "@/utils/system-helper";
// @ts-ignore
import { ElMessage } from "element-plus";
export default {
  name: "WagesCount",
  data () {
    return {
      zhCn,
      loading: false,
      //查询所需条件对象
      inquire: {
        time: "",
        nick: "",
        partitionId: 2,
        inquireonInfos: [
          { desc: "英语区", id: 1 },
          { desc: "阿拉伯区", id: 2 },
          { desc: "华语区", id: 4 },
        ],
      },
      // 表格
      tableData: [],
      // 分页
      total: 10, //总页数
      currentPage: 1, //页码
      pageSize: 10, //条数
      // 内嵌单个公会详情
      detailsDialog: false,
      detailsTitle: "工会昵称 时间段 结算明细",
      tableDataDetails: [],
      detailsClickOutObj: {},
      // 内嵌单个公会详情2
      detailsDialog2: false,
      detailsTitle2: "工会昵称 用户昵称（ID：0） 时间段 结算明细",
      tableDataDetails2: [],
      detailsClickOutObj2: {},
    };
  },
  created () {
    // this.getData();
  },
  methods: {
    // 查询接口
    getData () {
      // this.loading = true;
      let time = this.inquire.time;
      if (time) {
        time = dateFormat(this.inquire.time, "yyyy-MM");
      }
      statPageFamily({
        erbanNo: this.inquire.nick,
        partitionId: this.inquire.partitionId,
        month: time,
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      }).then((res) => {
        this.total = res.data.total;
        this.tableData = res.data.rows;
        this.loading = false;
      });
    },
    // 导出总外列表
    deriveFun (val) {
      let time = this.inquire.time;
      if (time) {
        time = dateFormat(this.inquire.time, "yyyy-MM");
      }
      statExportFamily({
        erbanNo: this.inquire.nick,
        month: time,
        partitionId: this.inquire.partitionId,
      }).then((res) => { });
    },
    // 导出列表最外层
    deriveFun2 (val) {
      statExportFamilyMember({
        familyId: val.id,
        month: dateFormat(this.inquire.time, "yyyy-MM"),
      });
      this.detailsDialog = false;
    },
    // 1层查看详情按钮
    ediClick (val) {
      console.log(val);
      var than = this;
      this.detailsClickOutObj = val;
      than.detailsTitle = `[${val.name}] [${dateFormat(
        than.inquire.time,
        "yyyy-MM"
      )}]结算明细`;
      listFamilyMember({
        familyId: val.id,
        month: dateFormat(than.inquire.time, "yyyy-MM"),
      }).then((res) => {
        this.tableDataDetails = res.data;
        this.detailsDialog = true;
      });
    },
    // 导出最外层数据按钮
    detailsClickOut () {
      statExportFamilyMember({
        familyId: this.detailsClickOutObj.id,
        month: dateFormat(this.inquire.time, "yyyy-MM"),
      });
      this.detailsDialog = false;
    },
    // 嵌套详情按钮
    detailsClick (val) {
      var than = this;
      this.detailsClickOutObj2 = val;
      than.detailsTitle2 = `公会名称：${val.familyName} 成员名称：${val.nick
        }（ID：${val.erbanNo}） ${dateFormat(
          than.inquire.time,
          "yyyy-MM"
        )} 结算明细`;
      listFamilyMemberDaily({
        familyId: val.familyId,
        month: dateFormat(than.inquire.time, "yyyy-MM"),
        uid: val.uid,
      }).then((res) => {
        than.tableDataDetails2 = res.data;
        than.detailsDialog2 = true;
      });
    },
    // 导出每日成员数据
    detailsClickOut2 () {
      exportFamilyMemberDaily({
        familyId: this.detailsClickOutObj2.id,
        month: dateFormat(this.inquire.time, "yyyy-MM"),
        uid: this.detailsClickOutObj2.uid,
      });
      this.detailsDialog2 = false;
    },
    // 分页导航
    handleSizeChange () {
      this.getData();
    },
    handleCurrentChange () {
      this.getData();
    },
  },
};
</script>
<style lang="less" scoped>
.box {
  padding-top: 20px;
  background: #ecf0f5;
  .inquire {
    display: inline-block;
    margin-right: 20px;
    span {
      margin-right: 10px;
    }
    .input {
      width: 180px;
      margin-right: 10px;
    }
  }
  .dialogTableVisibleBut {
    display: block;
    margin: 30px 0 0 830px;
  }
  .paginationClass {
    margin: 15px 0 5px 0px;
  }
}
</style>
