Newer
Older
KaiFengPC / src / views / publicService / quesNaire.vue
@zhangdeliang zhangdeliang on 23 May 13 KB 初始化项目
  1. <template>
  2. <!-- 排水防涝子系统 公众服务 问卷调查-->
  3. <div class="publicContainer">
  4. <!-- 搜索区域 -->
  5. <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
  6. <el-form-item label="问卷主题" prop="topicName">
  7. <el-input v-model="queryParams.topicName" placeholder="请输入" clearable @keyup.enter="handleQuery" />
  8. </el-form-item>
  9. <el-form-item label="调查状态" prop="adjustmentStatus">
  10. <el-select v-model="queryParams.adjustmentStatus" placeholder="请选择" clearable>
  11. <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  16. <el-button type="success" icon="Refresh" @click="resetQuery">重置</el-button>
  17. </el-form-item>
  18. </el-form>
  19. <!-- 按钮区域 -->
  20. <el-row :gutter="10" class="mb8">
  21. <el-col :span="1.5">
  22. <el-button type="primary" plain icon="Plus" @click="handleAdd">新增</el-button>
  23. </el-col>
  24. <right-toolbar v-model:showSearch="showSearch" @queryTable="getDataList"></right-toolbar>
  25. </el-row>
  26. <!-- 表格 -->
  27. <el-table v-loading="tableLoading" :data="tableData" max-height="700">
  28. <el-table-column label="调查问卷主题" prop="topicName" />
  29. <el-table-column label="调查状态" prop="adjustmentStatus">
  30. <template #default="scope">
  31. <dict-tag :options="statusList" :value="scope.row.adjustmentStatus" />
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="问卷状态" prop="ifStart">
  35. <template #default="scope">
  36. <span :class="scope.row.ifStart == 1 ? 'green' : 'red'">{{ scope.row.ifStart == 1 ? '启用' : '未启用' }}</span>
  37. </template>
  38. </el-table-column>
  39. <el-table-column label="调查年份" prop="year" />
  40. <el-table-column label="创建人" prop="createBy" />
  41. <el-table-column label="创建时间" prop="createTime" />
  42. <el-table-column label="操作" width="160" class-name="small-padding fixed-width">
  43. <template #default="scope">
  44. <el-button
  45. type="primary"
  46. icon="Edit"
  47. @click="handleUpdate(scope.row)"
  48. v-if="scope.row.ifStart == 1 && scope.row.adjustmentStatus != 'ended'"
  49. >
  50. 修改
  51. </el-button>
  52. <el-button
  53. type="danger"
  54. icon="Delete"
  55. @click="handleDelete(scope.row)"
  56. v-if="scope.row.ifStart == 0 && scope.row.adjustmentStatus != 'ended'"
  57. >
  58. 删除
  59. </el-button>
  60. <el-button type="warning" icon="Edit" @click="handleCount(scope.row)" v-if="scope.row.ifStart == 1"> 满意度统计 </el-button>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. <!-- 分页 -->
  65. <pagination
  66. v-show="total > 0"
  67. :total="total"
  68. v-model:page="queryParams.pageNum"
  69. v-model:limit="queryParams.pageSize"
  70. @pagination="getDataList"
  71. />
  72.  
  73. <!-- 添加或修改弹窗 -->
  74. <el-dialog :title="dialogTitle" v-model="dialogShow" width="600px" append-to-body>
  75. <el-form ref="formRef" :model="formData" :rules="rulesForm" label-width="120px" class="publicForm">
  76. <el-form-item label="问卷主题" prop="topicName">
  77. <el-input v-model="formData.topicName" />
  78. </el-form-item>
  79. <el-form-item label="年份选择" prop="year">
  80. <el-date-picker type="year" v-model="formData.year" value-format="YYYY" placeholder="请选择日期"> </el-date-picker>
  81. </el-form-item>
  82. <el-form-item label="问卷状态" prop="ifStart">
  83. <el-radio-group v-model="formData.ifStart">
  84. <el-radio :label="1">启用</el-radio>
  85. <el-radio :label="0">未启用</el-radio>
  86. </el-radio-group>
  87. </el-form-item>
  88. <el-form-item label="问卷介绍" prop="introduce">
  89. <el-input type="textarea" v-model="formData.introduce" />
  90. </el-form-item>
  91. <el-divider />
  92. <el-button type="primary" plain icon="Plus" @click="addQues">新增标题内容</el-button>
  93. <el-table :data="formData.problemConfigList" style="margin-top: 10px" max-height="300">
  94. <el-table-column label="问题名称" prop="problemName" />
  95. <el-table-column label="问题类型" prop="problemType">
  96. <template #default="scope">
  97. <dict-tag :options="typeList" :value="scope.row.problemType" />
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="操作" width="160" class-name="small-padding fixed-width">
  101. <template #default="scope">
  102. <el-button type="primary" icon="Edit" @click="changeQues(scope.row)"> 修改 </el-button>
  103. <el-button type="danger" icon="Edit" @click="deleteQues(scope.row)"> 删除 </el-button>
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. </el-form>
  108. <template #footer>
  109. <div class="dialog-footer">
  110. <el-button type="info" @click="cancelForm">取 消</el-button>
  111. <el-button type="primary" @click="submitForm">确 定</el-button>
  112. </div>
  113. </template>
  114. </el-dialog>
  115. <!-- 问题答案编辑 -->
  116. <el-dialog :title="dialogTitleAns" v-model="dialogShowAns" width="500px" append-to-body>
  117. <el-form ref="formRefAns" :model="formDataAns" :rules="rulesFormAns" label-width="80px" class="publicForm">
  118. <el-form-item label="试题名称" prop="problemName">
  119. <el-input v-model="formDataAns.problemName" />
  120. </el-form-item>
  121. <el-form-item label="满分" prop="fullScore">
  122. <el-input v-model="formDataAns.fullScore" placeholder="分值" />
  123. </el-form-item>
  124. <el-form-item label="题型" prop="problemType">
  125. <el-select v-model="formDataAns.problemType" placeholder="请选择">
  126. <el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value" />
  127. </el-select>
  128. </el-form-item>
  129. <el-divider />
  130. <el-button type="primary" plain icon="Plus" @click="addAnswer">新增问题答案</el-button>
  131. <!-- 批量新增 可新增区域 -->
  132. <el-table :data="formDataAns.problemOptionList" style="margin-top: 10px">
  133. <el-table-column label="选项名称" prop="optionName">
  134. <template #default="scope">
  135. <el-input v-model="scope.row.optionName" />
  136. </template>
  137. </el-table-column>
  138. <el-table-column label="分数" prop="score">
  139. <template #default="scope">
  140. <el-input v-model="scope.row.score" placeholder="分值" />
  141. </template>
  142. </el-table-column>
  143. <el-table-column label="操作" width="160" class-name="small-padding fixed-width">
  144. <template #default="scope">
  145. <el-button type="danger" icon="Edit" @click="deleteAnswer(scope.row)"> 删除 </el-button>
  146. </template>
  147. </el-table-column>
  148. </el-table>
  149. </el-form>
  150. <template #footer>
  151. <div class="dialog-footer">
  152. <el-button type="info" @click="sureAnswer">确定</el-button>
  153. </div>
  154. </template>
  155. </el-dialog>
  156. <!-- 满意度统计 -->
  157. <el-dialog title="满意度统计" v-model="dialogCount" width="1200px" append-to-body>
  158. <!-- <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['floodSys:paikou:export']">导出</el-button> -->
  159. <!-- <el-divider /> -->
  160. <div class="satisfied">
  161. <div class="part" v-for="(item, index) in tableDataCount" :key="item.id">
  162. <p>
  163. <span>{{ index + 1 }},题目名称:{{ item.problemName }},</span>
  164. <span>
  165. 题目类型:{{
  166. item.problemType == 'radio'
  167. ? '单选'
  168. : item.problemType == 'checkbox'
  169. ? '多选'
  170. : item.problemType == 'answers'
  171. ? '简答题'
  172. : '--'
  173. }}
  174. </span>
  175. <span>,本题有效填写人次:{{ item.fillTimes || 0 }}</span>
  176. </p>
  177. <el-table :data="item.problemOptionList">
  178. <el-table-column label="选项名称" prop="optionName" />
  179. <el-table-column label="问题选项填报次数" prop="optionTimes" />
  180. <el-table-column label="问题选项填报百分比" prop="percentage" />
  181. </el-table>
  182. </div>
  183. </div>
  184. </el-dialog>
  185. </div>
  186. </template>
  187.  
  188. <script setup name="问卷调查">
  189. import { quesNairePage, quesNaireAdd, quesNaireDel, quesNaireDetail, quesNaireEdit, quesNaireCount } from '@/api/publicService/index';
  190.  
  191. const { proxy } = getCurrentInstance();
  192.  
  193. const tableData = ref([]);
  194. const tableLoading = ref(true);
  195. const total = ref(0);
  196. const dialogShow = ref(false);
  197. const dialogTitle = ref('');
  198. const showSearch = ref(true);
  199. const dialogCount = ref(false);
  200. const tableDataCount = ref([]);
  201. const dialogTitleAns = ref('');
  202. const dialogShowAns = ref(false);
  203.  
  204. const allData = reactive({
  205. queryParams: {
  206. pageNum: 1,
  207. pageSize: 10,
  208. topicName: undefined,
  209. adjustmentStatus: undefined,
  210. },
  211. formData: {
  212. topicName: '',
  213. ifStart: 1,
  214. year: null,
  215. introduce: '',
  216. problemConfigList: [],
  217. },
  218. rulesForm: {
  219. topicName: [{ required: true, message: '请输入', trigger: 'blur' }],
  220. ifStart: [{ required: true, message: '请输入', trigger: 'change' }],
  221. year: [{ required: true, message: '请输入', trigger: 'change' }],
  222. },
  223. formDataAns: {
  224. problemType: '',
  225. problemName: '',
  226. fullScore: '100',
  227. questionnaireId: '',
  228. problemOptionList: [{ optionName: '', score: '', problemId: '' }],
  229. },
  230. rulesFormAns: {
  231. problemName: [{ required: true, message: '请输入', trigger: 'blur' }],
  232. fullScore: [{ required: true, message: '请输入', trigger: 'blur', type: 'number' }],
  233. problemType: [{ required: true, message: '请选择', trigger: 'change' }],
  234. },
  235. });
  236. const { queryParams, formData, rulesForm, formDataAns, rulesFormAns } = toRefs(allData);
  237. const statusList = ref([
  238. { value: 'not_start', label: '未开始' },
  239. { value: 'executing', label: '执行中' },
  240. { value: 'ended', label: '已结束' },
  241. ]);
  242. const typeList = ref([
  243. { value: 'radio', label: '单选' },
  244. { value: 'checkbox', label: '多选' },
  245. { value: 'answers', label: '简答题' },
  246. ]);
  247.  
  248. /** 获取查询数据列表 */
  249. function getDataList() {
  250. tableLoading.value = true;
  251. quesNairePage(queryParams.value).then(response => {
  252. tableData.value = response.data;
  253. total.value = response.total;
  254. tableLoading.value = false;
  255. });
  256. }
  257. /** 取消按钮 */
  258. function cancelForm() {
  259. dialogShow.value = false;
  260. }
  261. /** 搜索按钮操作 */
  262. function handleQuery() {
  263. queryParams.value.pageNum = 1;
  264. getDataList();
  265. }
  266. /** 重置按钮操作 */
  267. function resetQuery() {
  268. proxy.resetForm('queryRef');
  269. handleQuery();
  270. }
  271. /** 新增按钮操作 */
  272. function handleAdd() {
  273. proxy.resetForm('formRef'); //清空表单
  274. formData.value = {
  275. topicName: '',
  276. ifStart: 1,
  277. year: null,
  278. introduce: '',
  279. problemConfigList: [],
  280. };
  281. dialogShow.value = true;
  282. dialogTitle.value = '添加问卷调查';
  283. }
  284. /** 修改按钮操作 */
  285. function handleUpdate(row) {
  286. const postId = row.id;
  287. quesNaireDetail(postId).then(response => {
  288. dialogShow.value = true;
  289. dialogTitle.value = '修改问卷调查';
  290. nextTick(() => {
  291. formData.value = response.data;
  292. });
  293. });
  294. }
  295. /** 提交按钮 */
  296. function submitForm() {
  297. proxy.$refs['formRef'].validate(valid => {
  298. if (valid) {
  299. if (dialogTitle.value == '修改问卷调查') {
  300. quesNaireEdit(formData.value).then(response => {
  301. proxy.$modal.msgSuccess('修改成功');
  302. dialogShow.value = false;
  303. getDataList();
  304. });
  305. } else {
  306. quesNaireAdd(formData.value).then(response => {
  307. proxy.$modal.msgSuccess('新增成功');
  308. dialogShow.value = false;
  309. getDataList();
  310. });
  311. }
  312. }
  313. });
  314. }
  315. /** 删除按钮操作 */
  316. function handleDelete(row) {
  317. const postIds = row.id;
  318. proxy.$modal
  319. .confirm('是否确认删除该数据项?')
  320. .then(function () {
  321. return quesNaireDel(postIds);
  322. })
  323. .then(() => {
  324. getDataList();
  325. proxy.$modal.msgSuccess('删除成功');
  326. })
  327. .catch(() => {});
  328. }
  329. // 满意度统计
  330. function handleCount(row) {
  331. quesNaireCount(row.id).then(res => {
  332. tableDataCount.value = res.data.problemConfigList;
  333. dialogCount.value = true;
  334. });
  335. }
  336. /** 导出按钮操作 */
  337. function handleExport() {
  338. proxy.download(
  339. 'system/post/export',
  340. {
  341. ...queryParams.value,
  342. },
  343. `问卷调查满意度统计 ${new Date().getTime()}.xlsx`
  344. );
  345. }
  346. // 问题 新增
  347. const addQues = () => {
  348. dialogTitleAns.value = '新增问题答案';
  349. dialogShowAns.value = true;
  350. formDataAns.value = {
  351. problemType: '',
  352. problemName: '',
  353. fullScore: '100',
  354. questionnaireId: '',
  355. problemOptionList: [{ optionName: '', score: '', problemId: '' }],
  356. };
  357. };
  358. // 问题 修改
  359. function changeQues(row) {
  360. formDataAns.value = row;
  361. dialogTitleAns.value = '修改问题答案';
  362. dialogShowAns.value = true;
  363. }
  364. // 问题 删除
  365. function deleteQues(row) {
  366. formData.value.problemConfigList.splice(row, 1);
  367. }
  368.  
  369. // 新增问题答案
  370. function addAnswer() {
  371. formDataAns.value.problemOptionList.push({ optionName: '', score: '', problemId: '' });
  372. }
  373. // 删除问题答案
  374. const deleteAnswer = row => {
  375. formDataAns.value.problemOptionList.splice(row, 1);
  376. };
  377. // 问题答案编辑完成
  378. function sureAnswer() {
  379. if (dialogTitleAns.value == '新增问题答案') {
  380. formData.value.problemConfigList.push(formDataAns.value);
  381. } else {
  382. }
  383. dialogShowAns.value = false;
  384. }
  385. onMounted(() => {
  386. getDataList();
  387. });
  388. </script>
  389.  
  390. <style lang="scss">
  391. .satisfied {
  392. margin-bottom: 20px;
  393. max-height: 800px;
  394. overflow: auto;
  395. .part {
  396. p {
  397. display: flex;
  398. color: #c6c6c6;
  399. }
  400. .el-table {
  401. margin: 10px 0px;
  402. }
  403. }
  404. }
  405. </style>