vue3中使用jsx/tsx写ElMessageBox嵌套ElSelect、ElInput、ElDatePicker

-

message: () => h() 必须是函数形式才能update数据。

-

简单的

// 绑定参数
const pageData = reactive({
  statusValue: null
})
// 更改设备状态弹窗
const openDialogChangeStatus = (ids: number[], name: string, doTxt: string) => {
  // options
  const options = [
    { label: '正常', value: 0 },
    { label: '异常', value: 2 },
  ]
  //
  ElMessageBox({
    title: name,
    message: () =>
      h(
        ElSelect,
        {
          modelValue: pageData.statusValue,
          'onUpdate:modelValue': (value: any) => {
            console.log('=log=onUpdate:modelValue=', value)
            pageData.statusValue = value
          },
          placeholder: '请选择..',
          clearable: true,
          style: 'width: 100%; padding: 20px 0px;',
          onChange: (value) => {
            console.log('=log=onChange=', value, pageData.statusValue)
          }
        },
        () => {
          const optionDom = []
          options.forEach((row) => {
            optionDom.push(h(ElOption, { label: row.label, value: row.value, disabled: false }))
          })
          return optionDom
        }
      ),
    showCancelButton: false,
    confirmButtonText: '立即' + doTxt,
    cancelButtonText: '取消',
    beforeClose: (action, instance, done) => {
      if (action === 'confirm') {
        instance.confirmButtonLoading = true
        // 提交数据
        new Promise((resolve, reject) => {
          // 批量操作
          const allIds = {
            equipmentIdMap: ids,
            status: pageData.statusValue
          }
          resolve(setStatusEquipmentConfig(allIds))
        })
          .then((res) => {
            console.log('confirm=done()', res)
            ElMessage({
              message: res.msg,
              type: 'success'
            })
            instance.confirmButtonLoading = false
            done(true)
          })
          .catch((e) => {
            ElMessage.error('操作出错!')
            done(true)
          })
      } else {
        done(true)
      }
    }
  })
    .then((action) => {
      pageData.statusValue = null
    })
    .catch((e) => {
      pageData.statusValue = null
    })
}

-

复杂的:

// 绑定数据
const pageData = reactive({
  submissionInfo: {
    check_uncertainty: null,
    inspection_date: null,
    check_company: ''
  }
})

// 更改送检
const openDialogChangeSubmission = (ids: number[], name: string, doTxt: string) => {
  console.log('=log=openDialogChangeSubmission=', [ids, name, doTxt])
  // options
  const options = [
    { label: '不需要', value: 0 },
    { label: '需要', value: 1 }
  ]
  //
  ElMessageBox({
    title: name,
    message: () =>
      h(ElForm, { style: 'width: 100%; padding: 20px 0px 20px 0px;', labelWidth: '120px' }, [
        h(
          ElFormItem,
          { label: '检定单位' },
          h(ElInput, {
            modelValue: pageData.submissionInfo.check_company,
            'onUpdate:modelValue': (value: any) => {
              // console.log('=log=onUpdate:modelValue=', value)
              pageData.submissionInfo.check_company = value
            },
            placeholder: '请填写  ',
            style: 'width: 100%;'
          })
        ),
        h(
          ElFormItem,
          { label: '测量不确定度' },
          h(
            ElSelect,
            {
              modelValue: pageData.submissionInfo.check_uncertainty,
              'onUpdate:modelValue': (value: any) => {
                // console.log('=log=onUpdate:modelValue=', value)
                pageData.submissionInfo.check_uncertainty = value
              },
              placeholder: '请选择  ',
              clearable: true,
              style: 'width: 100%;',
              onChange: (value) => {
                console.log('=log=onChange=', value, pageData.submissionInfo.check_uncertainty)
              }
            },
            () => {
              const optionDom = []
              options.forEach((row) => {
                optionDom.push(h(ElOption, { label: row.label, value: row.value, disabled: false }))
              })
              return optionDom
            }
          )
        ),
        h(
          ElFormItem,
          { label: '送检日期' },
          h(ElDatePicker, {
            modelValue: pageData.submissionInfo.inspection_date,
            'onUpdate:modelValue': (value: any) => {
              console.log('=log=onUpdate:modelValue=', value)
              pageData.submissionInfo.inspection_date = value
            },
            placeholder: '请选择 送检日期 ',
            type: 'date',
            style: 'width: 100%;',
            format: 'YYYY-MM-DD',
            valueFormat: 'X'
          })
        )
      ]),
    showCancelButton: false,
    confirmButtonText: '立即' + doTxt,
    cancelButtonText: '取消',
    beforeClose: (action, instance, done) => {
      if (action === 'confirm') {
        instance.confirmButtonLoading = true
        if (
          pageData.submissionInfo.check_company === '' ||
          pageData.submissionInfo.check_uncertainty === null ||
          pageData.submissionInfo.inspection_date === null
        ) {
          ElMessage.error('信息未填写完整!')
          setTimeout(() => {
            instance.confirmButtonLoading = false
          }, 1500)
          return
        }
        // 提交数据
        new Promise((resolve, reject) => {
          // 批量操作
          const allIds = {
            equipmentIdMap: ids,
            inspection_date: pageData.submissionInfo.inspection_date,
            check_company: pageData.submissionInfo.check_company,
            check_uncertainty: pageData.submissionInfo.check_uncertainty
          }
          resolve(submissionEquipmentConfig(allIds))
        })
          .then((res) => {
            console.log('confirm=done()', res)
            ElMessage({
              message: res.msg,
              type: 'success'
            })
            instance.confirmButtonLoading = false
            done(true)
          })
          .catch((e) => {
            ElMessage.error('操作出错!')
            done(true)
          })
      } else {
        console.log('取消=', action, pageData.submissionInfo.check_uncertainty)
        done(true)
      }
    }
  })
    .then((action) => {
      console.log('ElMessageBox对话完成=1=', action)
      pageData.submissionInfo.check_uncertainty = null
      pageData.submissionInfo.inspection_date = null
      pageData.submissionInfo.check_company = ''
    })
    .catch((e) => {
      console.log('ElMessageBox对话完成=2=', e)
      pageData.submissionInfo.check_uncertainty = null
      pageData.submissionInfo.inspection_date = null
      pageData.submissionInfo.check_company = ''
    })
}

-

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值