<template>
  <div class="app-container">
    <div class="query-container">
      <el-form ref="formInline" v-model="formInline" size="mini" :inline="true">
        <el-form-item>
          <el-radio-group v-model="formInline.meetingEternal" @input="chooseMeeting()">
            <el-radio-button label="0" value="0">内部会议</el-radio-button>
            <el-radio-button label="1" value="1">外部会议</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-input v-model="formInline.meetingName" placeholder="会议主题"></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="formInline.meetingType" placeholder="会议类型" clearable>
            <el-option label="周例会" value="1" key="周例会">周例会</el-option>
            <el-option label="项目会议" value="2" key="项目会议">项目会议</el-option>
            <el-option label="实施会议" value="3" key="实施会议">实施会议</el-option>
            <el-option label="其他会议" value="4" key="其他会议">其他会议</el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="formInline.status" placeholder="会议状态" clearable>
            <el-option label="待开始" value="0"></el-option>
            <el-option label="进行中" value="1"></el-option>
            <el-option label="已结束" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="search()">查询</el-button>
          <el-button icon="el-icon-refresh" @click="resetSearch()">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" style="margin-bottom:8px">
        <el-col :span="1.5">
          <el-button type="success" icon="el-icon-plus" @click="createMeeting">创建会议</el-button>
        </el-col>
      </el-row>

    </div>

    <el-table
      :data="tableData"
      border
      stripe
      height="calc(100vh - 180px)"
      size="mini"
      style="width: 100%">
      <el-table-column type="index" label="序号" width="60" fixed>
      </el-table-column>
      <el-table-column label="会议主题" prop="meetingName">
      </el-table-column>

      <el-table-column label="会议地点" prop="meetingPlace" width="120">
      </el-table-column>
      <el-table-column prop="address" label="参会人员" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ scope.row.outAttendees }}</span>
          <span v-if="scope.row.outAttendees!=''">、</span>
          <span v-for="(item,index) in JSON.parse(scope.row.innerAttendees) ">
             <template v-if="index > 0">,</template>
             <span>{{ item.name }}</span>
           </span>
        </template>
      </el-table-column>
      <el-table-column prop="name" label="会议时间" width="240">
        <template slot-scope="scope">
          <div>{{ parseTime(scope.row.beginTime) }}——{{ parseTime(scope.row.endTime) }}</div>
        </template>
      </el-table-column>
      <el-table-column label="会议类型" prop="meetingType" width="80">
        <template slot-scope="scope">
          <!--会议类型（1-周例会，2-项目会议，3-实施会议，4-其他会议）-->
          <div v-if="scope.row.meetingType===1">周例会</div>
          <div v-else-if="scope.row.meetingType===2">项目会议</div>
          <div v-else-if="scope.row.meetingType===3">实施会议</div>
          <div v-else>其他会议</div>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="会议状态" width="80">
        <template slot-scope="scope">
          <!--会议状态，0待开始，1进行中，2已结束-->
          <div v-if="scope.row.status===0" style="color: green">待开始</div>
          <div v-else-if="scope.row.status===1" style="color: #3A71A8">进行中</div>
          <div v-else>已结束</div>
        </template>
      </el-table-column>
      <!--      <el-table-column prop="createTime" label="创建时间" width="130" :v-show="false">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime) }}</span>
              </template>
            </el-table-column>-->
      <el-table-column label="操作" prop="op" width="250">
        <template slot-scope="scope">

          <el-button v-if="scope.row.status!==2" size="mini" type="primary" @click="handleEdit(scope.row)">编辑
          </el-button>
          <el-button v-if="scope.row.status===0" size="mini" type="danger" @click="deleteMeeting( scope.row)">删除
          </el-button>
          <el-button v-if="scope.row.status===0" size="mini" type="success" @click="startMeeting( scope.row)">开始会议
          </el-button>
          <el-button v-if="scope.row.status!==0 " type="success" size="mini" @click="meetingDetail(scope.row)">会议详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <div style="margin-top: 10px;text-align: center">
      <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    </div>

    <!--编辑会议窗体-->
    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="950px" @click="closeDialog"
               :close-on-click-modal="false">
      <el-form label-width="120px" ref="form" size="mini" :model="editForm">
        <el-form-item label="会议主题:" prop="meetingName" :rules="[{required:true,message: '请输入会议主题', trigger: 'blur'}]">
          <el-input v-model="editForm.meetingName"></el-input>
        </el-form-item>
        <el-form-item label="会议类别:">
          <el-radio-group v-model="editForm.external" @input="changeMeetingExternal">
            <el-radio :label="1">外部会议</el-radio>
            <el-radio :label="0">内部会议</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="会议类型:" prop="meetingType"
                          :rules="[{required:true,message: '请选择会议类型', trigger: 'blur'}]">
              <el-select v-model="editForm.meetingType" placeholder="会议类型" clearable>
                <el-option label="周例会" :value="1" key="周例会" v-if="editForm.external===0">周例会</el-option>
                <el-option label="项目会议" :value="2" key="项目会议">项目会议</el-option>
                <el-option label="实施会议" :value="3" key="实施会议" v-if="editForm.external===0">实施会议</el-option>
                <el-option label="其他会议" :value="4" key="其他会议">其他会议</el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关联项目" v-if="editForm.meetingType===2" prop="projectId"
                          :rules="[{required:true,message: '请选择项目', trigger: 'change'}]">
              <el-select
                v-model="editForm.projectId"
                clearable
                style="width: 240px">
                <el-option v-for="item in projectList" :key="item.id" :label="item.projectName" :value="item.id"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="会议地点:" prop="meetingPlace" :rules="[{required:true,message: '请输入会议地点', trigger: 'blur'}]">
          <el-input size="mini" v-model="editForm.meetingPlace"></el-input>
        </el-form-item>
        <el-form-item v-show="false" label="会议时间:">
          <el-date-picker
            v-model="editForm.time"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会议时间:" prop="time">
          <el-date-picker
            v-model="editForm.startTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss" default-time="12:00:00"
            placeholder="选择会议开始时间" @change="chooseMeetingStartTime">
          </el-date-picker>
          <el-date-picker
            v-show="endTimeShow"
            v-model="editForm.endTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss" default-time="12:00:00"
            placeholder="选择会议结束时间" @change="chooseMeetingEndTime">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会议时长:">
          <el-select v-model="editForm.duration" placeholder="请选择会议时长" clearable @change="chooseMeetingTime">
            <el-option label="15分钟" :value="15" key="15分钟">15分钟</el-option>
            <el-option label="30分钟" :value="30" key="30分钟">30分钟</el-option>
            <el-option label="45分钟" :value="45" key="45分钟">45分钟</el-option>
            <el-option label="1小时" :value="60" key="15分钟">1小时</el-option>
            <el-option label="2小时" :value="120" key="2小时">2小时</el-option>
            <el-option label="3小时" :value="180" key="3小时">3小时</el-option>
            <el-option label="其他" :value="0" key="其他">其他</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="外部参会人员:">
          <el-input size="mini" v-model="editForm.outAttendees"></el-input>
        </el-form-item>
        <el-form-item label="内部参会人员:" prop="innerAttendUsers"
                      :rules="[{required:true,message: '请选择参会人员', trigger: 'change'}]">
          <el-input size="mini" v-model="editForm.innerAttendUsers" readonly="true" @keyup.enter.native="openUsers()">
            <el-button @click="openUsers" icon="el-icon-search" slot="append"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="主持人:" prop="emcee" :rules="[{required:true,message: '请选择会议主持人', trigger: 'change'}]">
          <el-input size="mini" v-model="editForm.emcee" readonly="true" @keyup.enter.native="openUsers1('emcee')">
            <el-button @click="openUsers1('emcee')" icon="el-icon-search" slot="append"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="记录人:" prop="recorder" :rules="[{required:true,message: '请选择会议记录人', trigger: 'change'}]">
          <el-input size="mini" v-model="editForm.recorder" readonly="true"
                    @keyup.enter.native="openUsers1('recorder')">
            <el-button @click="openUsers1('recorder')" icon="el-icon-search" slot="append"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="参会情况:" prop="remark" v-if="editForm.status>0">
          <el-input type="textarea" :rows="2" size="mini" v-model="editForm.remark"></el-input>
        </el-form-item>
        <el-form-item label="会议内容:">
          <el-table style="width: 100%" border stripe :show-header="false" :data="editForm.meetingContents">
            <el-table-column type="index" label="序号" width="40">
            </el-table-column>
            <el-table-column label="工作内容" prop="content">
              <template slot-scope="scope">
                <el-input size="mini" v-model="scope.row.content"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" prop="op" width="150">
              <template slot-scope="scope">
                <el-button size="mini" type="primary" @click="addRow()">添加</el-button>
                <el-button size="mini" type="danger" @click="deleteRow(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="closeDialog">取消</el-button>
        <el-button size="mini" type="primary"  class="title" @click="submitForm('editForm')">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog title="选择人员" :visible.sync="usersVisble" width="30%" @click="closeUserDialog"
               :close-on-click-modal="false">
      <el-tree
        ref="dept"
        :data="userList"
        node-key="id"
        show-checkbox
        :props="{label:'name'}" default-expand-all="true">
      </el-tree>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="closeUserDialog">取消</el-button>
        <el-button size="mini" type="primary" class="title" @click="submitUserForm('editForm')">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="选择人员" :visible.sync="users1Visble" width="30%" @click="closeUser1Dialog"
               :close-on-click-modal="false">
      <el-tree
        ref="dept1"
        :data="userList"
        node-key="id"
        :props="{label:'name'}" default-expand-all="true">
      </el-tree>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="closeUser1Dialog">取消</el-button>
        <el-button size="mini" type="primary" class="title" @click="submitUser1Form('editForm')">确定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="projectMeetingDetailVisble" width="95%" @click="closeProjectMeetingDailog" fullscreen
               :close-on-click-modal="false">
      <el-descriptions title="会议记录详情" border :column="2">
        <el-descriptions-item label="会议主题">
          {{ pro.meetingName }}
        </el-descriptions-item>
        <el-descriptions-item label="会议类别">
          {{ pro.external }}
        </el-descriptions-item>
        <el-descriptions-item label="会议类型">
          {{ pro.meetingType }}
        </el-descriptions-item>
        <el-descriptions-item label="会议地点">
          {{ pro.meetingPlace }}
        </el-descriptions-item>
        <el-descriptions-item label="会议时间">
          {{ pro.times }}
        </el-descriptions-item>
        <el-descriptions-item label="外部参会人员" v-if="pro.outAttendees!=''">
          {{ pro.outAttendees }}
        </el-descriptions-item>
        <el-descriptions-item label="记录人员" :span="2">
          {{ pro.recorder }}
        </el-descriptions-item>
        <el-descriptions-item label="内部参会人员">
          {{ pro.innerAttendees }}
        </el-descriptions-item>
        <el-descriptions-item label="参会情况">
          {{ pro.remark }}
        </el-descriptions-item>
      </el-descriptions>

      <el-table style="width: 100%;margin: 0" border stripe :data="pro.meetingContents">
        <el-table-column label="序号" width="60" type="index"></el-table-column>
        <el-table-column label="会议内容" prop="content"></el-table-column>
        <el-table-column label="会议问题" prop="question">
          <template slot-scope="scope">
            <el-input size="mini" v-model="scope.row.question" type="textarea"
                      :autosize="{ minRows: 4, maxRows: 10}" ></el-input>
          </template>
        </el-table-column>
        <el-table-column label="会议方案" prop="optionss">
          <template slot-scope="scope">
            <el-input size="mini" v-model="scope.row.optionss" type="textarea"
                      :autosize="{ minRows: 4, maxRows: 10}"></el-input>
          </template>

        </el-table-column>
        <el-table-column label="执行人" width="180">
          <template slot-scope="scope">
            <el-input size="mini" v-model="scope.row.executorName" readonly
                      @keyup.enter.native="openUsers1('executorName',scope.row)">
              <el-button @click="openUsers1('executorName',scope.row)" icon="el-icon-search" slot="append" ></el-button>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="周期时间" width="300">
          <template slot-scope="scope">
            <el-date-picker size="mini"
                            v-model="scope.row.times"
                            value-format="yyyy-MM-dd"
                            format="yyyy-MM-dd"
                            type="daterange"
                            style="width: 100%"
                            range-separator="至"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期">
            </el-date-picker>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="pro.status!==0" type="success" size="mini" @click="confirmMeeting(pro)">会议结果确认
        </el-button>
        <el-button size="mini" @click="closeProjectMeetingDailog" v-show="false">取消</el-button>
        <el-button size="mini" type="primary" class="title" @click="submitMeetingOptionsForm(pro,'editForm')">保存</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="otherMeetingDetailVisble" width="95%" @click="closeotherMeetingDailog" fullscreen
               :close-on-click-modal="false">
      <el-descriptions title="会议记录详情" border :column="2">
        <el-descriptions-item label="会议主题">
          {{ pro.meetingName }}
        </el-descriptions-item>
        <el-descriptions-item label="会议类别">
          {{ pro.external }}
        </el-descriptions-item>
        <el-descriptions-item label="会议类型">
          {{ pro.meetingType }}
        </el-descriptions-item>
        <el-descriptions-item label="会议地点">
          {{ pro.meetingPlace }}
        </el-descriptions-item>
        <el-descriptions-item label="会议时间">
          {{ pro.times }}
        </el-descriptions-item>
        <el-descriptions-item label="外部参会人员" v-if="pro.outAttendees!=''">
          {{ pro.outAttendees }}
        </el-descriptions-item>
        <el-descriptions-item label="记录人员" :span="2">
          {{ pro.recorder }}
        </el-descriptions-item>
        <el-descriptions-item label="内部参会人员">
          {{ pro.innerAttendees }}
        </el-descriptions-item>
        <el-descriptions-item label="参会情况">
          {{ pro.remark }}
        </el-descriptions-item>
      </el-descriptions>

      <el-table style="width: 100%;margin: 0" border stripe :data="pro.meetingContents">
        <el-table-column label="序号" width="60" type="index"></el-table-column>
        <el-table-column label="会议内容" prop="content"></el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="closeotherMeetingDailog">取消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import Pagination from '../../components/Page/Pagination'
