餐饮油烟智能监测与监管一体化平台
riku
2026-03-17 b1a0d701cf898c8b7812e66a808a1c91f2bae6cc
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
<template>
  <el-dialog
    :model-value="modelValue"
    @update:model-value="handleDialogChange"
    title="巡查单打印"
    class="dialog-wrapper"
    v-loading="loading"
  >
    <el-scrollbar
      ref="scrollbarRef"
      height="50vh"
      v-loading="loading"
      :always="true"
    >
      <el-checkbox-group v-model="checkList">
        <el-space
          direction="vertical"
          alignment="flex-start"
          fill
          style="width: 90%"
        >
          <el-checkbox
            v-for="(item, index) in sceneInfoList"
            :key="item.scense.guid"
            :value="index"
            :disabled="!item._valid"
            :class="(item.invalid ? 'checkbox-invalid' : '') + ' checkbox'"
          >
            <div>
              <el-text size="large" truncated style="width: 600px">{{
                item.scense.name
              }}</el-text>
            </div>
            <div class="m-t-4">
              <el-text size="small">{{
                '地址:' + item.scense.location
              }}</el-text>
            </div>
            <el-row justify="space-between">
              <el-space class="m-t-4">
                <el-tag>
                  {{
                    item.scense.cityname +
                    item.scense.districtname +
                    item.scense.townname
                  }}
                </el-tag>
                <el-tag>{{ item.scense.type }}</el-tag>
              </el-space>
              <el-space class="m-t-4">
                <!-- 工地类型的场景,巡查单据有简版和详版的区分 -->
                <template v-if="item.scense.typeid == 1">
                  <el-text type="warning" size="small" v-if="item._isFirstInspect">
                    首次巡查的工地需要使用详版巡查单据
                  </el-text>
                  <el-switch
                    v-model="item._isDetail"
                    :loading="item._loading"
                    :disabled="item._isFirstInspect"
                    inline-prompt
                    style="
                      --el-switch-on-color: #13ce66;
                      --el-switch-off-color: #c75000;
                    "
                    active-text="详版"
                    inactive-text="简版"
                  />
                </template>
                <el-text type="danger" size="small" v-if="!item._valid">
                  该场景目前没有巡查单据模板,无法打印
                </el-text>
                <el-button
                  type="default"
                  size="small"
                  class="m-t-4"
                  icon="IconPrinter"
                  :disabled="!item._valid"
                  @click="handlePreview(item)"
                >
                </el-button>
              </el-space>
            </el-row>
          </el-checkbox>
        </el-space>
      </el-checkbox-group>
    </el-scrollbar>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="danger" @click="cancel" icon="CloseBold"
          >取消</el-button
        >
        <el-button
          type="primary"
          :loading="docLoading"
          icon="Download"
          :disabled="checkList.length == 0"
          @click="handelDownload"
        >
          下载所选
        </el-button>
        <el-button
          type="default"
          :loading="docLoading"
          :disabled="checkList.length == 0"
          @click="handlePreview()"
          icon="IconPrinter"
        >
          打印所选
        </el-button>
      </div>
    </template>
  </el-dialog>
  <el-dialog v-model="previewVisible" :show-close="false" fullscreen>
    <template #header="{ close, titleId, titleClass }">
      <el-row justify="end" style="background-color: white">
        <el-button type="danger" @click="close" icon="CircleCloseFilled">
          关闭
        </el-button>
        <el-button
          type="primary"
          @click="handelPrint(refWord)"
          icon="IconPrinter"
        >
          打印
        </el-button>
      </el-row>
    </template>
    <div ref="refWord">
      <div
        :id="`word-preview-${i}`"
        v-for="(item, i) in previewList"
        :key="item"
      ></div>
    </div>
    <!-- <iframe ref="pdfPreview" width="100%" height="100vh" style="height: calc(100vh - 60px);"></iframe> -->
  </el-dialog>
</template>
<script setup>
/**
 * 场景巡查单据自动下载
 */
import { ref, watch } from 'vue';
import { useRouter } from 'vue-router';
import {
  exportDocx,
  prepareDocxBlob,
  preparePdf,
  previewDocx,
  downloadDocx,
  print
} from '@/utils/doc';
import sceneApi from '@/api/fysp/sceneApi';
import subtaskApi from '@/api/fysp/subtaskApi';
 
// 2025.12.22:有巡查单据模板的场景类型,[1:工地, 5:餐饮]
const validSceneType = [1, 5];
 
const props = defineProps({
  // 对话框开关
  modelValue: Boolean,
  // 场景基础信息数组
  value: Array,
  previewElement: String
});
 
const emits = defineEmits(['update:modelValue']);
 
const router = useRouter();
 
const refWord = ref(null);
const pdfPreview = ref(null);
 
const loading = ref(false);
const scrollbarRef = ref();
const sceneInfoList = ref([]);
const checkList = ref([]);
const docLoading = ref(false);
 
// 预览对话框开关
const previewVisible = ref(false);
// 预览的文档
const previewList = ref([]);
 
watch(
  () => [props.modelValue, props.value],
  (nV, oV) => {
    if (nV[0] && nV[1] && nV[1] != oV[1]) {
      fetchSceneInfo(nV[1]);
    }
  }
);
 
