ソースを参照

欢迎语设置,新增是校验课程必填

lmx 3 日 前
コミット
bdd2b93232
2 ファイル変更184 行追加133 行削除
  1. 92 67
      src/views/qw/friendWelcome/indexNew.vue
  2. 92 66
      src/views/qw/friendWelcome/myWelcome.vue

+ 92 - 67
src/views/qw/friendWelcome/indexNew.vue

@@ -484,7 +484,7 @@
         </div>
         <div v-if="welcomeItem.type==='miniprogram'">
 
-          <el-form-item label="选择课程">
+          <el-form-item label="选择课程" prop="miniprogramCourseId">
             <el-select  v-model="fileFrom.courseId" placeholder="请选择课程" style=" margin-right: 10px;" size="mini"  @change="courseChange(fileFrom,welcomeItem.index,welcomeItem.itemIndex)">
               <el-option
                 v-for="dict in courseList"
@@ -532,7 +532,7 @@
         </div>
       </el-form>
       <div slot="footer" class="dialog-footer" style="text-align: center">
-        <el-button type="primary" @click="confirmUpload">确定</el-button>
+        <el-button type="primary" @click="confirmUpload('fileFrom')">确定</el-button>
         <el-button type="primary" @click="cancelUpload">取消</el-button>
       </div>
     </el-dialog>
@@ -593,6 +593,24 @@ export default {
         linkTitle:[ { required: true, message: "图文标题不能为空", trigger: "submit" }],
         linkUrl:[ { required: true, message: "图文链接不能为空", trigger: "submit" }],
         miniprogramTitle:[ { required: true, message: "图文链接不能为空", trigger: "submit" }],
+        miniprogramCourseId:[
+          {
+            required: true,
+            validator: (rule, value, callback) => {
+              // 检查id是否为空
+              if (!this.fileFrom.courseId) {
+                return callback(new Error('请选择课程'));
+              }
+              // 检查ddId是否为空
+              if (!this.fileFrom.videoId) {
+                return callback(new Error('请选择小节'));
+              }
+              // 校验通过
+              callback();
+            },
+            trigger: 'change' // 下拉选择变化时触发校验
+          }
+        ]
       },
 
 
