浏览代码

feat:完成发布交流

DingXiaoYu 3 年之前
父节点
当前提交
cf1a7f53d2
共有 1 个文件被更改,包括 83 次插入 和 10 次删除
  1. 83 10
      src/views/CommunicationPage/PublishPage.vue

+ 83 - 10
src/views/CommunicationPage/PublishPage.vue

@@ -24,24 +24,43 @@
             <el-form-item label="单位院校">
                 <el-input v-model="form.organization"></el-input>
             </el-form-item>
-            <el-form-item label="联系方式">
-                <el-input v-model="form.contact"></el-input>
+            <el-form-item label="手机号">
+                <el-input v-model="form.phone"></el-input>
             </el-form-item>
-            <el-form-item label="图片">
-                <el-upload>
+            <el-form-item label="微信">
+                <el-input v-model="form.wechat"></el-input>
+            </el-form-item>
+            <el-form-item label="QQ">
+                <el-input v-model="form.qq"></el-input>
+            </el-form-item>
+            <el-form-item label="邮箱">
+                <el-input v-model="form.email"></el-input>
+            </el-form-item>
+            <el-form-item label="图片" >
+                <el-upload action="" :auto-upload="false" :limit="3" :on-remove="handlePictureChange" :on-change="handlePictureChange" :on-exceed="handleExceed" list-type="picture">
                     <el-button size="small" type="primary">点击上传</el-button>
                 </el-upload>
             </el-form-item>
             <el-form-item label="附件">
-                <el-upload>
+                <el-upload action="" :auto-upload="false" :limit="3" :on-remove="handleFileChange" :on-change="handleFileChange" :on-exceed="handleExceed">
                     <el-button size="small" type="primary">点击上传</el-button>
                 </el-upload>
             </el-form-item>
+            <el-form-item label="截止时间">
+                <el-date-picker
+                    v-model="form.deadline"
+                    type="datetime"
+                    size="mini"
+                />
+            </el-form-item>
         </el-form>
+
+        <el-button size="big" type="primary" style="margin-left: 500px" @click="publish">发布</el-button>
     </div>
 </template>
 
 <script>
+import {ElMessage} from "element-plus";
 export default {
   name: "Publish",
   data() {
@@ -49,14 +68,20 @@ export default {
       form: {
         title: "",
         organization: "",
-        contact: "",
+        phone: "",
+          wechat:"",
+          qq:"",
+          email:"",
+          deadline:null,
         type: null,
         textarea: "",
+        pictureList:[],
+        fileList:[],
+          photos:[],
+          attachments:[],
       },
-      typeOptions: [{
-        value: 0,
-        label: "其他"
-      }, {
+      typeOptions: [
+        {
         value: 1,
         label: "难题"
       }, {
@@ -65,6 +90,54 @@ export default {
       }],
     };
   },
+    methods: {
+        handlePictureChange(file,fileList) {
+            this.form.pictureList=fileList;
+        },
+        handleFileChange(file,fileList){
+            this.form.fileList=fileList;
+        },
+        handleExceed(file,fileList){
+            ElMessage.error("最多上传3个!");
+        },
+        async upload(){
+            for (let i=0;i<this.form.pictureList.length;i++){
+                this.$apis.uploadFile(this.form.pictureList[i].raw).then(res=>{
+                    this.form.photos.push(res.data.data);
+                });
+            }
+            for (let i=0;i<this.form.fileList.length;i++){
+                this.$apis.uploadFile(this.form.fileList[i].raw).then(res=>{
+                    this.form.attachments.push(res.data.data);
+                });
+            }
+            return 0;
+        },
+        publish(){
+            this.upload().then(res=>{
+                const communication={
+                    publisherId: Number(this.$store.state.user.id),
+                    title: this.form.title,
+                    type: this.form.type,
+                    description:this.form.textarea,
+                    organization: this.form.organization,
+                    phone: this.form.phone,
+                    wechat:this.form.wechat,
+                    qq:this.form.qq,
+                    email:this.form.email,
+                    publishTime:new Date(),
+                    deadline:this.form.deadline,
+                    photos:this.form.photos,
+                    attachments:this.form.attachments,
+                    publisherName:this.$store.state.user.username
+                };
+                this.$apis.postCommunication(communication).then(res=>{
+                    ElMessage.success("发布成功");
+                    this.$router.go(0);
+                });
+            });
+        }
+    }
 };
 </script>