Blame view

src/views/oa/editOwnerVotingList.vue 6.84 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
  <template>
    <div class="edit-owner-voting-container">
      <el-card>
        <div slot="header" class="clearfix">
          <span>{{ $t('editOwnerVoting.title') }}</span>
        </div>
  
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form ref="form" :model="editOwnerVotingInfo" label-width="120px">
              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item :label="$t('editOwnerVoting.voteName')" prop="qaName">
                    <el-input v-model="editOwnerVotingInfo.qaName" :placeholder="$t('editOwnerVoting.voteNamePlaceholder')"
                      clearable />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('editOwnerVoting.type')" prop="titleType">
                    <el-select v-model="editOwnerVotingInfo.titleType" :placeholder="$t('editOwnerVoting.typePlaceholder')"
                      @change="changeAddTitleType" style="width:100%">
                      <el-option :label="$t('editOwnerVoting.singleChoice')" value="1001" />
                      <el-option :label="$t('editOwnerVoting.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('editOwnerVoting.startTime')" prop="startTime">
                    <el-date-picker v-model="editOwnerVotingInfo.startTime" type="datetime"  value-format="yyyy-MM-dd HH:mm:ss"
                      :placeholder="$t('editOwnerVoting.startTimePlaceholder')" style="width:100%" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('editOwnerVoting.endTime')" prop="endTime">
                    <el-date-picker v-model="editOwnerVotingInfo.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
                      :placeholder="$t('editOwnerVoting.endTimePlaceholder')" style="width:100%" />
                  </el-form-item>
                </el-col>
              </el-row>
  
              <el-form-item v-for="(item, index) in editOwnerVotingInfo.titleValues" :key="index"
                :label="`${$t('editOwnerVoting.option')}${item.seq}`">
                <el-row :gutter="20">
                  <el-col :span="18">
                    <el-input v-model="item.qaValue" :placeholder="$t('editOwnerVoting.optionPlaceholder')" />
                  </el-col>
                  <el-col :span="5">
                    <el-button v-if="index === editOwnerVotingInfo.titleValues.length - 1" type="text" @click="addTitleValue">
                      {{ $t('editOwnerVoting.addOption') }}
                    </el-button>
                    <el-button v-else type="text" @click="deleteTitleValue(item.seq)">
                      {{ $t('editOwnerVoting.deleteOption') }}
                    </el-button>
                  </el-col>
                </el-row>
              </el-form-item>
  
              <el-form-item :label="$t('editOwnerVoting.description')">
                <el-input type="textarea" :rows="5" v-model="editOwnerVotingInfo.content"
                  :placeholder="$t('editOwnerVoting.descriptionPlaceholder')" />
              </el-form-item>
  
              <el-form-item :label="$t('editOwnerVoting.voteRooms')">
                <div v-show="editOwnerVotingInfo.updateRoomIds">
                  <select-rooms ref="selectRooms" @notifySelectRooms="handleSelectRooms" />
                </div>
                <div v-if="!editOwnerVotingInfo.updateRoomIds">
                  <span>{{ editOwnerVotingInfo.voteCount }}{{ $t('editOwnerVoting.houseVote') }}</span>
                  <el-button type="text" @click="updateRoomIdsMethod">
                    {{ $t('editOwnerVoting.reselect') }}
                  </el-button>
                </div>
              </el-form-item>
  
              <el-form-item>
                <el-button type="primary" @click="saveOwnerVoting">
                  <i class="el-icon-check"></i>&nbsp;{{ $t('common.save') }}
                </el-button>
                <el-button type="warning" @click="goBack">
                  {{ $t('common.cancel') }}
                </el-button>
              </el-form-item>
            </el-form>
          </el-col>
        </el-row>
      </el-card>
    </div>
  </template>
  
  <script>
  import SelectRooms from '@/components/room/selectRooms'
  import { updateOwnerVote, listOwnerVote } from '@/api/oa/editOwnerVotingApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'EditOwnerVotingList',
    components: {
      SelectRooms
    },
    data() {
      return {
        editOwnerVotingInfo: {
          qaId: '',
          qaName: '',
          startTime: '',
          endTime: '',
          communityId: '',
          content: '',
          titleType: '',
          titleValues: [],
          roomIds: [],
          updateRoomIds: false,
          voteCount: 0
        }
      }
    },
    created() {
      this.communityId = getCommunityId()
      this.editOwnerVotingInfo.qaId = this.$route.query.qaId
      this.loadOwnerVoting()
    },
    methods: {
      async loadOwnerVoting() {
        try {
          const params = {
            page: 1,
            row: 1,
            qaId: this.editOwnerVotingInfo.qaId,
            communityId: this.communityId
          }
          const { data } = await listOwnerVote(params)
          Object.assign(this.editOwnerVotingInfo, data[0])
        } catch (error) {
          console.error('Failed to load voting data:', error)
        }
      },
      handleSelectRooms(selectRooms) {
        this.editOwnerVotingInfo.roomIds = selectRooms.map(item => item.roomId)
      },
      
      async saveOwnerVoting() {
  
  
        try {
          await updateOwnerVote(this.editOwnerVotingInfo)
          this.$message.success(this.$t('editOwnerVoting.saveSuccess'))
          this.goBack()
        } catch (error) {
          this.$message.error(error.message || this.$t('editOwnerVoting.saveFailed'))
        }
      },
      changeAddTitleType() {
        const type = this.editOwnerVotingInfo.titleType
        if (type === '1001') {
          this.editOwnerVotingInfo.titleValues = [{ qaValue: '', seq: 1 }]
        } else if (type === '2002') {
          this.editOwnerVotingInfo.titleValues = [
            { qaValue: '', seq: 1 },
            { qaValue: '', seq: 2 }
          ]
        }
      },
      addTitleValue() {
        this.editOwnerVotingInfo.titleValues.push({
          qaValue: '',
          seq: this.editOwnerVotingInfo.titleValues.length + 1
        })
      },
      deleteTitleValue(seq) {
        this.editOwnerVotingInfo.titleValues = this.editOwnerVotingInfo.titleValues
          .filter(item => item.seq !== seq)
          .map((item, index) => ({ ...item, seq: index + 1 }))
      },
      updateRoomIdsMethod() {
        this.editOwnerVotingInfo.updateRoomIds = true
        this.$nextTick(() => {
          this.$refs.selectRooms.open()
        })
      },
      goBack() {
        this.$router.go(-1)
      }
    }
  }
  </script>
  
  <style scoped>
  .edit-owner-voting-container {
    padding: 20px;
  }
  </style>