import {
  addMeeting,
  getMeetingsByPage,
  deleteMeeting,
  getMeetingDetailsById,
  deleteMeetingContentById, saveMeetingOptionss, confirmMeetings, startMeetingById, meetingAuthById, meetingDeleteAuth
} from '@/api/meeting/meeting'
import {getDeptUserTree} from '@/api/system/user'
import {getProjectList} from "@/api/task/project";

export default {
  name: 'Meeting',
  data() {
    return {
      projectMeetingDetailVisble: false,
      otherMeetingDetailVisble: false,
      tableData: [],
      pageparm: {
        current: 1,
        size: 10,
        total: 0
      },

      formInline: {
        current: 1,
        size: 10,
        meetingEternal: '0',
        meetingName: '',
        meetingType: null,
        status: null

      },
      editFormVisible: false,
      title: '创建会议',
      endTimeShow:false,
      editForm: {
        id: null,
        meetingName: '',
        external: 0,
        meetingType: null,
        projectId: null,
        meetingPlace: '',
        time: null,
        startTime:null,
        endTime:null,
        outAttendees: '',
        innerAttendees: '',
        innerAttendesss: null,
        innerAttendUsers: '',
        remark: '',
        emcee: '',
        recorder: '',
        duration:null,
        meetingContents: [
          {content: '会议内容', 'op': ''}
        ]
      },
      usersVisble: false,
      userList: [],
      users1Visble: false,
      users1Flag: '',
      pro: {
        id: '',
        meetingName: '',
        meetingType: '',
        external: null,
        meetingPlace: '',
        times: '',
        outAttendees: '',
        innerAttendees: '',
        emcee: '',
        recorder: '',
        remark: '',
        status: null,
        beginTime:null,
        endTime:null,
        meetingConfirmStatus:0,
        meetingContents: [{
          id: null,
          meetingId: null,
          content: '',
          question: '',
          optionss: '',
          executorName: '',
          executorId: null,
          beginTime: null,
          endTime: null,
          times: []
        }],
        row: null,
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  mounted() {
    this.getData(this.formInline);
    this.getDeptUserTrees();
  },
  methods: {
    getDeptUserTrees() {
      getDeptUserTree('').then(res => {
        this.userList = res.data
      });
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.current = parm.current
      this.formInline.size = parm.size
      this.getData(this.formInline)
    },
    getData(data) {
      let searchParams = data
      getMeetingsByPage(searchParams).then(response => {
        this.tableData = response.data.records;
        this.pageparm.total = response.data.total;
      });
    },
    createMeeting() {
      getProjectList("").then(res => {
        this.projectList = res.data;
        this.title = '创建会议'
        this.editFormVisible = true
      })
      this.editForm = {
        id: null,
        meetingName: '',
        external: 0,
        meetingType: null,
        projectId: null,
        meetingPlace: '',
        time: null,
        outAttendees: '',
        innerAttendees: '',
        innerAttendesss: null,
        innerAttendUsers: '',
        remark: '',
        emcee: '',
        recorder: '',
        meetingContents: [
          {content: '会议内容', 'op': ''}
        ]
      }
    },
    closeDialog() {
      this.editFormVisible = false
    },
    addRow() {
      let row = {content: '', 'op': ''}
      this.editForm.meetingContents.push(row)
    },
    deleteRow(index, row) {
      if (index == 0) {
        this.$message({
          message: '不能删除会议内容',
          type: 'warning'
        });
        return;
      }
      this.editForm.meetingContents.splice(index, 1)
      if (row.id !== undefined) {
        deleteMeetingContentById(row.id).then(res => {
        });
      }

    },
    async meetingAuth(id){
     await  meetingAuthById(id).then(res=>{
        let flag=true
        if(res.success===false){
          flag=false
          this.$message.error(res.data)
        }
        return flag;
      });
    },
    submitForm(row,str) {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          let data = this.editForm;
          let times=[]
          times.push(this.editForm.startTime)
          times.push(this.editForm.endTime)
          this.editForm.time=times
          addMeeting(data).then(response => {
            this.$message({
              message: '操作成功!',
              type: 'success'
            });
            this.closeDialog();
            this.getData(this.formInline);
          });
        } else {
          return false;
        }
      });


    },
    resetSearch() {
      this.formInline = {
        current: 1,
        size: 10,
        meetingEternal: 0,
        meetingName: '',
        meetingType: null,
        status: null
      }
      this.getData(this.formInline);
    },
    search() {
      let searchParams = this.formInline
      this.getData(searchParams);
    },
    deleteMeeting(row) {
      //删除会议
      let id = row.id;
      //验证会议删除权限--创建者才能删除
      meetingDeleteAuth(id).then(res=>{
        if (res.success === false) {
          this.$message.error(res.data)
        }else{
          deleteMeeting(id).then(() => {
            this.$message({
              message: '操作成功!',
              type: 'success'
            });
            this.getData(this.formInline);
          })
        }
      });

    },
    confirmMeeting(row) {
      let status=row.status;
      if(status!==2){
        this.$message.warning("会议暂未结束，请会议结束后在确认!");
        return
      }
      let meetingConfirmStatus=row.meetingConfirmStatus
      if(meetingConfirmStatus===1){
        this.$message.warning("会议已经确认，请勿再次操作!")
        return
      }
      let id = row.id;
      //点击会议确认时候判断信息是否完整
      let data = this.pro.meetingContents;
      for (let i = 0; i < data.length; i++) {
        let t = data[i];
        if (t.question === '' || t.optionss === '' || t.executorName === '' || t.times===null ||  t.times.length ===0  ) {
          this.$message({
            message: '请将信息填写完整!',
            type: 'warning'
          });
          return
        }
      }
      saveMeetingOptionss(data).then(res => {
        confirmMeetings(id).then(res => {
          this.$message({
            message: '操作成功!',
            type: 'success'
          });
          this.getData(this.formInline);
          this.projectMeetingDetailVisble = false
        });
      });


    },
    meetingDetail(row) {
      let meetingType = row.meetingType
      if (meetingType !== 1) {
        if (row.meetingType == 2) {
          this.projectMeetingDetailVisble = true
        } else {
          this.otherMeetingDetailVisble = true
        }

        this.pro.meetingName = row.meetingName
        this.pro.outAttendees = row.outAttendees
        this.pro.innerAttendees = row.innerAttendees
        this.pro.recorder = row.recorder
        this.pro.times = row.beginTime + '至' + row.endTime
        this.pro.beginTime=row.beginTime
        this.pro.endTime=row.endTime
        this.pro.meetingPlace = row.meetingPlace
        this.pro.meetingConfirmStatus=row.meetingConfirmStatus
        let meetingType = row.meetingType
        //1-周例会，2-项目会议，3-实施会议，4-其他会议
        let meetingTypeNames = '';
        if (meetingType === 1) {
          meetingTypeNames = '周例会'
        } else if (meetingType === 2) {
          meetingTypeNames = '项目会议'
        } else if (meetingType === 3) {
          meetingTypeNames = '实施会议'
        } else {
          meetingTypeNames = '其他会议'
        }
        this.pro.meetingType = meetingTypeNames
        let external = row.external
        if (external === 0) {
          this.pro.external = '内部会议'
        } else {
          this.pro.external = '外部会议'
        }
        let innerAttendees = JSON.parse(row.innerAttendees);
        let innerPeople = '';
        for (let i = 0; i < innerAttendees.length; i++) {
          innerPeople += innerAttendees[i].name + '、'
        }
        innerPeople = innerPeople.substring(0, innerPeople.length - 1);
        this.pro.innerAttendees = innerPeople
        this.pro.remark = row.remark
        this.pro.status = row.status
        let meetingId = row.id
        this.pro.id = row.id
        getMeetingDetailsById(meetingId).then(res => {
          let data = res.data.meetingContents

          this.pro.meetingContents = data
        });
      }
      if (meetingType === 1) {
        let params = {
          meetingId: row.id,
          weeks: row.weeks
        }
        this.$router.push({path: '/meeting/weeklyRecords', query: params});
      }
    },
    startMeeting(row){
      let id=row.id;
      meetingAuthById(id).then(res=> {
        if (res.success === false) {
          this.$message.error(res.data)
        }else{
          startMeetingById(id).then(res => {
            this.$message({
              message: '操作成功!',
              type: 'info'
            });
            this.getData(this.formInline);
          })
        }
      })
    },
    openUsers() {
      this.usersVisble = true
    },
    closeUserDialog() {
      this.usersVisble = false
    },
    submitUserForm() {
      //获取选中的节点
      let node = this.$refs.dept.getCheckedNodes();

      if (node == undefined || node == null || node.length === 0) {
        this.$message({
          message: '请选择人员数据!',
          type: 'warning'
        });
        return;
      }
      let userList = []
      let userName = ''
      let saveUsers = []
      node.forEach(item => {
        if (item.type === 'u') {
          userList.push(item);
          userName += item.name + '、';
          saveUsers.push({
            id: item.id,
            name: item.name
          })
        }
      })
      userName = userName.substring(0, userName.length - 1);
      if (userList.length === 0) {
        this.$message({
          message: '请选择人员!',
          type: 'warning'
        });
        return;
      }
      this.closeUserDialog()
      this.editForm.innerAttendUsers = userName
      this.editForm.innerAttendesss = saveUsers
    },
    closeUser1Dialog() {
      this.users1Visble = false
    },
    openUsers1(data, row) {
      this.users1Visble = true
      this.users1Flag = data
      this.pro.row = row

    },
    submitUser1Form() {
      let node = this.$refs.dept1.getCurrentNode();
      if (node == undefined || node == null) {
        this.$message({
          message: '请选择数据!',
          type: 'warning'
        });
        return;
      }
      if (node.type !== 'u') {
        this.$message({
          message: '请选择人员!',
          type: 'warning'
        });
        return;
      }
      let user1Flag = this.users1Flag;
      if (user1Flag === 'emcee') {
        this.editForm.emcee = node.name
      } else if (user1Flag === 'executorName') {
        let row = this.pro.row
        row.executorName = node.name
        row.executorId = node.id
        this.pro.meetingContents.executorName = node.name
        this.pro.meetingContents.executorId = node.id

      } else {
        this.editForm.recorder = node.name
      }

      this.closeUser1Dialog()
    },
    handleEdit(row) {
      let meetingId=row.id
      meetingAuthById(meetingId).then(res=>{
        if (res.success === false) {
          this.$message.error(res.data)
        }else{
          getProjectList("").then(res => {
            this.projectList = res.data;
          })
          getMeetingDetailsById(row.id).then(res => {
            let data = res.data
            this.editForm = data
            let users = JSON.parse(data.innerAttendees)
            this.editForm.innerAttendees = ''
            for (let i = 0; i < users.length; i++) {
              this.editForm.innerAttendees += users[i].name + ','
            }
            this.editForm.innerAttendees = this.editForm.innerAttendees.substring(0, this.editForm.innerAttendees.length - 1)
            this.editForm.innerAttendesss = users;
            this.editForm.innerAttendUsers = this.editForm.innerAttendees
            this.editForm.meetingType = data.meetingType
            let time = [];
            time.push(data.beginTime);
            time.push(data.endTime);
            this.editForm.time = time;
            this.editForm.startTime=data.beginTime
            this.editForm.endTime=data.endTime
            this.editForm.duration=data.duration
            this.title = '修改会议'
            this.editFormVisible = true
          });
        }
      });

    },
    chooseMeeting() {
      let val = this.formInline.meetingEternal;
      let search = this.formInline
      search.meetingEternal = val;
      this.getData(search)
    },
    closeProjectMeetingDailog() {
      this.projectMeetingDetailVisble = false;
    },
    submitMeetingOptionsForm(row,str) {
      let meetingConfirmStatus=row.meetingConfirmStatus
      if(meetingConfirmStatus===1){
        this.$message.warning("会议已经确认，请勿再次操作!")
        return
      }
      let data = this.pro.meetingContents;
      for (let i = 0; i < data.length; i++) {
        let t = data[i];
        if (t.question === '' || t.optionss === '' || t.executorName === '' || t.times===null ||  t.times.length ===0) {
          this.$message({
            message: '请将信息填写完整!',
            type: 'warning'
          });
          return
        }
      }
      saveMeetingOptionss(data).then(res => {
        this.$message({
          message: '操作成功!',
          type: 'success'
        });
        this.closeProjectMeetingDailog();
      });
    },
    closeotherMeetingDailog() {
      this.otherMeetingDetailVisble = false;
    },
    changeMeetingExternal(){

    },
    chooseMeetingTime(){
      //选择会议时长
      let duration=this.editForm.duration
      if(duration===0){
        this.endTimeShow=true
      }else{
        this.endTimeShow=false
        //计算会议结束日期
        let startTime=this.editForm.startTime
        if(startTime===undefined || startTime===null){
          let currentDate = new Date();
          let newDate = new Date(currentDate.getTime() + duration * 60000);
          let now = this.$moment(newDate).format('YYYY-MM-DD HH:mm:ss')
          this.editForm.endTime=now
        }else{
          let currentDate = new Date(startTime);
          let newDate = new Date(currentDate.getTime() + duration * 60000);
          let now = this.$moment(newDate).format('YYYY-MM-DD HH:mm:ss')
          this.editForm.endTime=now
        }
      }
    },
    addMinutesToCurrentTime(minutes) {
      let currentDate = new Date();
      let newDate = new Date(currentDate.getTime() + minutes * 60000);
      return newDate;
    },
    chooseMeetingStartTime(){
      let startTime=this.editForm.startTime
      if(startTime===undefined || startTime===null){
        this.$message.error("请选择会议开始时间!")
        return
      }
      let duration=this.editForm.duration
      let currentDate = new Date(startTime);
      let newDate = new Date(currentDate.getTime() + duration * 60000);
      let now = this.$moment(newDate).format('YYYY-MM-DD HH:mm:ss')
      this.editForm.endTime=now

    },
    chooseMeetingEndTime(){
      let startTime=this.editForm.startTime
      let endTime=this.editForm.endTime
      if(startTime===undefined || startTime===null){
        this.$message.error("请选择会议开始时间!")
        return
      }
      if(endTime===undefined || endTime===null){
        this.$message.error("请选择会议结束时间!")
        return
      }
      if(startTime>endTime){
        this.$message.error("会议开始时间不能大于会议结束时间!")
        return
      }
      //计算时长
      let calculateTimeDuration=this.calculateTimeDuration(startTime,endTime);
      this.editForm.duration=calculateTimeDuration
    },
    calculateTimeDuration(time1, time2) {
      let date1 = new Date(time1);
      let date2 = new Date(time2);
      let duration = Math.abs(date1.getTime() - date2.getTime());
      return duration;
    }
  }

}
</script>

<style scoped lang="scss">
.el-form-item--mini.el-form-item, .el-form-item--small.el-form-item {
  margin-bottom: 10px;
}
</style>
