Blame view

src/views/oa/addQuestionAnswerList.vue 8.39 KB
0bf7e6a5   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
  <template>
    <div class="add-question-answer-container">
      <el-card class="box-card">
        <div slot="header" class="flex justify-between">
          <span>{{ $t('addQuestionAnswer.title') }}</span>
        </div>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form ref="form" :model="addQuestionAnswerInfo" label-width="120px">
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('addQuestionAnswer.qaName')" prop="qaName">
                    <el-input v-model="addQuestionAnswerInfo.qaName"
                      :placeholder="$t('addQuestionAnswer.qaNamePlaceholder')" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('addQuestionAnswer.startTime')" prop="startTime">
                    <el-date-picker v-model="addQuestionAnswerInfo.startTime" type="datetime"
                      :placeholder="$t('addQuestionAnswer.startTimePlaceholder')" value-format="yyyy-MM-dd HH:mm:ss"
                      style="width: 100%" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('addQuestionAnswer.endTime')" prop="endTime">
                    <el-date-picker v-model="addQuestionAnswerInfo.endTime" type="datetime"
                      :placeholder="$t('addQuestionAnswer.endTimePlaceholder')" value-format="yyyy-MM-dd HH:mm:ss"
                      style="width: 100%" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <el-form-item :label="$t('addQuestionAnswer.content')">
                    <el-input v-model="addQuestionAnswerInfo.content" type="textarea" :rows="5"
                      :placeholder="$t('addQuestionAnswer.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('addQuestionAnswer.questionTitle') }}</span>
          <el-button type="primary" class="float-right" @click="chooseTitle">
            <i class="el-icon-search"></i>{{ $t('addQuestionAnswer.chooseTitle') }}
          </el-button>
        </div>
        <el-table :data="addQuestionAnswerInfo.questionTitles" border style="width: 100%">
2e81c59f   wuxw   完成办公功能测试
55
56
          <el-table-column prop="qaTitle" :label="$t('questionTitle.table.name')" align="center" />
          <el-table-column prop="titleType" :label="$t('questionTitle.table.type')" align="center">
0bf7e6a5   wuxw   加入问卷功能代码
57
58
59
60
            <template slot-scope="scope">
              {{ getTitleTypeName(scope.row.titleType) }}
            </template>
          </el-table-column>
2e81c59f   wuxw   完成办公功能测试
61
          <el-table-column :label="$t('questionTitle.table.options')" align="center">
0bf7e6a5   wuxw   加入问卷功能代码
62
63
64
65
66
67
            <template slot-scope="scope">
              <div v-for="(item, index) in scope.row.titleValues" :key="index">
                {{ item.seq }}、{{ item.qaValue }}
              </div>
            </template>
          </el-table-column>
2e81c59f   wuxw   完成办公功能测试
68
          <el-table-column :label="$t('common.operation')" align="center" width="150">
0bf7e6a5   wuxw   加入问卷功能代码
69
70
            <template slot-scope="scope">
              <el-button type="danger" size="mini" @click="openDeleteQuestionTitle(scope.row)">
2e81c59f   wuxw   完成办公功能测试
71
                {{ $t('common.delete') }}
