zhouwx
2025-11-11 be57c60a2b1ce03ebdd264176149c52870c0b760
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
<template>
  <div class="app-container">
    <div style="margin-bottom: 10px">
      <el-form style="display: flex;flex-wrap: wrap;">
        <el-form-item>
          <el-button
              type="primary"
              plain
              icon="Plus"
              @click="openDialog('add',{})"
              v-hasPermi="['monthlyInspectionRecord:add']"
          >新增</el-button>
        </el-form-item>
        <el-form-item label="单位名称:" v-if="data.isAdmin" style="margin-left: 20px">
          <el-select v-model="data.queryParams.companyId" placeholder="请选择" filterable clearable>
            <el-option
                v-for="item in data.companyList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="data.isAdmin">
          <el-button type="primary" style="margin-left: 30px" @click="searchClick">查询</el-button>
          <el-button plain @click="reset">重置</el-button>
        </el-form-item>
        <el-form-item style="margin-left: 15px">
          <el-button
              type="primary"
              @click="exportData"
          >导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="dataList" :border="true"  @selection-change="handleSelectionChange" :span-method="mergeCells">
      <el-table-column type="selection" prop="selection" width="55" />
<!--      <el-table-column type="index" prop="sequenceNumber" label="序号" width="80" align="center"></el-table-column>-->
<!--      <el-table-column label="单位名称" prop="companyName" align="center" v-if="data.isAdmin" />-->
      <el-table-column label="名称" prop="recordName" align="center">
      </el-table-column>
      <el-table-column label="时间" prop="monthlyTime" align="center" />
      <el-table-column label="检查人" prop="checkUser" align="center" />
      <el-table-column label="防护" prop="entrench" align="center" />
      <el-table-column label="标识" prop="identification" align="center" />
      <el-table-column label="摆放" prop="place" align="center" />
      <el-table-column label="清洁" prop="clean" align="center" />
      <el-table-column label="安全" prop="safety" align="center" />
      <el-table-column label="环境" prop="environment" align="center" />
      <el-table-column label="帐务卡一致性" prop="consistency" align="center" />
      <el-table-column label="操作" align="center" prop="operate" class-name="small-padding fixed-width" width="160">
        <template #default="scope">
          <el-button link type="primary"  @click="openDialog('review',scope.row)" >查看</el-button>
          <el-button link type="primary"  @click="openDialog('edit',scope.row)" v-hasPermi="['monthlyInspectionRecord:edit']">编辑</el-button>
          <el-button link type="danger"  @click="handleDelete(scope.row)" v-hasPermi="['monthlyInspectionRecord:del']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
 
<!--    <div class="pag-container">-->
<!--      <el-pagination-->
<!--          v-model:current-page="data.queryParams.pageNum"-->
<!--          v-model:page-size="data.queryParams.pageSize"-->
<!--          :page-sizes="[10,15,20,25]"-->
<!--          layout="total, sizes, prev, pager, next, jumper"-->
<!--          :total="total"-->
<!--          @size-change="handleSizeChange"-->
<!--          @current-change="handleCurrentChange"-->
<!--      />-->
<!--    </div>-->
    <editDialog ref="noticeRef" @getList = "getList"></editDialog>
  </div>
</template>
 
<script setup>
import {getCurrentInstance, onMounted, reactive, ref, toRefs} from "vue";
import editDialog from "./components/editDialog.vue"
import {ElMessage, ElMessageBox} from "element-plus";
import {getCompany} from "@/api/onlineEducation/company";
import Cookies from "js-cookie";
import {generateWordDocument} from "@/utils/exportWord";
import {delTable, getTable} from "@/api/qualityObjectives/table";
import {delNeedDiscren, getNeedDiscren} from "@/api/need/need";
import {delMonthlyRecord, getMonthlyRecord, getMonthlyRecordById} from "@/api/monthlyInspectionRecord";
import {getQualityTemplateById} from "@/api/standardSys/standardSys";
const { proxy } = getCurrentInstance();
const loading = ref(false);
const noticeRef = ref();
const deptRef = ref()
const loadingCompany = ref(false)
const choosedData = ref([])
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    companyId: null,
    year: '',
    type: ''
  },
  companyList: [],
  isAdmin: false,
  dialogVisible: false,
});
const dataList = ref([]);
const total = ref(0);
 
const { queryParams } = toRefs(data);
 
onMounted(() => {
  const userInfo = JSON.parse(Cookies.get('userInfo'))
  console.log("userInfo",userInfo)
  data.isAdmin = userInfo.userType === 0;
  if(data.isAdmin){
    data.queryParams.companyId = null
  }else {
    data.queryParams.companyId = userInfo.companyId
  }
  getList();
  if(data.isAdmin){
    getCompanyList()
  }
});
 
