index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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="210">
  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-30px h-30px shrink-0"
  71. preview-teleported
  72. />
  73. <div>{{ scope.row.spuName }}</div>
  74. </div>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="评分星级" align="center" prop="scores" width="80" />
  78. <el-table-column label="描述星级" align="center" prop="descriptionScores" width="80" />
  79. <el-table-column label="服务星级" align="center" prop="benefitScores" width="80" />
  80. <el-table-column label="评论内容" align="center" prop="content" min-width="80">
  81. <template #default="scope">
  82. <p>{{ scope.row.content }}</p>
  83. <div class="flex justify-center gap-x-4px">
  84. <el-image
  85. v-for="(picUrl, index) in scope.row.picUrls"
  86. :key="index"
  87. :src="picUrl"
  88. :preview-src-list="scope.row.picUrls"
  89. :initial-index="index"
  90. class="w-30px h-30px"
  91. preview-teleported
  92. />
  93. </div>
  94. </template>
  95. </el-table-column>
  96. <el-table-column
  97. label="回复内容"
  98. align="center"
  99. prop="replyContent"
  100. min-width="100"
  101. show-overflow-tooltip
  102. />
  103. <el-table-column
  104. label="评论时间"
  105. align="center"
  106. prop="createTime"
  107. :formatter="dateFormatter"
  108. width="170"
  109. />
  110. <el-table-column label="状态" align="center" width="65px">
  111. <template #default="scope">
  112. <el-switch
  113. v-model="scope.row.visible"
  114. :active-value="true"
  115. :inactive-value="false"
  116. v-hasPermi="['product:comment:update']"
  117. @change="handleVisibleChange(scope.row)"
  118. />
  119. </template>
  120. </el-table-column>
  121. <el-table-column label="操作" align="center" min-width="60px" fixed="right">
  122. <template #default="scope">
  123. <el-button
  124. link
  125. type="primary"
  126. @click="handleReply(scope.row.id)"
  127. v-hasPermi="['product:comment:update']"
  128. >
  129. 回复
  130. </el-button>
  131. </template>
  132. </el-table-column>
  133. </el-table>
  134. <!-- 分页 -->
  135. <Pagination
  136. :total="total"
  137. v-model:page="queryParams.pageNo"
  138. v-model:limit="queryParams.pageSize"
  139. @pagination="getList"
  140. />
  141. </ContentWrap>
  142. <!-- 表单弹窗:添加/修改 -->
  143. <CommentForm ref="formRef" @success="getList" />
  144. <Dialog title="回复" v-model="replyDialog.visible">
  145. <el-form
  146. ref="replyFormRef"
  147. :model="replyDialog.formData"
  148. :rules="replyDialog.formRules"
  149. label-width="100px"
  150. v-loading="replyDialog.loading"
  151. >
  152. <el-form-item label="回复内容" prop="replyContent">
  153. <el-input type="textarea" v-model="replyDialog.formData.replyContent" />
  154. </el-form-item>
  155. </el-form>
  156. <template #footer>
  157. <el-button @click="submitReplyForm" type="primary" :disabled="replyDialog.loading"
  158. >确 定
  159. </el-button>
  160. <el-button @click="replyDialog.visible = false">取 消</el-button>
  161. </template>
  162. </Dialog>
  163. </template>
  164. <script setup lang="ts">
  165. import { dateFormatter } from '@/utils/formatTime'
  166. import * as CommentApi from '@/api/mall/product/comment'
  167. import CommentForm from './CommentForm.vue'
  168. import { ElInput } from 'element-plus'
  169. defineOptions({ name: 'ProductComment' })
  170. const message = useMessage() // 消息弹窗
  171. const { t } = useI18n() // 国际化
  172. const loading = ref(true) // 列表的加载中
  173. const total = ref(0) // 列表的总页数
  174. const list = ref([]) // 列表的数据
  175. const queryParams = reactive({
  176. pageNo: 1,
  177. pageSize: 10,
  178. userId: null,
  179. userNickname: null,
  180. userAvatar: null,
  181. anonymous: null,
  182. orderId: null,
  183. orderItemId: null,
  184. spuId: null,
  185. spuName: null,
  186. skuId: null,
  187. visible: null,
  188. scores: null,
  189. descriptionScores: null,
  190. benefitScores: null,
  191. content: null,
  192. picUrls: null,
  193. replyStatus: null,
  194. replyUserId: null,
  195. replyContent: null,
  196. replyTime: [],
  197. createTime: []
  198. })
  199. const queryFormRef = ref() // 搜索的表单
  200. /** 查询列表 */
  201. const getList = async () => {
  202. loading.value = true
  203. try {
  204. const data = await CommentApi.getCommentPage(queryParams)
  205. // visible 如果为 null,会导致刷新的时候触发e-switch的change事件
  206. data.list.forEach((item) => {
  207. if (!item.visible) {
  208. item.visible = false
  209. }
  210. })
  211. list.value = data.list
  212. total.value = data.total
  213. } finally {
  214. loading.value = false
  215. }
  216. }
  217. /** 搜索按钮操作 */
  218. const handleQuery = () => {
  219. queryParams.pageNo = 1
  220. getList()
  221. }
  222. /** 重置按钮操作 */
  223. const resetQuery = () => {
  224. queryFormRef.value.resetFields()
  225. handleQuery()
  226. }
  227. /** 添加/修改操作 */
  228. const formRef = ref()
  229. const openForm = (type: string, id?: number) => {
  230. formRef.value.open(type, id)
  231. }
  232. /** 回复 **/
  233. const replyFormRef = ref()
  234. const replyDialog = reactive({
  235. visible: false,
  236. loading: false,
  237. formData: {
  238. id: -1,
  239. replyContent: ''
  240. },
  241. formRules: {
  242. replyContent: [{ required: true, message: '回复内容不能为空', trigger: 'blur' }]
  243. }
  244. })
  245. const handleReply = (id: number) => {
  246. replyDialog.formData.id = id
  247. replyDialog.formData.replyContent = ''
  248. replyDialog.visible = true
  249. }
  250. const submitReplyForm = async () => {
  251. const valid = await replyFormRef?.value?.validate()
  252. if (!valid) return
  253. replyDialog.loading = true
  254. try {
  255. await CommentApi.replyComment(replyDialog.formData)
  256. message.success(t('common.createSuccess'))
  257. replyDialog.visible = false
  258. await getList()
  259. } finally {
  260. replyDialog.loading = false
  261. }
  262. }
  263. /** 显示/隐藏 **/
  264. const handleVisibleChange = async (row: CommentApi.CommentVO) => {
  265. if (loading.value) {
  266. return
  267. }
  268. let changedValue = row.visible
  269. try {
  270. await message.confirm(changedValue ? '是否显示评论?' : '是否隐藏评论?')
  271. await CommentApi.updateCommentVisible({ id: row.id, visible: changedValue })
  272. await getList()
  273. } catch {
  274. row.visible = !changedValue
  275. }
  276. }
  277. /** 初始化 **/
  278. onMounted(() => {
  279. getList()
  280. })
  281. </script>