noticeList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. <template>
  2. <div class="app-container calendar-list-container">
  3. <!-- 查询和其他操作 -->
  4. <div class="filter-container">
  5. <el-input clearable class="filter-item" style="width: 200px;" placeholder="标题"
  6. v-model="listQuery.title"></el-input>
  7. <el-date-picker
  8. class="filter-item"
  9. value-format="yyyy-MM-dd"
  10. v-model="listQuery.createTime"
  11. type="date"
  12. placeholder="创建日期">
  13. </el-date-picker>
  14. <el-button class="filter-item" type="primary" v-waves icon="el-icon-search" @click="handleFilter">查找</el-button>
  15. <el-button class="filter-item" type="primary" @click="handleCreate" icon="el-icon-edit">添加</el-button>
  16. </div>
  17. <!-- 查询结果 -->
  18. <el-table size="small" :data="list" v-loading="listLoading" element-loading-text="正在查询中。。。" border fit
  19. highlight-current-row>
  20. <el-table-column type="index" label="序号" header-align="center" align="center">
  21. </el-table-column>
  22. <el-table-column align="center" min-width="100px" label="标题" prop="title">
  23. </el-table-column>
  24. <el-table-column align="center" min-width="100px" label="简介" prop="subTitle">
  25. </el-table-column>
  26. <el-table-column align="center" min-width="80px" label="创建人" prop="sender">
  27. </el-table-column>
  28. <el-table-column align="center" min-width="150px" label="创建时间" prop="createTime">
  29. </el-table-column>
  30. <el-table-column align="center" min-width="80px" label="状态" prop="statusName">
  31. </el-table-column>
  32. <el-table-column align="center" label="操作" width="240px" class-name="small-padding fixed-width">
  33. <template slot-scope="scope">
  34. <el-button type="primary" size="small" @click="handleUpdate(scope.row)">编辑</el-button>
  35. <el-button v-if="scope.row.status == 0" type="success" size="small"
  36. @click="changeState(scope.row.msgId, 1)">开启</el-button>
  37. <el-button v-if="scope.row.status == 1" type="warning" size="small"
  38. @click="changeState(scope.row.msgId, 0)">关闭</el-button>
  39. <el-button type="danger" size="mini" @click="handleDelete(scope.row.welfareId, -1)">删除</el-button>
  40. </template>
  41. </el-table-column>
  42. </el-table>
  43. <!-- 分页 -->
  44. <div class="pagination-container">
  45. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
  46. :current-page="listQuery.page" :page-sizes="[10, 20, 30, 50]" :page-size="listQuery.limit"
  47. layout="total, sizes, prev, pager, next, jumper" :total="total">
  48. </el-pagination>
  49. </div>
  50. <!-- 添加或修改对话框 -->
  51. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="70%">
  52. <el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="100px" style='width:700px;margin-left:50px;'>
  53. <el-form-item label="标题" prop="title">
  54. <el-input v-model="dataForm.title" style="width: 350px"></el-input>
  55. </el-form-item>
  56. <el-form-item label="简介">
  57. <el-input v-model="dataForm.subTitle" style="width: 350px"></el-input>
  58. </el-form-item>
  59. <el-form-item style="width: 800px" label="通知图片">
  60. <el-upload :action="fileImgUrl" list-type="picture-card" :file-list="dataForm.images" :limit="1"
  61. :on-success="handleGallerySucess" :on-exceed="handleExceed" :before-upload="uploadBannerImg"
  62. :on-remove="handleRemove">
  63. <i class="el-icon-plus"></i>
  64. </el-upload>
  65. </el-form-item>
  66. <el-form-item style="width: 800px" label="内容" prop="content">
  67. <tinymce v-model="dataForm.content" ref="tinymce"></tinymce>
  68. </el-form-item>
  69. </el-form>
  70. <div slot="footer" class="dialog-footer">
  71. <el-button @click="dialogFormVisible = false">取消</el-button>
  72. <el-button v-if="dialogStatus == 'create'" type="primary" @click="createData">确定</el-button>
  73. <el-button v-else type="primary" @click="updateData">确定</el-button>
  74. </div>
  75. </el-dialog>
  76. </div>
  77. </template>
  78. <style>
  79. .demo-table-expand {
  80. font-size: 0;
  81. }
  82. .demo-table-expand label {
  83. width: 200px;
  84. color: #99a9bf;
  85. }
  86. .demo-table-expand .el-form-item {
  87. margin-right: 0;
  88. margin-bottom: 0;
  89. }
  90. </style>
  91. <script>
  92. import { createItem, updateItem, list, state } from "@/api/noticeList";
  93. import waves from "@/directive/waves"; // 水波纹指令
  94. import Tinymce from '@/components/Tinymce'
  95. export default {
  96. components: { Tinymce },
  97. directives: { waves },
  98. data() {
  99. return {
  100. fileImgUrl: this.upLoadUrl,
  101. list: [],
  102. total: 0,
  103. listLoading: false,
  104. listQuery: {
  105. page: 1,
  106. limit: 10,
  107. title: '',
  108. createTime: '',
  109. },
  110. dataForm: {
  111. title: '',
  112. subTitle:'',
  113. content: '',
  114. imgUrl: '',
  115. images: [],
  116. },
  117. dialogFormVisible: false,
  118. dialogStatus: '',
  119. textMap: {
  120. update: "编辑",
  121. create: "创建",
  122. },
  123. rules: {
  124. title: [{ required: true, message: "请填写活动名称", trigger: "blur" }],
  125. content: [{ required: true, message: "内容不能为空", trigger: "blur" }],
  126. },
  127. }
  128. },
  129. created() {
  130. this.getList();
  131. },
  132. methods: {
  133. handleRemove(file, fileList) {
  134. console.log(file, fileList);
  135. let images = [];
  136. for (let i in fileList) {
  137. let response = fileList[i].response;
  138. let url = response.data.url;
  139. images.push(url);
  140. this.dataForm.imgUrl = images.join(",");
  141. }
  142. },
  143. uploadBannerImg(file) {
  144. const isJPGs = file.type === "image/jpeg";
  145. console.log(isJPGs);
  146. },
  147. handleExceed(files, fileList) {
  148. this.$message.warning(
  149. `当前限制选择 1 个文件,本次选择了 ${files.length} 个文件!,共选择了 ${files.length + fileList.length
  150. } 个文件`
  151. );
  152. },
  153. handleGallerySucess(res, file, fileList) {
  154. this.dataForm.imgUrl = ""; // 清空画廊图片数组
  155. let images = [];
  156. for (let i in fileList) {
  157. let response = fileList[i].response;
  158. if (response.errno && response.errno != "0") {
  159. this.$message.error("该图片上传失败,已被移除,请重新上传!");
  160. // 上传失败移除该 file 对象
  161. fileList.splice(i, 1);
  162. } else {
  163. let url = response.data.url;
  164. images.push(url);
  165. }
  166. }
  167. this.dataForm.imgUrl = images.join(",");
  168. },
  169. resetForm() {
  170. this.dataForm = {
  171. title: '',
  172. subTitle:'',
  173. content: '',
  174. imgUrl: '',
  175. images: [],
  176. };
  177. },
  178. handleCreate() {
  179. this.resetForm();
  180. this.dialogFormVisible = true;
  181. this.dialogStatus = "create";
  182. this.$nextTick(() => {
  183. this.$refs.tinymce.setContent("");
  184. this.$refs["dataForm"].clearValidate();
  185. });
  186. },
  187. createData() {
  188. this.$refs["dataForm"].validate((valid) => {
  189. if (valid) {
  190. console.log(this.dataForm);
  191. createItem(this.dataForm)
  192. .then((response) => {
  193. this.getList();
  194. this.dialogFormVisible = false;
  195. this.$notify({
  196. title: "成功",
  197. message: "创建成功",
  198. type: "success",
  199. duration: 2000,
  200. });
  201. this.getList();
  202. })
  203. .catch(() => { });
  204. }
  205. });
  206. },
  207. handleUpdate(row) {
  208. this.dataForm = Object.assign({}, row);
  209. let content = this.dataForm.content;
  210. if (this.dataForm.imgUrl) {
  211. let images = this.dataForm.imgUrl.split(",");
  212. this.dataForm.images = [];
  213. for (let i in images) {
  214. let url = images[i];
  215. let name = "image_" + i;
  216. this.dataForm.images.push({
  217. name: name,
  218. url: url,
  219. response: { error: "0", data: { url: url } },
  220. });
  221. }
  222. }
  223. this.dialogStatus = 'update'
  224. this.dialogFormVisible = true
  225. this.$nextTick(() => {
  226. this.$refs.tinymce.setContent(content);
  227. this.$refs['dataForm'].clearValidate()
  228. })
  229. },
  230. updateData() {
  231. this.$refs['dataForm'].validate((valid) => {
  232. if (valid) {
  233. updateItem(this.dataForm).then(() => {
  234. this.dialogFormVisible = false
  235. this.$notify({
  236. title: '成功',
  237. message: '更新成功',
  238. type: 'success',
  239. duration: 2000
  240. })
  241. this.getList()
  242. })
  243. }
  244. })
  245. },
  246. changeState(msgId, index) {
  247. state({ msgId: msgId, status: index }).then(response => {
  248. this.$notify({
  249. title: '成功',
  250. message: '活动状态修改成功',
  251. type: 'success',
  252. duration: 2000
  253. })
  254. this.getList()
  255. })
  256. },
  257. handleDelete(welfareId, index) {
  258. this.$confirm('确认删除吗?', '提示', {
  259. confirmButtonText: '确定',
  260. cancelButtonText: '取消',
  261. type: 'warning'
  262. }).then(() => {
  263. state({ welfareId: welfareId, status: index }).then(response => {
  264. this.$notify({
  265. title: '成功',
  266. message: '删除成功',
  267. type: 'success',
  268. duration: 2000
  269. })
  270. this.getList();
  271. })
  272. }).catch(() => {})
  273. },
  274. getList() {
  275. this.listLoading = true
  276. list(this.listQuery).then(response => {
  277. this.list = response.data.data.items
  278. this.total = response.data.data.total
  279. this.listLoading = false
  280. }).catch(() => {})
  281. },
  282. handleFilter() {
  283. this.listQuery.page = 1
  284. this.getList()
  285. },
  286. handleSizeChange(val) {
  287. this.listQuery.limit = val
  288. this.getList()
  289. },
  290. handleCurrentChange(val) {
  291. this.listQuery.page = val
  292. this.getList()
  293. },
  294. }
  295. }
  296. </script>
  297. <style>
  298. .ad-avatar-uploader .el-upload {
  299. border: 1px dashed #d9d9d9;
  300. border-radius: 6px;
  301. cursor: pointer;
  302. position: relative;
  303. overflow: hidden;
  304. }
  305. .ad-avatar-uploader .el-upload:hover {
  306. border-color: #409EFF;
  307. }
  308. .ad-avatar-uploader-icon {
  309. font-size: 28px;
  310. color: #8c939d;
  311. width: 178px;
  312. height: 178px;
  313. line-height: 178px;
  314. text-align: center;
  315. }
  316. .ad-avatar {
  317. display: block;
  318. }
  319. </style>