loulijun2021
2022-06-17 38d11c5d99a78a7c65ccb2b24d6f49b97f9c0fdd
src/views/jcsz/zzjg.vue
@@ -46,6 +46,7 @@
        <el-table
          :data="tableData"
          border
          highlight-current-row
          :style="{width: 100+'%',height:tableHeight+'px'}"
          :header-cell-style="this.$headerCellStyle"
          :cell-style="this.$cellStyle"
@@ -130,8 +131,8 @@
      top="15vh"
      @closed="handleClose"
    >
      <el-form ref="dialogForm" :model="dialogForm" label-width="80px">
        <el-form-item label="组织类型" required>
      <el-form ref="dialogForm" :rules="dialogFormRules" :model="dialogForm" label-width="80px">
        <el-form-item label="组织类型" prop="OrgType">
          <el-radio-group
            v-model="dialogForm.OrgType"
            style="display: flex;align-items: end;height: 29px;"
@@ -145,13 +146,13 @@
            />
          </el-radio-group>
        </el-form-item>
        <el-form-item label="组织编码" required>
          <el-input v-model="dialogForm.OrgCode" style="width: 220px" />
        <el-form-item label="组织编码" prop="OrgCode">
          <el-input v-model="dialogForm.OrgCode" :disabled="operation!=='add'" style="width: 220px" />
        </el-form-item>
        <el-form-item label="组织名称" required>
        <el-form-item label="组织名称" prop="OrgName">
          <el-input v-model="dialogForm.OrgName" style="width: 220px" />
        </el-form-item>
        <el-form-item v-if="dialogFormOrgTypeSelected!=='F'" label="上级单位" required>
        <el-form-item v-if="dialogFormOrgTypeSelected!=='F'" prop="SupUnit" label="上级单位">
          <el-select
            v-model="dialogForm.SupUnit"
            style="width: 220px"
@@ -159,7 +160,6 @@
          >
            <el-option
              v-for="item in SupUnitArr"
              :key="item.id"
              :label="item.org_name"
              :value="item.id"
            />
@@ -181,12 +181,31 @@
import { AddUpdateOrganization, DeleteOrganization, OrganizationSearch, PrentOrganization } from '@/api/jcsz'
import { getCookie } from '@/utils/auth'
const SER_HZ = /^[\u4e00-\u9fa5]+$/
export default {
  name: 'Zzjg',
  components: {
    Pagination
  },
  data() {
    const validateName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请输入编码'))
      } else {
        if (SER_HZ.test(value)) {
          return callback(new Error('编码不能为中文'))
        } else {
          callback()
        }
      }
    }
    const validateTypeCode = (rule, value, callback) => {
      if (!value) {
        return callback(new Error('请选择上级'))
      } else {
        callback()
      }
    }
    return {
      mainHeight: 0,
      tableHeight: 0,
@@ -219,21 +238,21 @@
      },
      SupUnitArr: [],
      dialogFormOrgTypeSelected: '',
      operation: ''
      // dialogFormRules: {
      //   // OrgType: [
      //   //   { required: true, message: '请输入名称', trigger: 'blur' }
      //   // ],
      //   OrgCode: [
      //     { required: true, message: '请输入组织编码', trigger: 'blur' }
      //   ],
      //   OrgName: [
      //     { required: true, message: '请输入组织名称', trigger: 'blur' }
      //   ]
      //   // SupUnit: [
      //   //   { required: true, message: '请输入名称', trigger: 'blur' }
      //   // ]
      // }
      operation: '',
      dialogFormRules: {
        OrgType: [
          { required: true, message: '请输入选择类型', trigger: ['blur', 'change'] }
        ],
        OrgCode: [
          { required: true, validator: validateName, trigger: ['blur', 'change'] }
        ],
        OrgName: [
          { required: true, message: '请输入名称', trigger: ['blur', 'change'] }
        ],
        SupUnit: [
          { required: true, validator: validateTypeCode, trigger: ['blur', 'change'] }
        ]
      }
    }
  },
@@ -246,8 +265,9 @@
  },
  methods: {
    async getOrganizationSearch() {
      const { data: res } = await OrganizationSearch(this.form)
      this.tableData = res
      const res = await OrganizationSearch(this.form)
      this.tableData = res.data
      this.total = res.count
    },
    // 排序改变时
    sortChange({ column, prop, order }) {
@@ -312,10 +332,12 @@
      } else if (row.description === 'L') {
        this.dialogForm.OrgType = '生产线'
      }
      this.changeRadio(this.dialogForm.OrgType)
      this.dialogForm.OrgCode = row.org_code
      this.dialogForm.OrgName = row.org_name
      this.dialogForm.SupUnit = row.parent_id
      this.$nextTick(() => {
        this.changeRadio(this.dialogForm.OrgType)
        this.dialogForm.OrgCode = row.org_code
        this.dialogForm.OrgName = row.org_name
        this.dialogForm.SupUnit = row.parent_id
      })
    },
    // 删除按钮
    async del(id) {
@@ -340,42 +362,36 @@
      this.dialogForm.OrgCode = ''
      this.dialogForm.OrgName = ''
      this.dialogForm.SupUnit = ''
      this.$refs.dialogForm.clearValidate()
    },
    // 对话框取消
    dialogVisibleCancel() {
      this.dialogVisible = false
    },
    // 对话框确认
    async dialogVisibleConfirm() {
      if (this.dialogFormOrgTypeSelected.length < 1) {
        return this.$message.info('组织类型未选!')
      }
      if (this.dialogForm.OrgCode < 1) {
        return this.$message.info('组织编码未填!')
      }
      if (this.dialogForm.OrgName < 1) {
        return this.$message.info('组织名称未填!')
      }
      if (this.dialogForm.SupUnit < 1) {
        return this.$message.info('上级单位未选!')
      }
    dialogVisibleConfirm() {
      this.$refs.dialogForm.validate(valid => {
        if (valid) {
          const data = {
            OrganType: this.dialogFormOrgTypeSelected,
            OrganCode: this.dialogForm.OrgCode,
            OrganName: this.dialogForm.OrgName,
            SupUnit: this.dialogFormOrgTypeSelected === 'F' ? '0' : this.dialogForm.SupUnit,
            OperType: this.operation === 'add' ? 'Add' : 'Update',
            Operator: getCookie('admin')
          }
          AddUpdateOrganization(data).then(res => {
            if (res.code === '200') {
              this.$message.success(this.operation === 'add' ? '添加成功!' : '修改成功!')
              this.getOrganizationSearch()
            } else {
              this.$message.error(this.operation === 'add' ? '添加失败!' : '修改失败!')
            }
          })
      const data = {
        OrganType: this.dialogFormOrgTypeSelected,
        OrganCode: this.dialogForm.OrgCode,
        OrganName: this.dialogForm.OrgName,
        SupUnit: this.dialogFormOrgTypeSelected === 'F' ? '0' : this.dialogForm.SupUnit,
        OperType: this.operation === 'add' ? 'Add' : 'Update',
        Operator: getCookie('admin')
      }
      const res = await AddUpdateOrganization(data)
      if (res.code === '200') {
        this.$message.success('添加成功!')
        await this.getOrganizationSearch()
      } else {
        this.$message.error('添加失败!')
      }
      this.dialogVisible = false
          this.dialogVisible = false
        }
      })
    },
    // 获取页面高度
    getHeight() {