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