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


        <dialog-show ref="dialogform" @ok="getData" />
    </div>
</template>

<script>
    /** 表单弹出框模式需引入 */
    import dialogShow from "./dialogshow";
    import table from "@/assets/mixins/table";
    export default {
        name: "NoticeList",
        components: {
            dialogShow
},
        mixins: [table],
        created() {
        },
        methods: {
            /** 重写新增方法 */
            toAdd(row) {
                this.$refs.dialogform.add(row);
            },
            /** 重写编辑方法 */
            toEdit(row) {
                this.$refs.dialogform.edit(row);
            },
            /** 重写查看方法 */
            toView(row) {
                this.$refs.dialogform.view(row);
            },
          toOpenStudy(row) {
            this.noticeId = row.id;
            let query = {};
            query["noticeId"] = row.id;

            this.$post("/notice/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 {
              noticeId:0,
              openProjectData: {
                data:[],
                pageInfo: {
                  totalResult: 0,
                  prePageResult: 20,
                },
              },
              dialogTableVisible: false,
                config: {
                    search: [

                      {
                        name: "noticeType",
                        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: "noticeType",formatter: this.formatter},

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

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

                      {label: "发布部门", prop: "pubDeptId", formatter: this.formatter},

                      {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>
