<template>
    <div class="page">
        <LayoutTable :data="tableData" :config="tableConfig">
                    </LayoutTable>

      <el-dialog
          title="学习列表"
          width="50%"
          :visible.sync="dialogTableVisible"
      >
        <el-table

            :data="openProjectData.data"
            max-height="500px">
          <el-table-column  type="index" label="序号"></el-table-column>
          <el-table-column prop="userName" label="学员名称"></el-table-column>
          <el-table-column prop="deptName" label="所属部门"></el-table-column>

          <el-table-column prop="studyStatus" label="学习状态" >
            <template slot-scope="scope">
            <span style="margin-left: 10px">{{
                formatterString(scope.row, scope.column,scope.row.studyStatus)
              }}</span>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页器 -->
        <el-row type="flex" justify="end">
          <el-pagination
              @current-change="handleCurrentChange"
              @size-change="handleSizeChange"
              :current-page="openProjectData.pageInfo.currPage"
              :page-size="openProjectData.pageInfo.prePageResult"
              :page-sizes="[10, 20, 50, 100, 200]"
              layout="sizes, total, prev, pager, next, jumper"
              :total="openProjectData.pageInfo.totalResult"
          >
          </el-pagination>
        </el-row>
      </el-dialog>
        <dialog-show ref="dialogform" @ok="getData" />
    </div>
</template>

<script>
    /** 表单弹出框模式需引入 */
    import dialogShow from "./dialogshow";
    import table from "@/assets/mixins/table";
    export default {
        name: "ProjectList",
        components: {
            dialogShow
},
        mixins: [table],
        created() {
        },
        methods: {
          handleSizeChange(currSize) {
            console.log("currSize=" + currSize);
            this.openProjectData.pageInfo.prePageResult = currSize;
            this.getStudyPersonList(this.searchform);
          },
          handleCurrentChange(currPage) {
            console.log("handleCurrentChange=" + currPage);
            this.openProjectData.pageInfo.currPage = currPage;
            this.getStudyPersonList(this.searchform);
          },

          getStudyPersonList(query) {
            query["page"] = this.openProjectData.pageInfo.currPage;
            query["size"] =
                this.openProjectData.pageInfo.prePageResult;

            this.loading = true;
            query["projectId"] = this.projectId;

            this.$post("/project/study/list", query, {})
                .then((res) => {
                  if (res && res.code && res.code == 1) {
                    this.loading = false;
                    this.openProjectData = res.data;
                  }
                })
                .catch((error) => {
                  this.$message.error(error.message);
                });
          },
            /** 重写新增方法 */
            toAdd(row) {
                this.$refs.dialogform.add(row);
            },
            /** 重写编辑方法 */
            toEdit(row) {
                this.$refs.dialogform.edit(row);
            },
            /** 重写查看方法 */
            toView(row) {
                this.$refs.dialogform.view(row);
            },
          toOpenStudy(row) {
            this.projectId = row.id;
            let query = {};
            query["projectId"] = row.id;

            this.$post("/project/study/list", query, {})
                .then((res) => {
                  this.openProjectData = res.data;
                  console.log("res",res)
                  this.dialogTableVisible = true;
                })
                .catch((error) => {
                  this.$message.error(error.message);
                });
          },
        },
        data() {
            return {
              projectId:0,
              openProjectData: {
                data:[],
                pageInfo: {
                  totalResult: 0,
                  prePageResult: 20,
                },
              },
              dialogTableVisible: false,
                config: {
                    search: [
                        {
                            name: "projectType",
                            type: "select",
                            label: "项目类型",
                        },
                        {
                            name: "title",
                            type: "text",
                            label: "标题",
                            fuzzy: true
                        },
                    ],
                    columns: [
                        {type: "selection", width: 60},
                        {type: "index",label: "序号",width: 50},

                        {label: "标题", prop: "title"},

                        {label: "项目类型", prop: "projectType",formatter: this.formatter},

                      {label: "开始时间", prop: "projectStartTime",formatter: this.formatterDate},

                      {label: "截止时间", prop: "projectEndTime",formatter: this.formatterDate},

                      {label: "学习人数", prop: "studyPersonRadio",

                        formatter: (row) => {
                          return (
                              <el-button
                                  type="text"
                                  onClick={() => {
                                    this.toOpenStudy(row);
                                  }}
                              >
                                {row.studyPersonRadio ? row.studyPersonRadio : 0/0}
                              </el-button>
                          );
                        }
                        },

                      {label: "发布时间", prop: "createTime",formatter: this.formatterDate},

                        {label: "发布人", prop: "createUserId", formatter: this.formatter},
                        {
                            label: "操作",
                            width: 240,
                            formatter: row => {
                                return (
                                    <table-buttons noAdd row={row} onEdit={this.toEdit} onView={this.toView} onDel={this.toDel} />
                            );
                            }
                        }
                    ]
                }
            };
        }
    };
</script>
