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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<template>
  <div>
    <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" v-model="formDia" title="客户满意度调查表"
      width="70%" @close="closeFormDia">
      <table border="1" cellspacing="10" class="tables">
        <tr>
          <td class="td-title">
            <p>单位名称:</p>
          </td>
          <td class="td-info" colspan="2">
            <el-input v-model="form.unitName" placeholder="请输入内容" size="small">
            </el-input>
          </td>
          <td class="td-title">
            <p>日期:</p>
          </td>
          <td class="td-info" colspan="2">
            <el-date-picker v-model="form.fillDate" format="YYYY-MM-DD" placeholder="选择日期" size="small" type="date"
              value-format="YYYY-MM-DD">
            </el-date-picker>
          </td>
        </tr>
        <tr>
          <td class="td-title">
            <p>客户:</p>
          </td>
          <td class="td-info">
            <el-select v-model="form.orderId" filterable clearable size="small" style="width: 100%"
              popper-class="customer-select-popper" placeholder="请选择客户(已完成委托单)" @change="onCustomerChange">
              <el-option v-for="opt in customerOptions" :key="opt.id" :label="opt.company" :value="opt.id">
                <div class="customer-card">
                  <div>客户:{{ opt.company }}</div>
                  <div class="customer-card-sub">委托单编号:{{ opt.entrustCode || '--' }}</div>
                  <div class="customer-card-sub">样品名称:{{ opt.sampleName || '--' }}</div>
                </div>
              </el-option>
            </el-select>
          </td>
          <td class="td-title">
            <p>部门:</p>
          </td>
          <td class="td-info">
            <el-input v-model="form.department" placeholder="请输入内容" size="small">
            </el-input>
          </td>
          <td class="td-title">
            <p>联系电话:</p>
          </td>
          <td class="td-info">
            <el-input v-model="form.contactNumber" placeholder="请输入内容" size="small">
            </el-input>
          </td>
        </tr>
        <tr>
          <td class="td-title">
            <p>服务态度:</p>
          </td>
          <td class="td-info" colspan="2">
            <el-radio-group v-model="form.serviceAttitude">
              <el-radio :value="0">满意</el-radio>
              <el-radio :value="1">一般</el-radio>
              <el-radio :value="2">不满意</el-radio>
            </el-radio-group>
          </td>
          <td class="td-title">
            <p>建议:</p>
          </td>
          <td class="td-info" colspan="2">
            <el-input v-model="form.serviceAttitudeSuggestion" placeholder="请输入内容" size="small">
            </el-input>
          </td>
        </tr>
        <tr>
          <td class="td-title">
            <p>技术能力:</p>
          </td>
          <td class="td-info" colspan="2">
            <el-radio-group v-model="form.technicalCompetence">
              <el-radio :value="0">满意</el-radio>
              <el-radio :value="1">一般</el-radio>
              <el-radio :value="2">不满意</el-radio>
            </el-radio-group>
          </td>
          <td class="td-title">
            <p>建议:</p>
          </td>
          <td class="td-info" colspan="2">
            <el-input v-model="form.technicalCompetenceSuggestion" placeholder="请输入内容" size="small">
            </el-input>
          </td>
        </tr>
        <tr>
          <td class="td-title">
            <p>检测工作:</p>
          </td>
          <td class="td-info" colspan="2">
            <el-radio-group v-model="form.inspectionWork">
              <el-radio :value="0">满意</el-radio>
              <el-radio :value="1">一般</el-radio>
              <el-radio :value="2">不满意</el-radio>
            </el-radio-group>
          </td>
          <td class="td-title">
            <p>建议:</p>
          </td>
          <td class="td-info" colspan="2">
            <el-input v-model="form.inspectionWorkSuggestion" placeholder="请输入内容" size="small">
            </el-input>
          </td>
        </tr>
        <tr>
          <td class="td-title">
            <p>收费合理性:</p>
          </td>
          <td class="td-info" colspan="2">
            <el-radio-group v-model="form.reasonableFees">
              <el-radio :value="0">满意</el-radio>
              <el-radio :value="1">一般</el-radio>
              <el-radio :value="2">不满意</el-radio>
            </el-radio-group>
          </td>
          <td class="td-title">
            <p>建议:</p>
          </td>
          <td class="td-info" colspan="2">
            <el-input v-model="form.reasonableFeesSuggestion" placeholder="请输入内容" size="small">
            </el-input>
          </td>
        </tr>
        <tr>
          <td class="td-title">
            <p>您对我们的希望:</p>
          </td>
          <td class="td-info" colspan="5">
            <el-input v-model="form.remark" :rows="4" placeholder="请输入内容" size="small" type="textarea">
            </el-input>
          </td>
        </tr>
      </table>
      <template #footer><span  class="dialog-footer">
        <el-button @click="closeFormDia">取 消</el-button>
        <el-button :loading="editLoad" type="primary" @click="handleEdit">提 交</el-button>
      </span></template>
    </el-dialog>
  </div>
</template>
 
