zhangwencui
6 天以前 27977c931dd6b0043340f9061be4d56c50f06449
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
<template>
  <view class="client-visit-detail">
    <PageHeader :title="detailType === 1 ? '新增知识库' : '知识库详情'"
                @back="goBack" />
    <u-form ref="formRef"
            label-width="90">
      <!-- 客户信息 -->
      <!-- <u-cell-group title="知识信息"> -->
      <u-form-item label="知识标题"
                   prop="title"
                   required
                   border-bottom>
        <u-input v-model="form.title"
                 :readonly="readonly"
                 placeholder="请输入知识标题" />
      </u-form-item>
      <u-form-item label="知识类型"
                   prop="type"
                   required
                   border-bottom>
        <u-input v-model="equipmentname"
                 readonly
                 placeholder="请选择知识类型"
                 @click="showEquipmentSheet = true" />
        <template v-if="!readonly"
                  #right>
          <up-icon name="arrow-right"
                   @click="openEquipmentSheet"></up-icon>
        </template>
      </u-form-item>
      <u-form-item label="适用场景"
                   prop="scenario"
                   border-bottom>
        <u-input v-model="form.scenario"
                 readonly="readonly"
                 placeholder="请输入适用场景" />
      </u-form-item>
      <u-form-item label="解决效率"
                   prop="status"
                   border-bottom>
        <u-input v-model="statusname"
                 readonly
                 placeholder="请选择解决效率"
                 @click="showStatusSheet = true" />
        <template v-if="!readonly"
                  #right>
          <up-icon name="arrow-right"
                   @click="showStatusSheet = true"></up-icon>
        </template>
      </u-form-item>
      <u-form-item label="问题描述"
                   required
                   prop="remark"
                   border-bottom>
        <u-textarea v-model="form.problem"
                    type="textarea"
                    rows="4"
                    :disabled="readonly"
                    placeholder="请输入问题描述" />
      </u-form-item>
      <u-form-item label="解决方案"
                   prop="solution"
                   required
                   border-bottom>
        <u-textarea v-model="form.solution"
                    type="textarea"
                    rows="4"
                    :disabled="readonly"
                    placeholder="请输入解决方案" />
      </u-form-item>
      <u-form-item label="关键要点"
                   prop="keyPoints"
                   border-bottom>
        <u-textarea v-model="form.keyPoints"
                    type="textarea"
                    rows="4"
                    :disabled="readonly"
                    placeholder="请输入关键要点,用逗号分隔" />
      </u-form-item>
      <u-form-item label="创建人"
                   prop="creator"
                   border-bottom>
        <u-input v-model="form.creator"
                 :readonly="readonly"
                 placeholder="请输入创建人" />
      </u-form-item>
      <u-form-item label="使用次数"
                   prop="usageCount"
                   border-bottom>
        <uni-number-box v-model="form.usageCount"
                        :min="0"
                        :disabled="readonly"
                        placeholder="请输入使用次数" />
      </u-form-item>
      <!-- </u-cell-group> -->
      <!-- 提交按钮 -->
      <view v-if="!readonly"
            class="footer-btns">
        <u-button class="cancel-btn"
                  @click="goBack">取消</u-button>
        <u-button class="sign-btn"
                  type="primary"
                  @click="handleSubmit"
                  :loading="loading">保存</u-button>
      </view>
    </u-form>
    <!-- 设备配置选择器 -->
    <up-action-sheet :show="showEquipmentSheet"
                     :actions="equipmentOptions"
                     @select="handleEquipmentChange"
                     @close="showEquipmentSheet = false" />
    <!-- <u-popup :show="showEquipmentSheet"
             mode="bottom"
             @close="showEquipmentSheet = false"
             height="200px">
      <view class="popup-content">
        <view class="popup-body">
          <u-checkbox-group v-model="form.equipment"
                            @change="handleEquipmentChange"
                            icon-placement="right"
                            placement="row">
            <view style="width:100%;padding:10px;margin-top:20px;">
              <u-checkbox v-for="option in equipmentOptions"
                          :key="option.value"
                          :name="option.value"
                          :label="option.name"
                          class="checkbox-item"></u-checkbox>
            </view>
          </u-checkbox-group>
        </view>
      </view>
    </u-popup> -->
    <!-- 状态选择器 -->
    <up-action-sheet :show="showStatusSheet"
                     :actions="statusOptions"
                     @select="onStatusSelect"
                     @close="showStatusSheet = false" />
  </view>
