index.vue 8.7 KB

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