选煤厂生产管理平台前端代码
dongyukun
2024-12-11 121bafb30d19c8951812713f6a81d440d1149a97
src/views/proddisp/standingBook/raw-coal-stock/form.vue
@@ -1,212 +1 @@
<template>
  <el-dialog :visible.sync="visible" append-to-body :title="!dataForm.id ? $t('add') : $t('update')"
             :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="110px">
      <el-row>
        <el-col :span="12">
          <el-form-item prop="rq" label="日期">
            <el-date-picker
                style="width: 100%"
                v-model="dataForm.rq"
                type="date"
                :clearable="true"
                value-format="yyyy-MM-dd"
                placeholder="日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="bc" label="班次">
            <dict-select-tag style="width: 100%" v-model="dataForm.bc" clearable placeholder="班次" dictCode="bc"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="yxfw" label="影响范围">
            <el-input v-model="dataForm.yxfw" clearable placeholder="影响范围"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item prop="sgnr" label="事故内容">
            <el-input
                type="textarea"
                :autosize="{ minRows: 3, maxRows: 3}"
                placeholder="请输入事故内容"
                v-model="dataForm.sgnr">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item prop="kssj" label="开始时间">
            <el-date-picker
                style="width: 100%"
                v-model="dataForm.kssj"
                type="datetime"
                :clearable="true"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="开始时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item prop="jssj" label="结束时间">
            <el-date-picker
                style="width: 100%"
                v-model="dataForm.jssj"
                type="datetime"
                :clearable="true"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="结束时间">
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item prop="sgyy" label="事故原因">
            <el-input
                type="textarea"
                :autosize="{ minRows: 3, maxRows: 3}"
                placeholder="请输入事故原因"
                v-model="dataForm.sgyy">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item prop="sghg" label="事故后果">
            <el-input
                type="textarea"
                :autosize="{ minRows: 3, maxRows: 3}"
                placeholder="请输入事故后果"
                v-model="dataForm.sghg">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item prop="bz" label="备注">
            <el-input
                type="textarea"
                :autosize="{ minRows: 3, maxRows: 3}"
                placeholder="请输入备注"
                v-model="dataForm.bz">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template slot="footer">
      <el-button size="mini" :loading="loading" @click="visible = false">{{ $t('cancel') }}</el-button>
      <el-button size="mini" :loading="loading" type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}
      </el-button>
    </template>
  </el-dialog>
</template>
<script>
import debounce from 'lodash/debounce'
import DictSelectTag from '@/components/dict/dict-select-tag'
import {getDictItem} from "@/utils/dictUtils";
export default {
  data() {
    return {
      visible: false,
      loading: false,
      dataForm: {
        id: '',
        rq: '',
        bc: '',
        yxfw: '',
        sgnr: '',
        kssj: '',
        jssj: '',
        cxsj: '',
        sgyy: '',
        sghg: '',
        bz: ''
      }
    }
  },
  components: {
    DictSelectTag
  },
  computed: {
    dataRule() {
      return {
        rq: [
          {required: true, message: this.$t('validate.required'), trigger: 'blur'}
        ],
        bc: [
          {required: true, message: this.$t('validate.required'), trigger: 'blur'}
        ],
        yxfw: [
          {required: true, message: this.$t('validate.required'), trigger: 'blur'}
        ],
        sgnr: [
          {required: true, message: this.$t('validate.required'), trigger: 'blur'}
        ],
        kssj: [
          {required: true, message: this.$t('validate.required'), trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    init() {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.getInfo()
        }
      })
    },
    // 获取信息
    getInfo() {
      this.$http.get(`/iailab-iems-coal-proddisp/work/prod-accident/info/${this.dataForm.id}`).then(({data: res}) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.info
        }
      }).catch(() => {
      })
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function () {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return false
        }
        this.loading = true
        this.$http['post'](`/iailab-iems-coal-proddisp/work/prod-accident/${!this.dataForm.id ? 'add' : 'update'}`, this.dataForm).then(({data: res}) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
          this.loading = false
        }).catch(() => {
        })
      })
    }, 1000, {'leading': true, 'trailing': false})
  }
}
</script>
<template><div></div></template>