<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="事件类型" prop="eventType">
        <el-select v-model="queryParams.eventType" placeholder="请选择事件类型" clearable size="small" disabeld>
          <el-option
            v-for="dict in dict.type.event_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="事件编号" prop="eventNo">
        <el-input
          v-model="queryParams.eventNo"
          placeholder="请输入事件编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="事件名称" prop="eventName">
        <el-input
          v-model="queryParams.eventName"
          placeholder="请输入事件名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执行于" prop="eventTime">
        <el-date-picker
          clearable size="small"
          v-model="queryParams.eventTime"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择执行于">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="事件状态" prop="eventStatus">
        <el-select v-model="queryParams.eventStatus" placeholder="请选择事件状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.event_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['eventConfig:event:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['eventConfig:event:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['eventConfig:event:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['eventConfig:event:export']"
        >导出
        </el-button>
      </el-col>
      <el-col :span="1.5" v-if="queryParams.eventType === '1'">
        <el-button
          type="warning"
          plain
          icon="el-icon-edit"
          size="mini"
          :loading="exportLoading"
          @click="noticeShow"
        >预约公告
        </el-button>
      </el-col>
      <el-col :span="1.5" v-if="queryParams.eventType === '1'">
        <div style="padding: 5px">
          <el-switch
            @change="setNoticeStatus"
            v-model="noticeForm.openStatus"
            active-text="打开公告"
            inactive-text="关闭公告">
          </el-switch>
        </div>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>


    <!--社团活动-->
    <el-table v-if="queryParams.eventType === '1'" v-loading="loading" :data="eventList"
              @selection-change="handleSelectionChange"
              @expand-change="unfoldTable">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-upload
            :action="uploadImgUrl"
            list-type="picture-card"
            :before-upload="handleBeforeUpload"
            :on-error="handleUploadError"
            :on-success="handleUploadSuccess"
            :on-remove="handleRemove"
            :on-preview="handlePictureCardPreview"
            :headers="{
               eventId:props.row.id,
               Authorization: 'Bearer ' + token
            }"
            :file-list="props.row.eventImgUrls">
            <i class="el-icon-plus"></i>
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="">
          </el-dialog>
        </template>
      </el-table-column>
      <el-table-column type="selection" width="30" align="center"/>
      <el-table-column label="编码" align="center" prop="eventNo"/>
      <el-table-column label="事件类型" align="center" prop="eventType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.event_type" :value="scope.row.eventType"/>
        </template>
      </el-table-column>
      <el-table-column label="事件类型" align="center" prop="activityTypeId">
        <template slot-scope="scope">
          <el-select v-model="scope.row.activityTypeId" disabled>
            <el-option v-for="item in associationsList"
                       :label="item.projectName"
                       :value="item.id"
                       :key="item.id"
            />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="名称" align="center" prop="eventName"/>
      <el-table-column label="地点" align="center" prop="eventPlace" v-if="queryParams.eventStatus !== '1'" width="150">
        <template slot-scope="scope">
          <treeselect v-model="scope.row.eventPlace" :options="placeOptions" :normalizer="normalizer"
                      placeholder="请选择地点"
                      disabled/>
        </template>
      </el-table-column>
      <el-table-column label="数量限制" align="center" prop="limitNum"/>
      <el-table-column label="禁止取消预约时限" align="center" prop="banCancelSubscribeTimeLimit"/>
      <el-table-column label="开始前提醒时限" align="center" prop="howLongRemind"/>
      <el-table-column label="活动开始于" align="center" prop="eventStartTime" width="90">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.eventStartTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="活动结束于" align="center" prop="eventEndTime" width="90">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.eventEndTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预约开始于" align="center" prop="startTime" width="90">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="预约结束于" align="center" prop="endTime" width="90">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="事件状态" align="center" prop="eventStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.event_status" :value="scope.row.eventStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['eventConfig:event:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['eventConfig:event:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--积分兑换-->
    <el-table v-else-if="queryParams.eventType === '2'" v-loading="loading" :data="eventList"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="编码" align="center" prop="eventNo"/>
      <el-table-column label="事件类型" align="center" prop="eventType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.event_type" :value="scope.row.eventType"/>
        </template>
      </el-table-column>
      <el-table-column label="名称" align="center" prop="eventName"/>
      <el-table-column label="兑换开始于" align="center" prop="startTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="兑换结束于" align="center" prop="endTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="事件状态" align="center" prop="eventStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.event_status" :value="scope.row.eventStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-connection"
            @click="bindingGiftChild(scope.row)"
          >绑定商品
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['eventConfig:event:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['eventConfig:event:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改活动配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1400px" append-to-body>
      <el-form v-if="queryParams.eventType === '1'" ref="form" :model="form" :rules="rules">
        <el-row :gutter="30">
          <el-col :span="12">
            <el-form-item label="编码" prop="eventNo">
              <el-input v-model="form.eventNo" placeholder="请输入事件编号"/>
            </el-form-item>
            <el-form-item label="活动名称" prop="eventName">
              <el-input v-model="form.eventName" placeholder="请输入活动名称" disabled/>
            </el-form-item>
            <el-row :gutter="50">
              <el-col :span="12">
                <el-form-item label="项目" prop="eventName">
                  <el-select v-model="form.activityTypeId">
                    <el-option v-for="item in associationsList"
                               :label="item.projectName"
                               :value="item.id"
                               :key="item.id"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="事件状态" prop="eventStatus">
                  <el-select v-model="form.eventStatus" placeholder="请选择事件状态">
                    <el-option
                      v-for="dict in dict.type.event_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="地点" prop="eventPlace" v-if="queryParams.eventType === '1'">
              <treeselect v-model="form.eventPlace" :options="placeOptions" :normalizer="normalizer"
                          placeholder="请选择地点"/>
            </el-form-item>
            <el-row>
              <el-col :span="8">
                <el-form-item label="数量限制" prop="limitNum">
                  <el-row>
                    <el-col :span="18">
                      <el-input v-model="form.limitNum" placeholder="请输入数量限制"/>
                    </el-col>
                    <el-col :span="1">
                      <div style="padding: 0.5px">

                      </div>
                    </el-col>
                    <el-col :span="4"> 名</el-col>
                  </el-row>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="禁止取消预约时限" prop="banCancelSubscribeTimeLimit">
                  <el-row>
                    <el-col :span="18">
                      <el-input v-model="form.banCancelSubscribeTimeLimit" placeholder="请输入禁止取消预约时限"/>
                    </el-col>
                    <el-col :span="1">
                      <div style="padding: 0.5px">

                      </div>
                    </el-col>
                    <el-col :span="4">小时</el-col>
                  </el-row>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="活动开始前多久提示" prop="howLongRemind">
                  <el-row>
                    <el-col :span="19">
                      <el-input v-model="form.howLongRemind" placeholder="请输入活动开始前多久提示"/>
                    </el-col>
                    <el-col :span="1">
                      <div style="padding: 0.5px">

                      </div>
                    </el-col>
                    <el-col :span="4">小时</el-col>
                  </el-row>
                </el-form-item>
              </el-col>
            </el-row>
            <div v-if="form.id === null">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-plus"
                @click="addEvent()"
              >添加
              </el-button>
            </div>
            <div v-if="form.id === null && queryParams.eventType === '1'" class="eventDiv"
                 v-for="(item,index) in eventFormList">
              <el-row :gutter="10">
                <el-col :span="12">
                  <el-form-item label="活动开始于" prop="eventStartTime">
                    <el-date-picker
                      clearable size="small"
                      v-model="eventFormList[index].eventStartTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm"
                      placeholder="选择开始于">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="活动结束于" prop="eventEndTime">
                    <el-date-picker
                      clearable size="small"
                      v-model="eventFormList[index].eventEndTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm"
                      placeholder="选择开始于">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :span="12">
                  <el-form-item label="预约开始于" prop="startTime">
                    <el-date-picker
                      clearable size="small"
                      v-model="eventFormList[index].startTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择开始于">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
            <div v-if="form.id !== null" class="eventDiv">
              <el-row :gutter="10">
                <el-col :span="12">
                  <el-form-item label="活动开始于" prop="eventStartTime">
                    <el-date-picker
                      clearable size="small"
                      v-model="form.eventStartTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm"
                      placeholder="选择开始于">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="活动结束于" prop="eventEndTime">
                    <el-date-picker
                      clearable size="small"
                      v-model="form.eventEndTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm"
                      placeholder="选择开始于">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="10">
                <el-col :span="12">
                  <el-form-item label="预约开始于" prop="startTime">
                    <el-date-picker
                      clearable size="small"
                      v-model="form.startTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择开始于">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
          </el-col>
          <el-col :span="12">
            <el-form-item label="描述" v-if="queryParams.eventType === '1'">
              <editor v-model="form.eventDescribe" :min-height="392"/>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-form v-if="queryParams.eventType === '2'" ref="form" :model="form" :rules="rules">
        <el-form-item label="编码" prop="eventNo">
          <el-input v-model="form.eventNo" placeholder="请输入事件编号"/>
        </el-form-item>
        <el-form-item label="事件状态" prop="eventStatus">
          <el-select v-model="form.eventStatus" placeholder="请选择事件状态">
            <el-option
              v-for="dict in dict.type.event_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="活动名称" prop="eventName">
          <el-input v-model="item.eventName" placeholder="请输入活动名称"/>
        </el-form-item>
        <el-form-item label="预约开始于" prop="startTime">
          <el-date-picker
            clearable size="small"
            v-model="item.startTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择开始于">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预约结束于" prop="endTime">
          <el-date-picker
            clearable size="small"
            v-model="form.endTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择结束于">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
        <!--<el-form-item label="事件类型" prop="eventType">-->
        <!--  <el-select v-model="form.eventType" placeholder="请选择事件类型">-->
        <!--    <el-option-->
        <!--      v-for="dict in dict.type.event_type"-->
        <!--      :key="dict.value"-->
        <!--      :label="dict.label"-->
        <!--      :value="dict.value"-->
        <!--    ></el-option>-->
        <!--  </el-select>-->
        <!--</el-form-item>-->
        <!-- <el-form-item label="执行于" prop="eventTime">-->
        <!--   <el-date-picker-->
        <!--     clearable size="small"-->
        <!--     v-model="form.eventTime"-->
        <!--     type="datetime"-->
        <!--     value-format="yyyy-MM-dd HH:mm:ss"-->
        <!--     placeholder="选择执行于">-->
        <!--   </el-date-picker>-->
        <!-- </el-form-item>-->

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="!form.id" type="primary" @click="submitEvents()">确 定</el-button>
        <el-button v-else type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 设置公告对话框 -->
    <el-dialog title="设置公告" :visible.sync="noticeForm.open" width="600px" append-to-body>
      <el-input v-model="noticeForm.text" placeholder="请输入公告"/>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateNotice()" prevent-re-click>确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEvent, getEvent, delEvent, addEvent, updateEvent, exportEvent, addEvents } from '@/api/eventConfig/event'
import { addImg } from '@/api/event/img'
import { listPlace } from '@/api/canteen/place'
import user from '@/store/modules/user'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { listAssociations } from '@/api/event/associations'
import { addConfig, getConfigKey, updateConfig } from '@/api/system/config'
import { getToken } from '@/utils/auth'

export default {
  name: 'Event',
  components: {
    Treeselect
  },
  props: {
    eventType: {
      type: String,
      default: ''
    }
  },
  dicts: ['event_type', 'event_status'],
  data() {
    return {
      // 地点树选项
      placeOptions: [],
      // 遮罩层
      loading: true,
      loadingImg: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 活动配置表格数据
      eventList: [],
      associationsList: [],
      id: '',
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      dialogImageUrl: '',
      dialogVisible: false,
      hideUpload: false,
      uploadImgUrl: process.env.VUE_APP_BASE_API + '/event/img/upload', // 上传的图片服务器地址
      headers: {
        Authorization: 'Bearer ' + getToken()
      },
      token: getToken(),
      fileList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        eventNo: null,
        eventName: null,
        eventStartTime: null,
        eventEndTime: null,
        startTime: null,
        eventTime: null,
        endTime: null,
        eventType: null,
        eventPlace: null,
        eventDescribe: null,
        eventStatus: null,
        isDelete: null
      },
      noticeForm: {
        open: false,
        text: '',
        openStatus: false,
        openStatusKey: 'club_notice_open',
        openStatusData: {},
        key: 'club_notice',
        data: {}
      },
      // 表单参数
      form: {},
      eventFormList: [{
        eventName: '',
        startTime: null,
        eventType: '1',
        eventStartTime: null,
        eventEndTime: null
      }],
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getNoticeStatus()
    this.getNotice()
    this.getTreeselect()
    this.getAssList()
    this.getList()
  },
  methods: {
    submitEvents() {
      for (let i = 0; i < this.eventFormList.length; i++) {
        this.eventFormList[i] = { ...this.form, ...this.eventFormList[i] }
        this.eventFormList[i].eventNo = this.eventFormList[i].eventNo + i
      }
      addEvents(this.eventFormList).then(res => {
        if (res.code === 200) {
          this.getList()
          this.$modal.msgSuccess('新增成功')
          this.cancel()
        }
      })
    },
    addEvent() {
      if (this.eventFormList.length > 0) {
        this.eventFormList.push({
          eventName: this.eventFormList[0].eventName,
          startTime: this.eventFormList[0].startTime,
          eventType: '1',
          eventStartTime: this.eventFormList[0].eventStartTime,
          eventEndTime: this.eventFormList[0].eventEndTime
        })
      } else {
        this.eventFormList.push({
          eventName: '',
          startTime: null,
          eventType: '1',
          eventStartTime: null,
          eventEndTime: null
        })
      }
      console.log(this.eventFormList)
    },
    // 删除图片
    handleRemove(file, fileList) {
      const findex = this.fileList.map(f => f.name).indexOf(file.name)
      if (findex > -1) {
        this.fileList.splice(findex, 1)
      }
    },
    // 上传成功回调
    handleUploadSuccess(res) {
      let data = {
        name: res.fileName,
        url: res.url,
        type: res.type,
        eventId: res.eventId
      }
      this.fileList.push(data)
      addImg(data).then(res => {
        if (res.code === 200) {
          this.$message({
            type: 'success',
            message: '上传成功'
          })
        } else {
          this.$message({
            type: 'error',
            message: '上传失败'
          })
        }
      })
      this.loadingImg.close()
    },  // 上传失败
    handleUploadError() {
      this.$message({
        type: 'error',
        message: '上传失败'
      })
      this.loadingImg.close()
    },
    // 上传前loading加载
    handleBeforeUpload(file) {
      this.loadingImg = this.$loading({
        lock: true,
        text: '上传中',
        background: 'rgba(0, 0, 0, 0.7)'
      })
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    noticeShow() {
      this.noticeForm.open = true
    },
    updateNotice() {
      this.noticeForm.data.configValue = this.noticeForm.text
      updateConfig(this.noticeForm.data).then(re => {
        this.$modal.msgSuccess('修改成功')
        this.getNotice()
        this.noticeForm.open = false
      })
    },
    getNotice() {
      getConfigKey(this.noticeForm.key).then(re => {
        if (!re.data) {
          addConfig({
            configKey: this.noticeForm.key,
            configValue: ''
          })
        } else {
          this.noticeForm.text = re.msg
          this.noticeForm.data = re.data
        }
      })
    },
    setNoticeStatus() {
      this.noticeForm.openStatusData.configValue = this.noticeForm.openStatus ? 'true' : 'false'
      updateConfig(this.noticeForm.openStatusData).then(re => {
        this.getNoticeStatus()
        this.$modal.msgSuccess('更新成功')
      })
    },
    getNoticeStatus() {
      getConfigKey(this.noticeForm.openStatusKey).then(re => {
        if (!re.msg) {
          addConfig({
            configKey: this.noticeForm.openStatusKey,
            configValue: 'false'
          })
          this.noticeForm.openStatus = false
        } else {
          this.noticeForm.openStatus = re.msg !== 'false'
          this.noticeForm.openStatusData = re.data
        }
      })
    },
    /** 查询活动配置列表 */
    getList() {
      if (this.$root._route.query.eventType) {
        this.queryParams.eventType = this.$root._route.query.eventType
      }
      this.loading = true
      listEvent(this.queryParams).then(response => {
        this.eventList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    getEventId() {
      return this.id
    },
    /** 查询社团信息列表 */
    getAssList() {
      listAssociations().then(response => {
        this.associationsList = response.rows
      })
    },
    /** 查询地点下拉树结构 */
    getTreeselect() {
      listPlace({ jgid: user.state.organ, placeType: 4 }).then(response => {
        this.placeOptions = []
        const data = { placeId: 0, placeName: '最上级', children: [] }
        data.children = this.handleTree(response.data, 'placeId', 'parentId')
        this.placeOptions.push(data)
      })
    },
    /** 转换地点数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.placeId,
        label: node.placeName,
        children: node.children
      }
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.noticeForm.open = false
      this.eventGiftForm.open = false
      this.eventFormList = []
      this.noticeForm.text = ''
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        eventNo: null,
        eventName: null,
        eventTime: null,
        eventType: null,
        eventPlace: null,
        eventDescribe: null,
        eventStatus: null,
        isDelete: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      }
      this.resetForm('form')
    },
    bindingGiftChild(row) {
      this.id = row.id
      this.$parent.$parent.getBindingList()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    unfoldTable(row, expandedRows) {

    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.eventFormList = [{
        eventName: '',
        startTime: null,
        eventType: '1',
        eventStartTime: null,
        eventEndTime: null
      }]
      if (this.$root._route.query.eventType) {
        this.form.eventType = this.$root._route.query.eventType
      }
      this.open = true
      this.title = '添加活动配置'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getEvent(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改活动配置'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.form.eventType = this.$root._route.query.eventType
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEvent(this.form).then(() => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addEvent(this.form).then(() => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除活动配置编号为"' + ids + '"的数据项？').then(function() {
        return delEvent(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams
      this.$modal.confirm('是否确认导出所有活动配置数据项？').then(() => {
        this.exportLoading = true
        return exportEvent(queryParams)
      }).then(response => {
        this.$download.name(response.msg)
        this.exportLoading = false
      }).catch(() => {
      })
    }
  }
}
</script>
<style scoped>
.eventDiv {
  border: 1px solid #cbcbcb;
  padding: 20px 20px 0 20px;
  margin: 0 0 10px 0;
  border-radius: 10px;
}
</style>
