index.vue 5.4 KB

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