<template>
  <div class="app-container">
    <div v-show="viewState ==1">
      <el-tabs class="my-tabs" v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="论坛信息" name="roleList">
          <div class="container">
            <el-table :data="tableData" border style="width: 100%">
              <el-table-column label="序号" width="70px" type="index" align="center">
              </el-table-column>
              <el-table-column label="操作" width="150px" align="center">
                <template slot-scope="scope">
                  <el-button type="primary" size="mini" @click="editRow(scope.row)">
                    评论
                  </el-button>
                  <el-button type="danger" size="mini" @click.native.prevent="detail(scope.row)">
                    查看
                  </el-button>
                </template>
              </el-table-column>
              <el-table-column prop="type" label="论坛类别" align="center" />
              <el-table-column prop="title" label="论坛标题" align="center" />
              <el-table-column prop="content" label="论坛内容" align="center" />
            </el-table>
          </div>
        </el-tab-pane>

        <el-tab-pane label="论坛发布" name="addrole">
          <table class="e-table" cellspacing="0">
            <tr>
              <td>论坛类别</td>
              <td>
                <el-select v-model="form.type" class="addinputw" placeholder="请选择论坛类别" style="width:300px"
                  @change="getType">
                  <el-option v-for="item in typeList" :key="item.dictKey" :label="item.dictValue"
                    :value="item.dictKey" />
                </el-select>
              </td>
            </tr>
            <tr>
              <td>论坛标题</td>
              <td>
                <el-input v-model="form.title" style="width: 300px"></el-input>
              </td>
            </tr>
            <tr>
              <td>论坛内容</td>
              <td>
                <el-input v-model="form.content" style="width: 300px"></el-input>
              </td>
            </tr>
          </table>
          <div style="margin-top: 20px; text-align: center">
            <el-button type="primary" @click="save()">保存</el-button>
          </div>
        </el-tab-pane>
        <el-dialog :title="dialogTitle + '论坛信息'" :visible.sync="editDialog" width="40%">
          <table class="e-table" cellspacing="0">
            <tr>
              <td>论坛类别</td>
              <td>
                <!-- <el-select v-model="form.type" class="addinputw" placeholder="请选择论坛类别" style="width:300px"
             @change="getType">
             <el-option v-for="item in typeList" :key="item.dictKey" :label="item.dictValue"
               :value="item.dictKey" />
           </el-select> -->
                <span>{{form.type}}</span>
              </td>
            </tr>
            <tr>
              <td>论坛标题</td>
              <td>
                <span>{{form.title}}</span>
                <!-- <el-input v-model="form.title" style="width: 300px"></el-input> -->
              </td>
            </tr>
            <tr>
              <td>论坛内容</td>
              <td>
                <span>{{form.content}}</span>
                <!-- <el-input v-model="form.content" style="width: 300px"></el-input> -->
              </td>
            </tr>
            <tr>
              <td>评论内容</td>
              <td>
                <!-- <span>{{form.content}}</span> -->
                <el-input v-model="commentContent"></el-input>
              </td>
            </tr>
          </table>
          <div style="margin-top: 20px; text-align: center">
            <el-button type="primary" @click="save()">保存</el-button>
          </div>
        </el-dialog>
      </el-tabs>
    </div>
    <organizationManageInfo v-show="viewState ==4" ref="divInfo" @doback="resetState" />
  </div>
</template>

<script>
  import {
    selectSysForum,
    saveSysForum,
    alterSysForum,
    deleteSysForum,
    saveSysForumComment,
  } from "@/api/system/copyofprocess/liuchengchasongguanli.js";
  import organizationManageInfo from './organizationManageInfo.vue'
  export default {
    components: {
      organizationManageInfo,
    },
    data() {
      return {
        viewState: 1,
        activeName: "roleList",
        dialogTitle: "",
        editDialog: false,
        form: {},
        formBackup: Object.assign({}, this.form),
        tableData: [],
        commentContent: "", // 评论内容
        typeList: [{
            dictKey: "1",
            dictValue: "JAVA",
          }, {
            dictKey: "2",
            dictValue: "Python",
          }, {
            dictKey: "3",
            dictValue: "C++",
          }, {
            dictKey: "4",
            dictValue: "Excel",
          }, {
            dictKey: "5",
            dictValue: "英语四六级考试",
          }, {
            dictKey: "6",
            dictValue: "计算机等级考试",
          }

        ]
      };
    },
    mounted() {
      this.getPageList();
      console.log("sssssssssss", window.sessionStorage.getItem('userSid'))
    },
    methods: {
      getType(value) {
        console.log(">>>>>>>>>getType", value)
        const choose = this.typeList.filter((item) => item.dictKey === value)
        this.form.type = choose[0].dictValue
        // this.form.typeSid = choose[0].dictKey
      },
      getPageList() {
        // 获取列表
        selectSysForum().then((res) => {
          this.tableData = res.data;
        });
      },
      handleClick(tab, event) {
        if (tab.name == "addrole") {
          this.dialogTitle = "新增";
          this.roleForm = Object.assign({}, this.formBackup);
        } else {
          this.getPageList();
        }
      },
      save() {
        console.log("form", this.form)

        saveSysForumComment(

          {
            forumSid: this.form.sid,
            content: this.commentContent,
            createBySid: window.sessionStorage.getItem('userSid')
          }

        ).then((res) => {
          this.commentContent = ""
          this.editDialog = false;
          this.getPageList();
          this.$message({
            message: res.msg,
            type: "success",
          });
        });
      },
      resetState() {
        this.viewState = 1
      },
      editRow(row) {
        this.dialogTitle = "评论";
        this.editDialog = true;
        this.form = Object.assign({}, row);
      },
      detail(row) {
        this.viewState = 4
        this.$refs['divInfo'].showAdd(row)

      },
    },
  };
</script>

<style scoped="scoped" lang="scss">
  .my-tabs {
    margin-top: 10px;
  }
</style>