<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="status"> </el-form-item>

      <el-form-item label="会议状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择会议状态"
          clearable
          filterable
        >
          <el-option
            v-for="dict in statusList"
            :key="dict.value + 'statusList'"
            :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="['business:JOINTCONFERENCE: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="['business:JOINTCONFERENCE: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="['business:JOINTCONFERENCE:remove']"
          >删除</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      :data="JOINTCONFERENCEList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="会议标题" align="center" prop="conferenceTitle">
        <template slot-scope="scope">
          {{ scope.row.conferenceTitle }}
        </template>
      </el-table-column>

      <el-table-column label="协作单位" align="center" prop="cooperativeUnit">
        <template slot-scope="scope">
          {{ scope.row.cooperativeUnit }}
        </template>
      </el-table-column>

      <el-table-column label="会议状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1">未指派</el-tag>
          <el-tag v-else-if="scope.row.status == 2" type="success">进行中</el-tag>
          <el-tag v-else-if="scope.row.status == 3" type="info">已完成</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="已回复单位数量" align="center" prop="replied">
        <template slot-scope="scope">
          {{ scope.row.replied }}
        </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"
            @click="goDetail(scope.row)"
            v-hasPermi="['business:JOINTCONFERENCE:edit']"
            >会议详情</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleUnit(scope.row)"
            v-hasPermi="['business:JOINTCONFERENCE:edit']"
            >单位指派</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"
    />
  </div>
</template>

<script>
import {
  listJOINTCONFERENCE,
  getJOINTCONFERENCE,
  delJOINTCONFERENCE,
  addJOINTCONFERENCE,
  updateJOINTCONFERENCE,
} from "@/api/portal/JOINTCONFERENCE/JOINTCONFERENCE.js";
import add from "./add.vue";

export default {
  name: "JOINTCONFERENCE",
  data() {
    return {
      statusList: [
        { label: "未指派", value: 1 },
        { label: "进行中", value: 2 },
        { label: "已完成", value: 3 },
      ],
      // 根路径
      baseURL: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 联席会议表格数据
      JOINTCONFERENCEList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        delFlag: null,
        deptId: null,
        conferenceTitle: null,
        conferenceContent: null,
        cooperativeUnit: null,
        replied: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [{ required: true, message: "主键id不能为空", trigger: "blur" }],
        delFlag: [
          { required: true, message: "删除标志不能为空", trigger: "blur" },
        ],
        deptId: [
          { required: true, message: "部门id不能为空", trigger: "blur" },
        ],
        conferenceTitle: [
          { required: true, message: "会议标题不能为空", trigger: "blur" },
        ],
        conferenceContent: [
          { required: true, message: "会议内容不能为空", trigger: "blur" },
        ],
        cooperativeUnit: [
          { required: true, message: "协作单位不能为空", trigger: "blur" },
        ],
        replied: [
          {
            required: true,
            message: "已回复单位数量不能为空",
            trigger: "blur",
          },
        ],
        status: [
          {
            required: true,
            message: "会议状态1=未指派，2=进行中，3=已完成不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    goDetail(row){
      
    },
    handleUnit(row){
      const id = row.id || this.ids;
      this.iframe({ obj: add, param: { id: id }, title: '单位指派', width: '750px', height: '60%' });
    },
    /** 查询联席会议列表 */
    getList() {
      this.loading = true;
      listJOINTCONFERENCE(this.queryParams).then((response) => {
        this.JOINTCONFERENCEList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        delFlag: null,
        deptId: null,
        conferenceTitle: null,
        conferenceContent: null,
        cooperativeUnit: null,
        replied: null,
        status: "0",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    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;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.iframe({ obj: add, param: {}, title: '发起会议', width: '750px', height: '60%' });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getJOINTCONFERENCE(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改联席会议";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateJOINTCONFERENCE(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addJOINTCONFERENCE(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除？')
        .then(function () {
          return delJOINTCONFERENCE(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "business/JOINTCONFERENCE/export",
        {
          ...this.queryParams,
        },
        `JOINTCONFERENCE_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
