Newer
Older
garbageClassificationFront / src / views / garbageBag / inbound.vue
StephanieGitHub on 7 May 2021 3 KB first commit
<template>
  <el-dialog :visible.sync="dialogFormVisible" :fullscreen="false" title="垃圾袋入库" width="60%" append-to-body>
    <el-form ref="dataForm" :rules="rules" :model="dataForm" label-well-code="right" label-width="100px">
      <div class="form-div">
        <div class="form-left">
          <el-row :gutter="10">
            <el-col :span="12">
              <el-form-item label="数量" prop="num">
                <el-input v-model.trim="dataForm.num" :disabled="isDetailMode" type="text" placeholder=""/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="使用类型" prop="useType">
                <el-input v-model.trim="dataForm.useType" :disabled="isDetailMode" type="text" placeholder=""/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10">
            <el-col :span="12">
              <el-form-item label="回收情况" prop="recycable">
                <el-input v-model.trim="dataForm.recycable" :disabled="isDetailMode" type="text" placeholder=""/>
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-form>
    <div v-show="!isDetailMode" slot="footer" class="dialog-footer">
      <el-button :disabled="!canEdit" type="primary" @click="saveData">保存</el-button>
      <el-button @click="cancel">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { inbound } from '@/api/biz/garbageBag'
export default {
  name: 'Inbound',
  data() {
    return {
      dialogFormVisible: false, // 对话框是否显示
      dataForm: {
        num: '',
        useType: '',
        recycable: ''
      }, // 表单
      rules: {
        num: [{ required: true, message: '不能为空', trigger: ['blur', 'change'] }],
        useType: [{ required: true, message: '不能为空', trigger: ['blur', 'change'] }],
        recycable: [{ required: true, message: '不能为空', trigger: ['blur', 'change'] }]
      }, // 前端校验规则
      canEdit: true
    }
  },
  methods: {
    /**
     * 初始化对话框
     */
    initDialog: function() {
      this.dialogFormVisible = true
    },
    // 重置表单
    resetForm() {
      this.dataForm = {
        num: '',
        useType: '',
        recycable: ''
      }
    },
    // 保存数据
    saveData: function() {
      this.canEdit = false
      this.$refs['dataForm'].validate((valid) => {
        console.log(this.dataForm)
        if (valid) {
          this.$message.success('入库成功')
          this.resetForm()
          this.$refs['dataForm'].clearValidate()
          this.canEdit = true
          this.dialogFormVisible = false
          this.$emit('watchChild')
          // inbound(this.dataForm).then(response => {
          //   if (response.code === 200) {
          //     this.$message.success('入库成功')
          //     this.resetForm()
          //     this.$refs['dataForm'].clearValidate()
          //     this.canEdit = true
          //     this.dialogFormVisible = false
          //     this.$emit('watchChild')
          //   }
          // }).catch((e) => {
          //   this.canEdit = true
          // })
        } else {
          this.canEdit = true
        }
      })
    },
    cancel: function() {
      this.dialogFormVisible = false
      this.$emit('watchChild')
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .el-select{
    width: 100%;
  }
  .el-date-editor{
    width: 100%;
  }
  .form-div{
    width:100%;
    height:100%;
    display:flex;
    justify-content: space-between;
    .form-left{
      flex:1;
      height:100%;
    }
  }
</style>