index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item>
  5. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  6. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  7. </el-form-item>
  8. </el-form>
  9. <el-row :gutter="10" class="mb8">
  10. <el-col :span="1.5">
  11. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  12. v-hasPermi="['his:answer:add']">新增</el-button>
  13. </el-col>
  14. <el-col :span="1.5">
  15. <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
  16. v-hasPermi="['his:answer:edit']">修改</el-button>
  17. </el-col>
  18. <el-col :span="1.5">
  19. <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
  20. v-hasPermi="['his:answer:remove']">删除</el-button>
  21. </el-col>
  22. <!-- <el-col :span="1.5">
  23. <el-button
  24. type="warning"
  25. plain
  26. icon="el-icon-download"
  27. size="mini"
  28. :loading="exportLoading"
  29. @click="handleExport"
  30. v-hasPermi="['his:answer:export']"
  31. >导出</el-button>
  32. </el-col> -->
  33. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  34. </el-row>
  35. <el-table border v-loading="loading" :data="answerList" @selection-change="handleSelectionChange">
  36. <el-table-column type="selection" width="55" align="center" />
  37. <el-table-column label="id" align="center" prop="id" />
  38. <el-table-column label="问答名称" align="center" prop="questionName" />
  39. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  40. <template slot-scope="scope">
  41. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  42. v-hasPermi="['his:answer:edit']">修改</el-button>
  43. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  44. v-hasPermi="['his:answer:remove']">删除</el-button>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  49. @pagination="getList" />
  50. <!-- 添加或修改问答对话框 -->
  51. <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
  52. <el-form ref="form" :model="form" :rules="rules" label-width="110px">
  53. <el-form-item label="问答名称" prop="questionName">
  54. <el-input v-model="form.questionName" placeholder="请输入内容" />
  55. </el-form-item>
  56. <div v-if="form.answers && form.answers.length == 0" class="empty-state">
  57. <div class="empty-state-icon">
  58. <i class="el-icon-document"></i>
  59. </div>
  60. <p>暂无问题,请点击下方按钮添加</p>
  61. </div>
  62. <div v-for="(answer, index) in form.answers" :key="index" class="answer-section">
  63. <div class="answer-section-header">
  64. <span class="answer-section-title">
  65. <span class="answer-section-number">{{ index + 1 }}</span>
  66. 问题 {{ index + 1 }}
  67. </span>
  68. <div>
  69. <el-button
  70. v-if="index !== 0"
  71. type="danger"
  72. size="mini"
  73. icon="el-icon-delete"
  74. @click="delItem(answer, index)">
  75. 删除问题
  76. </el-button>
  77. </div>
  78. </div>
  79. <el-row :gutter="15">
  80. <el-col :span="16">
  81. <el-form-item label="问题标题" :prop="`answers[${index}].title`" :rules="rules.title">
  82. <el-input v-model="answer.title" placeholder="请输入问题标题"></el-input>
  83. </el-form-item>
  84. </el-col>
  85. </el-row>
  86. <el-form-item label="选项配置">
  87. <div v-for="(option, optionIndex) in answer.options" :key="optionIndex" class="option-item">
  88. <div class="option-input">
  89. <el-input
  90. v-model="answer.options[optionIndex]"
  91. :placeholder="`选项 ${optionIndex + 1}`">
  92. </el-input>
  93. </div>
  94. <div class="option-actions">
  95. <el-button
  96. v-if="optionIndex + 1 === answer.options.length"
  97. type="primary"
  98. size="mini"
  99. icon="el-icon-plus"
  100. circle
  101. @click="addOption(index, optionIndex)">
  102. </el-button>
  103. <el-button
  104. v-if="optionIndex !== 0"
  105. type="danger"
  106. size="mini"
  107. icon="el-icon-minus"
  108. circle
  109. @click="delOption(answer.options, optionIndex)">
  110. </el-button>
  111. </div>
  112. </div>
  113. <div class="option-tip">
  114. <span>提示:至少保留一个选项,点击 + 按钮添加更多选项</span>
  115. </div>
  116. </el-form-item>
  117. </div>
  118. <div class="add-section-btn">
  119. <el-button
  120. type="primary"
  121. icon="el-icon-plus"
  122. @click="addItem(form.answers.length)">
  123. 添加问题
  124. </el-button>
  125. </div>
  126. <!-- <div v-for="(i, index) in form.answers" :key="index">
  127. <el-row>
  128. <el-col :span="8">
  129. <el-form-item label="标题" prop="title">
  130. <el-input v-model="i.title"></el-input>
  131. </el-form-item>
  132. </el-col>
  133. <el-col :span="8">
  134. <el-button style="margin: 5px;" v-if="index + 1 == form.answers.length"
  135. @click="addItem(form.answers.length)" type="primary" size="mini">+</el-button>
  136. <el-button style="margin: 5px;" v-if="index !== 0" type="danger" size="mini"
  137. @click="delItem(i, index)">-</el-button>
  138. </el-col>
  139. </el-row>
  140. </div> -->
  141. </el-form>
  142. <div slot="footer" class="dialog-footer">
  143. <el-button type="primary" @click="submitForm">确 定</el-button>
  144. <el-button @click="cancel">取 消</el-button>
  145. </div>
  146. </el-dialog>
  147. </div>
  148. </template>
  149. <script>
  150. import { listAnswer, getAnswer, delAnswer, addAnswer, updateAnswer, exportAnswer } from "@/api/his/answer";
  151. export default {
  152. name: "Answer",
  153. data() {
  154. return {
  155. // 遮罩层
  156. loading: true,
  157. // 导出遮罩层
  158. exportLoading: false,
  159. // 选中数组
  160. ids: [],
  161. // 非单个禁用
  162. single: true,
  163. // 非多个禁用
  164. multiple: true,
  165. // 显示搜索条件
  166. showSearch: true,
  167. // 总条数
  168. total: 0,
  169. // 问答表格数据
  170. answerList: [],
  171. // 弹出层标题
  172. title: "",
  173. // 是否显示弹出层
  174. open: false,
  175. // 查询参数
  176. queryParams: {
  177. pageNum: 1,
  178. pageSize: 10,
  179. jsonInfo: null,
  180. },
  181. form: {
  182. questionName: '',
  183. answers: [
  184. {
  185. title: '',
  186. options: ['']
  187. }
  188. ]
  189. },
  190. rules: {
  191. questionName: [
  192. { required: true, message: '请输入问答名称', trigger: 'blur' }
  193. ],
  194. title: [
  195. { required: true, message: '请输入问题标题', trigger: 'blur' }
  196. ]
  197. }
  198. };
  199. },
  200. created() {
  201. this.getList();
  202. },
  203. methods: {
  204. addItem(length) {
  205. this.form.answers.push({
  206. title: '',
  207. options: ['']
  208. })
  209. },
  210. delItem(item, index) {
  211. if (this.form.answers.length > 1) {
  212. this.$confirm('确定要删除这个问题吗?', '提示', {
  213. confirmButtonText: '确定',
  214. cancelButtonText: '取消',
  215. type: 'warning'
  216. }).then(() => {
  217. this.form.answers.splice(index, 1)
  218. this.$message({
  219. type: 'success',
  220. message: '删除成功!'
  221. });
  222. }).catch(() => {
  223. this.$message({
  224. type: 'info',
  225. message: '已取消删除'
  226. });
  227. });
  228. } else {
  229. this.$message.warning('至少保留一个问题')
  230. }
  231. },
  232. addOption(answerIndex, optionIndex) {
  233. this.form.answers[answerIndex].options.push('')
  234. },
  235. delOption(options, index) {
  236. if (options.length > 1) {
  237. this.$confirm('确定要删除这个选项吗?', '提示', {
  238. confirmButtonText: '确定',
  239. cancelButtonText: '取消',
  240. type: 'warning'
  241. }).then(() => {
  242. options.splice(index, 1)
  243. this.$message({
  244. type: 'success',
  245. message: '删除成功!'
  246. });
  247. }).catch(() => {
  248. this.$message({
  249. type: 'info',
  250. message: '已取消删除'
  251. });
  252. });
  253. } else {
  254. this.$message.warning('至少保留一个选项')
  255. }
  256. },
  257. // addItem(length) {
  258. // this.form.answers.push({
  259. // title: '',
  260. // options: [],
  261. // })
  262. // },
  263. // delItem(item, index) {
  264. // this.form.answers.splice(index, 1)
  265. // },
  266. // addItem1(length,n) {
  267. // this.form.answers[n].options.push('')
  268. // },
  269. // delItem2(item, index) {
  270. // this.form.answers.splice(index, 1)
  271. // },
  272. /** 查询问答列表 */
  273. getList() {
  274. this.loading = true;
  275. listAnswer(this.queryParams).then(response => {
  276. this.answerList = response.rows;
  277. this.total = response.total;
  278. this.loading = false;
  279. });
  280. },
  281. // 取消按钮
  282. cancel() {
  283. this.open = false;
  284. this.reset();
  285. },
  286. // 表单重置
  287. reset() {
  288. this.form = {
  289. id: null,
  290. jsonInfo: null,
  291. createTime: null,
  292. updateTime: null
  293. };
  294. this.resetForm("form");
  295. },
  296. /** 搜索按钮操作 */
  297. handleQuery() {
  298. this.queryParams.pageNum = 1;
  299. this.getList();
  300. },
  301. /** 重置按钮操作 */
  302. resetQuery() {
  303. this.resetForm("queryForm");
  304. this.handleQuery();
  305. },
  306. // 多选框选中数据
  307. handleSelectionChange(selection) {
  308. this.ids = selection.map(item => item.id)
  309. this.single = selection.length !== 1
  310. this.multiple = !selection.length
  311. },
  312. /** 新增按钮操作 */
  313. handleAdd() {
  314. this.reset();
  315. this.open = true;
  316. this.title = "添加问答";
  317. if (this.form.answers == null) {
  318. this.form = {
  319. answers: [{
  320. title: '',
  321. options: ['']
  322. }
  323. ]
  324. }
  325. }
  326. },
  327. /** 修改按钮操作 */
  328. handleUpdate(row) {
  329. this.reset();
  330. const id = row.id || this.ids
  331. getAnswer(id).then(response => {
  332. this.form = response.data;
  333. if (this.form.answers == null) {
  334. this.form = {
  335. answers: [{
  336. title: '',
  337. options: []
  338. }
  339. ]
  340. }
  341. }
  342. this.form.questionName = response.data.questionName;
  343. this.form.id = response.data.id;
  344. this.open = true;
  345. this.title = "修改问答";
  346. });
  347. },
  348. /** 提交按钮 */
  349. submitForm() {
  350. this.$refs["form"].validate(valid => {
  351. if (valid) {
  352. if (this.form.answers) {
  353. this.form.jsonInfo = JSON.stringify(this.form.answers);
  354. }
  355. if (this.form.id != null) {
  356. updateAnswer(this.form).then(response => {
  357. this.msgSuccess("修改成功");
  358. this.open = false;
  359. this.getList();
  360. });
  361. } else {
  362. addAnswer(this.form).then(response => {
  363. this.msgSuccess("新增成功");
  364. this.open = false;
  365. this.getList();
  366. });
  367. }
  368. }
  369. });
  370. },
  371. /** 删除按钮操作 */
  372. handleDelete(row) {
  373. const ids = row.id || this.ids;
  374. this.$confirm('是否确认删除问答编号为"' + ids + '"的数据项?', "警告", {
  375. confirmButtonText: "确定",
  376. cancelButtonText: "取消",
  377. type: "warning"
  378. }).then(function () {
  379. return delAnswer(ids);
  380. }).then(() => {
  381. this.getList();
  382. this.msgSuccess("删除成功");
  383. }).catch(() => { });
  384. },
  385. /** 导出按钮操作 */
  386. handleExport() {
  387. const queryParams = this.queryParams;
  388. this.$confirm('是否确认导出所有问答数据项?', "警告", {
  389. confirmButtonText: "确定",
  390. cancelButtonText: "取消",
  391. type: "warning"
  392. }).then(() => {
  393. this.exportLoading = true;
  394. return exportAnswer(queryParams);
  395. }).then(response => {
  396. this.download(response.msg);
  397. this.exportLoading = false;
  398. }).catch(() => { });
  399. }
  400. }
  401. };
  402. </script>
  403. <style>
  404. .form-container {
  405. max-width: 900px;
  406. margin: 30px auto;
  407. padding: 25px;
  408. background: #fff;
  409. border-radius: 10px;
  410. box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  411. }
  412. .form-header {
  413. margin-bottom: 25px;
  414. padding-bottom: 15px;
  415. border-bottom: 1px solid #ebeef5;
  416. }
  417. .form-header h2 {
  418. margin: 0;
  419. color: #303133;
  420. font-size: 22px;
  421. }
  422. .form-header p {
  423. margin: 8px 0 0;
  424. color: #606266;
  425. font-size: 14px;
  426. }
  427. .answer-section {
  428. margin: 25px 0;
  429. padding: 20px;
  430. border: 1px solid #e6e9f0;
  431. border-radius: 8px;
  432. background-color: #f9fafc;
  433. transition: all 0.3s ease;
  434. }
  435. .answer-section:hover {
  436. border-color: #c0c4cc;
  437. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  438. }
  439. .answer-section-header {
  440. display: flex;
  441. justify-content: space-between;
  442. align-items: center;
  443. margin-bottom: 20px;
  444. padding-bottom: 12px;
  445. border-bottom: 1px dashed #dcdfe6;
  446. }
  447. .answer-section-title {
  448. font-weight: 600;
  449. color: #303133;
  450. font-size: 16px;
  451. }
  452. .answer-section-number {
  453. display: inline-flex;
  454. align-items: center;
  455. justify-content: center;
  456. width: 24px;
  457. height: 24px;
  458. background: #409EFF;
  459. color: white;
  460. border-radius: 50%;
  461. font-size: 12px;
  462. margin-right: 8px;
  463. }
  464. .option-item {
  465. display: flex;
  466. align-items: center;
  467. margin-bottom: 12px;
  468. }
  469. .option-input {
  470. flex: 1;
  471. }
  472. .option-actions {
  473. margin-left: 10px;
  474. display: flex;
  475. gap: 5px;
  476. }
  477. .section-actions {
  478. display: flex;
  479. justify-content: flex-end;
  480. margin-top: 20px;
  481. }
  482. .add-section-btn {
  483. margin-top: 15px;
  484. text-align: center;
  485. }
  486. .el-form-item {
  487. margin-bottom: 20px;
  488. }
  489. .el-col {
  490. padding-right: 15px;
  491. }
  492. .el-col:last-child {
  493. padding-right: 0;
  494. }
  495. .option-tip {
  496. margin-top: 10px;
  497. color: #909399;
  498. font-size: 12px;
  499. }
  500. .empty-state {
  501. text-align: center;
  502. padding: 30px;
  503. color: #909399;
  504. }
  505. .empty-state-icon {
  506. font-size: 48px;
  507. margin-bottom: 15px;
  508. color: #c0c4cc;
  509. }
  510. </style>