<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="通知名" prop="noticeName">
        <el-input v-model="queryParams.noticeName" placeholder="请输入通知名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类型" clearable>
          <el-option v-for="dict in dict.type.tb_conference_notice_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <!--      <el-form-item label="会议开始时间">-->
      <!--        <el-date-picker-->
      <!--          v-model="daterangeConferenceStartTime"-->
      <!--          style="width: 240px"-->
      <!--          value-format="yyyy-MM-dd"-->
      <!--          type="daterange"-->
      <!--          range-separator="-"-->
      <!--          start-placeholder="开始日期"-->
      <!--          end-placeholder="结束日期"-->
      <!--        ></el-date-picker>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="会议结束时间">-->
      <!--        <el-date-picker-->
      <!--          v-model="daterangeConferenceEndTime"-->
      <!--          style="width: 240px"-->
      <!--          value-format="yyyy-MM-dd"-->
      <!--          type="daterange"-->
      <!--          range-separator="-"-->
      <!--          start-placeholder="开始日期"-->
      <!--          end-placeholder="结束日期"-->
      <!--        ></el-date-picker>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="报名开始时间">-->
      <!--        <el-date-picker-->
      <!--          v-model="daterangeEnrollStartTime"-->
      <!--          style="width: 240px"-->
      <!--          value-format="yyyy-MM-dd"-->
      <!--          type="daterange"-->
      <!--          range-separator="-"-->
      <!--          start-placeholder="开始日期"-->
      <!--          end-placeholder="结束日期"-->
      <!--        ></el-date-picker>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="报名结束时间">-->
      <!--        <el-date-picker-->
      <!--          v-model="daterangeEnrollEndTime"-->
      <!--          style="width: 240px"-->
      <!--          value-format="yyyy-MM-dd"-->
      <!--          type="daterange"-->
      <!--          range-separator="-"-->
      <!--          start-placeholder="开始日期"-->
      <!--          end-placeholder="结束日期"-->
      <!--        ></el-date-picker>-->
      <!--      </el-form-item>-->
      <!--      <el-form-item label="审核状态" prop="examineStatus">-->
      <!--        <el-select v-model="queryParams.examineStatus" placeholder="请选择审核状态" clearable>-->
      <!--          <el-option-->
      <!--            v-for="dict in dict.type.tb_examine_status"-->
      <!--            :key="dict.value"-->
      <!--            :label="dict.label"-->
      <!--            :value="dict.value"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option v-for="dict in dict.type.tb_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="发布时间" prop="publicationTime">
        <el-date-picker clearable v-model="queryParams.publicationTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择发布时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="发布人" prop="publisher">
        <el-input v-model="queryParams.publisher" placeholder="请输入发布人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--      <el-form-item label="创建时间" prop="createTime">-->
      <!--        <el-date-picker clearable-->
      <!--          v-model="queryParams.createTime"-->
      <!--          type="date"-->
      <!--          value-format="yyyy-MM-dd"-->
      <!--          placeholder="请选择创建时间">-->
      <!--        </el-date-picker>-->
      <!--      </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="['hezhi:conferenceNotice: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="['hezhi:conferenceNotice: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="['hezhi:conferenceNotice:remove']">删除</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="warning"-->
      <!--          plain-->
      <!--          icon="el-icon-download"-->
      <!--          size="mini"-->
      <!--          @click="handleExport"-->
      <!--          v-hasPermi="['hezhi:conferenceNotice:export']"-->
      <!--        >导出</el-button>-->
      <!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="conferenceNoticeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="conferenceNoticeId" />
      <el-table-column label="封面图" align="center" prop="conferenceNoticeLogo" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.conferenceNoticeLogo" :width="50" :height="50" />
        </template>
      </el-table-column>
      <el-table-column label="通知名" align="center" prop="noticeName" width="100px">
        <template slot-scope="scope">
          <tooltip :contentName="scope.row.noticeName" />
        </template>
      </el-table-column>
      <!--      <el-table-column label="通知简介" align="center" prop="noticeIntroduce" />-->
      <!--      <el-table-column label="通知详情" align="center" prop="noticeDetails" />-->
      <el-table-column label="类型" align="center" prop="type" width="120px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_conference_notice_type" :value="scope.row.type" />
        </template>
      </el-table-column>
      <el-table-column label="会议开始时间" align="center" prop="conferenceStartTime" width="150" />
      <el-table-column label="会议结束时间" align="center" prop="conferenceEndTime" width="150" />
      <!--      <el-table-column label="报名开始时间" align="center" prop="enrollStartTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.enrollStartTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="报名开始时间" align="center" prop="enrollEndTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.enrollEndTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="会议状态" align="center" prop="conferenceStatus" />-->
      <!--      <el-table-column label="审核状态" align="center" prop="examineStatus">-->
      <!--        <template slot-scope="scope">-->
      <!--          <dict-tag :options="dict.type.tb_examine_status" :value="scope.row.examineStatus"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="审核反馈" align="center" prop="examineFeedback" />-->
      <el-table-column label="排序" align="center" prop="sort" />
      <!--      <el-table-column label="备注" align="center" prop="remarks" />-->
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.tb_status" :value="scope.row.status" />
        </template>
      </el-table-column>

      <el-table-column align="center" prop="screenConferencePeople" width="80">
        <template slot-scope="scope">
          <el-link type="primary" @click="getScreenConferencePeopleList(scope.row)" v-if="scope.row.type === 3">
            <span>参会嘉宾</span>
          </el-link>
        </template>
      </el-table-column>

      <el-table-column align="center" prop="screenConferenceRegistration" width="80">
        <template slot-scope="scope">
          <el-link type="primary" @click="getScreenConferenceRegistrationList(scope.row)" v-if="scope.row.type === 3">
            <span>参会报名</span>
          </el-link>
        </template>
      </el-table-column>

      <el-table-column label="发布时间" align="center" prop="publicationTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.publicationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发布人" align="center" prop="publisher" />
      <!--      <el-table-column label="创建时间" align="center" prop="createTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="删除时间" align="center" prop="deleteTime" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.deleteTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="删除人" align="center" prop="deleteBy" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['hezhi:conferenceNotice:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['hezhi:conferenceNotice: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="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="封面图" prop="conferenceNoticeLogo">
          <image-upload v-model="form.conferenceNoticeLogo" :limit="1" />
        </el-form-item>
        <el-form-item label="通知名" prop="noticeName">
          <el-input v-model="form.noticeName" placeholder="请输入通知名" />
        </el-form-item>
        <el-form-item label="通知简介" prop="noticeIntroduce">
          <el-input v-model="form.noticeIntroduce" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="通知详情">
          <editor v-model="form.noticeDetails" :min-height="192" />
        </el-form-item>
        <el-form-item label="类型" prop="type">
          <el-radio-group v-model="form.type">
            <el-radio v-for="dict in dict.type.tb_conference_notice_type" :key="dict.value"
              :label="parseInt(dict.value)">{{
              dict.label }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="发布时间" prop="publicationTime">
          <el-date-picker clearable v-model="form.publicationTime" type="date" value-format="yyyy-MM-dd"
                          placeholder="请选择发布时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="发布人" prop="publisher">
          <el-input v-model="form.publisher" placeholder="请输入发布人" />
        </el-form-item>
        <el-form-item label="会议开始时间" prop="conferenceStartTime" v-if="form.type === 3">
          <el-date-picker clearable v-model="form.conferenceStartTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择会议开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会议结束时间" prop="conferenceEndTime" v-if="form.type === 3">
          <el-date-picker clearable v-model="form.conferenceEndTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择会议结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报名开始时间" prop="enrollStartTime" v-if="form.type === 3">
          <el-date-picker clearable v-model="form.enrollStartTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择报名开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报名结束时间" prop="enrollEndTime" v-if="form.type === 3">
          <el-date-picker clearable v-model="form.enrollEndTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择报名结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会议报名要求" prop="demand" v-if="form.type === 3">
          <el-input v-model="form.demand" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <!--        <el-form-item label="审核状态" prop="examineStatus">-->
        <!--          <el-radio-group v-model="form.examineStatus">-->
        <!--            <el-radio-->
        <!--              v-for="dict in dict.type.tb_examine_status"-->
        <!--              :key="dict.value"-->
        <!--              :label="parseInt(dict.value)"-->
        <!--            >{{dict.label}}</el-radio>-->
        <!--          </el-radio-group>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="审核反馈" prop="examineFeedback">-->
        <!--          <el-input v-model="form.examineFeedback" type="textarea" placeholder="请输入内容" />-->
        <!--        </el-form-item>-->
        <el-form-item label="排序" prop="sort">
          <el-input-number v-model="form.sort" :step="1" :min="0" step-strictly />
        </el-form-item>
        <!--        <el-form-item label="备注" prop="remarks">-->
        <!--          <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" />-->
        <!--        </el-form-item>-->
        <el-form-item label="状态" prop="status">
          <el-radio-group v-model="form.status">
            <el-radio v-for="dict in dict.type.tb_status" :key="dict.value" :label="parseInt(dict.value)">{{ dict.label
              }}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--参会嘉宾列表-->
    <el-dialog title="参会嘉宾列表" :visible.sync="openScreenConferencePeople" @close="openScreenConferencePeopleCancel"
      width="1000px" append-to-body>
      <conference-people :screen-conference-notice-id="screenConferenceNoticeId" :key="screenConferenceNoticeId" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="openScreenConferencePeopleCancel">关 闭</el-button>
      </div>
    </el-dialog>

    <!--参会报名列表-->
    <el-dialog title="参会嘉宾列表" :visible.sync="openScreenConferenceRegistration"
      @close="openScreenConferenceRegistrationCancel" width="1000px" append-to-body>
      <conference-registration :screen-conference-notice-id="screenConferenceNoticeId"
        :key="screenConferenceNoticeId" />
      <div slot="footer" class="dialog-footer">
        <el-button @click="openScreenConferenceRegistrationCancel">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listConferenceNotice, getConferenceNotice, delConferenceNotice, addConferenceNotice, updateConferenceNotice } from "@/api/hezhi/conferenceNotice";
import ConferencePeople from "@/views/hezhi/conferencePeople";
import ConferenceRegistration from "@/views/hezhi/conferenceRegistration";

export default {
  name: "ConferenceNotice",
  components: { ConferenceRegistration, ConferencePeople },
  dicts: ['tb_examine_status', 'tb_status', 'tb_conference_notice_type'],
  data() {
    return {
      openScreenConferencePeople: false,
      openScreenConferenceRegistration: false,

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 数字教育大会通知表格数据
      conferenceNoticeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 删除标记时间范围
      daterangeConferenceStartTime: [],
      // 删除标记时间范围
      daterangeConferenceEndTime: [],
      // 删除标记时间范围
      daterangeEnrollStartTime: [],
      // 删除标记时间范围
      daterangeEnrollEndTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        noticeName: null,
        type: null,
        conferenceStartTime: null,
        conferenceEndTime: null,
        enrollStartTime: null,
        enrollEndTime: null,
        conferenceStatus: null,
        examineStatus: null,
        examineFeedback: null,
        remarks: null,
        status: null,
        publicationTime: null,
        publisher: null,
        createTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        conferenceNoticeLogo: [
          { required: true, message: "封面图不能为空", trigger: "blur" }
        ],
        noticeName: [
          { required: true, message: "通知名不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "通知类型不能为空", trigger: "blur" }
        ],
        publicationTime: [
          { required: true, message: "发布时间不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 参会嘉宾列表弹窗 */
    getScreenConferencePeopleList(row) {
      this.screenConferenceNoticeId = row.conferenceNoticeId;
      this.openScreenConferencePeople = true;
    },
    openScreenConferencePeopleCancel() {
      this.screenConferenceNoticeId = null;
      this.openScreenConferencePeople = false;
    },
    /** 参会报名列表弹窗 */
    getScreenConferenceRegistrationList(row) {
      this.screenConferenceNoticeId = row.conferenceNoticeId;
      this.openScreenConferenceRegistration = true;
    },
    openScreenConferenceRegistrationCancel() {
      this.screenConferenceNoticeId = null;
      this.openScreenConferenceRegistration = false;
    },

    /** 查询数字教育大会通知列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeConferenceStartTime && '' != this.daterangeConferenceStartTime) {
        this.queryParams.params["beginConferenceStartTime"] = this.daterangeConferenceStartTime[0];
        this.queryParams.params["endConferenceStartTime"] = this.daterangeConferenceStartTime[1];
      }
      if (null != this.daterangeConferenceEndTime && '' != this.daterangeConferenceEndTime) {
        this.queryParams.params["beginConferenceEndTime"] = this.daterangeConferenceEndTime[0];
        this.queryParams.params["endConferenceEndTime"] = this.daterangeConferenceEndTime[1];
      }
      if (null != this.daterangeEnrollStartTime && '' != this.daterangeEnrollStartTime) {
        this.queryParams.params["beginEnrollStartTime"] = this.daterangeEnrollStartTime[0];
        this.queryParams.params["endEnrollStartTime"] = this.daterangeEnrollStartTime[1];
      }
      if (null != this.daterangeEnrollEndTime && '' != this.daterangeEnrollEndTime) {
        this.queryParams.params["beginEnrollEndTime"] = this.daterangeEnrollEndTime[0];
        this.queryParams.params["endEnrollEndTime"] = this.daterangeEnrollEndTime[1];
      }
      listConferenceNotice(this.queryParams).then(response => {
        this.conferenceNoticeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        conferenceNoticeId: null,
        conferenceNoticeLogo: null,
        noticeName: null,
        noticeIntroduce: null,
        noticeDetails: null,
        type: 1,
        conferenceStartTime: null,
        conferenceEndTime: null,
        enrollStartTime: null,
        enrollEndTime: null,
        demand: null,
        conferenceStatus: null,
        examineStatus: null,
        examineFeedback: null,
        sort: null,
        remarks: null,
        status: 0,
        publicationTime: null,
        publisher: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        deleteTime: null,
        deleteBy: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeConferenceStartTime = [];
      this.daterangeConferenceEndTime = [];
      this.daterangeEnrollStartTime = [];
      this.daterangeEnrollEndTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.conferenceNoticeId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加数字教育大会通知";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const conferenceNoticeId = row.conferenceNoticeId || this.ids
      getConferenceNotice(conferenceNoticeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改数字教育大会通知";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.conferenceNoticeId != null) {
            updateConferenceNotice(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addConferenceNotice(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const conferenceNoticeIds = row.conferenceNoticeId || this.ids;
      this.$modal.confirm('是否确认删除数字教育大会通知编号为"' + conferenceNoticeIds + '"的数据项？').then(function () {
        return delConferenceNotice(conferenceNoticeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hezhi/conferenceNotice/export', {
        ...this.queryParams
      }, `conferenceNotice_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