</template>
 
<script setup>
  // 替换 toast 方法
  defineOptions({ name: "meeting-settings-detail" });
  const showToast = message => {
    uni.showToast({
      title: message,
      icon: "none",
    });
  };
 
  import { ref, onMounted, computed } from "vue";
  import PageHeader from "@/components/PageHeader.vue";
  import useUserStore from "@/store/modules/user";
  import { useDict } from "@/utils/dict";
  import { onLoad } from "@dcloudio/uni-app";
  import {
    addKnowledgeBase,
    updateKnowledgeBase,
    getKnowledgeBaseDetail,
  } from "@/api/managementMeetings/knowledgeBase";
 
  const userStore = useUserStore();
 
  // 表单数据
  const form = ref({
    title: "",
    type: "",
    scenario: "",
    efficiency: "",
    problem: "",
    solution: "",
    keyPoints: "",
    creator: "",
    usageCount: 0,
  });
  const { knowledge_type } = useDict("knowledge_type");
  const knowledgeTypeOptions = computed(() => knowledge_type?.value || []);
  const equipmentOptions = ref([]);
  const statusOptions = ref([
    { value: "high", name: "显著提升" },
    { value: "medium", name: "一般提升" },
    { value: "low", name: "轻微提升" },
  ]);
  //// 页面状态
  const loading = ref(false);
  const formRef = ref(null);
  const showEquipmentSheet = ref(false);
  const showStatusSheet = ref(false);
  const openEquipmentSheet = () => {
    showEquipmentSheet.value = true;
  };
  // 返回上一页
  const goBack = () => {
    uni.navigateBack();
  };
  const statusname = ref("");
  // 状态选择
  const onStatusSelect = action => {
    form.value.efficiency = action.value;
    statusname.value = action.name;
    showStatusSheet.value = false;
  };
  const equipmentname = ref("");
  // 设备配置选择
  const handleEquipmentChange = val => {
    form.value.type = val.value;
    equipmentname.value = val.name;
    showEquipmentSheet.value = false;
  };
  // 提交表单
  const handleSubmit = async () => {
    if (!form.value.title) {
      showToast("请输入标题");
      return;
    }
 
    if (!form.value.scenario) {
      showToast("请输入适用场景");
      return;
    }
 
    if (!form.value.problem) {
      showToast("请输入问题描述");
      return;
    }
    if (!form.value.solution) {
      showToast("请输入解决方案");
      return;
    }
    try {
      loading.value = true;
      if (detailType.value === 1) {
        addKnowledgeBase(form.value).then(res => {
          if (res.code !== 200) {
            showToast("保存失败,请重试");
            return;
          }
          loading.value = false;
          showToast("保存成功");
          setTimeout(() => {
            goBack();
          }, 500);
        });
      } else if (detailType.value === 2) {
        updateKnowledgeBase(form.value).then(res => {
          if (res.code !== 200) {
            showToast("保存失败,请重试");
            return;
          }
          loading.value = false;
          showToast("保存成功");
          setTimeout(() => {
            goBack();
          }, 500);
        });
      }
    } catch (e) {
      loading.value = false;
      console.error("保存失败:", e);
      showToast("保存失败,请重试");
    }
  };
 
  // 初始化页面数据
  const initPageData = () => {
    // 从本地存储中获取会议 room 数据
    const meetingRoom = uni.getStorageSync("meetingRoom");
    if (meetingRoom) {
      form.value = JSON.parse(JSON.stringify(meetingRoom));
      if (meetingRoom.equipment) {
        if (Array.isArray(meetingRoom.equipment)) {
          form.value.equipment = meetingRoom.equipment;
        } else {
          form.value.equipment = meetingRoom.equipment.split(",");
        }
      }
      statusname.value = meetingRoom.status === 1 ? "启用" : "禁用";
 
      // 清除本地存储中的数据,避免下次打开时仍然显示
      uni.removeStorageSync("meetingRoom");
    }
  };
  const readonly = ref(false);
  const detailType = ref(1);
  const knowledgeId = ref("");
 
  // 获取知识详情
  const getKnowledgeDetail = id => {
    loading.value = true;
    getKnowledgeBaseDetail(id)
      .then(res => {
        loading.value = false;
        if (res.code === 200) {
          form.value = res.data;
          equipmentname.value =
            equipmentOptions.value.find(item => item.value === form.value.type)
              ?.name || "";
          statusname.value =
            statusOptions.value.find(item => item.value === form.value.efficiency)
              ?.name || "";
        } else {
          showToast("获取知识详情失败");
        }
      })
      .catch(err => {
        loading.value = false;
        showToast("获取知识详情失败");
      });
  };
 
  onLoad(options => {
    detailType.value = Number(options.detailType);
    knowledgeId.value = options.id || "";
 
    // 如果是编辑或查看模式,获取知识详情
    if (knowledgeId.value && (detailType.value === 2 || detailType.value === 3)) {
      getKnowledgeDetail(knowledgeId.value);
    }
 
    // 查看模式设置只读
    if (detailType.value === 3) {
      readonly.value = true;
    }
  });
 
  onMounted(() => {
    // 从本地存储中获取知识数据
    const knowledgeBase = uni.getStorageSync("knowledgeBase");
    if (knowledgeBase) {
      form.value = JSON.parse(JSON.stringify(knowledgeBase));
    }
 
    initPageData();
    equipmentOptions.value = knowledgeTypeOptions.value.map(item => ({
      value: item.value,
      name: item.label,
    }));
 
    if (detailType.value != 1) {
      equipmentname.value =
        equipmentOptions.value.find(item => item.value === form.value.type)
          ?.name || "";
      statusname.value =
        statusOptions.value.find(item => item.value === form.value.efficiency)
          ?.name || "";
    }
  });
