mo 3 gadi atpakaļ
vecāks
revīzija
d482252e6b

+ 2 - 2
src/views/setQuestions/components/questionList.vue

@@ -17,12 +17,12 @@
             <el-option label="单选" value="radio"></el-option>
             <el-option label="多选" value="checkbox"></el-option>
             <el-option label="问答" value="textarea"></el-option>
-            <el-option label="附件" value="file"></el-option>
+            <!-- <el-option label="附件" value="file"></el-option> -->
             <el-option label="图片" value="image"></el-option>
           </el-select>
         </el-form-item>
       </el-col>
-      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
+      <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12"  v-if="!commitType">
         <el-form-item
           label="是否必填"
           prop="isRequire"

+ 4 - 4
src/views/setQuestions/index.vue

@@ -79,7 +79,7 @@
                 type="text"
                 >详情</el-button
               >
-              <!-- <el-button
+              <el-button
                 @click="onOperation(scope.row)"
                 v-if="
                   $helpers.permission(
@@ -90,9 +90,9 @@
                 "
                 type="text"
                 >{{ scope.row.status ? "停用" : "启用" }}</el-button
-              > -->
+              >
               <!-- 启用的问卷不能修改 -->
-              <el-button
+              <!-- <el-button
                 @click="onQuestionOperation('update', scope.row)"
                 v-if="
                   $helpers.permission(
@@ -101,7 +101,7 @@
                 "
                 type="text"
                 >修改</el-button
-              >
+              > -->
               <el-button
                 @click="lookAsk(scope.row)"
                 v-if="

+ 21 - 0
src/views/setQuestions/operation.vue

@@ -79,6 +79,7 @@
             <el-form-item
               label="是否逐题提交"
               prop="commitType"
+                class="memoWrapItem"
               :rules="[
                 {
                   required: true,
@@ -87,6 +88,26 @@
                 },
               ]"
             >
+                   <template slot="label">
+                <p style="position: relative" class="titleCell">
+                  <span style="color: #f56c6c; margin-right: 4px">*</span>
+                  是否逐题提交
+                  <el-tooltip placement="top" popper-class="mTooltip">
+                    <div slot="content">
+                      逐题模式下,所有问题默认必填
+                    </div>
+                    <i
+                      class="el-icon-question"
+                      style="
+                        font-size: 18px;
+                        color: #f56c6c;
+                        position: relative;
+                        top: 2px;
+                      "
+                    ></i>
+                  </el-tooltip>
+                </p>
+              </template>
               <el-select
                 v-model="form.commitType"
                 placeholder="请选择是否逐题提交"

+ 274 - 85
src/views/setQuestions/questionManger/component/Continuous.vue

@@ -9,104 +9,190 @@
       <h2 class="title">校管乐团启蒙课 调查问卷</h2>
     </div>
     <studentInfo v-if="form.loginFlag" class="studentInfo" />
-    <div class="questions" v-for="(item, index) in questionList" :key="index">
-      <van-tag class="form-mark" :color="themeColor" mark type="primary">{{
-        item["type"] | formTypeFormat
-      }}</van-tag>
-      <van-cell-group :border="false">
-        <van-cell title-class="questionName" :title="item['content']" />
-        <van-cell :border="false">
-          <template #title>
-            <van-radio-group v-model="check" v-if="item['type'] == 'radio'">
-              <van-cell-group :border="false">
-                <van-cell
-                  :border="false"
-                  v-for="item in item['questionnaireQuestionItemList']"
-                  :clickable="true"
-                  :key="item.id"
-                  :title="item.answerValue"
-                  class="teacher-item"
-                  @click="toggle(item.id)"
+    <van-form @submit="onSubmit"  ref="form">
+      <div class="questions" v-for="(item, index) in questionList" :key="index">
+        <van-tag class="form-mark" :color="themeColor" mark type="primary">{{
+          item["type"] | formTypeFormat
+        }}</van-tag>
+        <van-cell-group :border="false">
+          <van-cell
+            :title-class="['questionName', item['isRequire'] ? 'require' : '']"
+            :title="item['content']"
+          />
+          <van-field
+            v-if="item['type'] != 'textarea'"
+            :border="false"
+            :name="item.id + ''"
+            :rules="[
+              {
+                required: item['isRequire'] ? true : false,
+                message: getErrorMsg(item),
+              },
+            ]"
+          >
+            <template #input>
+              <div style="width: 100%">
+                <van-radio-group
+                  v-model="form[item.id]"
+                  v-if="item['type'] == 'radio'"
                 >