@@ -999,72 +1017,79 @@ export default {
 
     //提交附件
     confirmUpload(fileFrom) {
-      const { type, index, itemIndex } = this.welcomeItem;
-      let attachment = {};
-      if (type === 'image') {
-        attachment = {
-          msgtype: 'image',
-          image: {
-            pic_url: this.fileFrom.imagePicUrl
-          }
-        };
-      } else if (type === 'video') {
-        attachment = {
-          msgtype: 'video',
-          video: {
-            url:this.fileFrom.videoUrl,
-          }
-        };
-      } else if (type === 'link') {
-        attachment = {
-          msgtype: 'link',
-          link: {
-            title: this.fileFrom.linkTitle,
-            picurl: this.fileFrom.linkPicUrl,
-            desc: this.fileFrom.linkDesc,
-            url: this.fileFrom.linkUrl,
-            courseId:this.fileFrom.courseId,
-            videoId:this.fileFrom.videoId,
-            expiresDays:this.fileFrom.expiresDays,
-          }
-        };
-      }else if (type==='miniprogram'){
-        attachment = {
-          msgtype: 'miniprogram',
-          miniprogram: {
-            title: this.fileFrom.miniprogramTitle,
-            pic_media_id: "待查询",
-            appid: "wx73f85f8d62769119",
-            page: this.fileFrom.miniprogramPage,
-            courseId:this.fileFrom.courseId,
-            videoId:this.fileFrom.videoId,
-            expiresDays:this.fileFrom.expiresDays,
-          }
-        };
-      }
-
-      if (itemIndex === -1) {
-        // 默认欢迎语附件处理
-        if (index < this.form.attachments.length) {
-          // 存在附件则更新
-          this.form.attachments.splice(index, 1, attachment);
-        } else {
-          // 不存在附件则插入
-          this.form.attachments.push(attachment);
-        }
-
-      } else {
-        // 分时段欢迎语附件处理
-        if (index < this.form.daypartingItemlist[itemIndex].attachments.length) {
-          // 存在附件则更新
-          this.form.daypartingItemlist[itemIndex].attachments.splice(index, 1, attachment);
-        } else {
-          // 不存在附件则插入
-          this.form.daypartingItemlist[itemIndex].attachments.push(attachment);
-        }
-      }
+     this.$refs[fileFrom].validate((valid) => {
+          if (valid) {
+            const { type, index, itemIndex } = this.welcomeItem;
+            let attachment = {};
+            if (type === 'image') {
+              attachment = {
+                msgtype: 'image',
+                image: {
+                  pic_url: this.fileFrom.imagePicUrl
+                }
+              };
+            } else if (type === 'video') {
+              attachment = {
+                msgtype: 'video',
+                video: {
+                  url:this.fileFrom.videoUrl,
+                }
+              };
+            } else if (type === 'link') {
+              attachment = {
+                msgtype: 'link',
+                link: {
+                  title: this.fileFrom.linkTitle,
+                  picurl: this.fileFrom.linkPicUrl,
+                  desc: this.fileFrom.linkDesc,
+                  url: this.fileFrom.linkUrl,
+                  courseId:this.fileFrom.courseId,
+                  videoId:this.fileFrom.videoId,
+                  expiresDays:this.fileFrom.expiresDays,
+                }
+              };
+            }else if (type==='miniprogram'){
+              attachment = {
+                msgtype: 'miniprogram',
+                miniprogram: {
+                  title: this.fileFrom.miniprogramTitle,
+                  pic_media_id: "待查询",
+                  appid: "wx73f85f8d62769119",
+                  page: this.fileFrom.miniprogramPage,
+                  courseId:this.fileFrom.courseId,
+                  videoId:this.fileFrom.videoId,
+                  expiresDays:this.fileFrom.expiresDays,
+                }
+              };
+            }
 
-      this.resetFileFrom();
+            if (itemIndex === -1) {
+              // 默认欢迎语附件处理
+              if (index < this.form.attachments.length) {
+                // 存在附件则更新
+                this.form.attachments.splice(index, 1, attachment);
+              } else {
+                // 不存在附件则插入
+                this.form.attachments.push(attachment);
+              }
+
+            } else {
+              // 分时段欢迎语附件处理
+              if (index < this.form.daypartingItemlist[itemIndex].attachments.length) {
+                // 存在附件则更新
+                this.form.daypartingItemlist[itemIndex].attachments.splice(index, 1, attachment);
+              } else {
+                // 不存在附件则插入
+                this.form.daypartingItemlist[itemIndex].attachments.push(attachment);
+              }
+            }
+            this.resetFileFrom();
+          } else {
+            console.log('error submit!!');
+            return false;
+          }
+        });
+     
     },
 
     //取消附件

+ 92 - 66
src/views/qw/friendWelcome/myWelcome.vue

@@ -481,7 +481,7 @@
         </div>
         <div v-if="welcomeItem.type==='miniprogram'">
 
-          <el-form-item label="选择课程">
+          <el-form-item label="选择课程" prop="miniprogramCourseId">
             <el-select  v-model="fileFrom.courseId" placeholder="请选择课程" style=" margin-right: 10px;" size="mini"  @change="courseChange(fileFrom,welcomeItem.index,welcomeItem.itemIndex)">
               <el-option
                 v-for="dict in courseList"
@@ -529,7 +529,7 @@
         </div>
       </el-form>
       <div slot="footer" class="dialog-footer" style="text-align: center">
-        <el-button type="primary" @click="confirmUpload">确定</el-button>
+        <el-button type="primary" @click="confirmUpload('fileFrom')">确定</el-button>
         <el-button type="primary" @click="cancelUpload">取消</el-button>
       </div>
     </el-dialog>
@@ -591,6 +591,24 @@ export default {
         linkTitle:[ { required: true, message: "图文标题不能为空", trigger: "submit" }],
         linkUrl:[ { required: true, message: "图文链接不能为空", trigger: "submit" }],
         miniprogramTitle:[ { required: true, message: "图文链接不能为空", trigger: "submit" }],
+        miniprogramCourseId:[
+          {
+            required: true,
+            validator: (rule, value, callback) => {
+              // 检查id是否为空
+              if (!this.fileFrom.courseId) {
+                return callback(new Error('请选择课程'));
+              }
+              // 检查ddId是否为空
+              if (!this.fileFrom.videoId) {
+                return callback(new Error('请选择小节'));
+              }
+              // 校验通过
+              callback();
+            },
+            trigger: 'change' // 下拉选择变化时触发校验
+          }
+        ]
       },
 
 
@@ -999,73 +1017,81 @@ export default {
 
     //提交附件
     confirmUpload(fileFrom) {
+    this.$refs[fileFrom].validate((valid) => {
+      if (valid) {
+        const { type, index, itemIndex } = this.welcomeItem;
+            let attachment = {};
+            if (type === 'image') {
+              attachment = {
+                msgtype: 'image',
+                image: {
+                  pic_url: this.fileFrom.imagePicUrl
+                }
+              };
+            } else if (type === 'video') {
+              attachment = {
+                msgtype: 'video',
+                video: {
+                  url:this.fileFrom.videoUrl,
+                }
+              };
+            } else if (type === 'link') {
+              attachment = {
+                msgtype: 'link',
+                link: {
+                  title: this.fileFrom.linkTitle,
+                  picurl: this.fileFrom.linkPicUrl,
+                  desc: this.fileFrom.linkDesc,
+                  url: this.fileFrom.linkUrl,
+                  courseId:this.fileFrom.courseId,
+                  videoId:this.fileFrom.videoId,
+                  expiresDays:this.fileFrom.expiresDays,
+                }
+              };
+            }else if (type==='miniprogram'){
+              attachment = {
+                msgtype: 'miniprogram',
+                miniprogram: {
+                  title: this.fileFrom.miniprogramTitle,
+                  pic_media_id: "待查询",
+                  appid: "wx73f85f8d62769119",
+                  page: this.fileFrom.miniprogramPage,
+                  courseId:this.fileFrom.courseId,
+                  videoId:this.fileFrom.videoId,
+                  expiresDays:this.fileFrom.expiresDays,
+                }
+              };
+            }
 
-      const { type, index, itemIndex } = this.welcomeItem;
-      let attachment = {};
-      if (type === 'image') {
-        attachment = {
-          msgtype: 'image',
-          image: {
-            pic_url: this.fileFrom.imagePicUrl
-          }
-        };
-      } else if (type === 'video') {
-        attachment = {
-          msgtype: 'video',
-          video: {
-            url:this.fileFrom.videoUrl,
-          }
-        };
-      } else if (type === 'link') {
-        attachment = {
-          msgtype: 'link',
-          link: {
-            title: this.fileFrom.linkTitle,
-            picurl: this.fileFrom.linkPicUrl,
-            desc: this.fileFrom.linkDesc,
-            url: this.fileFrom.linkUrl,
-            courseId:this.fileFrom.courseId,
-            videoId:this.fileFrom.videoId,
-            expiresDays:this.fileFrom.expiresDays,
-          }
-        };
-      }else if (type==='miniprogram'){
-        attachment = {
-          msgtype: 'miniprogram',
-          miniprogram: {
-            title: this.fileFrom.miniprogramTitle,
-            pic_media_id: "待查询",
-            appid: "wx73f85f8d62769119",
-            page: this.fileFrom.miniprogramPage,
-            courseId:this.fileFrom.courseId,
-            videoId:this.fileFrom.videoId,
-            expiresDays:this.fileFrom.expiresDays,
-          }
-        };
-      }
-
-      if (itemIndex === -1) {
-        // 默认欢迎语附件处理
-        if (index < this.form.attachments.length) {
-          // 存在附件则更新
-          this.form.attachments.splice(index, 1, attachment);
-        } else {
-          // 不存在附件则插入
-          this.form.attachments.push(attachment);
-        }
+            if (itemIndex === -1) {
+              // 默认欢迎语附件处理
+              if (index < this.form.attachments.length) {
+                // 存在附件则更新
+                this.form.attachments.splice(index, 1, attachment);
+              } else {
+                // 不存在附件则插入
+                this.form.attachments.push(attachment);
+              }
+
+            } else {
+              // 分时段欢迎语附件处理
+              if (index < this.form.daypartingItemlist[itemIndex].attachments.length) {
+                // 存在附件则更新
+                this.form.daypartingItemlist[itemIndex].attachments.splice(index, 1, attachment);
+              } else {
+                // 不存在附件则插入
+                this.form.daypartingItemlist[itemIndex].attachments.push(attachment);
+              }
+            }
 
-      } else {
-        // 分时段欢迎语附件处理
-        if (index < this.form.daypartingItemlist[itemIndex].attachments.length) {
-          // 存在附件则更新
-          this.form.daypartingItemlist[itemIndex].attachments.splice(index, 1, attachment);
-        } else {
-          // 不存在附件则插入
-          this.form.daypartingItemlist[itemIndex].attachments.push(attachment);
+            this.resetFileFrom();
+        }else {
+          console.log('error submit!!');
+          return false;
         }
-      }
-
-      this.resetFileFrom();
+          
+      });
+      
     },
 
     //取消附件