index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <template>
  2. <div class="app-container">
  3. <div class="content">
  4. <byTable
  5. :source="sourceList.data"
  6. :pagination="sourceList.pagination"
  7. :config="config"
  8. :loading="loading"
  9. :selectConfig="selectConfig"
  10. highlight-current-row
  11. :action-list="[
  12. {
  13. text: '添加模板',
  14. action: () => openModal(),
  15. },
  16. ]"
  17. @get-list="getList"
  18. >
  19. </byTable>
  20. </div>
  21. <el-dialog
  22. :title="modalType == 'add' ? '新增' : '编辑'"
  23. v-if="dialogVisible"
  24. v-model="dialogVisible"
  25. width="500"
  26. v-loading="loadingOperation"
  27. >
  28. <byForm
  29. :formConfig="formConfig"
  30. :formOption="formOption"
  31. v-model="formData.data"
  32. :rules="rules"
  33. ref="submit"
  34. >
  35. </byForm>
  36. <template #footer>
  37. <el-button @click="dialogVisible = false" size="large"
  38. >取 消</el-button
  39. >
  40. <el-button type="primary" @click="submitForm()" size="large"
  41. >确 定</el-button
  42. >
  43. </template>
  44. </el-dialog>
  45. </div>
  46. </template>
  47. <script setup>
  48. import { ElMessage, ElMessageBox } from 'element-plus'
  49. import byTable from '/src/components/byTable/index'
  50. import byForm from '/src/components/byForm/index'
  51. import { computed, ref } from 'vue'
  52. import Editor from '/src/components/Editor/index.vue'
  53. const { proxy } = getCurrentInstance()
  54. const loading = ref(false)
  55. const companyList = ref({})
  56. const sourceList = ref({
  57. data: [],
  58. pagination: {
  59. total: 0,
  60. pageNum: 1,
  61. pageSize: 10,
  62. corporationId: '',
  63. keyword: '',
  64. },
  65. })
  66. const selectConfig = computed(() => {
  67. return [
  68. {
  69. label: '消息类型',
  70. prop: 'status',
  71. data: [
  72. {
  73. label: '已发送',
  74. value: '1',
  75. },
  76. {
  77. label: '未发送',
  78. value: '0',
  79. },
  80. ],
  81. },
  82. {
  83. label: '消息类型',
  84. prop: 'type',
  85. data: [
  86. {
  87. label: '系统公告',
  88. value: '1',
  89. },
  90. ],
  91. },
  92. ]
  93. })
  94. const config = computed(() => {
  95. return [
  96. {
  97. attrs: {
  98. label: '消息类型',
  99. prop: 'type',
  100. },
  101. render(type) {
  102. return type == 1 ? '系统公告' : ''
  103. },
  104. },
  105. {
  106. attrs: {
  107. label: '标题',
  108. prop: 'title',
  109. },
  110. },
  111. {
  112. attrs: {
  113. label: '正文',
  114. prop: 'content',
  115. },
  116. },
  117. {
  118. attrs: {
  119. label: '添加时间',
  120. prop: 'createTime',
  121. },
  122. },
  123. {
  124. attrs: {
  125. label: '发送时间',
  126. prop: 'sendTime',
  127. },
  128. },
  129. {
  130. attrs: {
  131. label: '消息状态',
  132. prop: 'status',
  133. },
  134. render(status) {
  135. return status == 1 ? '已发送' : '未发送'
  136. },
  137. },
  138. {
  139. attrs: {
  140. label: '操作',
  141. width: '120',
  142. align: 'center',
  143. },
  144. renderHTML(row) {
  145. return [
  146. row.status == 0 ? {
  147. attrs: {
  148. label: '发送',
  149. type: 'primary',
  150. text: true,
  151. },
  152. el: 'button',
  153. click() {
  154. ElMessageBox.confirm(
  155. '你确定发送此条信息?',
  156. '提示',
  157. {
  158. confirmButtonText: '确定',
  159. cancelButtonText: '取消',
  160. type: 'warning',
  161. }
  162. ).then(() => {
  163. proxy
  164. .post('/sendMeg/edit', {
  165. ...row,
  166. status:1,
  167. })
  168. .then(() => {
  169. ElMessage({
  170. message: '发送成功',
  171. type: 'success',
  172. })
  173. getList()
  174. })
  175. })
  176. },
  177. } : {},
  178. {
  179. attrs: {
  180. label: '删除',
  181. type: 'primary',
  182. text: true,
  183. },
  184. el: 'button',
  185. click() {
  186. ElMessageBox.confirm(
  187. '此操作将永久删除该数据, 是否继续?',
  188. '提示',
  189. {
  190. confirmButtonText: '确定',
  191. cancelButtonText: '取消',
  192. type: 'warning',
  193. }
  194. ).then(() => {
  195. proxy
  196. .post('/sendMeg/delete', {
  197. id: row.id,
  198. })
  199. .then(() => {
  200. ElMessage({
  201. message: '删除成功',
  202. type: 'success',
  203. })
  204. getList()
  205. })
  206. })
  207. },
  208. },
  209. ]
  210. },
  211. },
  212. ]
  213. })
  214. const getDict = () => {
  215. proxy
  216. .post('/corporation/page', { pageNum: 1, pageSize: 999 })
  217. .then((res) => {
  218. companyList.value = res.rows.map((item) => {
  219. return {
  220. label: item.name,
  221. value: item.id,
  222. }
  223. })
  224. })
  225. }
  226. const getList = async (req) => {
  227. sourceList.value.pagination = { ...sourceList.value.pagination, ...req }
  228. loading.value = true
  229. proxy.post('/sendMeg/page', sourceList.value.pagination).then((res) => {
  230. sourceList.value.data = res.rows
  231. sourceList.value.pagination.total = res.total
  232. setTimeout(() => {
  233. loading.value = false
  234. }, 200)
  235. })
  236. }
  237. getDict()
  238. getList()
  239. const modalType = ref('add')
  240. const dialogVisible = ref(false)
  241. const loadingOperation = ref(false)
  242. const submit = ref(null)
  243. const formData = reactive({
  244. data: {
  245. countryId: '44',
  246. },
  247. })
  248. const formOption = reactive({
  249. inline: true,
  250. labelWidth: 100,
  251. itemWidth: 100,
  252. rules: [],
  253. })
  254. const formConfig = computed(() => {
  255. return [
  256. {
  257. label: '基础信息',
  258. },
  259. {
  260. type: 'select',
  261. prop: 'type',
  262. label: '消息类型',
  263. data: [
  264. {
  265. label: '系统公告',
  266. value: '1',
  267. },
  268. ],
  269. },
  270. {
  271. type: 'input',
  272. prop: 'title',
  273. label: '标题',
  274. itemType: 'text',
  275. placeholder: '请输入标题',
  276. },
  277. {
  278. type: 'input',
  279. prop: 'content',
  280. label: '正文',
  281. itemType: 'textarea',
  282. placeholder: '请输入正文',
  283. },
  284. {
  285. type: 'date',
  286. prop: 'sendTime',
  287. label: '发送时间',
  288. placeholder: '请选择发送时间',
  289. itemType: 'date',
  290. },
  291. {
  292. type: 'date',
  293. prop: 'endTime',
  294. label: '结束时间',
  295. placeholder: '请选择结束时间',
  296. itemType: 'date',
  297. },
  298. ]
  299. })
  300. let rules = ref({
  301. sendTime: [
  302. { required: true, message: '请选择时间', trigger: 'blur' },
  303. ],
  304. type: [
  305. { required: true, message: '请选择类型', trigger: 'change' },
  306. ],
  307. title: [
  308. { required: true, message: '请输入标题', trigger: 'blur' },
  309. ],
  310. content: [
  311. { required: true, message: '请输入正文', trigger: 'blur' },
  312. ],
  313. })
  314. const openModal = () => {
  315. modalType.value = 'add'
  316. formData.data = {}
  317. loadingOperation.value = false
  318. dialogVisible.value = true
  319. }
  320. const submitForm = () => {
  321. submit.value.handleSubmit(() => {
  322. loadingOperation.value = true
  323. proxy.post('/sendMeg/' + modalType.value, formData.data).then(
  324. () => {
  325. ElMessage({
  326. message: modalType.value == 'add' ? '添加成功' : '编辑成功',
  327. type: 'success',
  328. })
  329. dialogVisible.value = false
  330. getList()
  331. },
  332. (err) => {
  333. console.log(err)
  334. loadingOperation.value = false
  335. }
  336. )
  337. })
  338. }
  339. const update = (row) => {
  340. modalType.value = 'edit'
  341. loadingOperation.value = true
  342. proxy.post('/contractTemplate/detail', { id: row.id }).then((res) => {
  343. formData.data = res
  344. loadingOperation.value = false
  345. dialogVisible.value = true
  346. })
  347. }
  348. </script>
  349. <style lang="scss" scoped>
  350. .tenant {
  351. padding: 20px;
  352. }
  353. </style>