reloaded %!s(int64=4) %!d(string=hai) anos
pai
achega
84fe127c68
Modificáronse 3 ficheiros con 82 adicións e 0 borrados
  1. 2 0
      src/store/index.js
  2. 64 0
      src/store/onlive/uploadquestion.js
  3. 16 0
      src/views/live/roomDetail.vue

+ 2 - 0
src/store/index.js

@@ -20,6 +20,7 @@ import gensign from './onlive/gensign';
 import room from './onlive/room';
 import quest from './onlive/quest';
 import chat from './chat';
+import uploadquestion from './onlive/uploadquestion';
 import * as ustate from '@/store/common/state';
 import * as umutations from '@/store/common/mutations';
 
@@ -51,5 +52,6 @@ export default new Vuex.Store({
     gensign,
     chat,
     quest,
+    uploadquestion,
   },
 });

+ 64 - 0
src/store/onlive/uploadquestion.js

@@ -0,0 +1,64 @@
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+import axios from 'axios';
+Vue.use(Vuex);
+const api = {
+  interface: `/api/onlive/uploadquestion`,
+};
+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}/${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;
+  },
+  async mergeRequest({ commit, dispatch }, { method, data }) {
+    let toRequest = () => {
+      let res = [];
+      for (const i of data) {
+        res.push(dispatch(method, i));
+      }
+      return res;
+    };
+    let result = await axios.all(toRequest());
+    let newFilter = data => {
+      let res = data.map(i => {
+        let type = _.isArray(i);
+        if (!type) {
+          //fetch的多个请求 是object 将errcode为0的data取出来
+          return _.get(i, `data`, i);
+        } else {
+          //query的多个请求 array 将此数据再次走这个方法
+          return newFilter(i);
+        }
+      });
+      return res;
+    };
+    let returns = _.flattenDeep(newFilter(result));
+    return returns;
+  },
+};
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 16 - 0
src/views/live/roomDetail.vue

@@ -93,6 +93,7 @@
           <van-field v-model="item.answer" placeholder="请输入" />
         </span>
       </van-col>
+      <van-button size="large" type="primary" @click="submitQuest">提交</van-button>
     </van-popup>
   </div>
 </template>
@@ -107,6 +108,7 @@ Vue.use(Swipe);
 Vue.use(SwipeItem);
 Vue.use(VanImage);
 Vue.use(Lazyload);
+const { mapActions: uploadquestion } = createNamespacedHelpers('uploadquestion');
 const { mapActions: gensign } = createNamespacedHelpers('gensign');
 const { mapActions: room } = createNamespacedHelpers('room');
 const { mapActions: quest } = createNamespacedHelpers('quest');
@@ -169,6 +171,7 @@ export default {
     ...room(['lookuserFetch', 'fetch', 'lookusercount', 'lookquery', 'lookupdate', 'lookrecord']),
     ...chat(['query', 'create']),
     ...quest(['questfetch']),
+    ...uploadquestion({ upcreate: 'create' }),
     async recordSave() {
       console.log(2121);
       let data = {};
@@ -261,6 +264,19 @@ export default {
         }
       }
     },
+    async submitQuest() {
+      let form = { roomid: this.id, userid: this.user.uid, questionnaireid: this.queid };
+      let answers = [];
+      for (const question of this.questInfo.question) {
+        answers.push({ questionid: question._id, answer: JSON.stringify(question.answer) });
+      }
+      form.answers = answers;
+      console.log(form);
+      let res = await this.upcreate(form);
+      if (res.errcode == '0') {
+        this.showQuest = false;
+      }
+    },
     async lookuserSearch() {
       if (this.user.uid) {
         let data = {};