weiximei пре 6 година
родитељ
комит
48bdced750

+ 56
- 0
VUECODE/smart-property-manage/src/api/activity.js Прегледај датотеку

@@ -14,3 +14,59 @@ export function activityList(data) {
14 14
   })
15 15
 }
16 16
 
17
+// 添加活动
18
+export function addActivity(data) {
19
+  return request({
20
+    url: '/activity/add',
21
+    method: 'post',
22
+    data: {
23
+      activityTitle: data.activityTitle,
24
+      activityCarouselImg: data.activityCarouselImg, // 轮播图
25
+      activityContent: data.activityContent, // 活动内容详细
26
+      contentImg: data.contentImg, // 活动内容配图
27
+      signUpMax: data.signUpMax, //  活动人数上限
28
+      registrationEndTime: data.registrationEndTime, // 报名活动结束时间
29
+      sort: data.sort, // 权重
30
+      status: data.status // 状态 0 是已作废 1 是已发布   2 是草稿 3 是已修改
31
+    }
32
+  })
33
+}
34
+
35
+// 修改活动
36
+export function updateActivity(data) {
37
+  return request({
38
+    url: '/activity/update',
39
+    method: 'put',
40
+    data: {
41
+      id: data.id,
42
+      activityTitle: data.activityTitle,
43
+      activityCarouselImg: data.activityCarouselImg, // 轮播图
44
+      activityContent: data.activityContent, // 活动内容详细
45
+      contentImg: data.contentImg, // 活动内容配图
46
+      signUpMax: data.signUpMax, //  活动人数上限
47
+      registrationEndTime: data.registrationEndTime, // 报名活动结束时间
48
+      sort: data.sort, // 权重
49
+      status: data.status // 状态 0 是已作废 1 是已发布   2 是草稿 3 是已修改
50
+    }
51
+  })
52
+}
53
+
54
+// 查询 活动详情
55
+export function activityById(id) {
56
+  return request({
57
+    url: '/activity/' + id,
58
+    method: 'get'
59
+  })
60
+}
61
+
62
+// 批量活动作废
63
+export function invalidActivity(data) {
64
+  return request({
65
+    url: '/activity/invalid',
66
+    method: 'put',
67
+    data: {
68
+      ids: data
69
+    }
70
+  })
71
+}
72
+

+ 38
- 1
VUECODE/smart-property-manage/src/store/modules/activity.js Прегледај датотеку

@@ -1,4 +1,4 @@
1
-import { activityList } from '@/api/activity'
1
+import { activityList, addActivity, updateActivity, activityById, invalidActivity  } from '@/api/activity'
2 2
 
3 3
 const activityInfo = {
4 4
   state: {
@@ -14,7 +14,44 @@ const activityInfo = {
14 14
           reject(error)
15 15
         })
16 16
       })
17
+    },
18
+    AddActivity({ commit, state }, data) { // 添加活动
19
+      return new Promise((resolve, reject) => {
20
+        addActivity(data).then(response => {
21
+          resolve(response)
22
+        }).catch(error => {
23
+          reject(error)
24
+        })
25
+      })
26
+    },
27
+    UpdateActivity({ commit, state }, data) { // 修改活动
28
+      return new Promise((resolve, reject) => {
29
+        updateActivity(data).then(response => {
30
+          resolve(response)
31
+        }).catch(error => {
32
+          reject(error)
33
+        })
34
+      })
35
+    },
36
+    ActivityById({ commit, state }, data) { // 查询活动详情
37
+      return new Promise((resolve, reject) => {
38
+        activityById(data).then(response => {
39
+          resolve(response)
40
+        }).catch(error => {
41
+          reject(error)
42
+        })
43
+      })
44
+    },
45
+    InvalidActivity({ commit, state }, data) { // 批量活动作废
46
+      return new Promise((resolve, reject) => {
47
+        invalidActivity(data).then(response => {
48
+          resolve(response)
49
+        }).catch(error => {
50
+          reject(error)
51
+        })
52
+      })
17 53
     }
54
+
18 55
   }
19 56
 }
20 57
 

+ 29
- 2
VUECODE/smart-property-manage/src/views/social/activity/add/index.vue Прегледај датотеку

@@ -16,10 +16,10 @@
16 16
           <i v-else class="el-icon-plus avatar-uploader-icon"/>
17 17
         </el-upload>
18 18
       </el-form-item>
19
-      <el-form-item label="活动详细描述" prop="activityContent">
19
+      <el-form-item label="活动详细描述">
20 20
         <el-input v-model="ruleForm.activityContent" :rows="10" type="textarea" placeholder="活动内容, 活动规则, 活动举办开始时间, 活动举办结束时间, 报名人数上限等"/>
21 21
       </el-form-item>
22
-      <el-form-item label="活动配图" prop="contentImg">
22
+      <el-form-item label="活动配图">
23 23
         <el-upload
24 24
           :on-preview="handlePictureCardPreview"
25 25
           :on-remove="handleRemove"
@@ -91,11 +91,38 @@ export default {
91 91
   },