0bf7e6a5   wuxw   加入问卷功能代码
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
              </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('addQuestionAnswer.questionRoom') }}</span>
        </div>
        <el-row>
          <el-col :span="24">
            <el-form>
              <el-form-item :label="$t('addQuestionAnswer.questionRoom')">
                <select-rooms ref="selectRooms" @notifySelectRooms="handleSelectRooms" />
              </el-form-item>
            </el-form>
          </el-col>
        </el-row>
      </el-card>
  
      <div class="action-buttons margin-top">
        <el-button type="primary" @click="saveQuestionAnswer">
          <i class="el-icon-check"></i>{{ $t('common.save') }}
        </el-button>
        <el-button type="warning" @click="goBack">
          {{ $t('common.cancel') }}
        </el-button>
      </div>
  
      <choose-question-title ref="chooseQuestionTitle" @chooseQuestionTitle="handleChooseQuestionTitle" />
    </div>
  </template>
  
  <script>
  import SelectRooms from '@/components/room/selectRooms'
  import ChooseQuestionTitle from '@/components/oa/chooseQuestionTitle'
  import { saveQuestionAnswer } from '@/api/oa/addQuestionAnswerApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'AddQuestionAnswer',
    components: {
      SelectRooms,
      ChooseQuestionTitle
    },
    data() {
      return {
        addQuestionAnswerInfo: {
          qaName: '',
          startTime: '',
          endTime: '',
          communityId: '',
          content: '',
          questionTitles: [],
          roomIds: []
        }
      }
    },
    created() {
      this.addQuestionAnswerInfo.communityId = getCommunityId()
    },
    methods: {
      getTitleTypeName(titleType) {
        if (titleType === '1001') {
2e81c59f   wuxw   完成办公功能测试
137
          return this.$t('questionTitle.types.singleChoice')
0bf7e6a5   wuxw   加入问卷功能代码
138
        } else if (titleType === '2002') {
2e81c59f   wuxw   完成办公功能测试
139
          return this.$t('questionTitle.types.multipleChoice')
0bf7e6a5   wuxw   加入问卷功能代码
140
        } else {
2e81c59f   wuxw   完成办公功能测试
141
          return this.$t('questionTitle.types.shortAnswer')
0bf7e6a5   wuxw   加入问卷功能代码
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
        }
      },
      chooseTitle() {
        this.$refs.chooseQuestionTitle.open()
      },
      handleChooseQuestionTitle(questionTitle) {
        const hasTitle = this.addQuestionAnswerInfo.questionTitles.some(
          item => item.titleId === questionTitle.titleId
        )
        if (hasTitle) {
          this.$message.warning(this.$t('addQuestionAnswer.titleExist'))
          return
        }
        this.addQuestionAnswerInfo.questionTitles.push(questionTitle)
      },
      openDeleteQuestionTitle(title) {
        this.$confirm(
          this.$t('addQuestionAnswer.confirmDeleteTitle'),
          this.$t('common.tip'),
          {
            confirmButtonText: this.$t('common.confirm'),
            cancelButtonText: this.$t('common.cancel'),
            type: 'warning'
          }
        ).then(() => {
          this.addQuestionAnswerInfo.questionTitles = this.addQuestionAnswerInfo.questionTitles.filter(
            item => item.titleId !== title.titleId
          )
        })
      },
      handleSelectRooms(rooms) {
        this.addQuestionAnswerInfo.roomIds = rooms.map(item => item.roomId)
      },
      validateForm() {
        if (!this.addQuestionAnswerInfo.qaName) {
          this.$message.warning(this.$t('addQuestionAnswer.qaNameRequired'))
          return false
        }
        if (!this.addQuestionAnswerInfo.startTime) {
          this.$message.warning(this.$t('addQuestionAnswer.startTimeRequired'))
          return false
        }
        if (!this.addQuestionAnswerInfo.endTime) {
          this.$message.warning(this.$t('addQuestionAnswer.endTimeRequired'))
          return false
        }
        if (this.addQuestionAnswerInfo.startTime >= this.addQuestionAnswerInfo.endTime) {
          this.$message.warning(this.$t('addQuestionAnswer.timeInvalid'))
          return false
        }
        if (!this.addQuestionAnswerInfo.content) {
          this.$message.warning(this.$t('addQuestionAnswer.contentRequired'))
          return false
        }
        if (this.addQuestionAnswerInfo.questionTitles.length === 0) {
          this.$message.warning(this.$t('addQuestionAnswer.titleRequired'))
          return false
        }
        if (this.addQuestionAnswerInfo.roomIds.length === 0) {
          this.$message.warning(this.$t('addQuestionAnswer.roomRequired'))
          return false
        }
        return true
      },
      async saveQuestionAnswer() {
        if (!this.validateForm()) return
  
        try {
          const res = await saveQuestionAnswer(this.addQuestionAnswerInfo)
          if (res.code === 0) {
            this.$message.success(this.$t('addQuestionAnswer.saveSuccess'))
            this.goBack()
          } else {
            this.$message.error(res.msg)
          }
        } catch (error) {
          this.$message.error(this.$t('addQuestionAnswer.saveError'))
        }
      },
      goBack() {
        this.$router.go(-1)
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .add-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;
      padding: 20px;
      background: #fff;
      border-radius: 4px;
    }
  }
  </style>