<template>
    <div class="g-main">
        <div class="m-search">
            <el-form :inline="true" ref="ref_searchform" :label-width="'100px'">
                <div>
                    <el-form-item label="标题">
                        <el-input v-model.trim="formData.title" size="small" class="item_width_1" clearable
                            placeholder="请输入">
                        </el-input>
                    </el-form-item>
                    <el-form-item label="发布时间">
                        <el-date-picker v-model="formData.releaseTime" type="datetime" placeholder="开始时间"
                            format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss">
                        </el-date-picker>
                    </el-form-item>

                    <el-form-item label="状态">
                        <el-select v-model="formData.online" placeholder="请选择" clearable>
                            <el-option v-for="item in onlineList" :key="item.value" :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="所属栏目">
                        <el-select v-model="formData.columnId" placeholder="请选择" clearable>
                            <el-option v-for="item in optionstype" :key="item.value" :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </div>
                <div class="block">
                    <div style="display: flex; justify-content: flex-end;">
                        <el-button style="margin-left:10px" class="diy-button--blue" size="small"
                            @click="handleSearch">查询</el-button>
                        <el-button style="margin-left:10px" class="diy-button--white" size="small"
                            @click="resetSearch">重置</el-button>
                    </div>
                </div>
            </el-form>
        </div>
        <div class="m-table">
            <el-button style="" class="diy-button--add" size="small" @click="handleAdd">新增</el-button>
            <!-- <el-button class="diy-button--white" size="small">
                <el-upload :headers="$getElUploadHeaders()" ref="upload" class="upload-btn" action="uploadUlr"
                    :limit="1" :accept="'.xls,.xlsx'" :with-credentials="true" :show-file-list="false"
                    :auto-upload="true" :on-progress="handleProgress" :on-success="handleExcelSuccess"
                    :before-upload="beforeExcelUpload" :http-request="uploadHttpRequest">
                    导入
                </el-upload>
            </el-button> -->
            <el-table class="table" :data="tableData" border style="width: 100%">
                <el-table-column label="序号" header-align="center" align="center" type="index"
                    width="80"></el-table-column>
                <el-table-column prop="releaseTime" header-align="center" align="center" label="发布时间"
                    :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="columnId" header-align="center" align="center" label="所属栏目"
                    :show-overflow-tooltip="true">
                    <template slot-scope="scope">
        <span>{{ scope.row.columnId === 1 ? '志愿风采' : '消息发布' }}</span>
      </template>
                </el-table-column>
                <el-table-column prop="title" header-align="center" align="center" label="标题"
                    :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="online" header-align="center" align="center" label="状态"
                    :show-overflow-tooltip="true">
                    <template slot-scope="scope">
        <span>{{ scope.row.online === 1 ? '下线' : '上线' }}</span>
      </template>
                </el-table-column>
                <el-table-column label="操作" fixed="right" width="350" header-align="center" align="center"
                    class="operate">
                    <template slot-scope="scope">
                        <el-button type="text" style="color:#1C6AFD;" size="small"
                            @click="handleDetail(scope.row)">查看</el-button>
                        <el-button type="text" style="color:#1C6AFD;" size="small"
                            @click="handleEdit(scope.row)">修改</el-button>
                        <el-button type="text" style="color:#1C6AFD;" size="small" v-if="scope.row.online === 0"
                            @click="handleupOnline(scope.row)">下线</el-button>
                        <el-button type="text" style="color:#1C6AFD;" size="small"
                            @click="handleupOnline(scope.row)" v-if="scope.row.online === 1">上线</el-button>
                        <el-button type="text" style="color:#1C6AFD;" size="small"
                            @click="handledelete(scope.row)">删除</el-button>
                        <!-- <el-button type="text" style="color:#1C6AFD;" size="small"
                            @click="handlerecruit(scope.row)">招募</el-button>
                        <el-button type="text" style="color:#1C6AFD;" size="small"
                            @click="handleprocessl(scope.row)">审核</el-button>
                            <el-button type="text" style="color:#1C6AFD;" size="small"
                            @click="handlerecord(scope.row)">记录</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <div>
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page.sync="pageNo" :page-sizes="[10, 20, 50]" :page-size="pageSize"
                    layout="sizes, prev, pager, next, total" :total="total">
                </el-pagination>
            </div>
            <el-dialog :visible.sync="showAdd" :close-on-click-modal="false" :close-on-press-escape="false" title="新增"
                width="850px" top="10vh" class="dialog-h" @closed="showAddClose">
                <add v-if="showAdd" @showAddClose="showAddClose" />
            </el-dialog>
            <el-dialog :visible.sync="showInfo" :close-on-click-modal="false" :close-on-press-escape="false" title="查看"
                width="850px" top="10vh" class="dialog-h" @closed="showInfoClose">
                <info v-if="showInfo" :infoList="infoList" @showInfoClose="showInfoClose" />
            </el-dialog>
            <el-dialog :visible.sync="showEdit" :close-on-click-modal="false" :close-on-press-escape="false" title="修改"
                width="850px" top="10vh" class="dialog-h" @closed="showEditClose">
                <edit v-if="showEdit" :EditList="EditList" @showEditClose="showEditClose" />
            </el-dialog>
            <!-- <el-dialog :visible.sync="showrecruit" :close-on-click-modal="false" :close-on-press-escape="false"
                title="招募" width="1000px" top="10vh" class="dialog-h" @closed="handlerecruitClose">
                <recruit v-if="showrecruit" :list="fmData" @handlerecruitClose="handlerecruitClose" />
            </el-dialog>
            <el-dialog :visible.sync="showprocess" :close-on-click-modal="false" :close-on-press-escape="false"
                title="审查" width="850px" top="10vh" class="dialog-h" @closed="handleprocesslClose">
                <process v-if="showprocess" @handleprocesslClose="handleprocesslClose" :VolunteerList="EditList" />
            </el-dialog>
            <el-dialog :visible.sync="showrecord" :close-on-click-modal="false" :close-on-press-escape="false"
                title="查看记录" width="850px" top="10vh" class="dialog-h" @closed="handleprocesslClose">
                <process v-if="showrecord" @handleprocesslClose="handleprocesslClose" :VolunteerList="EditList" />
            </el-dialog> -->
        </div>
    </div>
