lrf402788946 5 years ago
parent
commit
d75b949ac6

+ 4 - 0
src/store/index.js

@@ -8,6 +8,8 @@ import director from './director';
 import student from './student';
 import task from './task';
 import subject from './subject';
+import question from './question';
+import questionnaire from './questionnaire';
 Vue.use(Vuex);
 
 export default new Vuex.Store({
@@ -20,6 +22,8 @@ export default new Vuex.Store({
     student,
     task,
     subject,
+    question,
+    questionnaire,
   },
   state: {},
   mutations: {},

+ 38 - 0
src/store/question.js

@@ -0,0 +1,38 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  interface: `/api/question`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.interface}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/show/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 38 - 0
src/store/questionnaire.js

@@ -0,0 +1,38 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  interface: `/api/questionnaire`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    const res = await this.$axios.$get(`${api.interface}`, { skip, limit, ...info });
+    return res;
+  },
+  async create({ commit }, payload) {
+    const res = await this.$axios.$post(`${api.interface}`, payload);
+    return res;
+  },
+  async fetch({ commit }, payload) {
+    const res = await this.$axios.$get(`${api.interface}/show/${payload}`);
+    return res;
+  },
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.interface}/update/${id}`, data);
+    return res;
+  },
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.interface}/${payload}`);
+    return res;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 158 - 127
src/views/Itembank/detail.vue

@@ -1,68 +1,76 @@
 <template>
   <div id="lookdetail">
-    <detail-frame :title="mainTitle" returns="./index">
-      <data-form :fields="fields" :rules="rules" @save="handleSave" :isNew="isNew">
-        <template #options="{item}">
-          <template v-if="item.model === 'state'">
-            <el-option label="弃用" value="0"></el-option>
-            <el-option label="正常" value="1"></el-option>
-          </template>
-        </template>
-        <template #custom="{ item, form, fieldChange }">
-          <el-button type="text" @click="dialogFormVisible = true">选择题类型</el-button>
-          <el-dialog title="选择题类型" :visible.sync="dialogFormVisible">
-            <el-form :model="form">
-              <template>
-                <el-tabs v-model="activeName" @tab-click="handleClick">
-                  <el-tab-pane label="单选" name="first">
-                    <el-button type="text" @click="dialogFormVisible1 = true">增加</el-button>
-
-                    <el-dialog title="增加页面" :visible.sync="dialogFormVisible1">
-                      <el-form :model="form" label-width="80px">
-                        <el-form-item label="序号" :label-width="formLabelWidth">
-                          <el-input v-model="form.zuoyeid" autocomplete="off" placeholder="请输入序号" prop="zuoyeid"></el-input>
-                        </el-form-item>
-                        <el-form-item label="名称" :label-width="formLabelWidth">
-                          <el-input v-model="form.zuoyename" autocomplete="off" placeholder="请输入名称" prop="zuoyename"></el-input>
-                        </el-form-item>
-                        <el-form-item label="答案" :label-width="formLabelWidth">
-                          <el-input v-model="form.answer" autocomplete="off" placeholder="请输入答案" prop="answer"></el-input>
-                        </el-form-item>
-                      </el-form>
-                      <div slot="footer" class="dialog-footer">
-                        <el-button @click="dialogFormVisible1 = false">取 消</el-button>
-                        <el-button type="primary" @click="dialogFormVisible1 = false">确 定</el-button>
-                      </div>
-                    </el-dialog>
-                    <data-table :fields="fieldss" :data="index" :opera="opera" @edit="toEdit"></data-table>
-                  </el-tab-pane>
-                  <el-tab-pane label="多选" name="first"></el-tab-pane>
-                  <el-tab-pane label="问答" name="third">
-                    <el-form ref="form" :model="form" label-width="80px">
-                      <el-form-item label="问答">
-                        <el-input v-model="form.duoxuan" placeholder="请输入问答题"></el-input>
-                      </el-form-item>
-                    </el-form>
-                  </el-tab-pane>
-                </el-tabs>
-              </template>
-            </el-form>
-            <div slot="footer" class="dialog-footer">
-              <el-button @click="dialogFormVisible = false">取 消</el-button>
-              <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
-            </div>
-          </el-dialog>
-        </template>
-      </data-form>
+    <detail-frame :title="mainTitle" returns="/itembank/index">
+      <el-form ref="infoForm" :model="info" :rules="rules" label-width="120px" size="small" @submit.native.prevent style="background:#fff;padding:20px">
+        <el-form-item label="类型" :required="true" prop="type">
+          <el-radio-group v-model="info.type">
+            <el-radio v-for="(item, index) in radios" :key="index" :label="item.code">{{ item.name }}</el-radio>
+          </el-radio-group>
+        </el-form-item>
+        <el-form-item label="题目" :required="true" prop="topic">
+          <el-input v-model="info.topic"></el-input>
+        </el-form-item>
+        <el-form-item label="状态" :required="true" prop="status">
+          <el-radio-group v-model="info.status">
+            <el-radio label="0">禁用</el-radio>
+            <el-radio label="1">使用</el-radio>
+          </el-radio-group>
+        </el-form-item>
+        <el-form-item label="选项" prop="option" v-if="info.type === '0' || info.type === '1'">
+          <el-row>
+            <el-col :span="24" style="text-align:right;padding-bottom:10px">
+              <el-button type="primary" size="mini" @click="drawer = true">添加选项</el-button>
+            </el-col>
+            <el-col :span="24">
+              <el-table :data="info.option" border stripe size="mini">
+                <el-table-column align="center" label="序号" prop="number"></el-table-column>
+                <el-table-column align="center" label="内容" prop="option_name"></el-table-column>
+                <el-table-column align="center" label="操作">
+                  <template v-slot="{ row, $index }">
+                    <el-tooltip effect="dark" content="编辑" placement="bottom">
+                      <el-button type="text" size="mini" icon="el-icon-edit" @click="toOedit(row, $index)"></el-button>
+                    </el-tooltip>
+                    <el-tooltip effect="dark" content="删除" placement="bottom">
+                      <el-button type="text" size="mini" icon="el-icon-delete" @click="toOdelete(row, $index)"></el-button>
+                    </el-tooltip>
+                  </template>
+                </el-table-column>
+              </el-table>
+            </el-col>
+          </el-row>
+        </el-form-item>
+        <el-form-item label="答案" prop="answer" v-if="info.type === '0' || info.type === '1'">
+          <el-input v-model="info.answer"></el-input>
+        </el-form-item>
+        <el-form-item>
+          <el-row type="flex" justify="center">
+            <el-col :span="6">
+              <el-button type="primary" @click="handleSave">保&nbsp;&nbsp;&nbsp;&nbsp;存</el-button>
+            </el-col>
+            <el-col :span="6">
+              <el-button @click="$refs.infoForm.resetFields()">重&nbsp;&nbsp;&nbsp;&nbsp;置</el-button>
+            </el-col>
+          </el-row>
+        </el-form-item>
+      </el-form>
     </detail-frame>