-                  <template #right-icon>
-                    <van-radio :name="item.id">
-                      <template #icon="props">
-                        <!-- <img
+                  <van-cell-group :border="false">
+                    <van-cell
+                      :border="false"
+                      v-for="item in item['questionnaireQuestionItemList']"
+                      :clickable="true"
+                      :key="item.id"
+                      :title="item.answerValue"
+                      class="teacher-item"
+                      @click="toggle(item.id)"
+                    >
+                      <template #right-icon>
+                        <van-radio :name="item.id">
+                          <template #icon="props">
+                            <!-- <img
                           class="img-icon"
                           :src="props.checked ? activeButtonIcon : inactiveIcon"
                         /> -->
 
-                        <i
-                          class="iconfont"
-                          :class="
-                            props.checked
-                              ? 'icon-gouxuan'
-                              : 'icon-weigouxuan'
-                          "
-                          :style="{ color: themeColor }"
-                        ></i>
+                            <i
+                              class="iconfont"
+                              :class="
+                                props.checked
+                                  ? 'icon-gouxuan' : 'icon-weigouxuan'
+                              "
+                              :style="{ color: themeColor }"
+                            ></i>
+                          </template>
+                        </van-radio>
                       </template>
-                    </van-radio>
-                  </template>
-                </van-cell>
-              </van-cell-group>
-            </van-radio-group>
-            <van-checkbox-group
-              v-model="checkBox"
-              v-if="item['type'] == 'checkbox'"
-            >
-              <van-cell-group :border="false">
-                <van-cell
-                  :border="false"
-                  v-for="(item, index) in item['questionnaireQuestionItemList']"
-                  :clickable="true"
-                  :key="item.id"
-                  :title="item.answerValue"
-                  class="teacher-item"
-                  @click="toggle(index)"
+                    </van-cell>
+                  </van-cell-group>
+                </van-radio-group>
+                <van-checkbox-group
+                  v-model="form[item.id]"
+                  v-if="item['type'] == 'checkbox'"
                 >
-                  <template #right-icon>
-                    <van-checkbox
-                      shape="square"
-                      :name="item.id ? item.id.toString() : item.answerValue"
-                      ref="checkboxes"
+                  <van-cell-group :border="false">
+                    <van-cell
+                      :border="false"
+                      v-for="(item, index) in item[
+                        'questionnaireQuestionItemList'
+                      ]"
+                      :clickable="true"
+                      :key="item.id"
+                      :title="item.answerValue"
+                      class="teacher-item"
+                      @click="toggle(index)"
                     >
-                      <template #icon="props">
-                        <!-- <img
+                      <template #right-icon>
+                        <van-checkbox
+                          shape="square"
+                          :name="
+                            item.id ? item.id.toString() : item.answerValue
+                          "
+                          ref="checkboxes"
+                        >
+                          <template #icon="props">
+                            <!-- <img
                           class="img-icon"
                           :src="props.checked ? activeButtonIcon : inactiveIcon"
                         /> -->
-                        <i
-                          class="iconfont"
-                          :class="
-                            props.checked
-                              ? 'icon-gouxuan'
-                              : 'icon-weigouxuan'
-                          "
-                          :style="{ color: themeColor }"
-                        ></i>
+                            <i
+                              class="iconfont"
+                              :class="
+                                props.checked
+                                  ? 'icon-gouxuan' : 'icon-weigouxuan'
+                              "
+                              :style="{ color: themeColor }"
+                            ></i>
+                          </template>
+                        </van-checkbox>
                       </template>
-                    </van-checkbox>
-                  </template>
-                </van-cell>
-              </van-cell-group>
-            </van-checkbox-group>
+                    </van-cell>
+                  </van-cell-group>
+                </van-checkbox-group>
 
