inspection_report1.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <template>
  2. <ele-modal
  3. :visible.sync="visible"
  4. title="质检报告"
  5. width="70%"
  6. append-to-body
  7. :maxable="true"
  8. >
  9. <div id="printSection" style="padding: 20px; background-color: white;">
  10. <h1 style="text-align: center; font-size: 24px; margin-bottom: 20px; font-weight: bold;">质检报告</h1>
  11. <!-- 编号和报告单号 -->
  12. <div style="margin-bottom: 20px;">
  13. <el-row>
  14. <el-col :span="12">
  15. <div style="display: flex; align-items: center;">
  16. <span style="font-weight: bold; margin-right: 10px;">编号:</span>
  17. <span style="flex: 1;">{{ basicInfoData.code }}</span>
  18. </div>
  19. </el-col>
  20. <el-col :span="12">
  21. <div style="display: flex; align-items: center;">
  22. <span style="font-weight: bold; margin-right: 10px;">报告单号:</span>
  23. <span style="flex: 1;">
  24. <div v-if="isView">
  25. {{ basicInfoData.reportNumber }}
  26. </div>
  27. <div v-else>
  28. <el-input v-model="basicInfoData.reportNumber" placeholder="请输入报告编号"></el-input>
  29. </div>
  30. </span>
  31. </div>
  32. </el-col>
  33. </el-row>
  34. </div>
  35. <!-- 基本信息表格 -->
  36. <table class="basic-info-table" style="width: 100%; border-collapse: collapse; border: 1px solid #ccc;">
  37. <tbody>
  38. <tr>
  39. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">检品名称</td>
  40. <td style="border: 1px solid #ccc; padding: 8px;">{{ basicInfoData.productName }}</td>
  41. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">批号/序列号</td>
  42. <td style="border: 1px solid #ccc; padding: 8px;">{{ basicInfoData.batchNo }}</td>
  43. </tr>
  44. <tr>
  45. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">规格型号</td>
  46. <td style="border: 1px solid #ccc; padding: 8px;">{{ basicInfoData.specification }}/{{ basicInfoData.modelType }}</td>
  47. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">数量</td>
  48. <td style="border: 1px solid #ccc; padding: 8px;">{{ basicInfoData.total }}</td>
  49. </tr>
  50. <tr>
  51. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">请验日期</td>
  52. <td style="border: 1px solid #ccc; padding: 8px;">{{ basicInfoData.pleaseVerifyDate }}</td>
  53. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">请验部门</td>
  54. <td style="border: 1px solid #ccc; padding: 8px;">{{ basicInfoData.pleaseVerifyDepartment }}</td>
  55. </tr>
  56. <tr>
  57. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">报告日期</td>
  58. <td style="border: 1px solid #ccc; padding: 8px;">
  59. <div v-if="!isView">
  60. <el-date-picker
  61. v-model="basicInfoData.reportDate"
  62. type="date"
  63. value-format="yyyy-MM-dd"
  64. placeholder="选择日期"
  65. />
  66. </div>
  67. <div v-else>{{ basicInfoData.reportDate }}</div>
  68. </td>
  69. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">有效期</td>
  70. <td style="border: 1px solid #ccc; padding: 8px;">
  71. <div v-if="!isView">
  72. <el-date-picker
  73. v-model="basicInfoData.expirationDate"
  74. type="date"
  75. value-format="yyyy-MM-dd"
  76. placeholder="选择日期"
  77. />
  78. </div>
  79. <div v-else>{{ basicInfoData.expirationDate }}</div>
  80. </td>
  81. </tr>
  82. <tr>
  83. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">来源</td>
  84. <td style="border: 1px solid #ccc; padding: 8px;">
  85. <div v-if="!isView">
  86. <el-input v-model="basicInfoData.source" placeholder="请输入来源"></el-input>
  87. </div>
  88. <div v-else>{{ basicInfoData.source }}</div>
  89. </td>
  90. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">储存条件</td>
  91. <td style="border: 1px solid #ccc; padding: 8px;">
  92. <div v-if="!isView">
  93. <el-input v-model="basicInfoData.storageCondition" placeholder="请输入储存条件"></el-input>
  94. </div>
  95. <div v-else>{{ basicInfoData.storageCondition }}</div>
  96. </td>
  97. </tr>
  98. <tr>
  99. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">检验依据</td>
  100. <td style="border: 1px solid #ccc; padding: 8px;" colspan="3">
  101. <div v-if="!isView">
  102. <el-input v-model="basicInfoData.inspectionBasis" placeholder="请输入检验依据"></el-input>
  103. </div>
  104. <div v-else>{{ basicInfoData.inspectionBasis }}</div>
  105. </td>
  106. </tr>
  107. </tbody>
  108. </table>
  109. <!-- 检验项目表格 -->
  110. <table class="inspection-items-table" style="width: 100%; border-collapse: collapse; border: 1px solid #ccc; margin-bottom: 20px;">
  111. <thead>
  112. <tr>
  113. <th style="width: 150px; border: 1px solid #ccc; padding: 8px;">检验项目</th>
  114. <th style="border: 1px solid #ccc; padding: 8px;">标准规定</th>
  115. <th style="width: 150px; border: 1px solid #ccc; padding: 8px;">检验结果</th>
  116. </tr>
  117. </thead>
  118. <tbody>
  119. <tr v-for="(item, index) in inspectionItems" :key="index">
  120. <td style="width: 150px; border: 1px solid #ccc; padding: 8px; min-height: 37px;">{{ item.item }}</td>
  121. <td style="border: 1px solid #ccc; padding: 8px;">{{ item.standardRegulations }}</td>
  122. <td style="width: 150px; border: 1px solid #ccc; padding: 8px;">{{ item.results }}</td>
  123. </tr>
  124. <tr>
  125. <td style="width: 120px; border: 1px solid #ccc; padding: 8px;">结论</td>
  126. <td style="border: 1px solid #ccc; padding: 8px;" :colspan="2">
  127. <div v-if="!isView">
  128. <el-input v-model="basicInfoData.conclusion" placeholder="请输入结论"></el-input>
  129. </div>
  130. <div v-else>{{ basicInfoData.conclusion || '' }}</div>
  131. </td>
  132. </tr>
  133. <tr>
  134. <td style="width: 120px; border: 1px solid #ccc; padding: 8px;">备注</td>
  135. <td style="border: 1px solid #ccc; padding: 8px;" :colspan="2">
  136. <div v-if="!isView">
  137. <el-input v-model="basicInfoData.remarks" placeholder="请输入备注"></el-input>
  138. </div>
  139. <div v-else>{{ basicInfoData.remarks || '' }}</div>
  140. </td>
  141. </tr>
  142. </tbody>
  143. </table>
  144. <!-- 签名区域 -->
  145. <div style="margin-top: 20px;">
  146. <el-row :gutter="20" style="display: flex; align-items: center;">
  147. <el-col :span="8">
  148. <div style="display: flex; align-items: center; margin-bottom: 10px;">
  149. <span style="font-weight: bold; min-width: 100px;">检验员/日期:</span>
  150. <span style="flex: 1;">
  151. <div v-if="!isView" style="display: flex; align-items: center;">
  152. <el-input v-model="basicInfoData.inspector" placeholder="请输入检验员" style="width: 140px;"></el-input>
  153. <el-date-picker
  154. v-model="basicInfoData.inspectionTime"
  155. type="date"
  156. value-format="yyyy-MM-dd"
  157. placeholder="选择日期"
  158. style="width: 160px;"
  159. />
  160. </div>
  161. <div v-else>{{ basicInfoData.inspector || '' }} / {{ basicInfoData.inspectionTime || '' }}</div>
  162. </span>
  163. </div>
  164. </el-col>
  165. <el-col :span="8">
  166. <div style="display: flex; align-items: center; margin-bottom: 10px;">
  167. <span style="font-weight: bold; min-width: 100px;">复核人/日期:</span>
  168. <span style="flex: 1;">
  169. <div v-if="!isView" style="display: flex; align-items: center;">
  170. <el-input v-model="basicInfoData.reviewer" placeholder="请输入复核人" style="width: 140px;"></el-input>
  171. <el-date-picker
  172. v-model="basicInfoData.reviewTime"
  173. type="date"
  174. value-format="yyyy-MM-dd"
  175. placeholder="选择日期"
  176. style="width: 160px;"
  177. />
  178. </div>
  179. <div v-else>{{ basicInfoData.reviewer || '' }} / {{ basicInfoData.reviewTime || '' }}</div>
  180. </span>
  181. </div>
  182. </el-col>
  183. <el-col :span="8">
  184. <div style="display: flex; align-items: center; margin-bottom: 10px;">
  185. <span style="font-weight: bold; min-width: 100px;">审核人/日期:</span>
  186. <span style="flex: 1;">
  187. <div v-if="!isView" style="display: flex; align-items: center;">
  188. <el-input v-model="basicInfoData.checker" placeholder="请输入审核人" style="width: 140px;"></el-input>
  189. <el-date-picker
  190. v-model="basicInfoData.approvedDate"
  191. type="date"
  192. value-format="yyyy-MM-dd"
  193. placeholder="选择日期"
  194. style="width: 160px;"
  195. />
  196. </div>
  197. <div v-else>{{ basicInfoData.checker || '' }} / {{ basicInfoData.approvedDate || '' }}</div>
  198. </span>
  199. </div>
  200. </el-col>
  201. </el-row>
  202. </div>
  203. </div>
  204. <template v-slot:footer>
  205. <el-button v-if="isView" type="primary" @click="print" v-loading="loading">打印</el-button>
  206. <el-button v-if="!isView" type="primary" @click="save" v-loading="loading">确认</el-button>
  207. <el-button @click="cancel">关闭</el-button>
  208. </template>
  209. </ele-modal>
  210. </template>
  211. <script>
  212. import { queryInspectionReportData, queryInspectionReportList, generateReport } from '@/api/inspectionReport';
  213. export default {
  214. name: 'QualityReport',
  215. props: {
  216. isView: {
  217. type: Boolean,
  218. default: false
  219. },
  220. visible: {
  221. type: Boolean,
  222. default: false
  223. },
  224. row: {
  225. type: Object,
  226. default: () => {}
  227. },
  228. item: {
  229. type: Object,
  230. default: () => {}
  231. },
  232. },
  233. data() {
  234. return {
  235. // visible: false,
  236. loading: false,
  237. currentRow: {}, // 存储当前行数据
  238. templateItem: {}, // 存储当前模板项数据
  239. // 基本信息数据
  240. basicInfoData: {},
  241. // 检验项目
  242. inspectionItems: [],
  243. }
  244. },
  245. watch: {
  246. visible(newVal, oldVal) {
  247. if (newVal) {
  248. this.open(this.row, this.item);
  249. }
  250. }
  251. },
  252. created() {
  253. // 页面加载时可以在这里添加数据初始化逻辑
  254. },
  255. methods: {
  256. /* 打开质检报告 */
  257. open(row, item) {
  258. this.currentRow = row;
  259. this.templateItem = item || row;
  260. console.log('currentRow~~~', this.currentRow, this.templateItem);
  261. // this.visible = true;
  262. if(this.currentRow.reportTemplateJson?.basicInfoData) {
  263. this.basicInfoData = this.currentRow.reportTemplateJson.basicInfoData || {};
  264. this.inspectionItems = this.currentRow.reportTemplateJson.inspectionItems || [];
  265. } else {
  266. this.getBasicInfo();
  267. this.getInspectionItems();
  268. }
  269. },
  270. getBasicInfo() {
  271. queryInspectionReportData(this.currentRow.id).then(res => {
  272. this.basicInfoData = res;
  273. });
  274. },
  275. getInspectionItems() {
  276. queryInspectionReportList(this.currentRow.id).then(res => {
  277. this.inspectionItems = res;
  278. });
  279. },
  280. cancel() {
  281. // this.visible = false;
  282. this.$emit('update:visible', false);
  283. },
  284. /* 保存编辑 */
  285. save() {
  286. this.loading = true;
  287. const printSection = document.getElementById('printSection');
  288. const params = {
  289. id: this.currentRow.id,
  290. reportTemplateId: this.templateItem.id,
  291. reportTemplateCode: this.templateItem.code || this.templateItem.reportTemplateCode,
  292. reportTemplateName: this.templateItem.name || this.templateItem.reportTemplateName,
  293. reportTemplateJson: {
  294. template: printSection.innerHTML,
  295. basicInfoData: this.basicInfoData,
  296. inspectionItems: this.inspectionItems,
  297. }
  298. };
  299. generateReport(params).then(res => {
  300. this.loading = false;
  301. this.$message({
  302. message: '保存成功',
  303. type: 'success'
  304. });
  305. this.$emit('reload');
  306. this.cancel();
  307. // this.$emit('update:visible', false);
  308. // this.visible = false;
  309. }).catch(err => {
  310. this.loading = false;
  311. this.$message({
  312. message: err.message,
  313. type: 'error'
  314. });
  315. });
  316. },
  317. /* 打印 */
  318. print() {
  319. const printSection = document.getElementById('printSection');
  320. console.log('printSection', printSection.innerHTML);
  321. // 创建打印任务
  322. const printWindow = window.open('', '_blank');
  323. printWindow.document.open();
  324. printWindow.document.write('<html><head><title>打印预览</title>');
  325. printWindow.document.write(
  326. '<link rel="stylesheet" href="your-stylesheet-url.css" type="text/css" />'
  327. );
  328. printWindow.document.write('</head><body>');
  329. printWindow.document.write(printSection.innerHTML);
  330. printWindow.document.write('</body></html>');
  331. printWindow.document.close();
  332. printWindow.onload = function () {
  333. printWindow.print();
  334. };
  335. }
  336. }
  337. }
  338. </script>