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="60" />
  62. <el-table-column label="用户名称" align="center" prop="userNickname" width="80" />
  63. <el-table-column label="商品信息" align="center" min-width="300">
  64. <template #default="scope">
  65. <div class="flex row items-center gap-x-4px">
  66. <el-image
  67. v-if="scope.row.skuPicUrl"
  68. :src="scope.row.skuPicUrl"
  69. :preview-src-list="[scope.row.skuPicUrl]"
  70. class="w-40px h-40px shrink-0"
  71. preview-teleported
  72. />
  73. <div>{{ scope.row.spuName }}</div>
  74. <el-tag
  75. v-for="property in scope.row.skuProperties"
  76. :key="property.propertyId"
  77. class="mr-10px"
  78. >
  79. {{ property.propertyName }}: {{ property.valueName }}
  80. </el-tag>
  81. </div>
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="评分星级" align="center" prop="scores" width="80" />
  85. <el-table-column label="描述星级" align="center" prop="descriptionScores" width="80" />
  86. <el-table-column label="服务星级" align="center" prop="benefitScores" width="80" />
  87. <el-table-column label="评论内容" align="center" prop="content" min-width="80">
  88. <template #default="scope">
  89. <p>{{ scope.row.content }}</p>
  90. <div class="flex justify-center gap-x-4px">
  91. <el-image
  92. v-for="(picUrl, index) in scope.row.picUrls"
  93. :key="index"
  94. :src="picUrl"
  95. :preview-src-list="scope.row.picUrls"
  96. :initial-index="index"
  97. class="w-40px h-40px"
  98. preview-teleported
  99. />
  100. </div>
  101. </template>
  102. </el-table-column>
  103. <el-table-column
  104. label="回复内容"
  105. align="center"
  106. prop="replyContent"
  107. min-width="100"
  108. show-overflow-tooltip
  109. />
  110. <el-table-column
  111. label="评论时间"
  112. align="center"
  113. prop="createTime"
  114. :formatter="dateFormatter"
  115. width="170"
  116. />
  117. <el-table-column label="状态" align="center" width="65px">
  118. <template #default="scope">
  119. <el-switch
  120. v-model="scope.row.visible"
  121. :active-value="true"
  122. :inactive-value="false"
  123. v-hasPermi="['product:comment:update']"
  124. @change="handleVisibleChange(scope.row)"
  125. />
  126. </template>
  127. </el-table-column>
  128. <el-table-column label="操作" align="center" min-width="60px" fixed="right">
  129. <template #default="scope">
  130. <el-button
  131. link
  132. type="primary"
  133. @click="handleReply(scope.row.id)"
  134. v-hasPermi="['product:comment:update']"
  135. >
  136. 回复
  137. </el-button>
  138. </template>
  139. </el-table-column>
  140. </el-table>
  141. <!-- 分页 -->
  142. <Pagination
  143. :total="total"
  144. v-model:page="queryParams.pageNo"
  145. v-model:limit="queryParams.pageSize"
  146. @pagination="getList"
  147. />
  148. </ContentWrap>
  149. <!-- 表单弹窗:添加/修改 -->
  150. <CommentForm ref="formRef" @success="getList" />
  151. <!-- 回复表单弹窗 -->
  152. <ReplyForm ref="replyFormRef" @success="getList" />
  153. </template>
  154. <script setup lang="ts">
  155. import { dateFormatter } from '@/utils/formatTime'
  156. import * as CommentApi from '@/api/mall/product/comment'
  157. import CommentForm from './CommentForm.vue'
  158. import ReplyForm from './ReplyForm.vue'
  159. defineOptions({ name: 'ProductComment' })
  160. const message = useMessage() // 消息弹窗
  161. const { t } = useI18n() // 国际化
  162. const loading = ref(true) // 列表的加载中
  163. const total = ref(0) // 列表的总页数
  164. const list = ref([]) // 列表的数据
  165. const queryParams = reactive({
  166. pageNo: 1,
  167. pageSize: 10,
  168. replyStatus: null,
  169. spuName: null,
  170. userNickname: null,
  171. orderId: null,
  172. createTime: []
  173. })
  174. const queryFormRef = ref() // 搜索的表单
  175. /** 查询列表 */
  176. const getList = async () => {
  177. loading.value = true
  178. try {
  179. const data = await CommentApi.getCommentPage(queryParams)
  180. // visible 如果为 null,会导致刷新的时候触发 e-switch 的 change 事件
  181. data.list.forEach((item) => {
  182. if (!item.visible) {
  183. item.visible = false
  184. }
  185. })
  186. list.value = data.list
  187. total.value = data.total
  188. } finally {
  189. loading.value = false
  190. }
  191. }
  192. /** 搜索按钮操作 */
  193. const handleQuery = () => {
  194. queryParams.pageNo = 1
  195. getList()
  196. }
  197. /** 重置按钮操作 */
  198. const resetQuery = () => {
  199. queryFormRef.value.resetFields()
  200. handleQuery()
  201. }
  202. /** 添加/修改操作 */
  203. const formRef = ref()
  204. const openForm = (type: string, id?: number) => {
  205. formRef.value.open(type, id)
  206. }
  207. /** 回复按钮操作 **/
  208. const replyFormRef = ref()
  209. const handleReply = (id: number) => {
  210. replyFormRef.value.open(id)
  211. }
  212. /** 显示/隐藏 **/
  213. const handleVisibleChange = async (row: CommentApi.CommentVO) => {
  214. if (loading.value) {
  215. return
  216. }
  217. let changedValue = row.visible
  218. try {
  219. await message.confirm(changedValue ? '是否显示评论?' : '是否隐藏评论?')
  220. await CommentApi.updateCommentVisible({ id: row.id, visible: changedValue })
  221. await getList()
  222. } catch {
  223. row.visible = !changedValue
  224. }
  225. }
  226. /** 初始化 **/
  227. onMounted(() => {
  228. getList()
  229. })
  230. </script>