-            <div v-if="item['type'] == 'textarea'">
-              <van-field
-                v-model="textarea"
-                rows="4"
-                autosize
-                maxlength="255"
-                type="textarea"
-                class="textareaClass"
-                placeholder="请写下您的使用感受或建议~"
-              />
-            </div>
-          </template>
-        </van-cell>
-      </van-cell-group>
-    </div>
+                <div v-if="item['type'] == 'image'">
+                  <van-uploader
+                    v-model="list[item.id]"
+                    :max-count="1"
+                    :before-delete="
+                      (file) => {
+                        beforeDelete(file, item.id + '', item.id);
+                      }
+                    "
+                    :before-read="beforeRead"
+                    :after-read="
+                      (file) => {
+                        afterRead(file, item.id, item.id);
+                      }
+                    "
+                    accept="image/*"
+                  >
+                    <div class="uploaderBox">
+                      <img src="../images/imageIcon.png" alt="" />
+                    </div>
+                  </van-uploader>
+                  <!-- </van-button> -->
+                  <p class="uploaderTitle">请上传5M内的图片文件</p>
+                </div>
+
+                <!-- <div v-if="item['type'] == 'file'">
+                  <van-uploader
+                    v-model="list[item.id]"
+                    :max-count="1"
+                    accept="*"
+                    :before-delete="
+                      (file) => {
+                        beforeDelete(file, item.id, item.id);
+                      }
+                    "
+                    :before-read="
+                      (file) => {
+                        return beforeRead(file, item.type);
+                      }
+                    "
+                    :after-read="
+                      (file) => {
+                        afterRead(file, item.id, item.id);
+                      }
+                    "
+                  >
+                    <div class="uploaderBox">
+                      <img src="../images/fileIcon.png" alt="" />
+                      <p>点击上传</p>
+                    </div>
+                  </van-uploader>
+                  <p class="uploaderTitle">
+                    请上传5M以内的psd、ai、eps、svg、sketch类型文件
+                  </p>
+                </div> -->
+              </div>
+            </template>
+          </van-field>
+
+          <div v-if="item['type'] == 'textarea'">
+            <!--  class="textareaClass" -->
+            <van-field
+              v-model="form[item.id]"
+              :name="item.id + ''"
+              :rules="[
+                {
+                  required: item['isRequire'] ? true : false,
+                  message: getErrorMsg(item),
+                },
+              ]"
+              rows="4"
+              autosize
+              maxlength="255"
+              type="textarea"
+              class="textarea"
+              placeholder="请写下您的使用感受或建议~"
+            />
+          </div>
+        </van-cell-group>
+      </div>
+    </van-form>
     <van-goods-action>
       <!-- <van-goods-action-button
           class="btn-submit"
@@ -210,6 +296,7 @@ export default {
       checkList: [],
       templateType: 2,
          questionList: [{type:'',content:''}],
+         list:''
     };
   },
   async mounted() {
@@ -331,6 +418,50 @@ export default {
         this.$refs.checkboxes[index].toggle();
       }
     },
+      beforeRead(file, name) {
+      const isLt2M = file.size / 1024 / 1024 < 5;
+
+      if (!isLt2M) {
+        this.$toast("文件大小不能超过 5MB");
+        return false;
+      }
+      if (name && name == "fileUrl") {
+        let arr = ["psd", "ai", "eps", "svg", "sketch"];
+        let typeArr = file.name.split(".");
+        let type = typeArr[typeArr.length - 1];
+        if (arr.indexOf(type) == -1) {
+          this.$toast("请上传正确的文件");
+          return false;
+        }
+      }
+      return true;
+    },
+    beforeDelete(file, name, list) {
+      this.form[name] = ""; // 上传图片地址为空
+      this[list] = [];
+      return true;
+    },
+    async afterRead(file, name, origin) {
+      this.setLoading(true);
+      let formData = new FormData();
+      formData.append("file", file.file);
+      try {
+        await uploadFile(formData).then((res) => {
+          let result = res.data;
+          if (result.code == 200) {
+            this[name] = result.data.url;
+          } else {
+            this[origin] = [];
+            this[name] = "";
+            return false;
+          }
+        });
+        this.setLoading(false);
+      } catch (err) {
+        this.setLoading(false);
+        return false;
+      }
+    },
     async onSubmit() {
       this.$emit('close')
       // let selectList = this.questionList[this.currentIndex - 1];
@@ -405,6 +536,15 @@ export default {
         state.user.status = "init";
       }
     },
