<!--
 * @Descripttion: 
 * @version: 
 * @Author: 王三华
 * @Date: 2024-04-28 09:50:13
-->
<template>
  <div class="page" v-loading="loadingAll" element-loading-text="拼命加载中">
    <!-- <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar> -->
    <div class="topbox">
      <div
        class="levelList_i"
        :class="tabActive == item.id || item.isDisplayRed == 0 ? 'act' : ''"
        v-for="(item, index) in topList"
        :key="index"
        @click.prevent="handleLink(item)"
      >
        {{ item.settleDate }}
      </div>
    </div>
    <div class="main">
      <div class="form_all">
        <el-form ref="select" :model="select" label-width="auto">
          <el-row :gutter="10">
            <el-col :span="4">
              <el-form-item label="体系名称">
                <el-input clearable v-model="select.vertexName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="会员编号">
                <el-input clearable v-model="select.memberCode"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="会员名称">
                <el-input clearable v-model="select.memberName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button type="primary" @click="getList">
                {{ '搜索' }}</el-button
              >
              <el-button type="" @click="reset"> {{ '重置' }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="small" @click="addSave" class="exportBtn">
            新增</el-button
          >
          <el-button size="small" @click="remarkCirl" class="exportBtn">
            重算</el-button
          >
          <el-button
            size="small"
            @click="openDig"
            class="addBtn"
            v-if="tabActive == 0"
            >公布</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          height="700px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column align="center" prop="vertexName" label="体系名称" />
          <el-table-column align="center" prop="memberCode" label="会员编号" />
          <el-table-column align="center" prop="memberName" label="会员名称" />
          <el-table-column align="center" prop="dayAchieve" label="当日业绩" />
          <el-table-column align="center" prop="dayBonus" label="当日奖金" />
          <el-table-column align="center" prop="yesDayRatio" label="当日波比">
            <template slot-scope="scope">
              <div :class="scope.row.yesDayRatio > 65 ? 'redColor' : ''">
                {{ scope.row.yesDayRatio }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="curDayRatio" label="重算波比">
            <template slot-scope="scope">
              <div :class="scope.row.curDayRatio > 65 ? 'redColor' : ''">
                {{ scope.row.curDayRatio }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="monthAchieve"
            label="当月业绩"
          />
          <el-table-column align="center" prop="monthBonus" label="当月奖金" />
          <el-table-column align="center" prop="monthRatio" label="当月波比">
            <template slot-scope="scope">
              <div :class="scope.row.monthRatio > 65 ? 'redColor' : ''">
                {{ scope.row.monthRatio }}
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="addTouch" label="新增碰次" />
          <el-table-column
            align="center"
            prop="expandNumber"
            label="拓展次数"
          />
          <el-table-column align="center" prop="expandRatio" label="4-n比例" />
          <el-table-column
            align="center"
            prop="creationTime"
            label="创建时间"
          />
          <el-table-column
            align="center"
            :label="'操作'"
            width="150"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button @click="updateRow(scope.row)" type="text" size="small">
                修改
              </el-button>
              <el-button
                @click="details(scope.row)"
                type="text"
                size="small"
                style="color: #48b2fd"
              >
                详情
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 明细 -->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogVisible"
      title="详情"
      width="60%"
      center
      :before-close="handleClose"
    >
      <el-table
        :data="tableData1"
        height="500px"
        v-loading="loading1"
        style="width: 100%"
        :header-cell-style="{ background: '#EEEEEE' }"
        :row-class-name="tableRowClassName"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column align="center" prop="vertexName" label="体系名称" />
        <el-table-column align="center" prop="memberCode" label="会员编号" />
        <el-table-column align="center" prop="memberName" label="会员名称" />
        <el-table-column align="center" prop="dayAchieve" label="当日业绩" />
        <el-table-column align="center" prop="dayBonus" label="当日奖金" />
        <el-table-column align="center" prop="yesDayRatio" label="当日波比" />
        <el-table-column align="center" prop="curDayRatio" label="重算波比" />
        <el-table-column align="center" prop="monthAchieve" label="当月业绩" />
        <el-table-column align="center" prop="monthBonus" label="当月奖金" />
        <el-table-column align="center" prop="monthRatio" label="当月波比" />
        <el-table-column align="center" prop="addTouch" label="新增碰次" />
        <el-table-column align="center" prop="expandNumber" label="拓展次数" />
        <el-table-column align="center" prop="expandRatio" label="4-n比例" />
        <el-table-column align="center" prop="creationTime" label="创建时间" />
      </el-table>
      <pagination
        v-show="total1 > 0"
        :total="total1"
        :page.sync="queryParams1.pageNum"
        :limit.sync="queryParams1.pageSize"
        @pagination="getDetails"
      />
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose1">{{ '取消' }}</el-button>
      </span>
    </el-dialog>
    <!-- 修改 -->
    <el-dialog
      :close-on-click-modal="false"
      :visible.sync="dialogVisible1"
      :title="titles"
      width="30%"
      center
      :before-close="handleClose1"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="auto">
        <el-row :gutter="10" v-if="titles == '修改'">
          <el-col :span="24">
            <el-form-item label="新增碰次" prop="addTouch">
              <el-input
                clearable
                v-model="form.addTouch"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="拓展次数" prop="expandNumber">
              <el-input
                clearable
                v-model="form.expandNumber"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="4-n比例" prop="expandRatio">
              <el-input
                clearable
                v-model="form.expandRatio"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="10" v-if="titles == '新增'">
          <el-col :span="24">
            <el-form-item label="结算日期" prop="settleDate">
              <el-date-picker
                v-model="form.settleDate"
                placeholder="请输入结算日期"
                type="date"
                value-format="yyyy-MM-dd"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="新增碰次" prop="addTouch">
              <el-input
                clearable
                v-model="form.addTouch"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="拓展次数" prop="expandNumber">
              <el-input
                clearable
                v-model="form.expandNumber"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="4-n比例" prop="expandRatio">
              <el-input
                clearable
                v-model="form.expandRatio"
                :placeholder="'请输入'"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose1">{{ '取消' }}</el-button>
        <el-button
          v-if="titles == '新增'"
          type="primary"
          @click="onSubmits('form')"
          >{{ '确认' }}</el-button
        >
        <el-button
          v-if="titles == '修改'"
          type="primary"
          @click="onSubmit('form')"
          >{{ '确认' }}</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import * as api from "@/api/settle.js";
import * as gift from "@/api/giftGoods.js";
export default {
  name: "Bzpz",
  components: {
    topBar,
  },
  data() {
    return {
      topList: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
      },
      // 查询参数
      queryParams1: {
        pageNum: 1,
        pageSize: 50,
      },
      total: 0,
      total1: 0,
      dialogVisible1: false,
      dialogVisible: false,
      tableData: [],
      tableData1: [],
      loading: false,
      form: {},
      titles: "",
      rules: {
        addTouch: [
          { required: true, message: '请输入', trigger: "blur" },
        ],
        expandRatio: [
          { required: true, message: this.$t("4-n比例"), trigger: "blur" },
        ],
      },
      loading: false,
      loading1: false,
      loadingAll: false,
      tabActive: 0,
      settleDate: "",
      pkParent: "",
    };
  },
  mounted() {
    this.getTitle();
  },
  methods: {
    addSave() {
      this.dialogVisible1 = true;
      this.titles = "新增";
      this.form = {};
    },
    getTitle() {
      api.queryTitle().then((res) => {
        res.rows.forEach((item, index) => (item.id = index));
        this.topList = res.rows;
        this.settleDate = this.topList[0].settleDate;
        // 获取列表
        this.getList();
      });
    },
    handleLink(item) {
      this.tabActive = item.id;
      this.settleDate = item.settleDate;
      this.getList();
    },
    onSubmits(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let obj = {
            addTouch: this.form.addTouch,
            expandRatio: this.form.expandRatio,
            settleDate: this.form.settleDate,
            expandNumber: this.form.expandNumber,
          };
          api.touchSave(obj).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.dialogVisible1 = false;
              // 获取列表
              this.getList();
              this.$refs[formName].resetFields();
              this.$refs[formName].clearValidate();
            }
          });
        } else {
          return false;
        }
      });
    },
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let obj = {
            pkId: this.form.pkId,
            addTouch: this.form.addTouch,
            expandRatio: this.form.expandRatio,
            settleDate: this.settleDate,
            expandNumber: this.form.expandNumber,
          };
          api.touchSave(obj).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.dialogVisible1 = false;
              // 获取列表
              this.getList();
              this.$refs[formName].resetFields();
              this.$refs[formName].clearValidate();
            }
          });
        } else {
          return false;
        }
      });
    },
    reset() {
      this.select = {};
      this.getList();
    },
    openDig() {
      this.loadingAll = true;
      api
        .settleBonus({
          settleDate: this.settleDate,
        })
        .then((res) => {
          this.loadingAll = false;
          // 获取列表
          this.getList();
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: "success",
            });
          } else {
            this.$message({
              message: res.msg,
              type: "warning",
            });
          }
        });
    },
    remarkCirl() {
      this.loadingAll = true;
      api
        .touchRepeat({
          settleDate: this.settleDate,
        })
        .then((res) => {
          this.loadingAll = false;
          // 获取列表
          this.getList();
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: "success",
            });
          } else {
            this.$message({
              message: res.msg,
              type: "warning",
            });
          }
        });
    },
    updateRow(row) {
      this.titles = "修改";
      this.form = row;

      this.dialogVisible1 = true;
    },
    getDetails() {
      this.loading1 = true;
      api
        .touchQuery(
          Object.assign({}, this.queryParams1, {
            pkParent: this.pkParent,
            settleDate: this.settleDate,
          })
        )
        .then((res) => {
          this.loading1 = false;
          this.tableData1 = res.rows;
          this.total1 = res.total;
        });
    },
    details(row) {
      this.pkParent = row.pkId;
      this.getDetails();
      this.dialogVisible = true;
    },
    getList() {
      this.loading = true;
      api
        .touchQuery(
          Object.assign({}, this.queryParams, this.select, {
            settleDate: this.settleDate,
          })
        )
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
          this.loading = false;
        });
    },
    handleClose() {
      this.dialogVisible = false;
    },
    handleClose1() {
      this.dialogVisible1 = false;
    },
    handleSelectionChange(val) {},

    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>
