MrShi
2025-09-15 856f526f823f5dad88c28657d82f971ff66afb1e
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
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    width="690px"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="售后建议:" prop="symptomId">
        <div style="width: 600px;">
          <el-select v-model="form.symptomId" placeholder="请选择" clearable>
            <el-option
              v-for="item in problemLsit"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            ></el-option>
          </el-select>
        </div>
      </el-form-item>
      <div v-for="(item, index) in symptomOptDTOList" :key="index">
        <el-form-item :label='`${index}.${item.title}`'>
          <div v-if="!item.hasChild" class="option-list">
            <div
              v-for="(option, i) in item.opts"
              :key="i"
              class="option"
              @click="option.hasSelect=!option.hasSelect"
              :class="option.hasSelect ? 'option-sel':''"
            >{{ option.name }}</div>
          </div>
          <div v-else>
            <div v-for="(subItem, j) in item.childQuestionVOS" :key="j" style="display: flex;margin-bottom: 5px;">
              <div>{{ subItem.title }}:</div>
              <div class="option-list">
                <div
                  v-for="(option, i) in subItem.opts"
                  :key="i"
                  class="option"
                  @click="option.hasSelect=!option.hasSelect"
                  :class="option.hasSelect ? 'option-sel':''"
                >{{ option.name }}</div>
              </div>
            </div>
          </div>
        </el-form-item>
      </div>
      
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import UploadAvatarImage from '@/components/common/UploadAvatarImage'
import FileLink from '@/components/common/FileLink.vue'
import { findAllListByType } from '@/api/business/symptom'
import { numRule } from '@/utils/form'
export default {
  name: 'OperaSuggestValueDetailWindow',
  extends: BaseOpera,
  components: { GlobalWindow, UploadAvatarImage, FileLink },
  data () {
    return {
      // 表单数据
      form: {
        id: null,
        symptomId: '',
        aliDiagnosisId: '',
      },
      symptomOptDTOList: [],
      problemLsit: [],
      // 验证规则
      rules: {
        symptomId: [
         { required: true, validator: numRule, message: '请选择售后建议', tigger: 'change' }
        ],
      }
    }
  },
  created () {
    this.config({
      api: '/business/symptomMatch',
      'field.id': 'id'
    })
    findAllListByType({type: 1})
      .then(res => {
        this.problemLsit = res
      })
    
  },
  methods: {
    open (title, target, symptomOptDTOList) {
      this.title = title
      this.visible = true
      this.symptomOptDTOList = JSON.parse(JSON.stringify(symptomOptDTOList))
      // 新建
      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]
        }
        this.symptomOptDTOList = target.symptomQuestionVO
        this.symptomOptDTOList.forEach(item => {
          item.symptomOpt = item.symptomOpt||[]
          item.opts = item.opts||[]
          if (item.hasChild) {
            item.childQuestionVOS.forEach(element => {
              console.log(element);
              element.opts && element.opts.forEach(e => {
                e.hasSelect = element.symptomOpt.indexOf(e.id) != -1
              })
            })
          } else {
            item.opts.forEach(e => {
              e.hasSelect = item.symptomOpt.indexOf(e.id) != -1
            })  
          }
        })
      })
    },
    // 确认新建
    __confirmCreate () {
      this.$refs.form.validate((valid) => {
        // debugger
        if (!valid) {
          return
        }
        // 调用新建接口
        this.isWorking = true
        let symptomOptDTOList = this.setOption()
        this.api.create({...this.form, symptomOptDTOList, type: 1 })
          .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
        }
        // 调用新建接口
        this.isWorking = true
        let symptomOptDTOList = this.setOption()
        this.api.updateById({...this.form, symptomOptDTOList, type: 1 })
          .then(() => {
            this.visible = false
            this.$tip.apiSuccess('修改成功')
            this.$emit('success')
          })
          .catch(e => {
            this.$tip.apiFailed(e)
          })
          .finally(() => {
            this.isWorking = false
          })
      })
    },
    setOption() {
      let symptomOptDTOList = []
        this.symptomOptDTOList.forEach(item => {
          if (item.hasChild) {
            item.childQuestionVOS.forEach(element => {
              // element.map(element1 => {
                let opts = element.opts.filter(a => a.hasSelect)
                                       .map(e => e.id)
                                      //  debugger
                // if (opts.length) {
                // }
                symptomOptDTOList.push(
                  {
                    // id: item.oldId,
                    questionId: element.id,
                    optIds: opts.join(','),
                  }
                ) 
              // })
            });
          } else {
            let opts = item.opts.filter(a => a.hasSelect)
                                    .map(e => e.id)
                                    // debugger
            // if (opts.length) {
            // }
            symptomOptDTOList.push(
              {
                // id: item.oldId,
                questionId: item.id,
                optIds: opts.join(',')
              }
            ) 
          }
        })
      return symptomOptDTOList
    }
  }
}
/**
 * 
 */
</script>
 
<style lang="scss" scoped>
// @import "@/assets/style/alertstyle.scss";
::v-deep .el-input__inner {
  width: 600px;
}
::v-deep .el-textarea__inner {
  width: 600px;
}
.option-list {
  display: flex;
  flex-wrap: wrap;
  .option {
    box-sizing: border-box;
    border: 1px solid #999;
    min-width: 60px;
    height: 30px;
    line-height: 20px;
    padding: 5px;
    border-radius: 4px;
    color: #111;
    text-align: center;
    margin-right: 5px;
    cursor: pointer;
  }
  .option-sel {
    border: 1px solid #216EEE;
    background-color: #216EEE;
    color: white;
  }
}
</style>