+        getErrorMsg(item) {
+      if (item.type == "radio") {
+        return "请选择此题目";
+      } else if (item.type == "checkbox") {
+        return "请选择此题目";
+      } else {
+        return "";
+      }
+    },
   },
   filters: {
     formTypeFormat(type) {
@@ -412,6 +552,7 @@ export default {
         radio: "单选",
         checkbox: "多选",
         textarea: "问答",
+          image: "图片",
       };
       return template[type];
     },
@@ -1014,4 +1155,52 @@ export default {
     }
   }
 }
+.questions {
+  .van-cell--borderless {
+    // padding-bottom: 0;
+    &::after {
+      border-bottom: 1px solid #f0f0f0;
+    }
+  }
+}
+.questionName {
+  padding-bottom: 0 !important;
+}
+.questionName.require {
+  span {
+    position: relative;
+    &::before {
+      content: "*";
+      color: #ee0a24;
+      position: absolute;
+      left: -8px;
+      top: 2px;
+    }
+  }
+}
+.van-cell--required {
+  &::before {
+    content: "";
+  }
+}
+.textarea {
+  /deep/.van-field__value {
+    background-color: #f5f5f5;
+    padding: 14px 12px;
+  }
+}
+.uploaderBox {
+  img {
+    margin-top: 10px;
+    margin-bottom: 15px;
+    width: 76px;
+  }
+}
+.uploaderTitle {
+  font-size: 14px;
+  font-family: PingFangSC-Regular, PingFang SC;
+  font-weight: 400;
+  color: #999999;
+  line-height: 24px;
+}
 </style>

+ 151 - 4
src/views/setQuestions/questionManger/component/Progressive.vue

@@ -109,6 +109,42 @@
                 placeholder="请写下您的使用感受或建议~"
               />
             </div>
+            <div v-if="questionList[currentIndex - 1]['type'] == 'image'">
+              <van-field
+                :name="questionList[currentIndex - 1]['id'] + ''"
+                class="uploader"
+              >
+                <template
+                  slot="input"
+                  :id="questionList[currentIndex - 1]['id']"
+                >
+                  <div>
+                    <van-uploader
+                      v-model="imageList"
+                      :max-count="1"
+                      accept="image/*"
+                      :before-delete="
+                        (file) => {
+                          beforeDelete(file, 'imgUrl', 'imageList');
+                        }
+                      "
+                      :before-read="beforeRead"
+                      :after-read="
+                        (file) => {
+                          afterRead(file, 'imgUrl', 'imageList');
+                        }
+                      "
+                    >
+                      <div class="uploaderBox">
+                        <img src="../images/imageIcon.png" alt="" />
+                      </div>
+                    </van-uploader>
+                    <p class="uploaderTitle">请上传5M内的图片文件</p>
+                  </div>
+                  <!-- </van-button> -->
+                </template>
+              </van-field>
+            </div>
           </template>
         </van-cell>
       </van-cell-group>
@@ -167,6 +203,21 @@
               : '下一题'
           "
         />
+        <van-goods-action-button
+          class="btn-submit"
+          :color="themeColor"
+          :disabled="!imgUrl"
+          type="primary"
+          v-if="questionList[currentIndex - 1]['type'] == 'image'"
+          @click="onSubmit"
+          :text="
+            currentIndex == questionList.length
+              ? planStatus
+                ? '确定'
+                : '提交'
+              : '下一题'
+          "
+        />
       </van-goods-action>
     </div>
 
