<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.content" class="item_width_1" clearable placeholder="请输入">
            </el-input>
          </el-form-item>
          <el-form-item label="活动时间">
            <el-date-picker v-model="formData.strTime" type="datetime" placeholder="开始时间" format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
            <span style="margin: 0 10px">至</span>
            <el-date-picker v-model="formData.endTime" 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 formData.optionsStatus" :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-table class="table" :data="tableData" border v-loading="tableLoading" style="width: 100%">
        <el-table-column label="序号" header-align="center" align="center" type="index" width="80"></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="address" header-align="center" align="center" label="活动地点"
          :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="strTime" header-align="center" align="center" label="活动时间" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span>{{ scope.row.strTime }}至{{ scope.row.endTime }}</span>
          </template>

        </el-table-column>
        <el-table-column prop="deadline" header-align="center" align="center" label="报名截止时间"
          :show-overflow-tooltip="true">

        </el-table-column>
        <el-table-column prop="agencyName" header-align="center" align="center" label="主办方"
          :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column prop="updatedTime" header-align="center" align="center" label="发布时间"
          :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column prop="statusType" header-align="center" align="center" label="状态"
          :show-overflow-tooltip="true">
          <!-- <template slot-scope="scope">
            <span>{{ scope.row.online === 0 ? '下线' : '上线' }}</span>
          </template> -->
        </el-table-column>
        <el-table-column prop="Points" header-align="center" align="center" label="来源" :show-overflow-tooltip="true">
               <template slot-scope="scope">
            <span>{{ scope.row.client === 0 ? '管理端' : '移动端' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="Points" header-align="center" align="center" label="审核状态" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <span v-if="scope.row.auditStatus === 0">待审核</span>
            <span v-if="scope.row.auditStatus === 1">已通过</span>
            <span v-if="scope.row.auditStatus === 2">未通过</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="ActivityCount" header-align="center" align="center" label="所属项目">
        </el-table-column> -->
        <el-table-column label="操作" fixed="right" width="250" header-align="center" align="center" class="operate"
          :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <el-button type="text" v-if="scope.row.statusType=='未发布'&&scope.row.client !== 1" style="color:#1C6AFD;" size="small"
              @click="handleDetail(scope.row)">修改</el-button>
            <el-button type="text" style="color:#1C6AFD;" size="small" @click="handleselect(scope.row)">查看</el-button>
            <el-button type="text"v-if="scope.row.auditStatus === 0" style="color:#1C6AFD;" size="small" @click="handleprocessl(scope.row)">审核</el-button>
            <el-button v-if="scope.row.online === 1 &&scope.row.statusType!='进行中'" 
              type="text" style="color:#1C6AFD;" size="small" @click="handleupOnline(scope.row)">下线</el-button>
            <el-button v-if="scope.row.online === 0 &&scope.row.statusType!='进行中'"  type="text" style="color:#1C6AFD;"
              size="small" @click="handleupOnline(scope.row)">上线</el-button>
            <!-- <el-button type="text" style="color:#1C6AFD;" size="small" @click="handleintegral(scope.row)">更多</el-button> -->
            <el-dropdown trigger="click" style="margin-left: 10px"   v-if="scope.row.client !== 1||scope.row.auditStatus==1" 
              @command="(command) => handelRegister(command, scope.row)">
              <el-button type="text">
                更多<i class="el-icon-arrow-down el-icon--right"></i>
              </el-button>
              <el-dropdown-menu split-button="true" slot="dropdown">
                <el-dropdown-item command="signup">报名管理</el-dropdown-item>
                <el-dropdown-item command="clockin">打卡积分</el-dropdown-item>
                <el-dropdown-item v-if="scope.row.statusType!='进行中'" command="delete">删除活动</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </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="add" :close-on-click-modal="false" :close-on-press-escape="false" title="新增"
        width="1200px" top="10vh" class="dialog-h" @closed="AddClose" v-if="add">
        <add :list="fmData" @AddClose="AddClose" />
      </el-dialog>
      <el-dialog :visible.sync="showselect" :close-on-click-modal="false" :close-on-press-escape="false" title="修改"
        width="1000px" top="10vh" class="dialog-h" @closed="updateClose" v-if="showselect">
        <selecthande :list="fmData" @updateClose="updateClose" />
      </el-dialog> 
      <el-dialog :visible.sync="showdeltail" :close-on-click-modal="false" :close-on-press-escape="false" title="查看"
        width="1000px" top="10vh" class="dialog-h" @closed="selectClose">
        <realselect v-if="showdeltail" :list="fmData" @selectClose="selectClose" />
      </el-dialog>
      <el-dialog :visible.sync="HandlePointsshow" :close-on-click-modal="false" :close-on-press-escape="false"
        title="打卡积分" width="1200px" top="10vh" class="dialog-h" @closed="diaClose">
        <Points v-if="HandlePointsshow" :list="fmData" />
      </el-dialog>
      <el-dialog :visible.sync="ActivityCountshow" :close-on-click-modal="false" :close-on-press-escape="false"
        title="报名管理" width="750" top="10vh" class="dialog-h" @closed="diaClose">
        <ActivityCountshow v-if="ActivityCountshow" :list="fmData" />
      </el-dialog>
      <el-dialog :visible.sync="showprocess" :close-on-click-modal="false" :close-on-press-escape="false" title="审核"
                width="750px" top="10vh" class="dialog-h" @closed="handleprocesslClose">
                <process v-if="showprocess" @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 axios from "axios";
    import add from "./add.vue"
    import ActivityCountshow from "./Administration.vue"
    import Points from "./Points.vue"
    import selecthande from "./select.vue"
    import realselect from "./realselect.vue"
    import process from "./process.vue"
    
    export default {
      components: {add,ActivityCountshow,Points,realselect,selecthande,process},
    
      data() {
        return {
          showdeltail:false,
          HandlePointsshow: false,
          ActivityCountshow: false,
          add: false,
          showselect:false,
          formData: {
            content: "",
            strTime: "",
            endTime: "",
            optionsStatus: [{
              value: 0,
              label: '下线'
            }, {
              value: 1,
              label: '上线 '
            },],
            online:'',
            title:""

          },
          integral: false,
          tableLoading: false,
          formShow: false,
          //   pageType: "list", // 列表list 处理dispose 详情info 议题详情issue-info
          pageNo: 1,
          pageSize:20,
          total: 1,
          tableData: [
          ],
          Record: false,
          fmData: [],
          showprocess:false,

        };
      },
      computed: {
        maxTableHeight() {
          return this.$store.state.inIframe
            ? this.clientHeight - 400 + this.iframeHeigh
            : this.clientHeight - 400;
        },
        ...mapGetters(["clientHeight", "iframeHeight"]),
      },
      watch: {
 
      },
      mounted() {
        this.getTableData();
       
      },
      methods: {
                //审核
                handleprocessl(row){
            this.showprocess=true
            this.EditList=row
            console.log(row,this.fmData,"row");
        },
                //关闭审核
        
                handleprocesslClose(){
              
            this.showprocess=false
            this.getTableData()
        },
        //新增关闭
      //   AddClose(){
      //   this.Record=false
      //   this.integral=false
      //   this.getTableData()
      // },
        //活动上下线
        handleupOnline(row){
          console.log(row,"row");
          if (row.online==1) {
            row.online=0
            
          }else{
            row.online=1
          }

          let url="/voluntary/activityInfo/online",
          params={
            id:row.id,
            online:row.online
          }
          requestPost(url,params).then(res=>{
            console.log(res);
            this.getTableData()
            
          })
          
        },
        //查询
        handleSearch(){
          console.log("this.long");
          console.log(this.formData,"this.long");
          this.pageNo=1
          this.getTableData()
          
        },
        //活动列表
        async getTableData() {
        // const url = "http://yapi.elinkservice.cn/mock/245/gov/project/project/project-list";
        const url = "/voluntary/activityInfo/list";
        let params = {
          pageNo: this.pageNo,
          strTime:this.formData.strTime,
          content:this.formData.content,
          pageSize:this.pageSize,
          statusType:this.formData.statusType,
          endTime:this.formData.endTime,
          online:this.formData.online,
          // district: this.$store.state.user.agencyId,
      }
      requestPost(url, params).then((res) => {
        if (res.code == 0) {
          this.total = res.data.total || 0;
          this.tableData = res.data.list;
          console.log(this.tableData, "this.tableData");
        } else {
          this.$message.error(res.msg);
        }
      });
        // const { data, code, msg } = await requestGet(url, params)
        // if (code === 0) {
        //   console.log("列表请求成功！！！！！！！！！！！！！！");
        //   this.total = data.total || 0;
        //   this.tableData = data.list
        //   console.log(this.tableData,"this.tableData");
          
    
        // } else {
        // }
      },
        handelRegister(command, row) {
      if (command == "signup") {
        this.HandleRegistration(row);
      } else if (command == "clockin") {
        this.HandlePoints(row);
      } else if (command == "delete") {
        this.handledelete(row);
      }
    },
    handledelete(row){
      console.log(row,"删除活动");
      let url=`/voluntary/activityInfo/delete/${row.id}`
      requestGet(url).then((res)=>{
        if(res.code==0){
          this.$message.success("删除成功")
          this.getTableData()
        }else{
          this.$message.error(res.msg)
        }
      })
    },
        //分页
        handleCurrentChange(val) {
          console.log(`当前页: ${val}`);
          this.pageNo = val;
          this.getTableData();
        },
        //新增活动
        addActivity() {
          this.add = true
      requestGet()
    },
        HandleRegistration(row){
          this.fmData=row
          console.log(row,"报名管理");
          this.ActivityCountshow=true
        },
        HandlePoints(row){
          console.log(row,"打卡积分");
          this.fmData=row
          this.HandlePointsshow=true
        },
        handleTimeChange (time) {
        if (time) {
          const startTimeArray = util.dateFormatter(time[0], 'date').split('-')
          const endTimeArray = util.dateFormatter(time[1], 'date').split('-')
  
          this.formData.startTime = startTimeArray[0] + '-' + startTimeArray[1] + '-' + startTimeArray[2] + ' 00:00:00'
          this.formData.endTime = endTimeArray[0] + '-' + endTimeArray[1] + '-' + endTimeArray[2] + ' 23:59:59'
        } else {
          this.formData.startTime = ''
          this.formData.endTime = ''
        }
      },
  
        handleintegral(row){
          this.integral=true
          console.log(row,"row");
        },
        diaClose(){
          this.formShow=false
        },
        AddClose(){
          console.log("sdkjksd");
          
          this.add=false
          this.getTableData()
        },
        updateClose(){
          console.log("sdkjksd");
          this.showselect=false
          this.getTableData()
        },
        selectClose(){
          console.log("sdkjksd");
          this.showdeltail=false
          this.getTableData()
        },
        resetSearch(){
          this.formData=[]
          this.getTableData()
        },
        handleDetail(row){
          console.log(row,"row");
          this.showselect=true
          this.fmData=row
  
        },
        handleselect(row){
          console.log(row,"row");
          this.showdeltail=true
          this.fmData=row
  
        },
   
    
   
        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();
        },
        async handleAdd() {
          this.add=true
        },
        async handleEdit(row) {
          // let item = this.tableData[rowIndex];
          // this.currentProject = {
          //   projectId: item.projectId,
          // };
          // this.pageType = "edit";
          this.Record=true
        },
        handleClose() {
          this.pageType = "list";
          this.currentProject = {
            projectId: "",
          };
        },
  
      },
    };
    </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>
    