function fetchSceneInfo(sceneIdList) {
  loading.value = true;
  sceneInfoList.value = [];
  checkList.value = [];
  sceneIdList.forEach((sid) => {
    sceneApi
      .getSceneDetail(sid)
      .then((res) => {
        sceneInfoList.value.push(res.data);
        if (validSceneType.indexOf(res.data?.scense?.typeid) != -1) {
          checkList.value.push(sceneInfoList.value.length - 1);
 
          // todo _valid 的逻辑有错误
          const lastScene = sceneInfoList.value[sceneInfoList.value.length - 1];
          lastScene._valid = true;
          lastScene._loading = true;
          subtaskApi
            .findByDate(sid)
            .then((res) => {
              if (res.length == 0) {
                lastScene._isFirstInspect = true;
                lastScene._isDetail = true;
              }
            })
            .finally(() => {
              lastScene._loading = false;
            });
        }
      })
      .finally(() => {
        loading.value = false;
        scrollbarRef.value.setScrollTop(0);
      });
  });
}
 
function handleDialogChange(value) {
  emits('update:modelValue', value);
}
 
function setParam(value, length) {
  const _value = value ? value : '';
  const offset = length - _value.length;
  if (offset > 0) {
    let str = _value;
    for (let i = 0; i < offset; i++) {
      str += ' ';
    }
    return str;
  } else {
    return _value;
  }
}
 
// 格式化场景信息,生成参数结构
function parseParam(item) {
  const selected = item
    ? [item]
    : sceneInfoList.value.filter((v, i) => {
        return checkList.value.indexOf(i) != -1;
      });
  const param = selected.map((v) => {
    switch (v.scense.typeid) {
      // 工地
      case 1:
        return {
          type: v.scense.typeid,
          _isDetail: v._isDetail,
          params: {
            district: v.scense?.districtname ?? '',
            name: setParam(v.scense?.name ?? '', 0),
            employerUnit: setParam(v.subScene?.csEmployerUnit ?? '', 0),
            constructionUnit: setParam(
              v.subScene ? v.subScene.csConstructionUnit : '',
              0
            ),
            timeRange: setParam(
              v.subScene && v.subScene.csStartTime
                ? `${v.subScene.csStartTime}至${v.subScene.csEndTime}`
                : '',
              0
            ),
            stage: setParam(v.subScene ? v.subScene.siExtension1 : '', 0),
            contacts: setParam(v.scense?.contacts ?? '', 0),
            contactsTel: setParam(v.scense?.contactst ?? '', 0),
            location: setParam(v.scense?.location ?? '', 0)
          }
        };
      // 餐饮
      case 5:
        return {
          type: v.scense.typeid,
          params: {
            district: v.scense.districtname,
            location: setParam(v.scense.location, 63),
            name: setParam(v.scense.name, 64),
            contacts: setParam(v.scense.contacts, 67),
            contactsTel: setParam(v.scense.contactst, 62)
          }
        };
      // default:
      //   v.invalid = true;
      //   return undefined;
    }
  });
 
  return param;
}
 
// 根据场景类型,生成对应的word文档
function generateDoc(param, callback) {
  param.map((p, index) => {
    let template, _param;
    switch (p.type) {
      // 工地
      case 1:
        template = p._isDetail
          ? '/工地巡查单据模板-详版.docx'
          : '/工地巡查单据模板-简版.docx';
        _param = p.params;
        break;
      // 餐饮
      case 5:
        template = '/餐饮巡查单据模板.docx';
        _param = p.params;
        break;
      default:
        break;
    }
    prepareDocxBlob(template, _param).then((blob) => {
      callback(blob, `${_param.name}巡查单据.docx`, index);
    });
  });
}
 
function filePrepare(callback) {
  const param = parseParam();
  if (param) {
    return generateDoc(param, callback);
  }
}
 
// 点击下载按钮操作, 下载word文档
function handelDownload() {
  filePrepare((blob, name) => {
    downloadDocx(blob, name);
  });
}
 
// 点击打印按钮操作
function handelPrint(ref) {
  if (ref) {
    print({
      ref,
      // 根据目前使用的docx-preview组件,设置打印样式,主要去除多余的margin和padding,以及阴影效果
      style: `
        @page{size:A4;margin: 0 !important;padding:0 !important;} 
        body {margin: 0 !important;padding:0 !important;} 
        header {color: rgb(182, 182, 182);}
        footer {color: rgb(182, 182, 182);}
        .docx-wrapper {padding: 0 !important;}
        .docx {margin-bottom: 0 !important; box-shadow: none !important;}
        .docx_5 {
          display: flex;
          justify-content: space-between;
          align-items: flex-end;
        }
      `
    });
  }
}
 
function handlePreview(item) {
  // 预览的文档,区分单独打印和打印全部
  previewList.value = item ? ['0'] : checkList.value;
  const param = item ? parseParam(item) : parseParam();
  if (param) {
    generateDoc(param, (blob, name, index) => {
      previewVisible.value = true;
      setTimeout(() => {
        previewDocx(blob, document.getElementById(`word-preview-${index}`));
      }, 200);
    });
  }
}
 
// 取消操作
function cancel() {
  // 关闭对话框
  handleDialogChange(false);
}
</script>
<style scoped>
.checkbox {
  border: var(--el-border);
  padding: 8px;
}
.checkbox-invalid {
  border-color: var(--el-color-error);
}
:deep(.el-checkbox) {
  height: auto;
}
:deep(.el-checkbox__label) {
  width: 100%;
}
 
/* 文档字体 */
:deep(section.docx) {
  font-family: '黑体' !important;
}
/* 文档标题 */
:deep(header) {
  color: rgb(182, 182, 182);
}
:deep(.docx_5) {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}
 
/*  */
:deep(footer) {
  color: rgb(182, 182, 182);
}
</style>