Blame view

src/views/oa/editQuestionAnswerList.vue 9.28 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
0bf7e6a5   wuxw   加入问卷功能代码
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    <div class="edit-question-answer-container">
      <el-card class="box-card">
        <div slot="header" class="flex justify-between">
          <span>{{ $t('editQuestionAnswer.title') }}</span>
        </div>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form ref="form" :model="editQuestionAnswerInfo" label-width="120px">
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('editQuestionAnswer.qaName')" prop="qaName">
                    <el-input v-model="editQuestionAnswerInfo.qaName"
                      :placeholder="$t('editQuestionAnswer.qaNamePlaceholder')" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('editQuestionAnswer.startTime')" prop="startTime">
b25b036d   wuxw   v1.9 优化日期
19
                    <el-date-picker v-model="editQuestionAnswerInfo.startTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"                    :placeholder="$t('editQuestionAnswer.startTimePlaceholder')" style="width: 100%"  />
0bf7e6a5   wuxw   加入问卷功能代码
20
21
22
23
24
25
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('editQuestionAnswer.endTime')" prop="endTime">
b25b036d   wuxw   v1.9 优化日期
26
                    <el-date-picker v-model="editQuestionAnswerInfo.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss"                    :placeholder="$t('editQuestionAnswer.endTimePlaceholder')" style="width: 100%"  />
