index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <script setup lang="tsx">
  2. import { NButton, NPopconfirm, NTag } from 'naive-ui';
  3. import { commonStatus } from '@/constants/business';
  4. import {
  5. fetchAddHotSearch,
  6. fetchDeleteHotSearch,
  7. fetchGethotSearch,
  8. fetchUpdateHotSearch
  9. } from '@/service/api/operation/search';
  10. import { useTable } from '@/components/zt/Table/hooks/useTable';
  11. import { useModalFrom } from '@/components/zt/ModalForm/hooks/useModalForm';
  12. import { $t } from '@/locales';
  13. const columns: NaiveUI.TableColumn<Api.operation.HotSearch>[] = [
  14. {
  15. key: 'searchName',
  16. title: '用户昵称',
  17. align: 'center'
  18. },
  19. {
  20. key: 'type',
  21. title: '评分',
  22. align: 'center',
  23. render: row => {
  24. const arr = ['关键词', '热门搜索词', '推荐搜索词'];
  25. return arr[row.type - 1] || '暂无数据';
  26. }
  27. },
  28. {
  29. key: 'reachName1',
  30. title: '评价内容',
  31. align: 'center'
  32. },
  33. {
  34. key: 'jumpUrl',
  35. title: '图片',
  36. align: 'center'
  37. },
  38. {
  39. key: 'effectiveTime',
  40. title: '审核状态',
  41. align: 'center'
  42. },
  43. {
  44. key: 'endTime',
  45. title: '截止时间',
  46. align: 'center'
  47. },
  48. {
  49. key: 'status',
  50. title: '回复内容',
  51. align: 'center',
  52. render: row => {
  53. const tagMap: Record<Api.Common.commonStatus, NaiveUI.ThemeColor> = {
  54. 1: 'success',
  55. 0: 'warning'
  56. };
  57. const status = row.status || 0;
  58. const label = $t(commonStatus[status]);
  59. return <NTag type={tagMap[status]}>{label}</NTag>;
  60. }
  61. },
  62. {
  63. key: 'endTime',
  64. title: '手机号',
  65. align: 'center'
  66. },
  67. {
  68. key: 'endTime',
  69. title: '提交时间',
  70. align: 'center'
  71. },
  72. {
  73. key: 'endTime',
  74. title: '回复时间',
  75. align: 'center'
  76. },
  77. {
  78. key: 'endTime',
  79. title: '商品信息',
  80. align: 'center'
  81. },
  82. {
  83. key: 'endTime',
  84. title: '门店名称',
  85. align: 'center'
  86. }
  87. ];
  88. const [registerTable, { refresh, setTableLoading }] = useTable({
  89. searchFormConfig: {
  90. schemas: [
  91. {
  92. field: 'searchName',
  93. label: '名称',
  94. component: 'NInput'
  95. }
  96. ],
  97. inline: false,
  98. size: 'small',
  99. labelPlacement: 'left',
  100. isFull: false
  101. },
  102. tableConfig: {
  103. keyField: 'id',
  104. title: '用户评论列表',
  105. showAddButton: true
  106. }
  107. });
  108. async function handleDelete(row: Api.operation.HotSearch) {
  109. setTableLoading(true);
  110. await fetchDeleteHotSearch([row.id]);
  111. refresh();
  112. }
  113. const [registerModalForm, { openModal, closeModal, getFieldsValue, setFieldsValue }] = useModalFrom({
  114. modalConfig: {
  115. title: '跳转 ',
  116. width: 700,
  117. isShowHeaderText: true,
  118. height: 500
  119. },
  120. formConfig: {
  121. schemas: [
  122. {
  123. label: '',
  124. field: 'id',
  125. component: 'NInput',
  126. show: false
  127. },
  128. {
  129. field: 'searchName',
  130. label: '名称',
  131. component: 'NInput',
  132. required: true
  133. },
  134. {
  135. field: 'type',
  136. label: '类型',
  137. component: 'NSelect',
  138. componentProps: {
  139. options: [
  140. {
  141. label: '关键词',
  142. value: 1
  143. },
  144. {
  145. label: '热门搜索词',
  146. value: 2
  147. },
  148. {
  149. label: '推荐搜索词',
  150. value: 3
  151. }
  152. ]
  153. },
  154. required: true
  155. },
  156. {
  157. field: 'reachName',
  158. label: '落地页名称',
  159. component: 'NInput'
  160. },
  161. {
  162. field: 'jumpUrl',
  163. label: '跳转参数',
  164. component: 'NInput'
  165. },
  166. {
  167. field: 'effectiveTime',
  168. label: '有效时间',
  169. component: 'NDatePicker',
  170. required: true,
  171. componentProps: {
  172. type: 'date',
  173. valueFormat: 'yyyy-MM-dd'
  174. }
  175. },
  176. {
  177. field: 'endTime',
  178. label: '截止时间',
  179. component: 'NDatePicker',
  180. required: true,
  181. componentProps: {
  182. type: 'date',
  183. valueFormat: 'yyyy-MM-dd'
  184. }
  185. },
  186. {
  187. field: 'status',
  188. label: '状态',
  189. component: 'NSwitch',
  190. required: true,
  191. defaultValue: 1,
  192. componentProps: {
  193. checkedValue: 1,
  194. uncheckedValue: 0
  195. }
  196. }
  197. ],
  198. gridProps: {
  199. cols: '1'
  200. },
  201. labelWidth: 120
  202. }
  203. });
  204. async function handleSubmit() {
  205. const form = await getFieldsValue();
  206. if (form.id) {
  207. await fetchUpdateHotSearch(form);
  208. } else {
  209. await fetchAddHotSearch(form);
  210. }
  211. closeModal();
  212. refresh();
  213. }
  214. async function edit(row: Api.operation.HotSearch) {
  215. openModal(row);
  216. setFieldsValue(row);
  217. }
  218. </script>
  219. <template>
  220. <LayoutTable>
  221. <ZTable :columns="columns" :api="fetchGethotSearch" @register="registerTable" @add="openModal">
  222. <template #op="{ row }">
  223. <NButton size="small" ghost type="primary" @click="edit(row)">编辑</NButton>
  224. <NPopconfirm @positive-click="handleDelete(row)">
  225. <template #trigger>
  226. <NButton size="small" type="error" ghost>删除</NButton>
  227. </template>
  228. 确定删除吗?
  229. </NPopconfirm>
  230. </template>
  231. </ZTable>
  232. <BasicModelForm @register-modal-form="registerModalForm" @submit-form="handleSubmit"></BasicModelForm>
  233. </LayoutTable>
  234. </template>
  235. <style scoped></style>