index.vue 4.5 KB

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