index.vue 4.7 KB

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