92 92
   methods: {
93 93
     submitForm(formName) {
94
+      // 加载框
95
+      const loading = this.$loading({
96
+        lock: true,
97
+        text: 'Loading',
98
+        spinner: 'el-icon-loading',
99
+        background: 'rgba(0, 0, 0, 0.7)'
100
+      })
94 101
       this.$refs[formName].validate((valid) => {
95 102
         if (valid) {
103
+          if (this.ruleForm.activityContent.length <= 0 && this.ruleForm.contentImg.length <= 0) {
104
+            this.$message.error('活动内容描述 和 活动配图至少要存在一个!')
105
+            return false
106
+          }
96 107
           this.ruleForm.status = 1 // 发布状态
108
+          this.$store.dispatch('AddActivity', this.ruleForm).then((res) => {
109
+            if (res.code === '0') {
110
+              this.$message({
111
+                message: res.message,
112
+                type: 'success'
113
+              })
114
+              this.$router.push({ name: 'activity-index' })
115
+              loading.close()
116
+              return
117
+            }
118
+            this.$message.error(res.message)
119
+            loading.close()
120
+          }).catch(() => {
121
+            console.log('error AddActivity')
122
+          })
97 123
         } else {
98 124
           console.log('error submit!!')
125
+          loading.close()
99 126
           return false
100 127
         }
101 128
       })

+ 200
- 3
VUECODE/smart-property-manage/src/views/social/activity/edi/index.vue Прегледај датотеку

@@ -1,13 +1,210 @@
1 1
 <template>
2
-  <div>修改</div>
2
+  <div id="root">
3
+    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-position="top" label-width="150px" class="ruleForm">
4
+      <el-form-item label="活动标题" prop="activityTitle">
5
+        <el-input v-model="ruleForm.activityTitle" placeholder="15字以内"/>
6
+      </el-form-item>
7
+      <el-form-item label="活动轮播图" prop="activityCarouselImg">
8
+        <el-upload
9
+          :show-file-list="false"
10
+          :on-success="handleAvatarSuccess"
11
+          :before-upload="beforeAvatarUpload"
12
+          class="avatar-uploader"
13
+          name="uploadFiles"
14
+          action="http://localhost:8086/property-api/uploadimage">
15
+          <img v-if="imageUrl" :src="imageUrl" class="avatar">
16
+          <i v-else class="el-icon-plus avatar-uploader-icon"/>
17
+        </el-upload>
18
+      </el-form-item>
19
+      <el-form-item label="活动详细描述">
20
+        <el-input v-model="ruleForm.activityContent" :rows="10" type="textarea" placeholder="活动内容, 活动规则, 活动举办开始时间, 活动举办结束时间, 报名人数上限等"/>
21
+      </el-form-item>
22
+      <el-form-item label="活动配图">
23
+        <el-upload
24
+          :on-preview="handlePictureCardPreview"
25
+          :on-remove="handleRemove"
26
+          :on-success="handleSuccessContentImg"
27
+          name="uploadFiles"
28
+          action="http://localhost:8086/property-api/uploadimage"
29
+          list-type="picture-card">
30
+          <i class="el-icon-plus"/>
31
+        </el-upload>
32
+        <el-dialog :visible.sync="dialogVisible">
33
+          <img :src="dialogImageUrl" width="100%" alt="">
34
+        </el-dialog>
35
+      </el-form-item>
36
+      <el-form-item label="报名人数上限" prop="signUpMax">
37
+        <el-input v-model="ruleForm.signUpMax" placeholder="填写0则不限制报名人数"/>
38
+      </el-form-item>
39
+      <el-form-item label="报名截止时间" prop="registrationEndTime">
40
+        <el-date-picker
41
+          v-model="ruleForm.registrationEndTime"
42
+          type="date"
43
+          placeholder="选择日期"/>
44
+      </el-form-item>
45
+      <el-form-item label="权重值" prop="sort">
46
+        <el-input-number v-model="ruleForm.sort" :min="1" :max="10" label="权重值" @change="sortHandleChange"/>
47
+      </el-form-item>
48
+      <el-form-item>
49
+        <el-button @click="resetForm('ruleForm')">存为草稿</el-button>
50
+        <el-button type="primary" @click="submitForm('ruleForm')">发布</el-button>
51
+      </el-form-item>
52
+    </el-form>
53
+  </div>
3 54
 </template>
4 55
 
5 56
 <script>
6 57
 export default {
7
-  name: 'Index'
58
+  name: 'Index',
59
+  data() {
60
+    return {
61
+      ruleForm: {
62
+        id: '',
63
+        activityTitle: '',
64
+        activityCarouselImg: '', // 轮播图
65
+        activityContent: '', // 活动内容详细
66
+        contentImg: [], // 活动内容配图
67
+        signUpMax: '', //  活动人数上限
68
+        registrationEndTime: '', // 报名活动结束时间
69
+        sort: 1, // 权重
70
+        status: '' // 状态 0 是已作废 1 是已发布   2 是草稿 3 是已修改
71
+      },
72
+      imageUrl: '', // 轮播图预览
73
+      rules: {
74
+        activityTitle: [
75
+          { required: true, message: '请输入活动名称', trigger: 'blur' },
76
+          { min: 1, max: 15, message: '长度在 15 个字符以内', trigger: 'blur' }
77
+        ],
78
+        activityContent: [
79
+          { required: true, message: '活动详细描述', trigger: 'blur' }
80
+        ],
81
+        signUpMax: [
82
+          { required: true, message: '请输入报名人数上限', trigger: 'blur' }
83
+        ],
84
+        registrationEndTime: [
85
+          { type: 'date', required: true, message: '报名截止时间', trigger: 'change' }
86
+        ],
87
+        sort: [
88
+          { required: true, message: '请输入权重值', trigger: 'change' }
89
+        ]
90
+      }
91
+    }
92
+  },
93
+  methods: {
94
+    submitForm(formName) {
95
+      // 加载框
96
+      const loading = this.$loading({
97
+        lock: true,
98
+        text: 'Loading',
99
+        spinner: 'el-icon-loading',
100
+        background: 'rgba(0, 0, 0, 0.7)'
101
+      })
102
+      this.$refs[formName].validate((valid) => {
103
+        if (valid) {
104
+          if (this.ruleForm.activityContent.length <= 0 && this.ruleForm.contentImg.length <= 0) {
105
+            this.$message.error('活动内容描述 和 活动配图至少要存在一个!')
106
+            return false
107
+          }
108
+          this.ruleForm.status = 1 // 发布状态
109
+          this.$store.dispatch('UpdateActivity', this.ruleForm).then((res) => {
110
+            if (res.code === '0') {
111
+              this.$message({
112
+                message: res.message,
113
+                type: 'success'
114
+              })
115
+              this.$router.push({ name: 'activity-index' })
116
+              loading.close()
117
+              return
118
+            }
119
+            this.$message.error(res.message)
120
+            loading.close()
121
+          }).catch(() => {
122
+            console.log('error UpdateActivity')
123
+          })
124
+        } else {
125
+          console.log('error submit!!')
126
+          loading.close()
127
+          return false
128
+        }
129
+      })
130
+    },
131
+    resetForm(formName) {
132
+      this.$refs[formName].resetFields()
133
+    },
134
+    handleAvatarSuccess(res, file) { // 轮播图上传回调
135
+      this.ruleForm.activityCarouselImg = res.data[0]
136
+      this.imageUrl = URL.createObjectURL(file.raw)
137
+    },
138
+    beforeAvatarUpload(file) { // 轮播图上传前操作
139
+      // const isJPG = file.type === 'image/jpeg'
140
+      // const isLt2M = file.size / 1024 / 1024 < 2
141
+      //
142
+      // if (!isJPG) {
143
+      //   this.$message.error('上传头像图片只能是 JPG 格式!')
144
+      // }
145
+      // if (!isLt2M) {
146
+      //   this.$message.error('上传头像图片大小不能超过 2MB!')
147
+      // }
148
+      // return isJPG && isLt2M
149
+    },
150
+    handleRemove(file, fileList) { // 活动配图移除时
151
+      this.ruleForm.contentImg = []
152
+      for (let i = 0; i < fileList.length; i++) {
153
+        this.ruleForm.contentImg.push(fileList[i].response.data[0])
154
+      }
155
+      console.log(file, fileList)
156
+    },
157
+    handlePictureCardPreview(file) { // 点击活动配图文件列表中已上传的文件时的钩子
158
+      this.dialogImageUrl = file.url
159
+      this.dialogVisible = true
160
+    },
161
+    handleSuccessContentImg(response, file, fileList) { // 活动配图上传成功时回调
162
+      const resImg = response.data[0]
163
+      this.ruleForm.contentImg.push(resImg)
164
+      console.log('上传活动配图成功时回调!')
165
+    },
166
+    sortHandleChange(value) { // 权重值
167
+      this.ruleForm.sort = value
168
+      console.log(value)
169
+    },
170
+    getById() { // 根据 id 查询活动详情
171
+
172
+    }
173
+  }
8 174
 }
9 175
 </script>
10 176
 
11 177
 <style scoped>
12
-
178
+#root {
179
+  display: flex;
180
+}
181
+.ruleForm {
182
+  width: 800px;
183
+  margin-left: auto;
184
+  margin-right: auto;
185
+  margin-top: 50px;
186
+}
187
+.avatar-uploader .el-upload {
188
+  border: 1px dashed #d9d9d9;
189
+  border-radius: 6px;
190
+  cursor: pointer;
191
+  position: relative;
192
+  overflow: hidden;
193
+}
194
+.avatar-uploader .el-upload:hover {
195
+  border-color: #409EFF;
196
+}
197
+.avatar-uploader-icon {
198
+  font-size: 28px;
199
+  color: #8c939d;
200
+  width: 178px;
201
+  height: 178px;
202
+  line-height: 178px;
203
+  text-align: center;
204
+}
205
+.avatar {
206
+  width: 178px;
207
+  height: 178px;
208
+  display: block;
209
+}
13 210
 </style>