index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="商户号" prop="no">
  12. <el-input v-model="queryParams.no" placeholder="请输入商户号" clearable class="!w-240px" />
  13. </el-form-item>
  14. <el-form-item label="商户全称" prop="name">
  15. <el-input
  16. v-model="queryParams.name"
  17. placeholder="请输入商户全称"
  18. clearable
  19. class="!w-240px"
  20. />
  21. </el-form-item>
  22. <el-form-item label="商户简称" prop="shortName">
  23. <el-input
  24. v-model="queryParams.shortName"
  25. placeholder="请输入商户简称"
  26. clearable
  27. class="!w-240px"
  28. />
  29. </el-form-item>
  30. <el-form-item label="开启状态" prop="status">
  31. <el-select v-model="queryParams.status" placeholder="字典状态" clearable class="!w-240px">
  32. <el-option
  33. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  34. :key="dict.value"
  35. :label="dict.label"
  36. :value="dict.value"
  37. />
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item label="备注" prop="remark">
  41. <el-input
  42. v-model="queryParams.remark"
  43. placeholder="请输入备注"
  44. clearable
  45. class="!w-240px"
  46. />
  47. </el-form-item>
  48. <el-form-item label="创建时间" prop="createTime">
  49. <el-date-picker
  50. v-model="queryParams.createTime"
  51. value-format="YYYY-MM-DD HH:mm:ss"
  52. type="datetimerange"
  53. start-placeholder="开始日期"
  54. end-placeholder="结束日期"
  55. class="!w-240px"
  56. />
  57. </el-form-item>
  58. <el-form-item>
  59. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  60. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  61. <el-button
  62. plain
  63. type="primary"
  64. @click="openForm('create')"
  65. v-hasPermi="['pay:merchant:create']"
  66. >
  67. <Icon icon="ep:plus" class="mr-5px" /> 新增
  68. </el-button>
  69. <el-button
  70. type="success"
  71. plain
  72. @click="handleExport"
  73. :loading="exportLoading"
  74. v-hasPermi="['pay:merchant:export']"
  75. >
  76. <Icon icon="ep:download" class="mr-5px" /> 导出
  77. </el-button>
  78. </el-form-item>
  79. </el-form>
  80. </ContentWrap>
  81. <!-- 列表 -->
  82. <ContentWrap>
  83. <el-table v-loading="loading" :data="list">
  84. <el-table-column label="商户编号" align="center" prop="id" />
  85. <el-table-column label="商户号" align="center" prop="no" />
  86. <el-table-column label="商户全称" align="center" prop="name" />
  87. <el-table-column label="商户简称" align="center" prop="shortName" />
  88. <el-table-column label="开启状态" align="center" prop="status">
  89. <template #default="scope">
  90. <el-switch
  91. v-model="scope.row.status"
  92. :active-value="0"
  93. :inactive-value="1"
  94. @change="handleStatusChange(scope.row)"
  95. />
  96. </template>
  97. </el-table-column>
  98. <el-table-column label="备注" align="center" prop="remark" />
  99. <el-table-column
  100. label="创建时间"
  101. align="center"
  102. prop="createTime"
  103. :formatter="dateFormatter"
  104. width="180"
  105. />
  106. <el-table-column label="操作" align="center">
  107. <template #default="scope">
  108. <el-button
  109. link
  110. type="primary"
  111. @click="openForm('update', scope.row.id)"
  112. v-hasPermi="['pay:merchant:update']"
  113. >
  114. 修改
  115. </el-button>
  116. <el-button
  117. link
  118. type="danger"
  119. @click="handleDelete(scope.row.id)"
  120. v-hasPermi="['pay:merchant:delete']"
  121. >
  122. 删除
  123. </el-button>
  124. </template>
  125. </el-table-column>
  126. </el-table>
  127. <!-- 分页 -->
  128. <Pagination
  129. :total="total"
  130. v-model:page="queryParams.pageNo"
  131. v-model:limit="queryParams.pageSize"
  132. @pagination="getList"
  133. />
  134. </ContentWrap>
  135. <!-- 表单弹窗:添加/修改 -->
  136. <MerchantForm ref="formRef" @success="getList" />
  137. </template>
  138. <script lang="ts" setup>
  139. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  140. import { CommonStatusEnum } from '@/utils/constants'
  141. import { dateFormatter } from '@/utils/formatTime'
  142. import download from '@/utils/download'
  143. import * as MerchantApi from '@/api/pay/merchant'
  144. import MerchantForm from './MerchantForm.vue'
  145. defineOptions({ name: 'PayMerchant' })
  146. const message = useMessage() // 消息弹窗
  147. const { t } = useI18n() // 国际化
  148. const loading = ref(true) // 列表的加载中
  149. const total = ref(0) // 列表的总页数
  150. const list = ref([]) // 列表的数据
  151. const queryParams = reactive({
  152. pageNo: 1,
  153. pageSize: 10,
  154. name: '',
  155. shortName: '',
  156. status: undefined
  157. })
  158. const queryFormRef = ref() // 搜索的表单
  159. const exportLoading = ref(false) // 导出的加载中
  160. /** 查询列表 */
  161. const getList = async () => {
  162. loading.value = true
  163. try {
  164. const data = await MerchantApi.getMerchantPage(queryParams)
  165. list.value = data.list
  166. total.value = data.total
  167. } finally {
  168. loading.value = false
  169. }
  170. }
  171. /** 搜索按钮操作 */
  172. const handleQuery = () => {
  173. queryParams.pageNo = 1
  174. getList()
  175. }
  176. /** 重置按钮操作 */
  177. const resetQuery = () => {
  178. queryFormRef.value.resetFields()
  179. handleQuery()
  180. }
  181. /** 添加/修改操作 */
  182. const formRef = ref()
  183. const openForm = (type: string, id?: number) => {
  184. formRef.value.open(type, id)
  185. }
  186. /** 删除按钮操作 */
  187. const handleDelete = async (id: number) => {
  188. try {
  189. // 删除的二次确认
  190. await message.delConfirm()
  191. // 发起删除
  192. await MerchantApi.deleteMerchant(id)
  193. message.success(t('common.delSuccess'))
  194. // 刷新列表
  195. await getList()
  196. } catch {}
  197. }
  198. /** 修改状态操作 */
  199. const handleStatusChange = async (row: MerchantApi.MerchantVO) => {
  200. try {
  201. // 修改状态的二次确认
  202. const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
  203. await message.confirm('确认要"' + text + '""' + row.name + '"商户吗?', t('common.reminder'))
  204. // 发起修改状态
  205. await MerchantApi.updateMerchantStatus(row.id, row.status)
  206. // 刷新列表
  207. await getList()
  208. } catch {
  209. // 取消后,进行恢复按钮
  210. row.status =
  211. row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
  212. }
  213. }
  214. /** 导出按钮操作 */
  215. const handleExport = async () => {
  216. try {
  217. // 导出的二次确认
  218. await message.exportConfirm()
  219. // 发起导出
  220. exportLoading.value = true
  221. const data = await MerchantApi.exportMerchant(queryParams)
  222. download.excel(data, '商户信息.xls')
  223. } catch {
  224. } finally {
  225. exportLoading.value = false
  226. }
  227. }
  228. /** 初始化 **/
  229. onMounted(() => {
  230. getList()
  231. })
  232. </script>