0bf7e6a5   wuxw   加入问卷功能代码
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
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item :label="$t('editQuestionAnswer.content')">
                    <el-input v-model="editQuestionAnswerInfo.content" type="textarea" :rows="5"
                      :placeholder="$t('editQuestionAnswer.contentPlaceholder')" />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-col>
        </el-row>
      </el-card>
  
      <el-card class="box-card margin-top">
        <div slot="header" class="flex justify-between">
          <span>{{ $t('editQuestionAnswer.questionTitle') }}</span>
          <div class="float-right">
            <el-button type="primary" @click="chooseTitle">
              <i class="el-icon-search"></i>{{ $t('editQuestionAnswer.chooseTitle') }}
            </el-button>
          </div>
        </div>
        <el-table :data="editQuestionAnswerInfo.questionTitles" border style="width: 100%">
          <el-table-column prop="qaTitle" :label="$t('editQuestionAnswer.table.name')" align="center" />
          <el-table-column prop="titleType" :label="$t('editQuestionAnswer.table.type')" align="center">
            <template slot-scope="scope">
              {{ getTitleTypeName(scope.row.titleType) }}
            </template>
          </el-table-column>
          <el-table-column :label="$t('editQuestionAnswer.table.options')" align="center">
            <template slot-scope="scope">
              <div v-for="(item, index) in scope.row.titleValues" :key="index">
                {{ item.seq }}、{{ item.qaValue }}
              </div>
            </template>
          </el-table-column>
          <el-table-column :label="$t('editQuestionAnswer.table.actions')" align="center">
            <template slot-scope="scope">
              <el-button type="danger" size="mini" @click="openDeleteQuestionTitle(scope.row)">
                {{ $t('editQuestionAnswer.table.delete') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
  
      <el-card class="box-card margin-top">
        <div slot="header" class="flex justify-between">
          <span>{{ $t('editQuestionAnswer.questionRooms') }}</span>
        </div>
        <el-row>
          <el-col :span="24">
            <el-form>
            <el-form-item :label="$t('editQuestionAnswer.questionRooms')">
              <div v-if="editQuestionAnswerInfo.updateRoomIds">
                <select-rooms ref="selectRooms" @notifySelectRooms="handleSelectRooms" />
              </div>
              <div v-else>
                <span>{{ editQuestionAnswerInfo.voteCount }}{{ $t('editQuestionAnswer.household') }}</span>
                <el-button type="text" @click="updateRoomIdsMethod">
                  {{ $t('editQuestionAnswer.reselect') }}
                </el-button>
              </div>
            </el-form-item>
          </el-form>
          </el-col>
        </el-row>
      </el-card>
  
      <div class="action-buttons margin-top">
        <el-button type="primary" @click="updateQuestionAnswer">
          <i class="el-icon-check"></i>{{ $t('editQuestionAnswer.save') }}
        </el-button>
        <el-button type="warning" @click="goBack">
          {{ $t('editQuestionAnswer.cancel') }}
        </el-button>
      </div>
  
      <choose-question-title ref="chooseQuestionTitle" @chooseQuestionTitle="handleChooseQuestionTitle" />
    </div>
  </template>
  
  <script>
  import { getCommunityId } from '@/api/community/communityApi'
  import SelectRooms from '@/components/room/selectRooms'
  import ChooseQuestionTitle from '@/components/oa/chooseQuestionTitle'
  import { updateQuestionAnswer, listQuestionAnswer, listQuestionTitle } from '@/api/oa/editQuestionAnswerApi'
  
  export default {
    name: 'EditQuestionAnswerList',
    components: {
      SelectRooms,
      ChooseQuestionTitle
    },
    data() {
      return {
        editQuestionAnswerInfo: {
          qaName: '',
          startTime: '',
          endTime: '',
          communityId: '',
          content: '',
          titleType: '',
          questionTitles: [],
          roomIds: [],
          updateRoomIds: false,
          voteCount: 0,
          qaId: ''
        }
      }
    },
    created() {
      this.editQuestionAnswerInfo.communityId = getCommunityId()
      this.editQuestionAnswerInfo.qaId = this.$route.query.qaId
      this.loadQuestionAnswerInfo()
      this.loadQuestionTitles()
    },
    methods: {
      async loadQuestionAnswerInfo() {
        try {
          const params = {
            page: 1,
            row: 1,
            communityId: this.editQuestionAnswerInfo.communityId,
            qaId: this.editQuestionAnswerInfo.qaId
          }
          const { data } = await listQuestionAnswer(params)
          this.editQuestionAnswerInfo = { ...this.editQuestionAnswerInfo, ...data[0] }
        } catch (error) {
          console.error('Failed to load question answer info:', error)
        }
      },
      async loadQuestionTitles() {
        try {
          const params = {
            page: 1,
            row: 100,
            communityId: this.editQuestionAnswerInfo.communityId,
            qaId: this.editQuestionAnswerInfo.qaId
          }
          const { data } = await listQuestionTitle(params)
          this.editQuestionAnswerInfo.questionTitles = data
        } catch (error) {
          console.error('Failed to load question titles:', error)
        }
      },
      getTitleTypeName(titleType) {
        if (titleType === '1001') {
          return this.$t('editQuestionAnswer.singleChoice')
        } else if (titleType === '2002') {
          return this.$t('editQuestionAnswer.multipleChoice')
        } else {
          return this.$t('editQuestionAnswer.shortAnswer')
        }
      },
      chooseTitle() {
        this.$refs.chooseQuestionTitle.open()
      },
      handleChooseQuestionTitle(questionTitle) {
        const exists = this.editQuestionAnswerInfo.questionTitles.some(
          item => item.titleId === questionTitle.titleId
        )
        if (exists) {
          this.$message.warning(this.$t('editQuestionAnswer.duplicateTitle'))
          return
        }
        this.editQuestionAnswerInfo.questionTitles.push(questionTitle)
      },
      openDeleteQuestionTitle(title) {
        this.editQuestionAnswerInfo.questionTitles = this.editQuestionAnswerInfo.questionTitles.filter(
          item => item.titleId !== title.titleId
        )
      },
      updateRoomIdsMethod() {
        this.editQuestionAnswerInfo.updateRoomIds = true
      },
      handleSelectRooms(selectRooms) {
        this.editQuestionAnswerInfo.roomIds = selectRooms.map(item => item.roomId)
      },
      validateForm() {
        if (!this.editQuestionAnswerInfo.qaName) {
          this.$message.error(this.$t('editQuestionAnswer.validate.qaName'))
          return false
        }
        if (!this.editQuestionAnswerInfo.startTime) {
          this.$message.error(this.$t('editQuestionAnswer.validate.startTime'))
          return false
        }
        if (!this.editQuestionAnswerInfo.endTime) {
          this.$message.error(this.$t('editQuestionAnswer.validate.endTime'))
          return false
        }
        if (new Date(this.editQuestionAnswerInfo.startTime) >= new Date(this.editQuestionAnswerInfo.endTime)) {
          this.$message.error(this.$t('editQuestionAnswer.validate.timeError'))
          return false
        }
        return true
      },
      async updateQuestionAnswer() {
        if (!this.validateForm()) return
  
        try {
          await updateQuestionAnswer(this.editQuestionAnswerInfo)
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
233
          this.$message.success(this.$t('common.operationSuccess'))
0bf7e6a5   wuxw   加入问卷功能代码
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
          this.goBack()
        } catch (error) {
          console.error('Failed to update question answer:', error)
          this.$message.error(error.message || this.$t('editQuestionAnswer.updateFailed'))
        }
      },
      goBack() {
        this.$router.go(-1)
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .edit-question-answer-container {
    padding: 20px;
  
    .box-card {
      margin-bottom: 20px;
    }
  
    .margin-top {
      margin-top: 20px;
    }
  
    .float-right {
      float: right;
    }
  
    .action-buttons {
      text-align: right;
      margin-top: 20px;
    }
  }
  </style>