index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <!-- <doc-alert title="商城手册(功能开启)" url="https://doc.iocoder.cn/mall/build/" /> -->
  3. <!-- 搜索工作栏 -->
  4. <ContentWrap>
  5. <el-form
  6. class="-mb-15px"
  7. :model="queryParams"
  8. ref="queryFormRef"
  9. :inline="true"
  10. label-width="68px"
  11. >
  12. <el-form-item label="品牌名称" prop="name">
  13. <el-input
  14. v-model="queryParams.name"
  15. placeholder="请输入品牌名称"
  16. clearable
  17. @keyup.enter="handleQuery"
  18. class="!w-240px"
  19. />
  20. </el-form-item>
  21. <el-form-item label="状态" prop="status">
  22. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!w-240px">
  23. <el-option
  24. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  25. :key="dict.value"
  26. :label="dict.label"
  27. :value="dict.value"
  28. />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="创建时间" prop="createTime">
  32. <el-date-picker
  33. v-model="queryParams.createTime"
  34. value-format="YYYY-MM-DD HH:mm:ss"
  35. type="daterange"
  36. start-placeholder="开始日期"
  37. end-placeholder="结束日期"
  38. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  39. class="!w-240px"
  40. />
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  44. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  45. <el-button
  46. type="primary"
  47. plain
  48. @click="openForm('create')"
  49. v-hasPermi="['product:brand:create']"
  50. >
  51. <Icon icon="ep:plus" class="mr-5px" /> 新增
  52. </el-button>
  53. </el-form-item>
  54. </el-form>
  55. </ContentWrap>
  56. <!-- 列表 -->
  57. <ContentWrap>
  58. <el-table v-loading="loading" :data="list" row-key="id" default-expand-all>
  59. <el-table-column label="品牌名称" prop="name" sortable />
  60. <el-table-column label="品牌图片" align="center" prop="picUrl">
  61. <template #default="scope">
  62. <img v-if="scope.row.picUrl" :src="scope.row.picUrl" alt="品牌图片" class="h-30px" />
  63. </template>
  64. </el-table-column>
  65. <el-table-column label="品牌排序" align="center" prop="sort" />
  66. <el-table-column label="开启状态" align="center" prop="status">
  67. <template #default="scope">
  68. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  69. </template>
  70. </el-table-column>
  71. <el-table-column
  72. label="创建时间"
  73. align="center"
  74. prop="createTime"
  75. width="180"
  76. :formatter="dateFormatter"
  77. />
  78. <el-table-column label="操作" align="center">
  79. <template #default="scope">
  80. <el-button
  81. link
  82. type="primary"
  83. @click="openForm('update', scope.row.id)"
  84. v-hasPermi="['product:brand:update']"
  85. >
  86. 编辑
  87. </el-button>
  88. <el-button
  89. link
  90. type="danger"
  91. @click="handleDelete(scope.row.id)"
  92. v-hasPermi="['product:brand:delete']"
  93. >
  94. 删除
  95. </el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. <!-- 分页 -->
  100. <Pagination
  101. :total="total"
  102. v-model:page="queryParams.pageNo"
  103. v-model:limit="queryParams.pageSize"
  104. @pagination="getList"
  105. />
  106. </ContentWrap>
  107. <!-- 表单弹窗:添加/修改 -->
  108. <BrandForm ref="formRef" @success="getList" />
  109. </template>
  110. <script lang="ts" setup>
  111. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  112. import { dateFormatter } from '@/utils/formatTime'
  113. import * as ProductBrandApi from '@/api/mall/product/brand'
  114. import BrandForm from './BrandForm.vue'
  115. defineOptions({ name: 'ProductBrand' })
  116. const message = useMessage() // 消息弹窗
  117. const { t } = useI18n() // 国际化
  118. const loading = ref(true) // 列表的加载中
  119. const total = ref(0) // 列表的总页数
  120. const list = ref<any[]>([]) // 列表的数据
  121. const queryParams = reactive({
  122. pageNo: 1,
  123. pageSize: 10,
  124. name: undefined,
  125. status: undefined,
  126. createTime: []
  127. })
  128. const queryFormRef = ref() // 搜索的表单
  129. /** 查询列表 */
  130. const getList = async () => {
  131. loading.value = true
  132. try {
  133. const data = await ProductBrandApi.getBrandParam(queryParams)
  134. list.value = data.list
  135. total.value = data.total
  136. } finally {
  137. loading.value = false
  138. }
  139. }
  140. /** 搜索按钮操作 */
  141. const handleQuery = () => {
  142. getList()
  143. }
  144. /** 重置按钮操作 */
  145. const resetQuery = () => {
  146. queryFormRef.value.resetFields()
  147. handleQuery()
  148. }
  149. /** 添加/修改操作 */
  150. const formRef = ref()
  151. const openForm = (type: string, id?: number) => {
  152. formRef.value.open(type, id)
  153. }
  154. /** 删除按钮操作 */
  155. const handleDelete = async (id: number) => {
  156. try {
  157. // 删除的二次确认
  158. await message.delConfirm()
  159. // 发起删除
  160. await ProductBrandApi.deleteBrand(id)
  161. message.success(t('common.delSuccess'))
  162. // 刷新列表
  163. await getList()
  164. } catch {}
  165. }
  166. /** 初始化 **/
  167. onMounted(() => {
  168. getList()
  169. })
  170. </script>