</script>
 
<style scoped lang="scss">
  @import "@/static/scss/form-common.scss";
  .client-visit {
    min-height: 100vh;
    background: #f8f9fa;
    padding-bottom: 5rem;
  }
 
  .footer-btns {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.75rem 0;
    box-shadow: 0 -0.125rem 0.5rem rgba(0, 0, 0, 0.05);
    z-index: 1000;
  }
 
  .cancel-btn {
    font-weight: 400;
    font-size: 1rem;
    color: #666;
    background: #f5f5f5;
    border: 1px solid #ddd;
    width: 45%;
    height: 2.5rem;
    border-radius: 2.5rem 2.5rem 2.5rem 2.5rem;
  }
 
  .sign-btn {
    font-weight: 500;
    font-size: 1rem;
    color: #fff;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    width: 45%;
    height: 2.5rem;
    border-radius: 2.5rem 2.5rem 2.5rem 2.5rem;
  }
 
  .location-icon {
    color: #1989fa;
    font-size: 1.2rem;
  }
 
  .selector-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    height: 100%;
  }
 
  .selector-text {
    font-size: 14px;
    color: #333;
  }
 
  .popup-content {
    padding: 20rpx;
  }
 
  .popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20rpx;
  }
 
  .popup-title {
    font-size: 16px;
    font-weight: bold;
    color: #333;
  }
 
  .close-icon {
    font-size: 20px;
    color: #999;
  }
 
  .popup-body {
    max-height: 60vh;
    overflow-y: auto;
    margin-bottom: 20rpx;
  }
 
  .checkbox-item {
    margin-bottom: 15rpx;
    font-size: 14px;
  }
 
  .popup-footer {
    display: flex;
    justify-content: space-between;
    gap: 15rpx;
  }
 
  .cancel-btn-popup {
    flex: 1;
    border-radius: 8rpx;
  }
 
  .confirm-btn-popup {
    flex: 1;
    border-radius: 8rpx;
  }
  .checkbox-item {
    margin-top: 40rpx;
  }
</style>