<script>
import {
  addClientSatisfaction,
  updateClientSatisfaction
} from '@/api/cnas/systemManagement/customerSatisfaction.js'
import { selectCompletedOrders } from '@/api/business/productOrder'
export default {
  name: 'formDialog',
  // import 引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      formDia: false,
      form: {
        unitName: '',
        fillDate: '',
        userName: '',
        department: '',
        contactNumber: '',
        serviceAttitude: '',
        serviceAttitudeSuggestion: '',
        technicalCompetence: '',
        technicalCompetenceSuggestion: '',
        inspectionWork: '',
        inspectionWorkSuggestion: '',
        reasonableFees: '',
        reasonableFeesSuggestion: '',
        remark: '',
        clientSatisfactionId: '',
        orderId: '',
        entrustCode: '',
        sampleName: ''
      },
      // 客户下拉选项:只包含"已下过委托单且已完成"的数据
      customerOptions: [],
      operationType: '',
      editLoad: false,
 
    };
  },
  // 方法集合
  methods: {
    async openDia(type, row) {
      this.formDia = true;
      this.operationType = type
      await this.loadCustomerOptions()
      if (this.operationType === 'edit') {
        this.form = { ...row }
        // 老数据没有关联委托单:合成一个选项把原来的值回显出来,不强制重选
        if (row.orderId == null && row.userName) {
          this.customerOptions.unshift({
            id: 0,
            company: row.userName,
            entrustCode: row.entrustCode || '--',
            sampleName: row.sampleName || '--'
          })
          this.form.orderId = 0
        } else if (row.orderId && !this.customerOptions.some(o => o.id === row.orderId)) {
          // 关联的委托单已不是"已完成"状态,用记录里的信息兜底回显
          this.customerOptions.unshift({
            id: row.orderId,
            company: row.userName || '未知客户',
            entrustCode: row.entrustCode || '--',
            sampleName: row.sampleName || '--'
          })
        }
      } else {
        this.resetForm()
      }
    },
    resetForm() {
      this.form = {
        unitName: '',
        fillDate: '',
        userName: '',
        department: '',
        contactNumber: '',
        serviceAttitude: '',
        serviceAttitudeSuggestion: '',
        technicalCompetence: '',
        technicalCompetenceSuggestion: '',
        inspectionWork: '',
        inspectionWorkSuggestion: '',
        reasonableFees: '',
        reasonableFeesSuggestion: '',
        remark: '',
        clientSatisfactionId: '',
        orderId: '',
        entrustCode: '',
        sampleName: ''
      }
    },
    // 下拉数据:后端只返回"已检验"的委托单(state=4)
    loadCustomerOptions() {
      this.customerOptions = []
      return selectCompletedOrders().then(res => {
        if (res.code === 200 && res.data) {
          this.customerOptions = res.data.map(o => ({
            id: o.id,
            company: o.company,
            entrustCode: o.entrustCode,
            sampleName: o.sampleView
          }))
        }
      }).catch(err => {
        console.log('err---', err)
      })
    },
    // 选中客户后:回填客户名并自动带出单位名称、委托单编号、样品名称
    onCustomerChange(val) {
      const opt = this.customerOptions.find(o => o.id === val)
      if (!opt || opt.id === 0) {
        return
      }
      this.form.userName = opt.company
      this.form.entrustCode = opt.entrustCode
      this.form.sampleName = opt.sampleName
      this.form.unitName = opt.company
    },
    handleEdit() {
      const orderIdEmpty = this.form.orderId === '' || this.form.orderId === null || this.form.orderId === undefined
      if (orderIdEmpty) {
        this.$message.warning('请选择客户')
        return
      }
      if (!this.form.unitName) {
        this.$message.warning('请填写单位名称')
        return
      }
      if (!this.form.department) {
        this.$message.warning('请填写部门')
        return
      }
      this.editLoad = true
      const payload = { ...this.form }
      // 老数据合成的回显选项(id=0)不算真实关联,保存时仍保持未关联
      if (payload.orderId === 0) {
        payload.orderId = null
      }
      if (this.operationType === 'add') {
        addClientSatisfaction(payload).then(res => {
          this.editLoad = false
          this.$message.success('提交成功')
          this.closeFormDia()
        }).catch(err => {
          console.log('err---', err);
          this.editLoad = false
        })
      } else {
        updateClientSatisfaction(payload).then(res => {
          this.editLoad = false
          this.$message.success('提交成功')
          this.closeFormDia()
        }).catch(err => {
          console.log('err---', err);
          this.editLoad = false
        })
      }
    },
    closeFormDia() {
      this.formDia = false;
      this.$emit('closeFormDia')
    },
  }
};
</script>
 
<style scoped>
:deep(.el-dialog) {
  margin: 10vh auto 50px !important;
}
 
.tables {
  table-layout: fixed;
  width: 100%;
  margin-top: 10px;
}
 
.td-title {
  height: 40px;
  width: 170px;
  text-align: center;
  font-size: 14px;
  word-wrap: break-word;
  white-space: normal;
  padding: 6px;
}
 
.td-info {
  padding: 6px;
}
 
.td-info1 {
  display: inline-block;
  width: 100%;
  text-align: left;
  font-size: 14px;
  word-wrap: break-word;
  white-space: normal;
}
 
.customer-card-sub {
  color: #909399;
  font-size: 12px;
}
</style>
 
<style>
/* 下拉卡片三行需要自适应高度,弹层 teleport 到 body,用自定义 popper-class 命中 */
.customer-select-popper .el-select-dropdown__item {
  height: auto;
  line-height: 1.7;
  padding: 6px 12px;
}
</style>