ll
liukangdong
2024-10-18 e6acb39a2475e211f2c1decc45a95c868239c25f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<template>
  <GlobalAlertWindow v-loading="isUploading" :title="title" :visible.sync="visible" :confirm-working="isWorking"
    @confirm="confirm">
    <el-form :model="form" ref="form" :rules="rules" label-width="120px" label-suffix=":">
      <el-form-item label="会议室名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入会议室名称" :maxlength="10" v-trim />
      </el-form-item>
      <el-form-item label="开放时间" prop="timeRange">
        <el-time-picker is-range value-format="HH:mm" format="HH:mm" v-model="timeRange" range-separator="至"
          start-placeholder="开始时间" end-placeholder="结束时间" placeholder="选择时间范围" @change="selectRange"></el-time-picker>
      </el-form-item>
      <el-form-item label="粒度分钟" prop="intervalTime">
        <el-input v-model="form.intervalTime" type="number" placeholder="请输入时间粒度(分钟)" v-trim />
      </el-form-item>
      <el-form-item label="容纳人数" prop="limitNum">
        <el-input v-model="form.limitNum" type="number" placeholder="请输入容纳人数" v-trim />
      </el-form-item>
      <el-form-item label="管理员" prop="sysList">
        <el-select v-model="form.sysList" filterable multiple clearable placeholder="请选择部门">
          <!-- :label="`${item.department.name}-${item.realname}`" -->
          <el-option v-for="item in userList()" :key="item.id" :value="item.id"
            :label="item.companyId ? `${item.companyName}-${item.companyName}` : item.realname" />
        </el-select>
      </el-form-item>
      <el-form-item label="提供服务项目" prop="projectList">
        <el-checkbox-group v-model="form.projectList">
          <el-checkbox v-for="project in projectList" :label="project.id" :key="project.id">{{ project.name
            }}</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="空闲展示内容" prop="fileType">
        <el-radio v-model="form.fileType" @change="changeFile" :label="2">无</el-radio>
        <el-radio v-model="form.fileType" @change="changeFile" :label="0">图片</el-radio>
        <el-radio v-model="form.fileType" @change="changeFile" :label="1">视频</el-radio>
      </el-form-item>
      <el-form-item v-if="form.fileType == 0" label="展示图片" prop="imgurl">
        <div class="upload_wrap">
          <el-upload class="avatar-uploader" accept=".png,.jpg,.jpeg" :action="uploadImgUrl" :data="uploadData"
            :show-file-list="false" :on-success="handleImgSuccess">
            <div>
              <i class="el-icon-plus avatar-uploader-icon"></i>
            </div>
          </el-upload>
          <div v-for="item, i in form.multifileList" class="img_wrap">
            <img :src="item.fileurlFull" class="img">
            <i class="el-icon-error del" @click="imgDel(i)"></i>
          </div>
        </div>
      </el-form-item>
      <el-form-item v-if="form.fileType == 1" label="展示视频" prop="imgurl">
        <UploadAvatarVideo :file="{ 'videourlfull': form.videoFullUrl, 'videourl': form.videourl }" :uploadData="uploadData"
          @uploadSuccess="uploadAvatarSuccess" @uploadEnd="isUploading = false" @uploadBegin="isUploading = true" />
      </el-form-item>
      <el-form-item label="使用须知" prop="tips">
        <el-input v-model="form.tips" type="textarea" placeholder="请输入使用须知" v-trim />
      </el-form-item>
    </el-form>
  </GlobalAlertWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalAlertWindow from '@/components/common/GlobalAlertWindow'