const resData = ref([])
const getList = async () => {
  loading.value = true;
  const res = await getMonthlyRecord(data.queryParams);
  if(res.code === 200){
    const resultArray = [];
    for (const obj of  res.data.list) {
      const listItemArray = obj.inspectionMesses;
      for (const listItem of listItemArray) {
        resultArray.push({
          id:obj.id,
          companyName: obj.companyName,
          recordName: obj.recordName,
          monthlyTime: listItem.monthlyTime,
          checkUser: listItem.checkUser,
          entrench: listItem.entrench,
          identification: listItem.identification,
          place: listItem.place,
          clean: listItem.clean,
          safety: listItem.safety,
          environment: listItem.environment,
          consistency: listItem.consistency,
        });
      }
    }
    dataList.value = resultArray.map((item,index) => {
      return {
        ...item,
        sequenceNumber: index + 1
      }
    })
    calculateSpan()
    // dataList.value = res.data.list
    // total.value = res.data.total
  }else{
    ElMessage.warning(res.message)
  }
  loading.value = false;
}
 
const searchClick = () => {
  getList();
}
 
const openDialog = (type, value) => {
  noticeRef.value.openDialog(type, value,data.companyList);
}
 
const getCompanyList = async ()=>{
  const queryParams = {
    pageNum: 1,
    pageSize: 999
  }
  const res = await getCompany(queryParams)
  if (res.code == 200) {
    data.companyList = res.data.list?res.data.list:[]
  } else {
    ElMessage.warning(res.message)
  }
}
 
const handleSizeChange = (val) => {
  data.queryParams.pageSize = val
  getList()
}
const handleCurrentChange = (val) => {
  data.queryParams.pageNum = val
  getList()
}
const handleClose = () => {
  data.dialogVisible = false
}
 
/** 重置新增的表单以及其他数据  */
function reset() {
  if(data.isAdmin){
    data.queryParams = {
      companyId: '',
      pageNum: 1,
      pageSize: 10,
    }
    choosedData.value = []
    data.companyList = [];
    getCompanyList()
  }else {
    data.queryParams = {
      companyId: data.queryParams.companyId,
      pageNum: 1,
      pageSize: 10,
    }
  }
  getList();
 
}
const exportData = () => {
  if(choosedData.value && choosedData.value.length === 0){
    ElMessage.warning('请选择需要导出的数据')
  }else {
    startGeneration()
  }
}
const templatePath = ref('/monthRecordExample.docx')
const startGeneration = async () => {
  const data = JSON.parse(JSON.stringify(choosedData.value))
  data.forEach(item => {
    item.tableData = item.inspectionMesses
    console.log('xxx',item.tableData)
    try {
      generateWordDocument(templatePath.value, item, item.recordName + `_月度检查记录表.docx`);
    } catch (error){
      ElMessage({
        type: 'warning',
        message: '导出失败'
      });
    }
  })
}
const handleSelectionChange = async (val) => {
  let arr = []
  for (const item of val) {
    const res = await getMonthlyRecordById({monthlyId: item.id})
    if(res.code == 200){
      arr.push(res.data)
    }else{
      ElMessage.warning(res.message)
    }
  }
  choosedData.value = arr
}
const handleDelete = (val) => {
  ElMessageBox.confirm(
      '确定删除此条数据?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then( async() => {
        const res = await delMonthlyRecord(val.id);
        if(res.code === 200){
          ElMessage({
            type: 'success',
            message: '删除成功'
          });
          getList();
        }else{
          ElMessage.warning(res.message)
        }
      })
}
 
const mergeCells = ({ row, column, rowIndex, columnIndex }) => {
  if ( column.property == 'operate' || column.property == 'recordName' || column.property == 'selection') {
    const _row = spanArr.value[rowIndex];
    const _col = _row > 0 ? 1 : 0;
    return [_row, _col];
  }
};
 
const spanArr = ref([]); // 存储每一行的合并信息
const position = ref(0); // 记录当前位置
// 计算合并的行数
const calculateSpan = () => {
  spanArr.value = [];
  position.value = 0;
 
  dataList.value.forEach((item, index) => {
    if (index === 0) {
      spanArr.value.push(1);
      position.value = 0;
    } else {
      // 判断当前行的id与上一行是否相同
      if (dataList.value[index].id === dataList.value[index - 1].id) {
        spanArr.value[position.value] += 1;
        spanArr.value.push(0);
      } else {
        spanArr.value.push(1);
        position.value = index;
      }
    }
  });
};
 
</script>
<style lang="scss">
.pag-container{
  float: right;
  margin-top: 10px;
}
</style>