+    <el-drawer :visible.sync="drawer" @close="toOclose" direction="rtl" :with-header="false">
+      <el-tabs style="padding:10px;">
+        <el-tab-pane label="选项">
+          <data-form :styles="{ padding: 0 }" :data="optionForm" :fields="oFields" :rules="oRules" @save="handleOsave" :isNew="oIsNew"></data-form>
+        </el-tab-pane>
+      </el-tabs>
+    </el-drawer>
   </div>
 </template>
 
 <script>
-import dataTable from '@frame/components/data-table';
 import detailFrame from '@frame/layout/admin/detail-frame';
 import dataForm from '@frame/components/form';
 import upload from '@frame/components/upload';
+import _ from 'lodash';
+import { createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('question');
 export default {
   metaInfo: { title: '题库详情页' },
   name: 'lookdetail',
@@ -70,59 +78,50 @@ export default {
   components: {
     detailFrame,
     dataForm,
-    dataTable,
   },
   data: () => ({
+    oIsNew: true,
+    drawer: false,
+    loading: true,
     opera: [
       {
         label: '编辑',
         icon: 'el-icon-edit',
         method: 'edit',
       },
+      {
+        label: '删除',
+        icon: 'el-icon-delete',
+        method: 'delete',
+      },
     ],
-
-    activeName: '',
-    dialogTableVisible: false,
-    dialogTableVisible1: false,
-    dialogFormVisible: false,
-    dialogFormVisible1: false,
-    form: {
-      duoxuan: '',
-      name: '',
-      region: '',
-      date1: '',
-      date2: '',
-      delivery: false,
-      type: [],
-      zuoyeid: '',
-      zuoyename: '',
-      answer: '',
-    },
-    formLabelWidth: '120px',
-    fieldss: [
-      { label: '序号', required: true, model: 'zuoyeid' },
-      { label: '名称', required: true, model: 'zuoyename' },
-      { label: '答案', required: true, model: 'answer' },
+    form: {},
+    optionForm: {},
+    info: { status: `1` },
+    radios: [
+      { code: '0', name: '单选' },
+      { code: '1', name: '多选' },
+      { code: '2', name: '简答' },
     ],
-
-    index: [{ zuoyeid: '1' }],
-    fields: [
-      { label: '题名', required: true, model: 'title' },
-      { label: '状态', required: true, model: 'state', type: `select` },
-      { label: '题型', required: true, model: 'type', type: 'tixing', custom: true },
+    oFields: [
+      { label: '序号', required: true, model: 'number' },
+      { label: '内容', required: true, model: 'option_name' },
     ],
+    oRules: {
+      number: [{ required: true, message: '请输入序号' }],
+      option_name: [{ required: true, message: '请输入内容' }],
+    },
     rules: {
-      zuoyeid: [{ required: true, message: '请输入序号', trigger: 'blur' }],
-      zuoyename: [{ required: true, message: '请输入名称', trigger: 'blur' }],
-      answer: [{ required: true, message: '请输入答案', trigger: 'blur' }],
-      name: [{ required: true, message: '请输入作业姓名' }],
-      state: [{ required: true, message: '请选择状态' }],
-      tixing: [{ required: true, message: '请选择题类型' }],
-      title: [{ required: true, message: '请选择标题' }],
+      type: [{ required: true, message: '请选择类型', trigger: 'blur' }],
+      topic: [{ required: true, message: '请输入题目', trigger: 'blur' }],
+      status: [{ required: true, message: '请选择状态' }],
     },
   }),
   created() {},
   computed: {
+    id() {
+      return this.$route.query.id;
+    },
     mainTitle() {
       let meta = this.$route.meta;
       let main = meta.title || '';
@@ -138,50 +137,82 @@ export default {
       return this.$route.query.id ? false : true;
     },
   },
+  watch: {
+    isNew: {
+      immediate: true,
+      handler(val) {
+        if (val) this.loading = false;
+        else this.search();
+      },
+    },
+  },
   methods: {
-    search({ skip = 0, limit = 15, ...info } = {}) {
-      console.log(`in search`);
+    ...mapActions(['fetch', 'create', 'update']),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      const res = await this.fetch(this.id);
+      if (this.$checkRes(res)) {
+        this.$set(this, `info`, res.data);
+      }
+      this.loading = false;
+    },
+    handleSave() {
+      this.$refs['infoForm'].validate(valid => {
+        if (valid) {
+          this.toSave();
+        } else {
+          console.warn('form validate error!!!');
+        }
+      });
+    },
+    async toSave() {
+      let res;
+      let msg;
+      let newData = {};
+      let { type, option, answer, ...other } = this.info;
+      if (type === 0 || type === 1) newData = this.info;
+      else newData = { type, ...other };
+      if (this.isNew) {
+        res = await this.create(newData);
+        msg = `${this.keyWord}添加成功`;
+      } else {
+        res = await this.update(newData);
+        msg = `${this.keyWord}修改成功`;
+      }
+      if (this.$checkRes(res, msg)) this.$router.push({ path: '/itembank/index' });
     },
     toEdit({ data }) {
       console.log(`in toEdit`);
       console.log(data);
     },
-    handleClick(tab, event) {
-      console.log(tab, event);
-    },
 
-    uploadSuccess() {},
-    async handleSave({ isNew, data }) {
-      console.log(isNew);
-      console.log(data);
+    // 选项
+    toOclose() {
+      this.drawer = false;
+      this.oIsNew = true;
+      this.optionForm = {};
+    },
+    handleOsave({ isNew, data }) {
+      if (isNew) {
+        if (!_.isArray(this.info.option)) this.info.option = [];
+        this.info.option.push(data);
+      } else {
+        let { index, ...info } = data;
+        this.$set(this.info.option, index, info);
+      }
+      this.toOclose();
+    },
+    toOedit(row, index) {
+      let data = JSON.parse(JSON.stringify(row));
+      data.index = index;
+      this.optionForm = data;
+      this.drawer = true;
+      this.oIsNew = false;
+    },
+    toOdelete(row, index) {
+      this.info.option.splice(index, 1);
     },
   },
 };
 </script>
 
-<style lang="less" scoped>
-/deep/.el-tabs__nav-wrap::after {
-  content: '';
-  position: absolute;
-  left: 0;
-  bottom: 0;
-  width: 100%;
-  height: 2px;
-  background-color: #ffffff;
-  z-index: 1;
-}
-
-/deep/.el-tabs__active-bar {
-  position: absolute;
-  bottom: 0;
-  left: 0;
-  height: 2px;
-  background-color: #ffffff;
-}
-/deep/.el-tabs__item.is-active {
-  color: #303133;
-}
-/deep/.el-input__inner {
-  margin: 0 0 20px 0;
-}
-</style>
+<style lang="less" scoped></style>

+ 38 - 25
src/views/Itembank/index.vue

@@ -3,20 +3,22 @@
     <list-frame title="题库列表页" @query="search" :total="total" :filter="filFields" @add="$router.push({ path: '/itembank/detail' })">
       <template #options="{item}">
         <template v-if="item.model == 'state'">
-          <el-option v-for="(item, index) in lists" :key="index" :value="item.label"></el-option>
+          <el-option v-for="(item, index) in statusList" :key="index" :value="item.label"></el-option>
         </template>
         <template v-if="item.model == 'type'">
-          <el-option v-for="(item, index) in list" :key="index" :value="item.label"></el-option>
+          <el-option v-for="(item, index) in typeList" :key="index" :value="item.label"></el-option>
         </template>
       </template>
 
-      <data-table :fields="fields" :data="index" :opera="opera" @edit="toEdit"> </data-table>
+      <data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit" @delete="toDelete"> </data-table>
     </list-frame>
   </div>
 </template>
 <script>
 import listFrame from '@frame/layout/admin/list-frame';
 import dataTable from '@frame/components/data-table';
+import { createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('question');
 export default {
   metaInfo: { title: '题库列表页' },
   name: 'index',
@@ -26,14 +28,14 @@ export default {
     dataTable,
   },
   data: () => ({
-    list: [
-      { label: '单选', value: 0 },
-      { label: '多选', value: 1 },
-      { label: '问答', value: 2 },
+    typeList: [
+      { label: '单选', value: `0` },
+      { label: '多选', value: `1` },
+      { label: '问答', value: `2` },
     ],
-    lists: [
-      { label: '弃用', value: 0 },
-      { label: '正常', value: 1 },
+    statusList: [
+      { label: '禁用', value: `0` },
+      { label: '使用', value: `1` },
     ],
     opera: [
       {
@@ -41,11 +43,15 @@ export default {
         icon: 'el-icon-edit',
         method: 'edit',
       },
+      {
+        label: '删除',
+        icon: 'el-icon-delete',
+        method: 'delete',
+        confirm: true,
+      },
     ],
     fields: [
-      { label: '题编号', prop: 'id' },
-
-      { label: '题名', prop: 'name' },
+      { label: '题目', prop: 'topic' },
       {
         label: '类型',
         prop: 'type',
@@ -55,20 +61,14 @@ export default {
       },
       {
         label: '状态',
-        prop: 'state',
+        prop: 'status',
         format: item => {
           return item === '0' ? '弃用' : '使用';
         },
       },
     ],
-    index: [
-      { id: '题编号', name: '礼仪题01', type: '1', state: '1' },
-      { id: '题编号', name: 'sss', type: '0', state: '1' },
-      { id: '题编号', name: 'test5', type: '2', state: '0' },
-    ],
     filFields: [
       { label: '题名', model: 'name' },
-
       {
         label: '题类型',
         model: 'type',
@@ -80,16 +80,29 @@ export default {
         type: 'select',
       },
     ],
+    list: [],
+    total: 0,
   }),
-  created() {},
+  created() {
+    this.search();
+  },
   computed: {},
   methods: {
-    search({ skip = 0, limit = 15, ...info } = {}) {
-      console.log(`in search`);
+    ...mapActions(['query', 'delete']),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      const res = await this.query({ skip, limit, ...info });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data);
+        this.$set(this, `total`, res.total);
+      }
     },
     toEdit({ data }) {
-      console.log(`in toEdit`);
-      console.log(data);
+      this.$router.push({ path: '/itembank/detail', query: { id: data.id } });
+    },
+    async toDelete({ data }) {
+      const res = await this.delete(data.id);
+      this.$checkRes(res, '删除成功', '删除失败');
+      this.search();
     },
   },
 };

+ 1 - 1
src/views/bedroom/index.vue

@@ -54,7 +54,7 @@ export default {
   computed: {},
   methods: {
     ...mapActions(['query', 'delete']),
-    async search({ skip = 0, limit = 15, ...info } = {}) {
+    async search({ skip = 0, limit = 10, ...info } = {}) {
       const res = await this.query({ skip, limit, ...info });
       if (this.$checkRes(res)) {
         this.$set(this, `list`, res.data);

+ 2 - 2
src/views/classes/detail.vue

@@ -73,10 +73,10 @@ export default {
       let res;
       let msg;
       if (isNew) {
-        res = this.create(data);
+        res = await this.create(data);
         msg = `${this.keyWord}添加成功`;
       } else {
-        res = this.update(data);
+        res = await this.update(data);
         msg = `${this.keyWord}修改成功`;
       }
       if (this.$checkRes(res, msg)) this.$router.push({ path: '/classes/index' });

+ 1 - 1
src/views/classes/index.vue

@@ -47,7 +47,7 @@ export default {
   computed: {},
   methods: {
     ...mapActions(['query', 'delete']),
-    async search({ skip = 0, limit = 15, ...info } = {}) {
+    async search({ skip = 0, limit = 10, ...info } = {}) {
       const res = await this.query({ skip, limit, ...info });
       if (this.$checkRes(res)) {
         this.$set(this, `list`, res.data);

+ 2 - 2
src/views/dept/detail.vue

@@ -68,10 +68,10 @@ export default {
       let res;
       let msg;
       if (isNew) {
-        res = this.create(data);
+        res = await this.create(data);
         msg = `${this.keyWord}添加成功`;
       } else {
-        res = this.update(data);
+        res = await this.update(data);
         msg = `${this.keyWord}修改成功`;
       }
       if (this.$checkRes(res, msg)) this.$router.push({ path: '/dept/index' });

+ 1 - 1
src/views/dept/index.vue

@@ -55,7 +55,7 @@ export default {
   },
   methods: {
     ...mapActions(['query', 'delete']),
-    async search({ skip = 0, limit = 15, ...info } = {}) {
+    async search({ skip = 0, limit = 10, ...info } = {}) {
       const res = await this.query({ skip, limit, ...info });
       if (this.$checkRes(res)) {
         this.$set(this, `list`, res.data);

+ 2 - 2
src/views/director/detail.vue

@@ -81,10 +81,10 @@ export default {
       let msg;
       if (isNew) {
         data.openid = new Date().getTime();
-        res = this.create(data);
+        res = await this.create(data);
         msg = `${this.keyWord}添加成功`;
       } else {
-        res = this.update(data);
+        res = await this.update(data);
         msg = `${this.keyWord}修改成功`;
       }
       if (this.$checkRes(res, msg)) this.$router.push({ path: '/director/index' });

+ 1 - 1
src/views/director/index.vue

@@ -89,7 +89,7 @@ export default {
   methods: {
     ...mapActions(['query', 'delete']),
     ...mapDept({ dept: 'query' }),
-    async search({ skip = 0, limit = 15, ...info } = {}) {
+    async search({ skip = 0, limit = 10, ...info } = {}) {
       const res = await this.query({ skip, limit, ...info });
       if (this.$checkRes(res)) {
         this.$set(this, `list`, res.data);

+ 1 - 1
src/views/location/index.vue

@@ -43,7 +43,7 @@ export default {
   computed: {},
   methods: {
     ...mapActions(['query', 'delete']),
-    async search({ skip = 0, limit = 15, ...info } = {}) {
+    async search({ skip = 0, limit = 10, ...info } = {}) {
       const res = await this.query({ skip, limit, ...info });
       if (this.$checkRes(res)) {
         console.log(res);

+ 217 - 33
src/views/questionnaire/detail.vue

@@ -1,54 +1,129 @@
 <template>
   <div id="detail">
-    <detail-frame :title="问卷详情页" returns="./index">
-      <data-form :fields="fields" :rules="rules" @save="handleSave" :isNew="isNew">
-        <template #custom="{ item, form, fieldChange }">
-          <el-select v-model="form[item.model]" multiple placeholder="请选择">
-            <el-option v-for="item in options" :key="item.code" :label="item.label" :value="item.code"> </el-option>
-          </el-select>
-        </template>
-      </data-form>
+    <detail-frame :title="mainTitle" returns="./index">
+      <el-form ref="infoForm" :model="info" label-width="120px" :rules="rules" size="small" @submit.native.prevent style="background:#fff;padding:50px">
+        <el-form-item label="序号" required prop="num">
+          <el-input v-model="info.num"></el-input>
+        </el-form-item>
+        <el-form-item label="标题" required prop="name">
+          <el-input v-model="info.name"></el-input>
+        </el-form-item>
+        <el-form-item label="题目" prop="question">
+          <el-row>
+            <el-col :span="24" style="text-align:right;padding-bottom:10px">
+              <el-button type="primary" size="mini" @click="addQuestion()">添加题目</el-button>
+            </el-col>
+            <el-col :span="24">
+              <el-table :data="info.question" border stripe size="mini">
+                <el-table-column align="center" label="标题" prop="topic"></el-table-column>
+                <!-- :formatter="codeDisplay" -->
+                <el-table-column align="center" label="类型" prop="type" :formatter="typeFormat"></el-table-column>
+                <el-table-column align="center" label="操作">
+                  <template v-slot="{ row, $index }">
+                    <el-tooltip effect="dark" content="删除" placement="bottom">
+                      <el-button type="text" size="mini" icon="el-icon-delete" @click="toCdelete(row, $index)"></el-button>
+                    </el-tooltip>
+                  </template>
+                </el-table-column>
+              </el-table>
+            </el-col>
+          </el-row>
+        </el-form-item>
+        <el-form-item>
+          <el-row type="flex" justify="center">
+            <el-col :span="6">
+              <el-button type="primary" @click="handleSave">保&nbsp;&nbsp;&nbsp;&nbsp;存</el-button>
+            </el-col>
+            <el-col :span="6">
+              <el-button @click="$refs.infoForm.resetFields()">重&nbsp;&nbsp;&nbsp;&nbsp;置</el-button>
+            </el-col>
+          </el-row>
+        </el-form-item>
+      </el-form>
     </detail-frame>
+    <el-dialog :visible.sync="dialog" title="题库" center>
+      <el-row>
+        <el-col :span="24" style="text-align:center;padding-bottom:20px">已选择{{ this.info.question.length }}道题</el-col>
+        <el-col :span="24">
+          <el-table
+            v-loading="qProp.loading"
+            ref="selectTable"
+            :data="qList"
+            @select="handleSelect"
+            @select-all="handleSelectAll"
+            border
+            stripe
+            size="mini"
+            :height="350"
+            row-key="id"
+          >
+            <el-table-column type="selection" align="center" width="55" :reserve-selection="true"> </el-table-column>
+            <el-table-column label="题目" align="center" prop="topic"></el-table-column>
+            <el-table-column label="类型" align="center" prop="type" :formatter="typeFormat"></el-table-column>
+          </el-table>
+        </el-col>
+        <el-col :span="24" style="text-align:right">
+          <el-pagination
+            background
+            small
+            layout="total,sizes, prev, pager, next"
+            :total="qProp.total"
+            :page-sizes="[5, 10, 15, 20]"
+            :pageSize="qProp.pageSize"
+            @size-change="size => pagChange(size, undefined)"
+            @current-change="page => pagChange(undefined, page)"
+          >
+          </el-pagination>
+        </el-col>
+      </el-row>
+      <el-row type="flex" justify="center">
+        <el-col :span="2" style="padding-top:20px">
+          <el-button type="primary" plain size="mini" @click="dialog = false">关&nbsp;&nbsp;&nbsp;&nbsp;闭</el-button>
+        </el-col>
+      </el-row>
+    </el-dialog>
   </div>
 </template>
 
 <script>
 import detailFrame from '@frame/layout/admin/detail-frame';
-import dataForm from '@frame/components/form';
+import { createNamespacedHelpers } from 'vuex';
+import _ from 'lodash';
+const { mapActions } = createNamespacedHelpers('questionnaire');
+const { mapActions: mapQuestion } = createNamespacedHelpers('question');
+
 export default {
   metaInfo: { title: '问卷详情页' },
   name: 'detail',
   props: {},
   components: {
     detailFrame,
-    dataForm,
   },
   data: () => ({
-    options: [
-      {
-        code: '选项4',
-        label: '龙须面',
-      },
-      {
-        code: '选项5',
-        label: '北京烤鸭',
-      },
-    ],
-    code: [],
-
-    fields: [
-      { label: '序号', required: true, model: 'id' },
-      { label: '标题', required: true, model: 'name' },
-      { label: '题名', required: true, model: 'code', custom: true },
-    ],
+    info: { question: [] },
+    dialog: true,
+    loading: true,
     rules: {
-      id: [{ required: true, message: '请输入序号' }],
+      num: [{ required: true, message: '请输入序号' }],
       name: [{ required: true, message: '请输入标题' }],
-      code: [{ required: true, message: '请选择题名' }],
+      // question: [{ required: true, message: '请选择题目' }],
+    },
+    qList: [], //题库
+    qProp: {
+      loading: true,
+      page: 1,
+      total: 0,
+      pageSize: 5,
     },
   }),
-  created() {},
+  async created() {
+    this.dialog = false;
+    await this.getOtherList();
+  },
   computed: {
+    id() {
+      return this.$route.query.id;
+    },
     isNew() {
       return this.$route.query.id ? false : true;
     },
@@ -64,10 +139,119 @@ export default {
       return main;
     },
   },
+  watch: {
+    isNew: {
+      immediate: true,
+      handler(val) {
+        if (val) this.loading = false;
+        else this.search();
+      },
+    },
+  },
   methods: {
-    async handleSave({ isNew, data }) {
-      console.log(isNew);
-      console.log(data);
+    ...mapActions(['fetch', 'create', 'update']),
+    ...mapQuestion({ qQuery: 'query' }),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      const res = await this.fetch(this.id);
+      if (this.$checkRes(res)) {
+        this.$set(this, `info`, res.data);
+        //需要将code中的id转换为题目重新放进列表中
+        //需要过滤出已选择的题目,每次选择题目时也需要过滤
+      }
+      this.loading = false;
+    },
+    // 分页
+    pagChange(size = this.qProp.pageSize, page = this.qProp.page) {
+      this.qProp.pageSize = size;
+      this.qProp.page = page;
+      let skip = (this.qProp.page - 1) * this.qProp.pageSize;
+      this.getOtherList({ skip, limit: size });
+    },
+    // 分页
+    async getOtherList({ skip = 0, limit = this.qProp.pageSize } = {}) {
+      this.qProp.loading = true;
+      const res = await this.qQuery({ skip, limit });
+      if (this.$checkRes(res)) {
+        this.$set(this, `qList`, res.data);
+        this.$set(this.qProp, `total`, res.total);
+      }
+      this.qProp.loading = false;
+    },
+    //打开添加题目dialog
+    addQuestion() {
+      this.dialog = true;
+      this.$nextTick(() => {
+        this.setNewTableSelect();
+      });
+    },
+    toCdelete(row, index) {
+      this.info.question.splice(index, 1);
+      this.setNewTableSelect();
+    },
+    // 刷新选择题库的表格选择状态
+    setNewTableSelect() {
+      this.$refs.selectTable.clearSelection();
+      if (this.info.question.length > 0) {
+        for (const item of this.info.question) {
+          let res = this.qList.filter(fil => fil.id === item.id);
+          if (res.length > 0) this.$refs.selectTable.toggleRowSelection(res[0]);
+        }
+      }
+    },
+    // 题库操作
+    handleSelect(selection, row) {
+      if (selection.length > 0) {
+        let data = this.info.question.concat(selection);
+        data = _.unionBy(data, 'id');
+        this.$set(this.info, `question`, data);
+      } else {
+        this.$set(this.info, `question`, []);
+      }
+    },
+    //全选
+    handleSelectAll(selection) {
+      let data = this.info.question.concat(selection);
+      data = _.unionBy(data, 'id');
+      this.$set(this.info, `question`, selection);
+    },
+    //提交操作
+    handleSave() {
+      this.$refs['infoForm'].validate(valid => {
+        if (valid) {
+          this.toSave();
+        } else {
+          console.warn('form validate error!!!');
+        }
+      });
+    },
+    async toSave() {
+      let res;
+      let msg;
+      let data = JSON.parse(JSON.stringify(this.info));
+      let ids = data.question.map(item => item.id);
+      data.question = ids;
+      if (this.isNew) {
+        res = await this.create(data);
+        msg = `${this.keyWord}添加成功`;
+      } else {
+        res = await this.update(data);
+        msg = `${this.keyWord}修改成功`;
+      }
+      if (this.$checkRes(res, msg)) this.$router.push({ path: '/questionnaire/index' });
+    },
+    // format转换
+    codeDisplay(row, column, cellValue, index) {
+      let cell = '';
+      let prop = column.property;
+      let res = this.qList.filter(fil => fil.id === row);
+      if (res.length > 0) {
+        if (prop === 'type') cell = this.typeFormat(null, null, _.get(res[0], prop, ''));
+        else cell = _.get(res[0], prop, '');
+      }
+      return cell;
+    },
+    typeFormat(row, column, cellValue, index) {
+      return cellValue === '0' ? '单选' : cellValue === '1' ? '多选' : '简答';
     },
   },
 };

+ 28 - 12
src/views/questionnaire/index.vue

@@ -1,7 +1,7 @@
 <template>
   <div id="index">
     <list-frame title="问卷列表页" @query="search" :total="total" :filter="filFields" @add="$router.push({ path: '/questionnaire/detail' })">
-      <data-table :fields="fields" :data="index" :opera="opera" @edit="toEdit"></data-table>
+      <data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit" @delete="toDelete"></data-table>
     </list-frame>
   </div>
 </template>
@@ -9,6 +9,9 @@
 <script>
 import listFrame from '@frame/layout/admin/list-frame';
 import dataTable from '@frame/components/data-table';
+import { createNamespacedHelpers } from 'vuex';
+const { mapActions } = createNamespacedHelpers('questionnaire');
+
 export default {
   name: 'index',
   props: {},
@@ -23,31 +26,44 @@ export default {
         icon: 'el-icon-edit',
         method: 'edit',
       },
+      {
+        label: '删除',
+        icon: 'el-icon-delete',
+        method: 'delete',
+      },
     ],
     fields: [
-      { label: '问卷序号', prop: 'id' },
+      { label: '问卷序号', prop: 'num' },
       { label: '问卷标题', prop: 'name' },
     ],
-    index: [
-      { id: '01', name: '问卷1' },
-      { id: '02', name: '问卷2' },
-      { id: '03', name: '问卷3' },
-    ],
     filFields: [
       { label: '问卷名', model: 'name' },
       { label: '问卷序号', model: 'id' },
     ],
+    list: [],
+    total: 0,
   }),
 
-  created() {},
+  created() {
+    this.search();
+  },
   computed: {},
   methods: {
-    search({ skip = 0, limit = 15, ...info } = {}) {
-      console.log(`in search`);
+    ...mapActions(['query', 'delete']),
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      const res = await this.query({ skip, limit, ...info });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data);
+        this.$set(this, `total`, res.total);
+      }
     },
     toEdit({ data }) {
-      console.log(`in toEdit`);
-      console.log(data);
+      this.$router.push({ path: '/questionnaire/detail', query: { id: data.id } });
+    },
+    async toDelete({ data }) {
+      const res = await this.delete(data.id);
+      this.$checkRes(res, '删除成功', '删除失败');
+      this.search();
     },
   },
 };

+ 2 - 2
src/views/student/detail.vue

@@ -132,10 +132,10 @@ export default {
         data.yard = `测试学院`;
         data.major = `测试专业`;
         data.school_name = `测试学校`;
-        res = this.create(data);
+        res = await this.create(data);
         msg = `${this.keyWord}添加成功`;
       } else {
-        res = this.update(data);
+        res = await this.update(data);
         msg = `${this.keyWord}修改成功`;
       }
       if (this.$checkRes(res, msg)) this.$router.push({ path: '/student/index' });

+ 1 - 1
src/views/student/index.vue

@@ -89,7 +89,7 @@ export default {
   computed: {},
   methods: {
     ...mapActions(['query', 'delete']),
-    async search({ skip = 0, limit = 15, ...info } = {}) {
+    async search({ skip = 0, limit = 10, ...info } = {}) {
       const res = await this.query({ skip, limit, ...info });
       if (this.$checkRes(res)) {
         this.$set(this, `list`, res.data);

+ 2 - 2
src/views/subject/detail.vue

@@ -70,10 +70,10 @@ export default {
       let res;
       let msg;
       if (isNew) {
-        res = this.create(data);
+        res = await this.create(data);
         msg = `${this.keyWord}添加成功`;
       } else {
-        res = this.update(data);
+        res = await this.update(data);
         msg = `${this.keyWord}修改成功`;
       }
       if (this.$checkRes(res, msg)) this.$router.push({ path: '/subject/index' });

+ 1 - 1
src/views/subject/index.vue

@@ -49,7 +49,7 @@ export default {
   computed: {},
   methods: {
     ...mapActions(['query', 'delete']),
-    async search({ skip = 0, limit = 15, ...info } = {}) {
+    async search({ skip = 0, limit = 10, ...info } = {}) {
       const res = await this.query({ skip, limit, ...info });
       if (this.$checkRes(res)) {
         this.$set(this, `list`, res.data);

+ 1 - 1
src/views/teacher/index.vue

@@ -148,7 +148,7 @@ export default {
   created() {},
   computed: {},
   methods: {
-    search({ skip = 0, limit = 15, ...info } = {}) {
+    search({ skip = 0, limit = 10, ...info } = {}) {
       console.log(`in search`);
     },
     toEdit({ data }) {

+ 1 - 1
src/views/teacher/means.vue

@@ -41,7 +41,7 @@ export default {
   created() {},
   computed: {},
   methods: {
-    search({ skip = 0, limit = 15, ...info } = {}) {
+    search({ skip = 0, limit = 10, ...info } = {}) {
       console.log(`in search`);
     },
     toEdit({ data }) {

+ 1 - 1
src/views/test/list.vue

@@ -73,7 +73,7 @@ export default {
   created() {},
   computed: {},
   methods: {
-    search({ skip = 0, limit = 15, ...info } = {}) {
+    search({ skip = 0, limit = 10, ...info } = {}) {
       console.log(`in search`);
     },
     toEdit({ data }) {

+ 2 - 2
src/views/work/detail.vue

@@ -86,10 +86,10 @@ export default {
       let msg;
       data.name = this.getName(data.code);
       if (isNew) {
-        res = this.create(data);
+        res = await this.create(data);
         msg = `${this.keyWord}添加成功`;
       } else {
-        res = this.update(data);
+        res = await this.update(data);
         msg = `${this.keyWord}修改成功`;
       }
       if (this.$checkRes(res, msg)) this.$router.push({ path: '/work/index' });

+ 1 - 1
src/views/work/index.vue

@@ -67,7 +67,7 @@ export default {
   methods: {
     ...mapActions(['query', 'delete']),
     ...mapSubject({ subject: 'query' }),
-    async search({ skip = 0, limit = 15, ...info } = {}) {
+    async search({ skip = 0, limit = 10, ...info } = {}) {
       const res = await this.query({ skip, limit, ...info });
       if (this.$checkRes(res)) {
         this.$set(this, `list`, res.data);

+ 6 - 5
src/views/work/look.vue

@@ -1,7 +1,7 @@
 <template>
   <div id="index">
-    <list-frame title="作业题列表页" returns="/work/index" @query="search" :needPag="false" :needFilter="false" @add="toAdd">
-      <el-row type="flex" justify="center" style="padding-bottom:1.875rem;">
+    <list-frame :title="`${title}-作业题`" returns="/work/index" @query="search" :needPag="false" :needFilter="false" @add="toAdd">
+      <el-row type="flex" justify="end" style="padding-bottom:1.875rem;">
         <el-col :span="3">
           <el-button type="primary" @click="submit" size="small">保存作业</el-button>
         </el-col>
@@ -83,6 +83,7 @@ export default {
     dataForm,
   },
   data: () => ({
+    title: '',
     loading: false,
     isNew: true,
     oIsNew: true,
@@ -100,9 +101,8 @@ export default {
         method: 'delete',
       },
     ],
-
     fields: [
-      { label: '题名称', prop: 'topic' },
+      { label: '题', prop: 'topic' },
       {
         label: '问题类型',
         prop: 'type',
@@ -172,10 +172,11 @@ export default {
   },
   methods: {
     ...mapActions(['fetch', 'update']),
-    async search({ skip = 0, limit = 15, ...info } = {}) {
+    async search({ skip = 0, limit = 10, ...info } = {}) {
       const res = await this.fetch(this.id);
       if (this.$checkRes(res)) {
         this.$set(this, `list`, _.get(res.data, `question`));
+        this.$set(this, `title`, _.get(res.data, `name`));
       }
       this.loading = false;
     },

+ 1 - 1
src/views/work/lookdetail.vue

@@ -139,7 +139,7 @@ export default {
     },
   },
   methods: {
-    search({ skip = 0, limit = 15, ...info } = {}) {
+    search({ skip = 0, limit = 10, ...info } = {}) {
       console.log(`in search`);
     },
     toEdit({ data }) {