gaoluyang
2 天以前 d0716996bcc06c5b4dbeb4a11c909dd1a77f4368
src/views/CNAS/resourceDemand/device/component/accidentForm.vue
@@ -9,7 +9,7 @@
        <el-step title="技术负责人意见" @click="setStep(3)"></el-step>
        <el-step title="主任意见" @click="setStep(4)"></el-step>
      </el-steps>
      <el-form ref="modelForm" :model="form" :rules="rules" label-width="160px">
      <el-form ref="modelForm" :model="form" :rules="rules" label-width="160px" :disabled="!canOperate">
        <el-col v-if="showStep === 0" :span="12">
          <el-form-item label="地点:" prop="address">
            <el-input v-model="form.address" :disabled="currentStep !== 0" clearable size="small"></el-input>
@@ -87,7 +87,7 @@
      </el-form>
      <template #footer><span  class="dialog-footer">
        <el-button @click="resetForm">取 消</el-button>
        <el-button v-if="currentStep !== 5" :loading="submitFormLoading" type="primary" @click="submitForm">确
        <el-button v-if="currentStep !== 5 && canOperate" :loading="submitFormLoading" type="primary" @click="submitForm">确
          认</el-button>
      </span></template>
    </el-dialog>
@@ -96,21 +96,21 @@
<script>
import { selectUserCondition } from "@/api/business/inspectionTask";
import { mapGetters } from "@/utils/store-compat";
import {
  getDeviceAccidentReport,
  addDeviceAccidentReport,
} from '@/api/cnas/resourceDemand/device.js'
import draftSave from '@/mixins/draftSave'
export default {
  name: "accident-form",
  // import 引入的组件需要注入到对象中才能使用
  components: {},
  mixins: [draftSave],
  data() {
    // 这里存放数据
    return {
      dialogVisible: false,
      submitFormLoading: false,
      canOperate: true,
      form: {
        accidentReportId: '',
        address: '',
@@ -147,22 +147,19 @@
    // 打开弹框
    openDialog(id, deviceId) {
      this.dialogVisible = true
      this.canOperate = true
      this.form.accidentReportId = id
      this.form.deviceId = deviceId
      this.getUserList()
      if (this.form.accidentReportId) {
        this.searchInfo()
      } else {
        this.draftRestore('accidentForm', 'form', this.form.deviceId, 'dialogVisible')
      }
    },
    // 查询详情
    searchInfo() {
      getDeviceAccidentReport({ accidentReportId: this.form.accidentReportId }).then(res => {
        if (res.code === 200) {
          const id = this.form.accidentReportId
          this.form = { ...res.data }
          this.draftRestore('accidentForm', 'form', id, 'dialogVisible')
          if (res.data.isFinish === 0) {
            if (this.form.assessorUserId) {
              this.currentStep = 1
@@ -184,10 +181,30 @@
            this.currentStep = 5
            this.showStep = 4
          }
          this.applyPermission()
        }
      }).catch(error => {
        console.error(error)
      })
    },
    // 非当前环节责任人只允许查看
    applyPermission() {
      if (this.form.isFinish === 1 || this.currentStep >= 5) {
        this.canOperate = false
        return
      }
      const responsibleList = [
        this.form.reportUser,
        this.form.assessorUser,
        this.form.departmentHeadUser,
        this.form.technicalDirectorUser,
        this.form.directorHeadUser,
      ]
      const responsible = responsibleList[this.currentStep]
      this.canOperate = !responsible || responsible === this.nickName
      if (!this.canOperate) {
        this.$message.warning('当前环节责任人为:' + responsible + ',您只能查看')
      }
    },
    setStep(step) {
      this.showStep = step
@@ -197,10 +214,10 @@
      this.form.flowType = this.currentStep
      this.$refs.modelForm.validate((valid) => {
        if (valid) {
          this.submitFormLoading = true
          addDeviceAccidentReport(this.form).then(res => {
            if (res.code == 200) {
              this.$message.success('新增成功')
              this.draftClear('accidentForm')
              this.resetForm()
            }
            this.submitFormLoading = false
@@ -212,7 +229,6 @@
    },
    // 关闭弹框
    resetForm() {
      this.draftStop('accidentForm')
      this.dialogVisible = false
      this.$emit('closeDialog')
    },
@@ -222,6 +238,9 @@
      })
    },
  },
  computed: {
    ...mapGetters(["nickName"]),
  },
}
</script>