srm-form.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div>
  3. <el-dialog v-model="state.showDialog" destroy-on-close :title="title" :close-on-click-modal="false" draggable width="600px">
  4. <el-form :model="form" ref="formRef" size="default" label-width="80px">
  5. <el-row :gutter="35">
  6. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  7. <el-form-item label="" prop="" :rules="[]"> </el-form-item>
  8. </el-col>
  9. </el-row>
  10. </el-form>
  11. <template #footer>
  12. <span class="dialog-footer">
  13. <el-button @click="onCancel" size="default">取 消</el-button>
  14. <el-button type="primary" @click="onSure" size="default" :loading="state.sureLoading">确 定</el-button>
  15. </span>
  16. </template>
  17. </el-dialog>
  18. </div>
  19. </template>
  20. <script lang="ts" setup>
  21. import { getCurrentInstance, ref, reactive, toRefs } from 'vue'
  22. defineProps({
  23. title: {
  24. type: String,
  25. default: '',
  26. },
  27. })
  28. const { proxy } = getCurrentInstance() as any
  29. const formRef = ref()
  30. const state = reactive({
  31. showDialog: false,
  32. sureLoading: false,
  33. form: {} as any,
  34. })
  35. const { form } = toRefs(state)
  36. // 打开对话框
  37. const open = async (row: any = {}) => {
  38. proxy.$modal.loading()
  39. if (row.id > 0) {
  40. const res = {} as any
  41. if (res?.success) {
  42. state.form = res.data as any
  43. }
  44. } else {
  45. state.form = {} as any
  46. }
  47. proxy.$modal.closeLoading()
  48. state.showDialog = true
  49. }
  50. // 取消
  51. const onCancel = () => {
  52. state.showDialog = false
  53. }
  54. // 确定
  55. const onSure = () => {
  56. formRef.value.validate(async (valid: boolean) => {
  57. if (!valid) return
  58. state.sureLoading = true
  59. let res = {} as any
  60. if (state.form.id != undefined && state.form.id > 0) {
  61. res = {} as any
  62. } else {
  63. res = {} as any
  64. }
  65. state.sureLoading = false
  66. if (res?.success) {
  67. proxy.eventBus.emit('refresh')
  68. state.showDialog = false
  69. }
  70. })
  71. }
  72. defineExpose({
  73. open,
  74. })
  75. </script>
  76. <script lang="ts">
  77. import { defineComponent } from 'vue'
  78. export default defineComponent({
  79. name: 'admin/srm/form',
  80. })
  81. </script>
  82. <style lang="scss" scoped></style>