Newer
Older
ProductionSysFront / src / views / factoryManager / components / addWellDialog.vue
<!-- 新增、编辑井(数据预录入使用) -->
<template>
  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false" append-to-body>
    <el-form ref="dataForm" :rules="rules" :model="form" label-well-code="right" label-width="120px">
      <el-form-item label="所属项目" prop="project">
        <el-select v-model="form.project" placeholder="请选择" @change="changeSelectProject">
          <el-option
            v-for="item in projectList"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
      </el-form-item>
      <el-form-item class="selectForm-container-item" label="井编号" prop="wellNo">
        <el-input v-model.trim="form.wellNo" placeholder="井编号" clearable/>
      </el-form-item>
      <el-form-item class="selectForm-container-item" label="井名称" prop="wellName">
        <el-input v-model.trim="form.wellName" placeholder="井名称" clearable/>
      </el-form-item>
      <el-form-item class="selectForm-container-item" label="井类型" prop="wellType">
        <el-select v-model="form.wellType" filterable placeholder="井类型" clearable value="" >
          <el-option
            v-for="item in wellTypeList"
            :key="item.value"
            :label="item.name"
            :value="item.value"/>
        </el-select>
      </el-form-item>
      <el-form-item class="selectForm-container-item" label="位置" prop="wellPosition">
        <el-input v-model.trim="form.wellPosition" placeholder="位置" clearable/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="saveData">提交</el-button>
      <el-button @click="cancel">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'AddUserDialog',
  data() {
    return {
      dialogFormVisible: false, // 对话框是否显示
      dialogStatus: '', // 对话框类型:create,update
      form: {
        phone: '', // 手机号
        name: '', // 名称
        keyword: '111111', // 密码
        project: '', // 所在项目
        id: '' // 主键
      }, // 表单
      textMap: {
        update: '编辑',
        create: '新增',
        detail: '详情'
      }, // 表头显示标题
      rules: {
        wellNo: [{ required: true, message: '井编号不能为空', trigger: ['blur', 'change'] }],
        wellType: [{ required: true, message: '井类型不能为空', trigger: ['blur', 'change'] }],
        project: [{ required: true, message: '所属项目不能为空', trigger: ['blur', 'change'] }],
        wellName: [{ required: true, message: '井名称不能为空', trigger: ['blur', 'change'] }]
      }, // 前端校验规则
      projectList: [
        {
          value: '1',
          label: '项目1'
        },
        {
          value: '2',
          label: '项目2'
        },
        {
          value: '3',
          label: '项目3'
        }
      ],
      wellTypeList: [
        {
          id: '1',
          name: '液位井'
        },
        {
          id: '2',
          name: '燃气井'
        }
      ]
    }
  },
  created() {
    // this.fetchPrincipalList()
    // this.fetchDeptList()
  },
  methods: {
    // 初始化对话框
    initDialog: function(dialogStatus, dialogFormVisible, row = null) {
      this.dialogStatus = dialogStatus // 类型 新增create 编辑update 详情detail
      this.dialogFormVisible = dialogFormVisible // 对话框显隐
      if (dialogStatus === 'create') { // 如果是新增,清除验证
        this.resetForm()
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
      } else if (dialogStatus === 'update') { // 如果是修改,将row中数据填写到输入框中
        this.form = {
          wellNo: row.wellNo, // 井编号
          wellName: row.wellName, // 井名称
          wellType: row.wellType, // 井类型
          wellPosition: row.wellPosition, // 位置
          project: row.project, // 所在项目
          id: row.id
        }
        console.log(this.form)
      }
    },
    // 重置表单
    resetForm() {
      this.form = {
        wellNo: '', // 井编号
        wellName: '', // 井名称
        wellType: '', // 井类型
        wellPosition: '', // 位置
        project: '', // 所在项目
        id: '' // 主键
      }
    },
    // 点击提交
    saveData: function() {
      if (this.dialogStatus === 'update') {
        this.updateData()
      } else if (this.dialogStatus === 'create') {
        this.createData()
      }
    },
    // 新增数据
    createData: function() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          // 在这里注意如果密码是空的话,就默认111111
          // addDeviceType(this.form.productName, this.form.productModel, this.form.machineVersion,
          //   this.form.hardwareVersion, this.form.softwareVersion, this.form.designArchive,
          //   this.form.batchFiling, this.form.status, this.form.principal,
          //   this.form.kpi, this.form.quotaSummary, this.quotaSummaryFile, this.form.communicationVersion,
          //   this.form.productType).then(response => {
          //   if (response.code === 200) {
          //     this.$confirm('新增成功,是否继续新增?', '提示', {
          //       confirmButtonText: '是',
          //       cancelButtonText: '否',
          //       type: 'info'
          //     }).then(() => {
          //       this.resetForm()
          //       this.$nextTick(() => {
          //         this.$refs['dataForm'].clearValidate()
          //       })
          //     }).catch(() => {
          //       this.$emit('watchChild')
          //       this.dialogFormVisible = false
          //     })
          //   }
          // })
        }
      })
    },
    // 修改数据
    updateData: function() {
      this.$refs['dataForm'].validate((valid) => {
        // 在这里注意如果密码是空的话,就默认111111
        if (valid) {
          // updateDeviceType(this.form.id, this.form.productName, this.form.productModel, this.form.machineVersion,
          //   this.form.hardwareVersion, this.form.softwareVersion, this.form.designArchive,
          //   this.form.batchFiling, this.form.status, this.form.principal,
          //   this.form.kpi, this.form.quotaSummary, this.quotaSummaryFile, this.form.communicationVersion,
          //   this.form.productType).then(response => {
          //   if (response.code === 200) {
          //     this.$message.success('修改成功')
          //     this.$emit('watchChild')
          //     this.dialogFormVisible = false
          //   }
          // })
        }
      })
    },
    // 点击取消
    cancel: function() {
      this.dialogFormVisible = false
      this.$emit('watchChild')
    },
    // 所在项目选中值发生变化
    changeSelectProject(val) {
      console.log(val)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .el-select{
    width: 100%;
  }
  .el-date-editor{
    width: 100%;
  }
</style>