</template>

<script>
import { requestPost, requestGet } from "@/js/dai/request";
import nextTick from "dai-js/tools/nextTick";
import { mapGetters } from "vuex";
import add from "./add.vue"
import info from "./info.vue"
import edit from "./edit.vue"
import axios from "axios";
// import recruit from "./recruit"

// import process from "./process.vue"
// import Record from "./activeRecord"
// import integral from "./integral"
// //   import projectInfo from "./cpts/project-info";

export default {
    components: {
        add,edit,info
    },

    data() {
        return {
            onlineList:[
                { value: 0, label: "上线" },
                { value: 1, label: "下线" },
                
            ],
            optionstype: [
                    { value: 0, label: "消息发布" },
                    { value: 1, label: "志愿风采" },
            ],
            formData: {
                title:"",
                content:"",
                top:"",
                online:"",
                releaseTime:"",
               
            },
            showrecord:false,
            infoList:{},
            showrecruit:false,
            showprocess:false,
            EditList:{},
            showAdd: false,
            showMember: false,
            showEdit: false,
            //   pageType: "list", // 列表list 处理dispose 详情info 议题详情issue-info
            pageNo: 1,
            pageSize: 20,
            total: 1,
            tableData: [
                
          ],
          showInfo:false,

        };
      },
      computed: {
        maxTableHeight() {
          return this.$store.state.inIframe
            ? this.clientHeight - 400 + this.iframeHeigh
            : this.clientHeight - 400;
        },
        ...mapGetters(["clientHeight", "iframeHeight"]),
      },
      watch: {
    
      },
      mounted() {
        this.getTableData();
      },
      methods: {
        handlerecordClose(){
        this.showrecord=false 
        },
        //删除活动
        handledelete(row){
      console.log(row,"删除活动");
      let url=`/voluntary/newsTrends/deleteById/${row.id}`
      axios({
        url: window.SITE_CONFIG["apiURL"] + url,
        method: "DELETE",
      })
        .then((res) => {
         if(res.code==0){
          this.$message.success("删除成功")
          this.getTableData()
        }else{
          this.$message.error(res.msg)
        }
        })
    //   requestGet(url).then((res)=>{
    //     if(res.code==0){
    //       this.$message.success("删除成功")
    //       this.getTableData()
    //     }else{
    //       this.$message.error(res.msg)
    //     }
    //   })
    },
         //活动上下线
         handleupOnline(row){
          console.log(row,"row");
          if (row.online==1) {
            row.online=0
            
          }else{
            row.online=1
          }
          let url="/voluntary/newsTrends/onlineOrDownLine",
          params={
            id:row.id,
            online:row.online
          }
          requestPost(url,params).then(res=>{
            console.log(res);
            this.getTableData()
            
          })
          
        },
        //修改
        handleEdit(row){
            this.showEdit=true,
            this.EditList=row
             console.log(row,this.EditList,"row");
        },
        //关闭修改
        showEditClose(){
            this.showEdit=false
        },
        //新增
        handleAdd(){
            this.showAdd=true
        },
        //关闭新增
        showAddClose(){
            console.log("sdlkfjklsdf1");
            this.showAdd=false
            this.getTableData()
        },
                //查看
          handleDetail(row) {
              this.showInfo = true
              this.infoList = row
              console.log(this.infoList, "fmData");

          },

        //关闭查看
        showInfoClose(){
            this.showEdit=false
        },
        //查询列表
        async getTableData() {
            console.log("sdlkkj");
          const url = "/voluntary/newsTrends/list";
  
          let params={
            ...this.formData,
            pageSize:this.pageSize,
            pageNo:this.pageNo,
          }
          const { data, code, msg } = await requestPost(url,params);
          if (code === 0) {
            console.log("列表请求成功！！！！！！！！！！！！！！");
            this.total = data.total || 0;
            this.tableData = data.list
          } else {
          }
        },
        //重置
        resetSearch(){
          this.formData=[]
        },

   

        handleSizeChange(val) {
          console.log(`每页 ${val} 条`);
          this.pageSize = val;
          window.localStorage.setItem("pageSize", val);
          this.getTableData();
        },
        handleCurrentChange(val) {
          console.log(`当前页: ${val}`);
          this.pageNo = val;
          this.getTableData();
        },
        //查询
        handleSearch(val) {
          console.log(this.fmData);
          this.pageNo = 1;
          this.getTableData();
        },


  
      },
    };
    </script>
    
    <style lang="scss" scoped>
    @import "@/assets/scss/modules/management/list-main.scss";
    .g-main {
            width: 100%;
          }
          .m-search {
            background: #ffffff;
            border-radius: 4px;
            padding: 30px 20px 5px;
            box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.1);
          }
          .item_width_1 {
            width: 260px;
          }
          .item_width_2 {
            width: 495px;
          }
          .m-table {
            background: #ffffff;
            box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.1);
            border-radius: 4px;
            margin-top: 15px;
            padding: 23px 30px 10px;
            .table {
              margin-top: 20px;
            }
          }
          .div_btn {
            display: flex;
            justify-content: space-between;
          }
          .el-row {
            /* margin-bottom: 20px; */
            display: flex;
            flex-wrap: wrap;
            margin-top: 10px;
            margin-right: 50px;
          }
        
    
    </style>
    