<template>
  <div class="studentDetails">
    <el-tabs v-model="tabType" @tab-click="handleClick">
      <el-tab-pane label="学员详情" name="1">
        <search-box-new
          ref="searchBox"
          :formData="formData"
          :formList="formList"
          @search="search"
          @init="search('init')"
          ><template slot="customize">
            <!-- <el-button
              v-if="ShowStatus === 3"
              type="success"
              size="small"
              @click="orderCheck(1, '')"
              >批量审核</el-button
            > -->
            <span style="color: rgb(110, 101, 198); margin-left: 14px"
              >共：{{
                tableData1.length > 0 ? tableData1[0].userCount : 0
              }}人；{{ total }}条</span
            >
          </template></search-box-new
        >
        <table-list
          ref="tableList"
          rowKey="orderGoodsId"
          :tableSets="computedTableSet(tableSet1, ShowStatus)"
          :tableData="tableData1"
          :navText="dialogNavText1"
        >
        </table-list>
        <pagination
          :total="total"
          :pageSize.sync="formData.pageSize"
          :currentPage.sync="formData.pageNum"
          @search="search"
        />
      </el-tab-pane>
      <el-tab-pane label="操作历史" name="2">
        <table-list
          :tableSets="tableSet2"
          :tableData="tableData2"
          :navText="dialogNavText2"
        >
        </table-list>
        <pagination
          :total="total"
          :pageSize.sync="formData.pageSize"
          :currentPage.sync="formData.pageNum"
          @search="search"
        />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import searchBoxNew from "@/components/searchBoxNew";
