index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <XTable @register="registerTable">
  5. <template #toolbar_buttons>
  6. <!-- 操作:新增 -->
  7. <XButton
  8. type="primary"
  9. preIcon="ep:zoom-in"
  10. :title="t('action.add')"
  11. v-hasPermi="['pay:order:create']"
  12. @click="handleCreate()"
  13. />
  14. <!-- 操作:导出 -->
  15. <XButton
  16. type="warning"
  17. preIcon="ep:download"
  18. :title="t('action.export')"
  19. v-hasPermi="['pay:order:export']"
  20. @click="exportList('订单数据.xls')"
  21. />
  22. </template>
  23. <template #actionbtns_default="{ row }">
  24. <!-- 操作:详情 -->
  25. <XTextButton
  26. preIcon="ep:view"
  27. :title="t('action.detail')"
  28. v-hasPermi="['pay:order:query']"
  29. @click="handleDetail(row.id)"
  30. />
  31. </template>
  32. </XTable>
  33. </ContentWrap>
  34. <XModal
  35. v-model="dialogVisible"
  36. :title="dialogTitle"
  37. :height="['create', 'update'].includes(actionType) ? '99%' : ''"
  38. >
  39. <!-- 对话框(添加 / 修改) -->
  40. <Form
  41. v-if="['create', 'update'].includes(actionType)"
  42. :schema="allSchemas.formSchema"
  43. :rules="rules"
  44. ref="formRef"
  45. />
  46. <!-- 对话框(详情) -->
  47. <Descriptions
  48. v-if="actionType === 'detail'"
  49. :schema="allSchemas.detailSchema"
  50. :data="detailData"
  51. />
  52. <!-- 操作按钮 -->
  53. <template #footer>
  54. <!-- 按钮:保存 -->
  55. <XButton
  56. v-if="['create', 'update'].includes(actionType)"
  57. type="primary"
  58. :title="t('action.save')"
  59. :loading="actionLoading"
  60. @click="submitForm()"
  61. />
  62. <!-- 按钮:关闭 -->
  63. <XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
  64. </template>
  65. </XModal>
  66. </template>
  67. <script setup lang="ts" name="PayOrder">
  68. import type { FormExpose } from '@/components/Form'
  69. import { rules, allSchemas } from './order.data'
  70. import * as OrderApi from '@/api/pay/order'
  71. const { t } = useI18n() // 国际化
  72. // 列表相关的变量
  73. const [registerTable, { reload, exportList }] = useXTable({
  74. allSchemas: allSchemas,
  75. getListApi: OrderApi.getOrderPageApi,
  76. exportListApi: OrderApi.exportOrderApi
  77. })
  78. // ========== CRUD 相关 ==========
  79. const actionLoading = ref(false) // 遮罩层
  80. const actionType = ref('') // 操作按钮的类型
  81. const dialogVisible = ref(false) // 是否显示弹出层
  82. const dialogTitle = ref('edit') // 弹出层标题
  83. const formRef = ref<FormExpose>() // 表单 Ref
  84. const detailData = ref() // 详情 Ref
  85. const message = useMessage() // 消息弹窗
  86. // 设置标题
  87. const setDialogTile = (type: string) => {
  88. dialogTitle.value = t('action.' + type)
  89. actionType.value = type
  90. dialogVisible.value = true
  91. }
  92. // 新增操作
  93. const handleCreate = () => {
  94. setDialogTile('create')
  95. }
  96. // 详情操作
  97. const handleDetail = async (rowId: number) => {
  98. setDialogTile('detail')
  99. const res = await OrderApi.getOrderApi(rowId)
  100. detailData.value = res
  101. }
  102. // 提交新增/修改的表单
  103. const submitForm = async () => {
  104. const elForm = unref(formRef)?.getElFormRef()
  105. if (!elForm) return
  106. elForm.validate(async (valid) => {
  107. if (valid) {
  108. actionLoading.value = true
  109. // 提交请求
  110. try {
  111. const data = unref(formRef)?.formModel as OrderApi.OrderVO
  112. if (actionType.value === 'create') {
  113. await OrderApi.createOrderApi(data)
  114. message.success(t('common.createSuccess'))
  115. } else {
  116. await OrderApi.updateOrderApi(data)
  117. message.success(t('common.updateSuccess'))
  118. }
  119. dialogVisible.value = false
  120. } finally {
  121. actionLoading.value = false
  122. await reload()
  123. }
  124. }
  125. })
  126. }
  127. </script>