<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:meeting:edit']"
    >{{ $t('保存会议') }}</el-button>

    <h3
      v-if="this.meetingId != null"
      style="margin: 15px 1px 1px 35px;"
    >{{ $t('会议内容') }}</h3>

    <el-tabs tab-position="left">
      <el-tab-pane :label="$t('装置会议执行')" >
        <actionlist />
      </el-tab-pane>
      <el-tab-pane :label="$t('EHS开项追踪')" >
        <ehsopenitem />
      </el-tab-pane>
      <el-tab-pane :label="$t('下周关键维修')" >
        <keymaintenance />
      </el-tab-pane>
      <el-tab-pane :label="$t('信息提醒')" >
        <messageattention />
      </el-tab-pane>
      <el-tab-pane :label="$t('关键机组联锁旁路')" >
        <interlock />
      </el-tab-pane>
      <el-tab-pane :label="$t('风险提醒')" >
        <riskreminder />
      </el-tab-pane>
      <el-tab-pane :label="$t('OpEx项目跟踪')" >
        <opextrack />
      </el-tab-pane>
      <el-tab-pane :label="$t('与会者')" >
      <person :isCc = "0"></person>
      </el-tab-pane>
      <el-tab-pane :label="$t('抄报')" >
        <person :isCc = "1"></person>
      </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="$t('装置名称')" prop="plantCode">-->
<!--          <el-select v-model="form.plantCode" :placeholder="$t('请选择') + $t('装置名称')">-->
<!--            <el-option-->
<!--              v-for="dict in plantCodeOptions"-->
<!--              :key="dict.dictValue"-->
<!--              :label="dict.dictLabel"-->
<!--              :value="dict.dictValue"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
        <el-form-item :label="$t('会议时间')" prop="meetingDate">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.meetingDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          :placeholder="$t('请选择') + $t('会议时间')">
          </el-date-picker>
        </el-form-item>

        <el-form-item :label="$t('会议编号')" prop="meetingNo">
          <el-input v-model="form.meetingNo" :placeholder="$t('请输入') +$t('会议编号')" />
        </el-form-item>

        <el-form-item :label="$t('会议地点')" prop="venue">
          <el-input v-model="form.venue" :placeholder="$t('请输入') + $t('会议地点')" />
        </el-form-item>
        <el-form-item :label="$t('主题')" prop="subject">
          <el-input v-model="form.subject" :placeholder="$t('请输入') + $t('主题')" />
        </el-form-item>
        <el-form-item :label="$t('记录人')" prop="recorder">
          <el-input v-model="form.recorder" :placeholder="$t('请输入') + $t('记录人')" />
        </el-form-item>
        <el-form-item :label="$t('备注')" prop="remarks">
          <el-input v-model="form.remarks" :placeholder="$t('请输入') + $t('备注')" />
        </el-form-item>
<!--        <el-form-item :label="$t('归属部门')" prop="deptId">-->
<!--          <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" :placeholder="$t('请选择') + $t('归属部门')" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">{{ $t('确 定') }}</el-button>
        <el-button @click="cancel">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMeeting, getMeeting,getLastMeeting, delMeeting, addMeeting, updateMeeting, exportMeeting, importTemplate} from "@/api/plant/meeting";
import Keymaintenance from "../../components/meeting/keymaintenance";
import Actionlist from "../../components/meeting/actionlist";
import Ehsopenitem from "../../components/meeting/ehsopenitem";
import Messageattention from "../../components/meeting/messageattention";
import Riskreminder from "../../components/meeting/riskreminder";
import Opextrack from "../../components/meeting/opextrack";
import Interlock from "../../components/meeting/interlock";
import Treeselect from "@riophae/vue-treeselect";
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";

export default {
  name: "Weekmeeting",
  components: {
    Person,
    Actionlist,
    Keymaintenance,
    Ehsopenitem,
    Messageattention,
    Riskreminder,
    Opextrack,
    Interlock,
    Treeselect
  },
  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: {
        meetingDate: [
          { required: true, message: this.$t('不能为空'), 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
      };
      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();
      let param = {}
      getLastMeeting(param).then(response => {
        this.form = response.data;
        this.form.meetingDate = null
        this.open = true;
        this.title = this.$t('新增') + " " + this.$t('装置会议');
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getMeeting(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = this.$t('修改') + this.$t('装置会议');
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateMeeting(this.form).then(response => {
              this.msgSuccess(this.$t('修改成功'));
              this.open = false;
              this.getList();
            });
          } else {
            addMeeting(this.form).then(response => {
              this.msgSuccess(this.$t('新增成功'));
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 报告附件按钮操作 */
    importMeeting(row) {
      this.doc.open = true;
      this.$nextTick(() => {
        this.$refs.doc.clearFiles()
      })
    },
  }
};
</script>

<style>

</style>
