<template>
  <div class="app-container noticeconfig">
    <el-form :model="form" ref="form" :inline="true" label-width="120px">
      <div class="top-title-box">
        <p>预案通知</p>
        <p class="inquire-button-one" @click="upData" v-if="form.id" v-hasPermi="['laboratory:noticeconfig:edit']">保存</p>
        <p class="inquire-button-one" @click="upData" v-if="!form.id" v-hasPermi="['laboratory:noticeconfig:add']">提交</p>
      </div>
      <el-form-item label="广播通知" prop="riskRadio" class="form-item-box">
        <el-input
          style="width:350px;"
          type="textarea"
          maxlength="50"
          :rows="3"
          resize="none"
          placeholder="请输入广播通知内容"
          v-model="form.riskRadio">
        </el-input>
      </el-form-item>
      <el-form-item label="语音播报" prop="riskVoice" class="form-item-box">
        <el-input
          style="width:350px;"
          type="textarea"
          maxlength="50"
          :rows="3"
          resize="none"
          placeholder="请输入语音播报内容"
          v-model="form.riskVoice">
        </el-input>
      </el-form-item>
      <el-form-item label="电话通知" prop="riskPhone" class="form-item-box">
        <el-input
          style="width:350px;"
          type="textarea"
          maxlength="50"
          :rows="3"
          resize="none"
          placeholder="请输入电话通知内容"
          v-model="form.riskPhone">
        </el-input>
      </el-form-item>
      <el-form-item label="短信提示" prop="riskMessage" class="form-item-box">
        <el-input
          style="width:350px;"
          type="textarea"
          maxlength="50"
          :rows="3"
          resize="none"
          placeholder="请输入短信提示内容"
          v-model="form.riskMessage">
        </el-input>
      </el-form-item>
      <div class="top-title-box">
        <p>疏散通知</p>
      </div>
      <el-form-item label="广播通知" prop="exitRadio" class="form-item-box">
        <el-input
          style="width:350px;"
          type="textarea"
          maxlength="50"
          :rows="3"
          resize="none"
          placeholder="请输入广播通知内容"
          v-model="form.exitRadio">
        </el-input>
      </el-form-item>
      <el-form-item label="语音播报" prop="exitVoice" class="form-item-box">
        <el-input
          style="width:350px;"
          type="textarea"
          maxlength="50"
          :rows="3"
          resize="none"
          placeholder="请输入语音播报内容"
          v-model="form.exitVoice">
        </el-input>
      </el-form-item>
      <el-form-item label="电话通知" prop="exitPhone" class="form-item-box">
        <el-input
          style="width:350px;"
          type="textarea"
          maxlength="50"
          :rows="3"
          resize="none"
          placeholder="请输入电话通知内容"
          v-model="form.exitPhone">
        </el-input>
      </el-form-item>
      <el-form-item label="短信提示" prop="exitMessage" class="form-item-box">
        <el-input
          style="width:350px;"
          type="textarea"
          maxlength="50"
          :rows="3"
          resize="none"
          placeholder="请输入短信提示内容"
          v-model="form.exitMessage">
        </el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getNoticeconfigInfo, postNoticeconfigInfo, putNoticeconfigInfo } from "@/api/laboratory/noticeconfig";

export default {
  name: "Noticeconfig",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 通知配置表格数据
      form: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        riskVoice: null,
        riskPhone: null,
        riskMessage: null,
        exitRadio: null,
        exitVoice: null,
        exitPhone: null,
        exitMessage: null
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    upData(){
      let self = this;
      this.$confirm('是否确定提交？', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        if(self.form.id){
          self.putNoticeconfigInfo();
        }else{
          self.postNoticeconfigInfo();
        }
      }).then(() => {

      }).catch(() => {});
    },
    postNoticeconfigInfo(){
      postNoticeconfigInfo(this.form).then( response => {
        this.msgSuccess("操作成功")
        this.getList();
      });
    },
    putNoticeconfigInfo(){
      putNoticeconfigInfo(this.form).then( response => {
        this.msgSuccess("操作成功")
        this.getList();
      });
    },
    /** 查询通知配置列表 */
    getList() {
      this.loading = true;
      getNoticeconfigInfo().then( response => {
        this.form =  response.data;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        riskVoice: null,
        riskPhone: null,
        riskMessage: null,
        exitRadio: null,
        exitVoice: null,
        exitPhone: null,
        exitMessage: 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();
      this.open = true;
      this.title = "添加通知配置";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNoticeconfig(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) {
            updateNoticeconfig(this.form).then( response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNoticeconfig(this.form).then( response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除通知配置编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delNoticeconfig(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('laboratory/noticeconfig/export', {
        ...this.queryParams
      }, `laboratory_noticeconfig.xlsx`)
    }
  }
};
</script>

<style scoped lang="scss">
  .noticeconfig{
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
    padding:0 20px 20px!important;
    *{
      margin:0;
    }
    .top-title-box{
      display: flex;
      height:80px;
      border-bottom:1px solid #E0E0E0;
      margin-bottom:54px;
      p:nth-child(1){
        line-height:80px;
        font-size:18px;
        color:#0045AF;
        flex:1;
      }
      p:nth-child(2){
        margin-top:20px;
      }
    }
    .form-item-box{
      display: inline-block;
      margin-bottom:28px;
    }
  }
</style>