import UploadAvatarVideo from '@/components/common/UploadAvatarVideo'
import { numRule } from '@/utils/form'
import { fetchList } from '@/api/meeting/projects'
export default {
  name: 'OperaRoomsWindow',
  extends: BaseOpera,
  components: { GlobalAlertWindow, UploadAvatarVideo },
  data() {
    let timeRangeRule = (rule, value, callBack) => {
      if (!this.form.startTime) {
        callBack(new Error('请选择开始时间'))
        return
      }
      if (!this.form.endTime) {
        callBack(new Error('请选择结束时间'))
        return
      }
      callBack()
    }
    return {
      uploadImgUrl: process.env.VUE_APP_API_PREFIX + '/visitsAdmin/cloudService/public/upload',
      isUploading: false,
      uploadData: {
        folder: 'projects'
      },
      timeRange: ['', ''],
      // 表单数据
      form: {
        id: null,
        sysList: [],
        multifileList: [],
        projectList: [],
        createDate: '',
        editor: '',
        editDate: null,
        isdeleted: 0,
        fileType: 2,
        name: '',
        remark: '',
        startTime: '',
        endTime: '',
        limitNum: 0,
        imgurl: '',
        imgFullUrl: '',
        tips: '',
        status: 0,
        intervalTime: 0
      },
      user: [],
      projectList: [],
      // 验证规则
      rules: {
        name: [
          { required: true, message: '请输入会议室名称', tigger: 'blur' }
        ],
        intervalTime: [
          { required: true, validator: numRule, message: '请输入时间粒度', tigger: 'blur' }
        ],
        timeRange: [
          { required: true, validator: timeRangeRule, tigger: 'change' }
        ]
      }
    }
  },
  inject: ['userList'],
  created() {
    this.config({
      api: '/meeting/rooms',
      'field.id': 'id'
    })
    // realname: this.filterText
    fetchList({
      page: 1,
      capacity: 9999,
      model: {},
    })
      .then(res => {
        this.projectList = res.records
      })
  },
  methods: {
    /**
     * 打开窗口
     * @title 窗口标题
     * @target 编辑的对象
     */
    open(title, target) {
      this.title = title
      this.visible = true
      this.timeRange = ['', '']
      // 新建
      if (target == null) {
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.form[this.configData['field.id']] = null
        })
        return
      }
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        if(target.fileType == 1 && target.multifileList && target.multifileList.length > 0){
          this.$set(this.form, 'videoFullUrl', target.multifileList[0].fileurlFull)
          this.$set(this.form, 'videourl', target.multifileList[0].fileurl)
        }
        this.timeRange = [target.startTime, target.endTime]
        this.form.projectList = this.form.projectList ? target.projectList.map(item => item.projectId) : []
        this.form.sysList = this.form.sysList ? this.form.sysList.map(item => item.userId) : []
        // console.log(this.form.imgFullUrl);
      })
    },
    imgDel(i) {
      this.form.multifileList.splice(i, 1)
    },
    handleImgSuccess(res) {
      const list = [...this.form.multifileList]
      if (res.code == 200) {
        let { data } = res
        list.push({
          fileurl: data.imgaddr,
          fileurlFull: data.url,
          type: 0
        })
        this.$set(this.form, 'multifileList', list)
 
      }
    },
    selectRange(v) {
      // console.log(this.timeRange);
      console.log(v)
      this.form.startTime = v[0]
      this.form.endTime = v[1]
      console.log(this.form.startTime, this.form.endTime)
    },
    changeFile() {
      this.$set(this.form, 'multifileList', [])
    },
    uploadAvatarSuccess(file) {
      console.log('file', file)
      this.form.multifileList.push({
        fileurl: file.imgurl,
        fileurlFull: file.imgurlfull,
        type: 1
      })
      this.$set(this.form, 'videourl', file.imgurl)
      this.$set(this.form, 'videoFullUrl', file.imgurlfull)
    },
    // 确认新建
    __confirmCreate() {
      this.$refs.form.validate((valid) => {
        // debugger
        if (!valid) {
          return
        }
        // console.log(this.form);
        // debugger
        // 调用新建接口
        this.isWorking = true
        let sysList = [...this.form.sysList]
        sysList = sysList.map(item => {
          return { userId: item }
        })
        let projectList = [...this.form.projectList]
        projectList = projectList.map(item => {
          return { projectId: item }
        })
        this.api.create({
          ...this.form,
          sysList,
          projectList
        })
          .then(() => {
            this.visible = false
            this.$tip.apiSuccess('新建成功')
            this.$emit('success')
          })
          .catch(e => {
            // this.$tip.apiFailed(e)
          })
          .finally(() => {
            this.isWorking = false
          })
      })
    },
    // 确认修改
    __confirmEdit() {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return
        }
        console.log(this.form)
        debugger
        // 调用新建接口
        this.isWorking = true
        let sysList = [...this.form.sysList]
        sysList = sysList.map(item => {
          return { userId: item }
        })
        let projectList = [...this.form.projectList]
        projectList = projectList.map(item => {
          return { projectId: item }
        })
        this.api.updateById({
          ...this.form,
          sysList,
          projectList
        })
          .then(() => {
            this.visible = false
            this.$tip.apiSuccess('修改成功')
            this.$emit('success')
          })
          .catch(e => {
            // this.$tip.apiFailed(e)
          })
          .finally(() => {
            this.isWorking = false
          })
      })
    }
  },
}
</script>
 
<style lang="scss" scoped>
$image-width: 90px;
 
.upload_wrap {
  display: flex;
 
  .img_wrap {
    margin-left: 10px;
    border: 1px dashed #d9d9d9;
    width: $image-width;
    height: $image-width;
    border-radius: 6px;
    position: relative;
 
    .img {
      width: $image-width;
      height: $image-width;
    }
 
    .del {
      position: absolute;
      top: -6px;
      right: -6px;
      cursor: pointer;
      color: red;
    }
  }
}
 
.avatar-uploader {
  width: $image-width;
  height: $image-width;
}
 
::v-deep .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
 
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
 
.avatar-uploader-icon {
  line-height: 90px;
  font-size: 28px;
  color: #8c939d;
  width: $image-width;
  height: $image-width;
  text-align: center;
}
 
.avatar {
  width: 90px;
  max-height: 90px;
  display: block;
}
</style>