wenjuan.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <div id="wenjuan">
  3. <el-row>
  4. <el-col :span="24">
  5. <el-col class="add" :span="24">
  6. <el-select v-model="status" placeholder="请选择问卷状态">
  7. <el-option v-for="item in statusoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
  8. </el-select>
  9. <el-button size="mini" type="primary" @click="search" style="margin-left:10px;">查询</el-button>
  10. <el-button size="mini" type="primary" @click="add">添加</el-button>
  11. </el-col>
  12. <el-col :span="24"
  13. ><el-table :data="list" border style="width: 100%">
  14. <el-table-column prop="num" label="序号"> </el-table-column>
  15. <el-table-column prop="name" label="问卷名称" show-overflow-tooltip> </el-table-column>
  16. <el-table-column prop="status" label="状态">
  17. <template slot-scope="scope">
  18. <span>{{ scope.row.status == '0' ? '草稿' : scope.row.status == '1' ? '发布' : scope.row.status == '2' ? '弃用' : '未识别' }}</span>
  19. </template>
  20. </el-table-column>
  21. <el-table-column label="操作">
  22. <template slot-scope="scope">
  23. <el-button size="mini" @click="detailBtn(scope.row)">查看</el-button>
  24. <el-button size="mini" @click="deleteBtn(scope.row.id)" type="danger">删除</el-button>
  25. </template>
  26. </el-table-column>
  27. </el-table>
  28. </el-col>
  29. <el-col :span="24" class="page">
  30. <el-pagination background layout="prev, pager, next,total" :total="total" @current-change="handleCurrentChange"> </el-pagination>
  31. </el-col>
  32. <el-dialog title="添加问卷" :visible.sync="dialogFormVisible">
  33. <el-form size="mini" :model="form" ref="form" label-width="100px" class="demo-dynamic" :rules="rules">
  34. <el-form-item prop="status" label="状态">
  35. <el-radio-group v-model="form.status">
  36. <el-radio :label="'0'">草稿</el-radio>
  37. <el-radio :label="'1'">发布</el-radio>
  38. <el-radio :label="'2'">停用</el-radio>
  39. </el-radio-group>
  40. </el-form-item>
  41. <el-form-item prop="num" label="序号">
  42. <el-input v-model="form.num"></el-input>
  43. </el-form-item>
  44. <el-form-item prop="name" label="问卷名称">
  45. <el-input v-model="form.name"></el-input>
  46. </el-form-item>
  47. <el-col :span="24" style="margin: 0 0 10px 0;">
  48. <el-select v-model="qtype" placeholder="请选择题目类型">
  49. <el-option v-for="item in qtypeoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
  50. </el-select>
  51. <el-select v-model="qstatus" placeholder="请选择题目状态">
  52. <el-option v-for="item in qstatusoptions" :key="item.value" :label="item.label" :value="item.value"> </el-option>
  53. </el-select>
  54. <el-button size="mini" type="primary" @click="searchQuestion" style="margin-left:10px;">查询</el-button>
  55. </el-col>
  56. <el-table
  57. :row-key="getRowKey"
  58. ref="multipleTable"
  59. :data="questions"
  60. tooltip-effect="dark"
  61. style="width: 100%"
  62. @selection-change="handleSelectionChange"
  63. >
  64. <el-table-column prop="_id" type="selection" width="55" :reserve-selection="true"> </el-table-column>
  65. <el-table-column prop="type" label="类型">
  66. <template slot-scope="scope">
  67. <span>{{ scope.row.type == '0' ? '单选' : scope.row.type == '1' ? '多选' : scope.row.type == '2' ? '问答' : '未识别' }}</span>
  68. </template>
  69. </el-table-column>
  70. <el-table-column prop="topic" label="题目"> </el-table-column>
  71. <el-table-column prop="status" label="状态">
  72. <template slot-scope="scope">
  73. <span>{{ scope.row.status == '0' ? '弃用' : scope.row.status == '1' ? '正常' : '未识别' }}</span>
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. <el-col :span="24" class="page">
  78. <el-pagination background layout="prev, pager, next,total" :total="questiontotal" @current-change="questionChange"> </el-pagination>
  79. </el-col>
  80. </el-form>
  81. <div slot="footer" class="dialog-footer">
  82. <el-button @click="dialogFormVisible = false">取 消</el-button>
  83. <el-button type="primary" @click="submitFrom">确 定</el-button>
  84. </div>
  85. </el-dialog>
  86. </el-col>
  87. </el-row>
  88. </div>
  89. </template>
  90. <script>
  91. import { createNamespacedHelpers, mapState } from 'vuex';
  92. const { mapActions: questionnaire } = createNamespacedHelpers('questionnaire');
  93. const { mapActions: question } = createNamespacedHelpers('question');
  94. export default {
  95. name: 'wenjuan',
  96. props: {},
  97. components: {},
  98. data: () => ({
  99. list: [], //列表
  100. total: 0, //总数
  101. status: null, //选择的状态
  102. statusoptions: [
  103. { value: '0', label: '草稿' },
  104. { value: '1', label: '发布' },
  105. { value: '2', label: '停用' },
  106. ], //状态选择数组
  107. dialogFormVisible: false, //控制dialog是否显示
  108. form: {},
  109. questions: [], //问题数组
  110. questiontotal: 0, //问题总数
  111. multipleSelection: [], //选择的问题数组
  112. qtype: null, //选择的问题类型
  113. qtypeoptions: [
  114. { value: '0', label: '单选' },
  115. { value: '1', label: '多选' },
  116. { value: '2', label: '问答' },
  117. ], //问题类型选择数组
  118. qstatus: null, //选择的问题状态
  119. qstatusoptions: [
  120. { value: '0', label: '弃用' },
  121. { value: '1', label: '正常' },
  122. ], //问题状态选择数组
  123. rules: {
  124. name: { required: true, message: '问卷名称不能为空', trigger: 'blur' },
  125. num: { required: true, message: '序号不能为空', trigger: 'blur' },
  126. status: { required: true, message: '状态不能为空', trigger: 'blur' },
  127. }, //表单验证规则
  128. }),
  129. created() {
  130. this.search();
  131. },
  132. computed: {},
  133. methods: {
  134. ...questionnaire(['create', 'query', 'update', 'delete']),
  135. ...question({ questionQuery: 'query' }),
  136. //查询问卷列表
  137. async search({ skip = 0, limit = 10, ...info } = {}) {
  138. info = { status: this.status };
  139. const list = await this.query({ skip, limit, ...info });
  140. if (list.errcode == '0') {
  141. this.$set(this, `list`, list.data);
  142. this.$set(this, `total`, list.total);
  143. }
  144. },
  145. //查询题库列表
  146. async searchQuestion({ skip = 0, limit = 10, ...info } = {}) {
  147. info = { type: this.qtype, status: this.qstatus };
  148. const list = await this.questionQuery({ skip, limit, ...info });
  149. if (list.errcode == '0') {
  150. this.$set(this, `questions`, list.data);
  151. this.$set(this, `questiontotal`, list.total);
  152. }
  153. },
  154. // 查看详情
  155. async detailBtn(item) {
  156. this.dialogFormVisible = true;
  157. this.form = item;
  158. this.searchQuestion();
  159. this.$nextTick(function() {
  160. item.question.forEach(row => {
  161. let r = this.questions.find(f => f._id == row._id);
  162. //this.multipleSelection.push(row);
  163. this.$refs.multipleTable.toggleRowSelection(r);
  164. });
  165. });
  166. console.log(this.multipleSelection);
  167. },
  168. //删除
  169. async deleteBtn() {
  170. let res = await this.delete(id);
  171. if (res.errcode == 0) this.search();
  172. },
  173. //问卷分页
  174. handleCurrentChange(val) {
  175. this.search({ skip: (val - 1) * 10, limit: val * 10 });
  176. },
  177. //提交问卷
  178. async submitFrom() {
  179. this.form.question = this.multipleSelection;
  180. let res;
  181. if (this.form.id) res = await this.update(this.form);
  182. else res = await this.create(this.form);
  183. if (res.errcode == '0') {
  184. this.dialogFormVisible = false;
  185. this.search();
  186. }
  187. },
  188. //添加问卷
  189. add() {
  190. this.dialogFormVisible = true;
  191. this.qstatus = null;
  192. this.qtype = null;
  193. this.form = {};
  194. this.searchQuestion();
  195. this.multipleSelection = [];
  196. },
  197. //选中问题时触发
  198. handleSelectionChange(val) {
  199. this.multipleSelection = val;
  200. },
  201. //题库分页
  202. questionChange(val) {
  203. this.searchQuestion({ skip: (val - 1) * 10, limit: val * 10 });
  204. },
  205. getRowKey(row) {
  206. return row._id;
  207. },
  208. },
  209. };
  210. </script>
  211. <style lang="less" scoped>
  212. .add {
  213. margin: 0 0 10px 0;
  214. }
  215. .add .el-button:last-child {
  216. float: right;
  217. }
  218. /deep/.el-dialog {
  219. width: 70%;
  220. }
  221. </style>