postList.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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="80px" label="类型" prop="typeName">
  25. </el-table-column>
  26. <el-table-column align="center" min-width="80px" label="积分" prop="integral">
  27. </el-table-column>
  28. <el-table-column align="center" min-width="100px" label="截止日期" prop="deadline">
  29. </el-table-column>
  30. <el-table-column align="center" min-width="100px" label="创建日期" prop="createTime">
  31. </el-table-column>
  32. <el-table-column align="center" min-width="80px" label="状态" prop="statusName">
  33. </el-table-column>
  34. <el-table-column align="center" label="操作" width="240px" class-name="small-padding fixed-width">
  35. <template slot-scope="scope">
  36. <el-button type="primary" size="small" @click="handleUpdate(scope.row)">编辑</el-button>
  37. <el-button v-if="scope.row.status == 0" type="success" size="small"
  38. @click="changeState(scope.row.id, 1)">开启</el-button>
  39. <el-button v-if="scope.row.status == 1" type="warning" size="small"
  40. @click="changeState(scope.row.id, 0)">关闭</el-button>
  41. <el-button type="danger" size="small" @click="handleDelete(scope.row.id, -1)">删除</el-button>
  42. </template>
  43. </el-table-column>
  44. </el-table>
  45. <!-- 分页 -->
  46. <div class="pagination-container">
  47. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
  48. :current-page="listQuery.page" :page-sizes="[10, 20, 30, 50]" :page-size="listQuery.limit"
  49. layout="total, sizes, prev, pager, next, jumper" :total="total">
  50. </el-pagination>
  51. </div>
  52. <!-- 添加或修改对话框 -->
  53. <el-dialog :close-on-click-modal="false" :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="65%">
  54. <el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="100px" style='width:750px;margin-left:50px;'>
  55. <el-form-item label="标题" prop="title">
  56. <el-input v-model="dataForm.title" style="width: 100%"></el-input>
  57. </el-form-item>
  58. <el-form-item label="类型" prop="type">
  59. <el-select v-model="dataForm.type" placeholder="请选择" style="width: 100%" @change="changeType">
  60. <el-option :key="item.value" v-for="item in typeList" :label="item.name" :value="item.value">
  61. </el-option>
  62. </el-select>
  63. </el-form-item>
  64. <el-form-item style="width: 800px" label="图片" prop="media">
  65. <el-tooltip content="建议图片宽高比120*80" placement="top-start">
  66. <el-upload :action="fileImgUrl" list-type="picture-card" :file-list="dataForm.mediaFiles" :limit="1"
  67. :on-success="handleGallerySucess" :on-exceed="handleExceed" :before-upload="uploadBannerImg"
  68. :on-remove="handleRemove">
  69. <i class="el-icon-plus"></i>
  70. </el-upload>
  71. </el-tooltip>
  72. </el-form-item>
  73. <el-form-item label="积分" prop="integral">
  74. <el-input-number style="width: 100%" :min="0" :step="1" v-model="dataForm.integral"></el-input-number>
  75. </el-form-item>
  76. <el-form-item label="截止日期" prop="deadline">
  77. <el-date-picker value-format="yyyy-MM-dd" v-model="dataForm.deadline" type="date" placeholder="请选择结束时间" style="width: 100%">
  78. </el-date-picker>
  79. </el-form-item>
  80. <el-form-item label="参与人">
  81. <el-select v-model="dataForm.participants" multiple filterable placeholder="请选择" style="width: 100%">
  82. <el-option :key="item.loginId" v-for="item in participantsList" :label="item.userName+'_'+item.deptName" :value="item.loginId">
  83. </el-option>
  84. </el-select>
  85. </el-form-item>
  86. <el-form-item label="内容" prop="content">
  87. <el-input type="textarea" :rows="4" style="width: 100%" v-model="dataForm.content"></el-input>
  88. </el-form-item>
  89. <el-form-item label="问题类型" prop="questions">
  90. <el-select v-model="qesType" placeholder="请选择" style="width: 84%">
  91. <el-option :key="item.value" v-for="item in qesTypeList" :label="item.name" :value="item.value">
  92. </el-option>
  93. </el-select>
  94. <el-button type="success" @click="addquest">添加问题</el-button>
  95. </el-form-item>
  96. <div style="margin: 50px 0;" v-for="(item,index) in dataForm.questions" :key="index">
  97. <el-form-item v-if="item.type=='SCQ'" :label="'问题'+(index+1)+'(单选)'">
  98. <el-input v-model="item.description" style="width: 67%"></el-input>
  99. <el-button type="primary" @click="additem(index)">添加选项</el-button>
  100. <el-button type="danger" @click="delectquest(index)">删除问题</el-button>
  101. </el-form-item>
  102. <el-form-item v-if="item.type=='MCQ'" :label="'问题'+(index+1)+'(多选)'">
  103. <el-input v-model="item.description" style="width: 67%"></el-input>
  104. <el-button type="primary" @click="additem(index)">添加选项</el-button>
  105. <el-button type="danger" @click="delectquest(index)">删除问题</el-button>
  106. </el-form-item>
  107. <el-form-item v-if="item.type=='SAQ'" :label="'问题'+(index+1)+'(问答)'">
  108. <el-input v-model="item.description" style="width: 84%"></el-input>
  109. <el-button type="danger" @click="delectquest(index)">删除问题</el-button>
  110. </el-form-item>
  111. <div v-for="(val,childindex) in item.options" :key="childindex">
  112. <el-form-item :label="'选项'+(childindex+1)">
  113. <el-input v-model="val.name" style="width: 84%"></el-input>
  114. <el-button type="danger" @click="delectitem(index,childindex)">删除选项</el-button>
  115. </el-form-item>
  116. </div>
  117. </div>
  118. </el-form>
  119. <div slot="footer" class="dialog-footer">
  120. <el-button @click="dialogFormVisible = false">取消</el-button>
  121. <el-button v-if="dialogStatus == 'create'" type="primary" @click="createData">确定</el-button>
  122. <el-button v-else type="primary" @click="updateData">确定</el-button>
  123. </div>
  124. </el-dialog>
  125. </div>
  126. </template>
  127. <style>
  128. .demo-table-expand {
  129. font-size: 0;
  130. }
  131. .demo-table-expand label {
  132. width: 200px;
  133. color: #99a9bf;
  134. }
  135. .demo-table-expand .el-form-item {
  136. margin-right: 0;
  137. margin-bottom: 0;
  138. }
  139. </style>
  140. <script>
  141. import { create, update, getList, changeState, getDetailInfo } from "@/api/postManage";
  142. import { allUserList } from "@/api/public";
  143. import waves from "@/directive/waves"; // 水波纹指令
  144. import Tinymce from '@/components/Tinymce'
  145. export default {
  146. name: 'getList',
  147. components: { Tinymce },
  148. directives: { waves },
  149. data() {
  150. return {
  151. fileImgUrl: this.upLoadUrl,
  152. qesType:'',
  153. qesTypeList:[
  154. {
  155. value:'SCQ',
  156. name:'单选'
  157. },
  158. {
  159. value:'MCQ',
  160. name:'多选'
  161. },
  162. {
  163. value:'SAQ',
  164. name:'问答'
  165. },
  166. ],
  167. typeList:[
  168. {
  169. value:4,
  170. name:'投票'
  171. },
  172. {
  173. value:5,
  174. name:'问卷调查'
  175. }
  176. ],
  177. participantsList: [],
  178. list: [
  179. {
  180. title:'问卷调查标题',
  181. type:5,
  182. typeName:'问卷调查',
  183. integral:500,
  184. deadline:'2023-11-08',
  185. participants: ["13564541778","13651932750","18616396637","13817835530"],
  186. content: '2222',
  187. questions: [
  188. {
  189. description: "测试—问题1",
  190. type: "SCQ",
  191. options:[
  192. {
  193. name: "A"
  194. },
  195. {
  196. name: "B"
  197. },
  198. {
  199. name: "C"
  200. },
  201. {
  202. name: "D"
  203. }
  204. ]
  205. },
  206. {
  207. type: "MCQ",
  208. description: "测试—问题2",
  209. options: [
  210. {
  211. name: "A"
  212. },
  213. {
  214. name: "B"
  215. },
  216. {
  217. name: "C"
  218. },
  219. {
  220. name: "D"
  221. }
  222. ]
  223. },
  224. {
  225. type: "SAQ",
  226. description: "测试—问题3",
  227. options: []
  228. }
  229. ],
  230. },
  231. {
  232. title:'投票标题',
  233. type:4,
  234. typeName:'投票',
  235. integral:500,
  236. deadline:'2023-11-08',
  237. participants: ["13564541778","13651932750"],
  238. content: '2222',
  239. questions: [
  240. {
  241. description: "测试—问题1",
  242. type: "SCQ",
  243. options:[
  244. {
  245. name: "A"
  246. },
  247. {
  248. name: "B"
  249. },
  250. {
  251. name: "C"
  252. },
  253. {
  254. name: "D"
  255. }
  256. ]
  257. },
  258. {
  259. type: "MCQ",
  260. description: "测试—问题2",
  261. options: [
  262. {
  263. name: "A"
  264. },
  265. {
  266. name: "B"
  267. },
  268. {
  269. name: "C"
  270. },
  271. {
  272. name: "D"
  273. }
  274. ]
  275. },
  276. ],
  277. },
  278. ],
  279. total: 0,
  280. listLoading: false,
  281. listQuery: {
  282. page: 1,
  283. limit: 10,
  284. title: '',
  285. createTime: '',
  286. },
  287. dataForm: {
  288. title: '',
  289. type: '',
  290. media: '',
  291. mediaFiles: [],
  292. integral: '',
  293. deadline: '',
  294. participants: [],
  295. content: '',
  296. questions: [],
  297. },
  298. dialogFormVisible: false,
  299. dialogStatus: '',
  300. textMap: {
  301. update: "编辑",
  302. create: "创建",
  303. },
  304. rules: {
  305. title: [{ required: true, message: "请填写标题", trigger: "blur" }],
  306. type: [{ required: true, message: "请选择类型", trigger: "blur" }],
  307. media: [{ required: true, message: "图片不能为空", trigger: "blur" }],
  308. integral: [{ required: true, message: "请填写积分", trigger: "blur" }],
  309. deadline: [{ required: true, message: "请选择截止日期", trigger: "blur" }],
  310. content: [{ required: true, message: "内容不能为空", trigger: "blur" }],
  311. questions: [{ required: true, message: "请添加至少一个问题", trigger: "blur" }],
  312. },
  313. }
  314. },
  315. created() {
  316. this.getAllUserList();
  317. this.getList();
  318. },
  319. methods: {
  320. handleRemove(file, fileList) {
  321. console.log(file, fileList);
  322. let mediaFiles = [];
  323. for (let i in fileList) {
  324. let response = fileList[i].response;
  325. let url = response.data.url;
  326. mediaFiles.push(url);
  327. this.dataForm.media = mediaFiles.join(",");
  328. }
  329. },
  330. uploadBannerImg(file) {
  331. const isJPGs = file.type === "image/jpeg";
  332. console.log(isJPGs);
  333. },
  334. handleExceed(files, fileList) {
  335. this.$message.warning(
  336. `当前限制选择 1 个文件,本次选择了 ${files.length} 个文件!,共选择了 ${files.length + fileList.length
  337. } 个文件`
  338. );
  339. },
  340. handleGallerySucess(res, file, fileList) {
  341. this.dataForm.media = ""; // 清空画廊图片数组
  342. let mediaFiles = [];
  343. for (let i in fileList) {
  344. let response = fileList[i].response;
  345. if (response.errno && response.errno != "0") {
  346. this.$message.error("该图片上传失败,已被移除,请重新上传!");
  347. // 上传失败移除该 file 对象
  348. fileList.splice(i, 1);
  349. } else {
  350. let url = response.data.url;
  351. mediaFiles.push(url);
  352. }
  353. }
  354. this.dataForm.media = mediaFiles.join(",");
  355. },
  356. //改变类型
  357. changeType(val){
  358. if(val==5){
  359. this.qesTypeList = [
  360. {
  361. value:'SCQ',
  362. name:'单选'
  363. },
  364. {
  365. value:'MCQ',
  366. name:'多选'
  367. },
  368. {
  369. value:'SAQ',
  370. name:'问答'
  371. },
  372. ];
  373. }
  374. if(val==4){
  375. this.qesTypeList = [
  376. {
  377. value:'SCQ',
  378. name:'单选'
  379. },
  380. {
  381. value:'MCQ',
  382. name:'多选'
  383. },
  384. ];
  385. }
  386. },
  387. //添加问题
  388. addquest(){
  389. let tempArray = this.dataForm.questions;
  390. if(this.qesType){
  391. var temp0 = {
  392. type: this.qesType,
  393. description: '',
  394. options:[],
  395. };
  396. tempArray.push(temp0);
  397. this.dataForm.questions = tempArray;
  398. }else{
  399. this.$message.error('请选择问题类型');
  400. }
  401. this.qesType = '';
  402. },
  403. //删除问题
  404. delectquest(index){
  405. let qusetion = this.dataForm.questions;
  406. qusetion.splice(index, 1);
  407. this.dataForm.questions = qusetion;
  408. },
  409. //添加选项
  410. additem(index){
  411. console.log(index);
  412. let qusetion = this.dataForm.questions;
  413. let options = qusetion[index].options;
  414. options.push({ name:''});
  415. this.dataForm.questions = qusetion;
  416. },
  417. //删除选项
  418. delectitem(index,childindex){
  419. console.log(index,childindex);
  420. let qusetion = this.dataForm.questions;
  421. let options = qusetion[index].options;
  422. options.splice(childindex, 1);
  423. this.dataForm.questions = qusetion;
  424. },
  425. resetForm() {
  426. this.dataForm = {
  427. title: '',
  428. type: '',
  429. media: '',
  430. mediaFiles: [],
  431. integral: '',
  432. deadline: '',
  433. participants: [],
  434. content: '',
  435. questions: [],
  436. };
  437. },
  438. handleCreate() {
  439. this.resetForm();
  440. this.dialogFormVisible = true;
  441. this.dialogStatus = "create";
  442. this.$nextTick(() => {
  443. this.$refs["dataForm"].clearValidate();
  444. });
  445. },
  446. //验证是否为空的函数
  447. ifnone_data() {
  448. let stati_top = 200;
  449. let qusetion = this.dataForm.questions;
  450. for (let i = 0; i < qusetion.length; i++) {
  451. if (qusetion[i].description == '') {
  452. stati_top = '请填写问题'; break;
  453. }
  454. if (qusetion[i].type != 'SAQ') {
  455. if (qusetion[i].options.length == 0) {
  456. stati_top = '请添加选项'; break;
  457. }
  458. for (let j = 0; j < qusetion[i].options.length; j++) {
  459. if (qusetion[i].options[j].name == '') {
  460. stati_top = '请填写选项'; break;
  461. }
  462. }
  463. }
  464. }
  465. return stati_top;
  466. },
  467. createData() {
  468. this.$refs["dataForm"].validate((valid) => {
  469. let ifnone_data = this.ifnone_data();
  470. if (valid&&ifnone_data==200) {
  471. console.log(this.dataForm);
  472. create(this.dataForm)
  473. .then((response) => {
  474. this.getList();
  475. this.dialogFormVisible = false;
  476. this.$notify({
  477. title: "成功",
  478. message: "创建成功",
  479. type: "success",
  480. duration: 2000,
  481. });
  482. this.getList();
  483. })
  484. .catch(() => { });
  485. }else{
  486. this.$message.error(ifnone_data);
  487. }
  488. });
  489. },
  490. handleUpdate(row) {
  491. getDetailInfo({postId:row.id}).then(response => {
  492. this.dataForm = response.data.data;
  493. this.dataForm.questions = response.data.data.data;
  494. if (this.dataForm.media) {
  495. let mediaFiles = this.dataForm.media.split(",");
  496. this.dataForm.mediaFiles = [];
  497. for (let i in mediaFiles) {
  498. let url = mediaFiles[i];
  499. let name = "image_" + i;
  500. this.dataForm.mediaFiles.push({
  501. name: name,
  502. url: url,
  503. response: { error: "0", data: { url: url } },
  504. });
  505. }
  506. }
  507. this.dialogStatus = 'update'
  508. this.dialogFormVisible = true
  509. this.$nextTick(() => {
  510. this.$refs["dataForm"].clearValidate();
  511. });
  512. }).catch(() => {})
  513. },
  514. updateData() {
  515. this.$refs['dataForm'].validate((valid) => {
  516. if (valid) {
  517. update(this.dataForm).then(() => {
  518. this.dialogFormVisible = false
  519. this.$notify({
  520. title: '成功',
  521. message: '更新成功',
  522. type: 'success',
  523. duration: 2000
  524. })
  525. this.getList()
  526. })
  527. }
  528. })
  529. },
  530. changeState(postId, index) {
  531. changeState({ postId: postId, status: index }).then(response => {
  532. this.$notify({
  533. title: '成功',
  534. message: '状态修改成功',
  535. type: 'success',
  536. duration: 2000
  537. })
  538. this.getList()
  539. })
  540. },
  541. handleDelete(postId, index) {
  542. this.$confirm('确认删除吗?', '提示', {
  543. confirmButtonText: '确定',
  544. cancelButtonText: '取消',
  545. type: 'warning'
  546. }).then(() => {
  547. changeState({ postId: postId, status: index }).then(response => {
  548. this.$notify({
  549. title: '成功',
  550. message: '删除成功',
  551. type: 'success',
  552. duration: 2000
  553. })
  554. this.getList();
  555. })
  556. }).catch(() => {})
  557. },
  558. getAllUserList() {
  559. allUserList().then(response => {
  560. this.participantsList = response.data.data;
  561. }).catch(() => {});
  562. },
  563. getList() {
  564. this.listLoading = true
  565. getList(this.listQuery).then(response => {
  566. this.list = response.data.data.items
  567. this.total = response.data.data.total
  568. this.listLoading = false
  569. }).catch(() => {})
  570. },
  571. handleFilter() {
  572. this.listQuery.page = 1
  573. this.getList()
  574. },
  575. handleSizeChange(val) {
  576. this.listQuery.limit = val
  577. this.getList()
  578. },
  579. handleCurrentChange(val) {
  580. this.listQuery.page = val
  581. this.getList()
  582. },
  583. }
  584. }
  585. </script>
  586. <style>
  587. .ad-avatar-uploader .el-upload {
  588. border: 1px dashed #d9d9d9;
  589. border-radius: 6px;
  590. cursor: pointer;
  591. position: relative;
  592. overflow: hidden;
  593. }
  594. .ad-avatar-uploader .el-upload:hover {
  595. border-color: #409EFF;
  596. }
  597. .ad-avatar-uploader-icon {
  598. font-size: 28px;
  599. color: #8c939d;
  600. width: 178px;
  601. height: 178px;
  602. line-height: 178px;
  603. text-align: center;
  604. }
  605. .ad-avatar {
  606. display: block;
  607. }
  608. </style>