@@ -225,13 +276,15 @@ export default {
       textarea: null,
       checkList: [],
       templateType: 1,
-      questionList: [{type:'',content:''}],
+      questionList: [{ type: "", content: "" }],
+      imageList: [],
+      imgUrl: "",
     };
   },
   async mounted() {
     this.templateType = this.form.templateType;
     this.questionList = this.form.questionnaireQuestionList;
-    console.log(this.form)
+    console.log(this.form);
   },
   computed: {
     planStatus() {
@@ -393,7 +446,7 @@ export default {
           // } catch {
           //   //
           // }
-          this.$emit('close')
+          this.$emit("close");
           return;
         }
 
@@ -422,6 +475,51 @@ export default {
         state.user.status = "init";
       }
     },
+    beforeRead(file, name) {
+      const isLt2M = file.size / 1024 / 1024 < 5;
+
+      if (!isLt2M) {
+        this.$toast("文件大小不能超过 5MB");
+        return false;
+      }
+      if (name && name == "fileUrl") {
+        let arr = ["psd", "ai", "eps", "svg", "sketch"];
+        let typeArr = file.name.split(".");
+        let type = typeArr[typeArr.length - 1];
+        if (arr.indexOf(type) == -1) {
+          this.$toast("请上传正确的文件");
+          return false;
+        }
+      }
+      return true;
+    },
+    beforeDelete(file, name, list) {
+      this.form[name] = ""; // 上传图片地址为空
+      this[list] = [];
+      return true;
+    },
+    async afterRead(file, name, origin) {
+      // this.setLoading(true);
+      let formData = new FormData();
+      formData.append("file", file.file);
+ this[name] = name;
+      // try {
+      //   await uploadFile(formData).then((res) => {
+      //     let result = res.data;
+      //     if (result.code == 200) {
+      //       this[name] = result.data.url;
+      //     } else {
+      //       this[origin] = [];
+      //       this[name] = "";
+      //       return false;
+      //     }
+      //   });
+      //   // this.setLoading(false);
+      // } catch (err) {
+      //   // this.setLoading(false);
+      //   return false;
+      // }
+    },
   },
   filters: {
     formTypeFormat(type) {
@@ -429,6 +527,7 @@ export default {
         radio: "单选",
         checkbox: "多选",
         textarea: "问答",
+        image: "图片",
       };
       return template[type];
     },
@@ -968,7 +1067,6 @@ export default {
     align-items: flex-start;
   }
   /deep/.van-goods-action {
-
     position: inherit;
     padding: 0 15px;
     margin: 20px auto 28px;
@@ -1028,4 +1126,53 @@ export default {
     }
   }
 }
+
+.questions {
+  .van-cell--borderless {
+    // padding-bottom: 0;
+    &::after {
+      border-bottom: 1px solid #f0f0f0;
+    }
+  }
+}
+.questionName {
+  padding-bottom: 0 !important;
+}
+.questionName.require {
+  span {
+    position: relative;
+    &::before {
+      content: "*";
+      color: #ee0a24;
+      position: absolute;
+      left: -8px;
+      top: 2px;
+    }
+  }
+}
+.van-cell--required {
+  &::before {
+    content: "";
+  }
+}
+.textarea {
+  /deep/.van-field__value {
+    background-color: #f5f5f5;
+    padding: 14px 12px;
+  }
+}
+.uploaderBox {
+  img {
+    margin-top: 10px;
+    margin-bottom: 15px;
+    width: 76px;
+  }
+}
+.uploaderTitle {
+  font-size: 14px;
+  font-family: PingFangSC-Regular, PingFang SC;
+  font-weight: 400;
+  color: #999999;
+  line-height: 24px;
+}
 </style>

BIN
src/views/setQuestions/questionManger/images/imageIcon.png


+ 3 - 2
src/views/setQuestions/questionManger/index.vue

@@ -37,7 +37,8 @@ import {
   Form,
   GoodsActionButton,
   GoodsAction,
-  Tag
+  Tag,
+  Uploader
 } from "vant";
 Vue.use(Button)
   .use(Popup)
@@ -53,7 +54,7 @@ Vue.use(Button)
   .use(Radio)
   .use(CheckboxGroup)
   .use(Checkbox)
-  .use(ImagePreview).use(GoodsActionButton).use(GoodsAction).use(Tag);
+  .use(ImagePreview).use(GoodsActionButton).use(GoodsAction).use(Tag).use(Uploader);
 import 'vant/lib/index.css'
 export default {
   props:['form'],