index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <script setup lang="ts">
  2. import { ref, unref } from 'vue'
  3. import { ElMessage } from 'element-plus'
  4. import { DICT_TYPE } from '@/utils/dict'
  5. import { useTable } from '@/hooks/web/useTable'
  6. import { useI18n } from '@/hooks/web/useI18n'
  7. import { FormExpose } from '@/components/Form'
  8. import type { OrderVO } from '@/api/pay/order/types'
  9. import { rules, allSchemas } from './order.data'
  10. import * as OrderApi from '@/api/pay/order'
  11. const { t } = useI18n() // 国际化
  12. // ========== 列表相关 ==========
  13. const { register, tableObject, methods } = useTable<OrderVO>({
  14. getListApi: OrderApi.getOrderPageApi,
  15. delListApi: OrderApi.deleteOrderApi,
  16. exportListApi: OrderApi.exportOrderApi
  17. })
  18. const { getList, setSearchParams, delList, exportList } = methods
  19. // ========== CRUD 相关 ==========
  20. const actionLoading = ref(false) // 遮罩层
  21. const actionType = ref('') // 操作按钮的类型
  22. const dialogVisible = ref(false) // 是否显示弹出层
  23. const dialogTitle = ref('edit') // 弹出层标题
  24. const formRef = ref<FormExpose>() // 表单 Ref
  25. // 设置标题
  26. const setDialogTile = (type: string) => {
  27. dialogTitle.value = t('action.' + type)
  28. actionType.value = type
  29. dialogVisible.value = true
  30. }
  31. // 新增操作
  32. const handleCreate = () => {
  33. setDialogTile('create')
  34. }
  35. // 修改操作
  36. const handleUpdate = async (row: OrderVO) => {
  37. setDialogTile('update')
  38. // 设置数据
  39. const res = await OrderApi.getOrderApi(row.id)
  40. unref(formRef)?.setValues(res)
  41. }
  42. // 提交按钮
  43. const submitForm = async () => {
  44. const elForm = unref(formRef)?.getElFormRef()
  45. if (!elForm) return
  46. elForm.validate(async (valid) => {
  47. if (valid) {
  48. actionLoading.value = true
  49. // 提交请求
  50. try {
  51. const data = unref(formRef)?.formModel as OrderVO
  52. if (actionType.value === 'create') {
  53. await OrderApi.createOrderApi(data)
  54. ElMessage.success(t('common.createSuccess'))
  55. } else {
  56. await OrderApi.updateOrderApi(data)
  57. ElMessage.success(t('common.updateSuccess'))
  58. }
  59. // 操作成功,重新加载列表
  60. dialogVisible.value = false
  61. await getList()
  62. } finally {
  63. actionLoading.value = false
  64. }
  65. }
  66. })
  67. }
  68. // ========== 详情相关 ==========
  69. const detailRef = ref() // 详情 Ref
  70. // 详情操作
  71. const handleDetail = async (row: OrderVO) => {
  72. setDialogTile('detail')
  73. // 设置数据
  74. const res = await OrderApi.getOrderApi(row.id as number)
  75. detailRef.value = res
  76. }
  77. // ========== 初始化 ==========
  78. getList()
  79. </script>
  80. <template>
  81. <!-- 搜索工作区 -->
  82. <ContentWrap>
  83. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  84. </ContentWrap>
  85. <ContentWrap>
  86. <!-- 操作工具栏 -->
  87. <div class="mb-10px">
  88. <el-button type="primary" v-hasPermi="['pay:order:create']" @click="handleCreate">
  89. <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.add') }}
  90. </el-button>
  91. <el-button
  92. type="warning"
  93. v-hasPermi="['pay:order:export']"
  94. :loading="tableObject.exportLoading"
  95. @click="exportList('订单数据.xls')"
  96. >
  97. <Icon icon="ep:download" class="mr-5px" /> {{ t('action.export') }}
  98. </el-button>
  99. </div>
  100. <!-- 列表 -->
  101. <Table
  102. :columns="allSchemas.tableColumns"
  103. :selection="false"
  104. :data="tableObject.tableList"
  105. :loading="tableObject.loading"
  106. :pagination="{
  107. total: tableObject.total
  108. }"
  109. v-model:pageSize="tableObject.pageSize"
  110. v-model:currentPage="tableObject.currentPage"
  111. @register="register"
  112. >
  113. <template #status="{ row }">
  114. <DictTag :type="DICT_TYPE.COMMON_STATUS" :value="row.status" />
  115. </template>
  116. <template #action="{ row }">
  117. <el-button link type="primary" v-hasPermi="['pay:order:update']" @click="handleUpdate(row)">
  118. <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
  119. </el-button>
  120. <el-button link type="primary" v-hasPermi="['pay:order:update']" @click="handleDetail(row)">
  121. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.detail') }}
  122. </el-button>
  123. <el-button
  124. link
  125. type="primary"
  126. v-hasPermi="['pay:order:delete']"
  127. @click="delList(row.id, false)"
  128. >
  129. <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
  130. </el-button>
  131. </template>
  132. </Table>
  133. </ContentWrap>
  134. <XModal v-model="dialogVisible" :title="dialogTitle">
  135. <!-- 对话框(添加 / 修改) -->
  136. <Form
  137. v-if="['create', 'update'].includes(actionType)"
  138. :schema="allSchemas.formSchema"
  139. :rules="rules"
  140. ref="formRef"
  141. />
  142. <!-- 对话框(详情) -->
  143. <Descriptions
  144. v-if="actionType === 'detail'"
  145. :schema="allSchemas.detailSchema"
  146. :data="detailRef"
  147. />
  148. <!-- 操作按钮 -->
  149. <template #footer>
  150. <el-button
  151. v-if="['create', 'update'].includes(actionType)"
  152. type="primary"
  153. :loading="actionLoading"
  154. @click="submitForm"
  155. >
  156. {{ t('action.save') }}
  157. </el-button>
  158. <el-button @click="dialogVisible = false">{{ t('dialog.close') }}</el-button>
  159. </template>
  160. </XModal>
  161. </template>