index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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="replyStatus">
  12. <el-select v-model="queryParams.replyStatus">
  13. <el-option label="已回复" :value="true" />
  14. <el-option label="未回复" :value="false" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="商品名称" prop="spuName">
  18. <el-input v-model="queryParams.spuName" placeholder="请输入商品名称" />
  19. </el-form-item>
  20. <el-form-item label="用户名称" prop="userNickname">
  21. <el-input v-model="queryParams.userNickname" placeholder="请输入用户名称" />
  22. </el-form-item>
  23. <el-form-item label="订单编号" prop="orderId">
  24. <el-input v-model="queryParams.orderId" placeholder="请输入订单编号" />
  25. </el-form-item>
  26. <el-form-item label="评论时间" prop="createTime">
  27. <el-date-picker
  28. v-model="queryParams.createTime"
  29. value-format="YYYY-MM-DD HH:mm:ss"
  30. type="daterange"
  31. start-placeholder="开始日期"
  32. end-placeholder="结束日期"
  33. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  34. class="!w-240px"
  35. />
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button @click="handleQuery">
  39. <Icon icon="ep:search" class="mr-5px" />
  40. 搜索
  41. </el-button>
  42. <el-button @click="resetQuery">
  43. <Icon icon="ep:refresh" class="mr-5px" />
  44. 重置
  45. </el-button>
  46. <el-button
  47. type="primary"
  48. plain
  49. @click="openForm('create')"
  50. v-hasPermi="['product:comment:create']"
  51. >
  52. <Icon icon="ep:plus" class="mr-5px" />
  53. 添加虚拟评论
  54. </el-button>
  55. </el-form-item>
  56. </el-form>
  57. </ContentWrap>
  58. <!-- 列表 -->
  59. <ContentWrap>
  60. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="false">
  61. <el-table-column label="评论编号" align="center" prop="id" min-width="80" />
  62. <el-table-column label="商品信息" align="center" min-width="400">
  63. <template #default="scope">
  64. <div class="row flex items-center gap-x-4px">
  65. <el-image
  66. v-if="scope.row.skuPicUrl"
  67. :src="scope.row.skuPicUrl"
  68. :preview-src-list="[scope.row.skuPicUrl]"
  69. class="h-40px w-40px shrink-0"
  70. preview-teleported
  71. />
  72. <div>{{ scope.row.spuName }}</div>
  73. <el-tag
  74. v-for="property in scope.row.skuProperties"
  75. :key="property.propertyId"
  76. class="mr-10px"
  77. >
  78. {{ property.propertyName }}: {{ property.valueName }}
  79. </el-tag>
  80. </div>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="用户名称" align="center" prop="userNickname" width="100" />
  84. <el-table-column label="商品评分" align="center" prop="descriptionScores" width="90" />
  85. <el-table-column label="服务评分" align="center" prop="benefitScores" width="90" />
  86. <el-table-column label="评论内容" align="center" prop="content" min-width="210">
  87. <template #default="scope">
  88. <p>{{ scope.row.content }}</p>
  89. <div class="flex justify-center gap-x-4px">
  90. <el-image
  91. v-for="(picUrl, index) in scope.row.picUrls"
  92. :key="index"
  93. :src="picUrl"
  94. :preview-src-list="scope.row.picUrls"
  95. :initial-index="index"
  96. class="h-40px w-40px"
  97. preview-teleported
  98. />
  99. </div>
  100. </template>
  101. </el-table-column>
  102. <el-table-column
  103. label="回复内容"
  104. align="center"
  105. prop="replyContent"
  106. min-width="250"
  107. show-overflow-tooltip
  108. />
  109. <el-table-column
  110. label="评论时间"
  111. align="center"
  112. prop="createTime"
  113. :formatter="dateFormatter"
  114. width="180"
  115. />
  116. <el-table-column label="是否展示" align="center" width="80px">
  117. <template #default="scope">
  118. <el-switch
  119. v-model="scope.row.visible"
  120. :active-value="true"
  121. :inactive-value="false"
  122. v-hasPermi="['product:comment:update']"
  123. @change="handleVisibleChange(scope.row)"
  124. />
  125. </template>
  126. </el-table-column>
  127. <el-table-column label="操作" align="center" min-width="60px" fixed="right">
  128. <template #default="scope">
  129. <el-button
  130. link
  131. type="primary"
  132. @click="handleReply(scope.row.id)"
  133. v-hasPermi="['product:comment:update']"
  134. >
  135. 回复
  136. </el-button>
  137. </template>
  138. </el-table-column>
  139. </el-table>
  140. <!-- 分页 -->
  141. <Pagination
  142. :total="total"
  143. v-model:page="queryParams.pageNo"
  144. v-model:limit="queryParams.pageSize"
  145. @pagination="getList"
  146. />
  147. </ContentWrap>
  148. <!-- 表单弹窗:添加/修改 -->
  149. <CommentForm ref="formRef" @success="getList" />
  150. <!-- 回复表单弹窗 -->
  151. <ReplyForm ref="replyFormRef" @success="getList" />
  152. </template>
  153. <script setup lang="ts">
  154. import { dateFormatter } from '@/utils/formatTime'
  155. import * as CommentApi from '@/api/mall/product/comment'
  156. import CommentForm from './CommentForm.vue'
  157. import ReplyForm from './ReplyForm.vue'
  158. defineOptions({ name: 'ProductComment' })
  159. const message = useMessage() // 消息弹窗
  160. const { t } = useI18n() // 国际化
  161. const loading = ref(true) // 列表的加载中
  162. const total = ref(0) // 列表的总页数
  163. const list = ref([]) // 列表的数据
  164. const queryParams = reactive({
  165. pageNo: 1,
  166. pageSize: 10,
  167. replyStatus: null,
  168. spuName: null,
  169. userNickname: null,
  170. orderId: null,
  171. createTime: []
  172. })
  173. const queryFormRef = ref() // 搜索的表单
  174. /** 查询列表 */
  175. const getList = async () => {
  176. loading.value = true
  177. try {
  178. const data = await CommentApi.getCommentPage(queryParams)
  179. // visible 如果为 null,会导致刷新的时候触发 e-switch 的 change 事件
  180. data.list.forEach((item) => {
  181. if (!item.visible) {
  182. item.visible = false
  183. }
  184. })
  185. list.value = data.list
  186. total.value = data.total
  187. } finally {
  188. loading.value = false
  189. }
  190. }
  191. /** 搜索按钮操作 */
  192. const handleQuery = () => {
  193. queryParams.pageNo = 1
  194. getList()
  195. }
  196. /** 重置按钮操作 */
  197. const resetQuery = () => {
  198. queryFormRef.value.resetFields()
  199. handleQuery()
  200. }
  201. /** 添加/修改操作 */
  202. const formRef = ref()
  203. const openForm = (type: string, id?: number) => {
  204. formRef.value.open(type, id)
  205. }
  206. /** 回复按钮操作 **/
  207. const replyFormRef = ref()
  208. const handleReply = (id: number) => {
  209. replyFormRef.value.open(id)
  210. }
  211. /** 显示/隐藏 **/
  212. const handleVisibleChange = async (row: CommentApi.CommentVO) => {
  213. if (loading.value) {
  214. return
  215. }
  216. let changedValue = row.visible
  217. try {
  218. await message.confirm(changedValue ? '是否显示评论?' : '是否隐藏评论?')
  219. await CommentApi.updateCommentVisible({ id: row.id, visible: changedValue })
  220. await getList()
  221. } catch {
  222. row.visible = !changedValue
  223. }
  224. }
  225. /** 初始化 **/
  226. onMounted(() => {
  227. getList()
  228. })
  229. </script>