Blame view

src/views/oa/addOwnerVotingList.vue 7.21 KB
a99eb7a5   wuxw   开发完成办公下功能
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
  <template>
    <div class="add-owner-voting-container">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>{{ $t('addOwnerVoting.title') }}</span>
        </div>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form ref="form" :model="addOwnerVotingInfo" label-width="120px">
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item :label="$t('addOwnerVoting.voteName')" prop="qaName">
                    <el-input v-model="addOwnerVotingInfo.qaName" :placeholder="$t('addOwnerVoting.voteNamePlaceholder')" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('addOwnerVoting.type')" prop="titleType">
                    <el-select v-model="addOwnerVotingInfo.titleType" :placeholder="$t('addOwnerVoting.typePlaceholder')"
                      style="width:100%" @change="changeAddTitleType">
                      <el-option :label="$t('addOwnerVoting.singleChoice')" value="1001" />
                      <el-option :label="$t('addOwnerVoting.multipleChoice')" value="2002" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
  
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item :label="$t('addOwnerVoting.startTime')" prop="startTime">
                    <el-date-picker v-model="addOwnerVotingInfo.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                      :placeholder="$t('addOwnerVoting.startTimePlaceholder')" style="width:100%" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('addOwnerVoting.endTime')" prop="endTime">
                    <el-date-picker v-model="addOwnerVotingInfo.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                      :placeholder="$t('addOwnerVoting.endTimePlaceholder')" style="width:100%" />
                  </el-form-item>
                </el-col>
              </el-row>
  
              <el-row v-for="(item, index) in addOwnerVotingInfo.titleValues" :key="index" :gutter="20">
                <el-col :span="12">
                  <el-form-item :label="$t('addOwnerVoting.option') + item.seq">
                    <el-input v-model="item.itemValue" :placeholder="$t('addOwnerVoting.optionPlaceholder')" />
                  </el-form-item>
                </el-col>
                <el-col :span="4">
                  <el-button v-if="index === addOwnerVotingInfo.titleValues.length - 1" type="text" @click="addTitleValue">
                    {{ $t('addOwnerVoting.addOption') }}
                  </el-button>
                  <el-button v-else type="text" @click="deleteTitleValue(item.seq)">
                    {{ $t('addOwnerVoting.deleteOption') }}
                  </el-button>
                </el-col>
              </el-row>
  
              <el-row :gutter="20">
                <el-col :span="24">
                  <el-form-item :label="$t('addOwnerVoting.voteDescription')">
                    <el-input v-model="addOwnerVotingInfo.content" type="textarea" :rows="4"
                      :placeholder="$t('addOwnerVoting.voteDescriptionPlaceholder')" />
                  </el-form-item>
                </el-col>
              </el-row>
  
              <el-row :gutter="20">
                <el-col :span="24">
                  <el-form>
                    <el-form-item :label="$t('addOwnerVoting.voteRooms')">
                      <SelectRooms ref="selectRooms" @notifySelectRooms="handleSelectRooms" />
                    </el-form-item>
                  </el-form>
                </el-col>
              </el-row>
  
              <el-row :gutter="20">
                <el-col :span="24" class="text-right">
                  <el-button type="warning" @click="goBack">
                    {{ $t('common.cancel') }}
                  </el-button>
                  <el-button type="primary" @click="saveOwnerVoting">
                    <i class="el-icon-check" /> {{ $t('common.save') }}
                  </el-button>
                </el-col>
              </el-row>
            </el-form>
          </el-col>
        </el-row>
      </el-card>
    </div>
  </template>
  
  <script>
  import SelectRooms from '@/components/room/selectRooms'
  import { saveOwnerVote } from '@/api/oa/addOwnerVotingApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'AddOwnerVoting',
    components: {
      SelectRooms
    },
    data() {
      return {
        addOwnerVotingInfo: {
          qaName: '',
          startTime: '',
          endTime: '',
          communityId: '',
          content: '',
          titleType: '',
          titleValues: [],
          roomIds: []
        }
      }
    },
    created() {
      this.addOwnerVotingInfo.communityId = getCommunityId()
    },
    methods: {
      handleSelectRooms(rooms) {
        this.addOwnerVotingInfo.roomIds = rooms.map(item => item.roomId)
      },
      validateForm() {
        if (!this.addOwnerVotingInfo.qaName) {
          this.$message.error(this.$t('addOwnerVoting.validate.voteName'))
          return false
        }
        if (!this.addOwnerVotingInfo.titleType) {
          this.$message.error(this.$t('addOwnerVoting.validate.type'))
          return false
        }
        if (!this.addOwnerVotingInfo.startTime) {
          this.$message.error(this.$t('addOwnerVoting.validate.startTime'))
          return false
        }
        if (!this.addOwnerVotingInfo.endTime) {
          this.$message.error(this.$t('addOwnerVoting.validate.endTime'))
          return false
        }
        if (this.addOwnerVotingInfo.titleValues.some(item => !item.itemValue)) {
          this.$message.error(this.$t('addOwnerVoting.validate.option'))
          return false
        }
        return true
      },
      async saveOwnerVoting() {
        if (!this.validateForm()) return
  
        try {
          const res = await saveOwnerVote(this.addOwnerVotingInfo)
          if (res.code === 0) {
            this.$message.success(this.$t('common.saveSuccess'))
            this.$router.go(-1)
          } else {
            this.$message.error(res.msg)
          }
        } catch (error) {
          this.$message.error(this.$t('common.saveError'))
        }
      },
      changeAddTitleType() {
        const type = this.addOwnerVotingInfo.titleType
        if (type === '1001') {
          this.addOwnerVotingInfo.titleValues = [{
            itemValue: '',
            seq: 1
          }]
        } else if (type === '2002') {
          this.addOwnerVotingInfo.titleValues = [
            {
              itemValue: '',
              seq: 1
            },
            {
              itemValue: '',
              seq: 2
            }
          ]
        } else {
          this.addOwnerVotingInfo.titleValues = []
        }
      },
      addTitleValue() {
        this.addOwnerVotingInfo.titleValues.push({
          itemValue: '',
          seq: this.addOwnerVotingInfo.titleValues.length + 1
        })
      },
      deleteTitleValue(seq) {
        this.addOwnerVotingInfo.titleValues = this.addOwnerVotingInfo.titleValues
          .filter(item => item.seq !== seq)
          .map((item, index) => ({
            ...item,
            seq: index + 1
          }))
      },
      goBack() {
        this.$router.go(-1)
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .add-owner-voting-container {
    padding: 20px;
  
    .box-card {
      margin-bottom: 20px;
    }
  
    .text-right {
      text-align: right;
    }
  }
  </style>