<template>
  <div>
    <el-button
      v-if="this.meetingId == null"
      style="margin: 15px 1px 1px 35px;"
      type="success"
      icon="el-icon-edit"
      size="mini"
      @click="handleAdd"
      v-hasPermi="['plant:keymaintenance:edit']"
    >保存会议
    </el-button>
    <!--    <el-button-->
    <!--      v-if="this.meetingId == null"-->
    <!--      style="margin: 15px 1px 1px 35px;"-->
    <!--      type="success"-->
    <!--      icon="el-icon-edit"-->
    <!--      size="mini"-->
    <!--      @click="importMeeting"-->
    <!--      v-hasPermi="['plant:keymaintenance:edit']"-->
    <!--    >导入会议-->
    <!--    </el-button>-->
    <h3
      v-if="this.meetingId != null"
      style="margin: 15px 1px 1px 35px;"
    >会议内容</h3>

    <el-tabs tab-position="left">
      <el-tab-pane label="参会人员">
        <person :meetingId="meetingId" :isCc="1"/>
      </el-tab-pane>
      <el-tab-pane label="内容">
        <agenda :contentTitle="'内容'" :agendaType="1" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="EHS信息分享">
        <agenda :contentTitle="'√ EHS信息分享'" :agendaType="2" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="质量议题">
        <agenda :contentTitle="'√ 质量议题'" :agendaType="3" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="行动项追踪系统状态">
        <agenda :contentTitle="'√ 行动项追踪系统状态'" :agendaType="4" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="生产计划">
        <agenda :contentTitle="'√ 生产计划'" :agendaType="14" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="装置运行状态，负荷等">
        <agenda :contentTitle="'√ 装置运行状态，负荷等'" :agendaType="5" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="OpEx/KPIs 议题">
        <agenda :contentTitle="'√ OpEx/KPIs 议题'" :agendaType="6" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="MOC议题">
        <agenda :contentTitle="'√ MOC议题'" :agendaType="7" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="CapEx/检修议题">
        <agenda :contentTitle="'√ CapEx/检修议题'" :agendaType="8" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="文档完整性">
        <agenda :contentTitle="'√ 文档完整性'" :agendaType="9" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="其他/5S">
        <agenda :contentTitle="'√ 其他/5S'" :agendaType="10" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="其他/LEAN">
        <agenda :contentTitle="'√ 其他/LEAN'" :agendaType="11" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="静设备近期PM/检维修计划">
        <agenda :contentTitle="'√ 静设备近期PM/检维修计划'" :agendaType="12" :meetingId="meetingId"/>
      </el-tab-pane>
      <el-tab-pane label="电气仪表近期PM/检维修计划">
        <agenda :contentTitle="'√ 电气仪表近期PM/检维修计划'" :agendaType="13" :meetingId="meetingId"/>
      </el-tab-pane>
    </el-tabs>
    <!-- 添加或修改装置会议对话框 -->
    <el-dialog :close-on-click-modal="false" v-dialogDrag :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="主题" prop="subject">
          <el-input v-model="form.subject" placeholder="请输入主题"/>
        </el-form-item>
        <el-form-item label="主持人" prop="presided">
          <el-input v-model="form.presided" placeholder="请输入主持人"/>
        </el-form-item>
        <el-form-item label="记录人" prop="recorder">
          <el-input v-model="form.recorder" placeholder="请输入记录人"/>
        </el-form-item>
        <el-form-item label="会议编号" prop="meetingNo">
          <el-input v-model="form.meetingNo" placeholder="请输入会议编号"/>
        </el-form-item>
        <el-form-item label="会议时间" prop="meetingDate">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.meetingDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择会议时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会议地点" prop="venue">
          <el-input v-model="form.venue" placeholder="请输入会议地点"/>
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注"/>
        </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>
  </div>
</template>

<script>
import {addMeeting, getMeeting, updateMeeting} from "@/api/plant/meeting";
import {treeselect} from "@/api/system/dept";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import Person from "../../components/meeting/person";
import {getToken} from "@/utils/auth";
import Agenda from "@/views/plant/agenda/index.vue";

export default {
  name: "Weekmeeting",
  components: {
    Agenda,
    Person
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 装置会议表格数据
      meetingList: [],
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      clientHeight: 300,
      // 是否显示弹出层
      open: false,
      // 装置字典
      plantCodeOptions: [],
      // 表单参数
      form: {},
      meetingId: 0,
      // 附件参数
      doc: {
        file: "123",
        // 是否显示弹出层（报告附件）
        open: false,
        // 弹出层标题（报告附件）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 报告附件上传位置编号
        ids: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/common/commonfile/uploadFile",
        commonfileList: null,
        queryParams: {
          pId: null,
          pType: 'manageactivity'
        },
        pType: 'manageactivity',
        pId: null
      },
      // 表单校验
      rules: {
        subject: [
          {required: true, message: '会议主题不能为空', trigger: "change"}
        ],
      }
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.meetingId = this.$route.params && this.$route.params.tableId;
    //设置表格高度对应屏幕高度
    this.$nextTick(() => {
      this.clientHeight = (document.body.clientHeight - 80) * 0.8
    })
    this.getTreeselect();
    this.getDicts("PLANT_DIVIDE").then(response => {
      this.plantCodeOptions = response.data;
    });
  },
  methods: {
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 装置字典翻译
    plantCodeFormat(row, column) {
      return this.selectDictLabel(this.plantCodeOptions, row.plantCode);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        plantCode: null,
        recorder: null,
        meetingNo: null,
        meetingDate: null,
        venue: null,
        subject: null,
        delFlag: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null,
        remarks: null,
        presided: null,
        mtType: 1,
      };
      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.reset();
      this.open = true;
      this.title = '新增装置会议';
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMeeting(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) {
              updateMeeting(this.form).then(response => {
                this.$modal.msgSuccess('修改成功');
                this.open = false;
                // this.getList();
              });
            } else {
              // this.form.tMtAgenda = {};//传过来的值存到这里
              addMeeting(this.form).then(response => {
                this.$modal.msgSuccess('新增成功');
                this.open = false;
                // this.getList();
                location.reload();
              });
            }
          }
        }
      )
      ;
    },
    /** 报告附件按钮操作 */
    importMeeting(row) {
      this.doc.open = true;
      this.$nextTick(() => {
        this.$refs.doc.clearFiles()
      })
    },
  }
};
</script>

<style>

</style>
