index.vue 5.3 KB

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