<style scoped lang="scss">
.topbox {
  align-items: center;
  // height:74px;
  padding: 0px 0 3px 0;
  display: flex;
  //   background: skyblue;
  .levelList_i {
    padding: 4px 15px;
    margin-left: 20px;
    position: relative;
    cursor: pointer;
    min-width: 88px;
    // height: 28px;
    border-radius: 17px;
    border: 1px solid #cccccc;
    font-size: 12px;
    font-family: MicrosoftYaHei;
    text-align: center;
    font-weight: 600;
    // line-height: 28px;
  }
}
.act {
  color: #ffffff;
  background: #c8161d;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}

::v-deep .el-table thead {
  color: #000000;
}

::v-deep .el-select {
  width: 100%;
}

.uploadIcon ::v-deep .el-upload--picture-card {
  display: none !important;
  /* 上传按钮隐藏 */
}

.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;

  .main {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .form_all {
      padding: 0px 20px 0 20px;
      // margin-bottom: 20px;
      background: #fff;
      border-radius: 8px;
    }

    .maintop {
      display: flex;
      padding: 0px 0px;
      justify-content: space-between;
      align-items: center;

      background: #f8f8f8;

      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
        }

        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
        }
      }

      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
  }

  .tem {
    display: flex;
    align-items: center;
    justify-content: center;

    img {
      width: 28px;
      height: 20px;
      margin-right: 3px;
    }
  }

  .isRed {
    color: #ed1d25;
  }

  .isGreen {
    color: #1ab62b;
  }

  .bgImg {
    width: 48px;
    height: 48px;
  }
}

.openClose {
  text-align: right;
  margin-right: 10px;
  color: #3181e5;
}

.dizhi {
  ::v-deep .el-cascader {
    width: 100%;
  }
}

::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto;
}

::v-deep .el-form-item {
  margin-bottom: 20px !important;
}

::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100% !important;
}

.blueCor {
  color: #589ff8;
  cursor: pointer;
}

::v-deep .el-input__icon {
  line-height: 33px;
}

::v-deep .el-button {
  margin-top: 0;
}
.redColor {
  color: #ed1d25;
}
</style>
