Regular check whether it has been registered in the database

 enterpriseName: [
          { required: true, message: '供应方名称不能为空', trigger: 'blur' },
          {
            validator: async (rule, value, callback) => {
              let { rows } = await listSupplierList({ supplierType: '0', })
              if (this.title == '修改供应方') {
                rows = rows.filter(item => item.enterpriseName !== value)
              }
              const flag = rows.some((item) => item.enterpriseName === value)
              if (flag) {
                callback(new Error('供应方名称不能重复'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ],
  socialCreditCode: [
          { required: true, message: '统一社会信用代码不能为空', trigger: 'blur' },
          {
            validator: async (rule, value, callback) => {
              let { rows } = await listSupplierList({ supplierType: '0', })
              if (this.title == '修改供应方') {
                rows = rows.filter(item => item.socialCreditCode !== value)
              }

              const flag = rows.some((item) => item.socialCreditCode === value)
              if (flag) {
                callback(new Error('统一社会信用代码不能重复'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          },
          { validator: validateTaxpayerSeniority, trigger: 'blur' }
        ],

These two checks are the same reason, call the interface in the validator to filter whether the input value exists in the database, and throw an error through the return function

Guess you like

Origin blog.csdn.net/weixin_69811594/article/details/131682123