index.vue 4.3 KB

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