import { exportFn } from "@/utils/index.js";
import tableList from "@/components/tableList";
import pagination from "@/components/pagination";
export default {
  name: "SaasMasterPlatformStudentDetails",
  components: {
    tableList,
    pagination,
    searchBoxNew,
  },
  props: {
    orderSn: {
      type: String,
    },
    orderFrom: {
      type: Number,
    },
    ShowStatus: {
      type: Number,
      default: 0,
    },
    checkStatus: {
      type: Number,
      default: null,
    },
  },
  data() {
    return {
      //搜索
      formList: [
        {
          prop: "checkStatus",
          placeholder: "订单状态",
          scope: "select",
          options: [
            { label: "待审核", value: 0 },
            { label: "已通过", value: 1 },
          ],
        },
        {
          prop: "userName",
          placeholder: "姓名",
        },
        {
          prop: "userCard",
          placeholder: "身份证号",
        },
      ],
      formData: {
        pageSize: 10,
        pageNum: 1,
      },
      tableSet1: [
        {
          label: "姓名",
          prop: "userName",
          hidden: true,
        },
        {
          label: "身份证号",
          prop: "userCard",
          hidden: true,
        },
        {
          label: "手机号",
          prop: "userPhone",
          hidden: true,
        },
        {
          label: "课程",
          prop: "goodsName",
          hidden: true,
        },
        {
          label: "年份",
          prop: "year",
          hidden: true,
        },
        {
          label: "专业",
          prop: "majorName",
          hidden: true,
        },
        {
          label: "原价(元)",
          prop: "goodsPrice",
          scope: "toFixedYuan",
          hidden: true,
        },
        {
          label: "单价(元)",
          prop: "goodsRealPrice",
          scope: "toFixedYuan",
          hidden: true,
        },
        {
          label: "学习状态",
          prop: "studyStatus",
          hidden: true,
        },
        {
          label: "审核状态",
          prop: "checkStatus",
          hidden: true,
          scope: "isOptions",
          options: [
            {
              label: "待审核",
              value: 0,
            },
            {
              label: "已通过",
              value: 1,
            },
            {
              label: "未通过",
              value: 2,
            },
            {
              label: "已撤销",
              value: 3,
            },
            {
              label: "已取消",
              value: -1,
            },
          ],
        },
        {
          label: "发起原因",
          prop: "refundReason",
          hidden: true,
        },
        {
          label: "审核意见",
          prop: "checkReason",
          hidden: true,
          style: { color: "red" },
        },
      ],
      tableData1: [],
      tableSet2: [
        {
          label: "时间",
          prop: "createTime",
          hidden: true,
          scope: "aTimeList",
        },
        {
          label: "操作者",
          prop: "createBy",
          hidden: true,
        },
        {
          label: "动作",
          prop: "action",
          hidden: true,
          scope: "isOptions",
          options: [
            {
              label: "修改",
              value: "update",
            },
            {
              label: "新增",
              value: "insert",
            },
            {
              label: "删除",
              value: "delete",
            },
          ],
        },
        {
          label: "字段",
          prop: "field",
          hidden: true,
        },
        {
          label: "操作前",
          prop: "fieldBefore",
          hidden: true,
        },
        {
          label: "操作后",
          prop: "fieldAfter",
          hidden: true,
        },
      ],
      tableData2: [],
      dialogNavText1: {
        index: 0,
        num: true,
        border: true,
        choice: false,
        choiceRadio: false,
        openCheckMore: true,
        radioKey: "specTemplateId",
        radioFixed: false,
        addHide: !false,
        tableHide: true,
        dontNum: false,
        headShow: false,
        tableColor: true,
        tableColorFunc: (row, rowIndex) => {
          if (row.checkStatus === -1) {
            return "info-row";
          }
          return "";
        },
        selectableStatus: true,
        selectableFunc: (row, rowIndex) => {
          if (row.checkStatus === 0) {
            return true;
          } else {
            return false;
          }
        },
        backFatherBtn: {
          status: false,
          title: "未定义",
        },
      },
      dialogNavText2: {
        index: 0,
        num: true,
        border: true,
        choice: false,
        choiceRadio: false,
        radioKey: "specTemplateId",
        radioFixed: false,
        addHide: !false,
        tableHide: true,
        dontNum: false,
        headShow: false,
        backFatherBtn: {
          status: false,
          title: "未定义",
        },
      },
      formData: {
        pageSize: 10,
        pageNum: 1,
      },
      total: 0,
      tabType: "1",
    };
  },
  created() {
    this.search("init");
    if (!this.ShowStatus) {
      this.dialogNavText1.choice = false;
    }
  },
  computed: {
    computedTableSet: function () {
      return function (array, num) {
        let copyArray = JSON.parse(JSON.stringify(array))
        if (num === 3) {
          let data = [
            {
              label: "实际单价",
              prop: "tt",
              hidden: true,
            },
            {
              label: "分成类型",
              prop: "tt",
              hidden: true,
            },
            {
              label: "分成计算",
              prop: "tt",
              hidden: true,
            },
            {
              label: "分成金额",
              prop: "tt",
              hidden: true,
            },
          ];
          copyArray.splice(array.length - 1, 1, ...data);
        }
        return copyArray;
      };
    },
  },
  methods: {
    exportData() {
      this.$api.systemtoporderstudentexport(this.formData).then((res) => {
        if (res.msg) {
          exportFn(res.msg, `导出数据`);
        } else {
          this.$message.error("导出失败");
        }
      });
    },
    orderCheck(e, ch) {
      return;
      if (this.$refs.tableList.allCheckData.length === 0) {
        this.$message.error("请勾选数据");
        return;
      }
      this.$confirm(`确定学员${ch}审核通过吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api
            .systemtopordercheckstudent({
              checkStatus: e,
              orderSn: this.orderSn,
              orderGoodsIds: this.$refs.tableList.allCheckData.map(
                (i) => i.orderGoodsId
              ),
            })
            .then((res) => {
              this.search("init");
              this.$message.success("操作成功");
              this.$emit("parentsSearch");
            });
        })
        .catch(() => {});
    },
    search(e) {
      if (e === "init") {
        this.formData = {
          pageSize: 10,
          pageNum: 1,
          orderSn: this.orderSn,
          orderFrom: this.orderFrom,
        };
        this.$nextTick(() => {
          this.$refs.tableList.clearMoreActive();
        });
      }
      this.$api[
        this.tabType === "1" ? "systemtopordergoodslist" : "systemtoporderlog"
      ](this.formData).then((res) => {
        if (this.tabType === "1") {
          this.tableData1 = res.rows;
          this.total = res.total;
        }
        if (this.tabType === "2") {
          this.tableData2 = res.rows;
          this.total = res.total;
        }
      });
    },
    handleClick(tab) {
      this.search("init");
    },
  },
};
</script>

<style lang="scss" scoped>
.studentDetails {
  margin-top: 10px;
  #tableList {
    padding: 0;
  }
}
/deep/ .el-input--small .el-input__inner {
  width: 120px;
}
</style>
