report-template.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <script setup lang="ts">
  2. import { ref } from "vue";
  3. import TemplateList from "./com/templateList.vue";
  4. import {
  5. getProductCodeListById,
  6. getTestedProductList,
  7. getTestingDataByCode,
  8. saveExcelTemplate,
  9. updateExcelTemplate,
  10. } from "@/api/project/template";
  11. const excelRef = ref(null);
  12. const excelData = ref(null);
  13. // 打开模版
  14. const temsDrawerVisible = ref(false);
  15. const listRef = ref();
  16. const currentTemplate = ref(null);
  17. const onSelectTemplate = (tem) => {
  18. currentTemplate.value = tem;
  19. temsDrawerVisible.value = false;
  20. formData.engineeringId = tem.engineeringId;
  21. formData.formName = tem.formName;
  22. formData.productCode = tem.productCode;
  23. // 如果有值 并且是json字符串 则解析
  24. excelData.value = null;
  25. if (tem.excelData) {
  26. excelData.value = JSON.parse(tem.excelData);
  27. }
  28. console.log("返回的exccel数据", excelData.value);
  29. getProductCodeListById(formData.engineeringId).then((res) => {
  30. codeAllList.value = res.data;
  31. codeList.value = codeAllList.value;
  32. });
  33. };
  34. const onOpenTemplate = () => {
  35. temsDrawerVisible.value = true;
  36. nextTick(() => {
  37. listRef.value && listRef.value.openDrawer();
  38. });
  39. };
  40. const onImportTemplate = () => {
  41. if (excelRef.value) {
  42. excelRef.value.importExcel();
  43. }
  44. };
  45. const onExportTemplate = () => {
  46. if (excelRef.value) {
  47. excelRef.value.exportExcel();
  48. }
  49. console.log("onExportTemplate");
  50. };
  51. // ===== 右侧区域 =======
  52. const formRef = ref(null);
  53. const formData = reactive({
  54. engineeringId: "",
  55. formName: "",
  56. productCode: "",
  57. });
  58. const rules = reactive({
  59. engineeringId: { required: true, message: "请选择产品", trigger: "blur" },
  60. productCode: { required: true, message: "请选择编号", trigger: "blur" },
  61. formName: { required: true, message: "请输入模版名称", trigger: "blur" },
  62. });
  63. // 产品选择器
  64. const productAllList = ref<any[]>([]); // 产品列表
  65. const productList = ref<any[]>([]); // 产品列表
  66. const proProps = {
  67. label: "engineeringProductName",
  68. value: "id",
  69. };
  70. const proLoading = ref(false);
  71. const proRemoteMethod = (query: string) => {
  72. let queryString = query.trim();
  73. if (queryString.length === 0) {
  74. productList.value = productAllList.value;
  75. return;
  76. }
  77. getTestedProductList({
  78. engineeringProductName: queryString,
  79. executeStatus: true,
  80. }).then((res) => {
  81. productList.value = res.data;
  82. });
  83. };
  84. const onProductChange = (val) => {
  85. getProductCodeListById(formData.engineeringId).then((res) => {
  86. codeAllList.value = res.data;
  87. codeList.value = codeAllList.value;
  88. });
  89. };
  90. // 产品编号选择器
  91. const codeAllList = ref<any[]>([]); // 产品编号列表
  92. const codeList = ref<any[]>([]); // 产品编号列表
  93. const codeProps = {
  94. label: "productCode",
  95. value: "productCode",
  96. };
  97. const codeLoading = ref(false);
  98. const codeRemoteMethod = (query: string) => {
  99. let queryString = query.trim();
  100. if (queryString.length === 0) {
  101. codeList.value = codeAllList.value;
  102. return;
  103. }
  104. getProductCodeListById(formData.engineeringId, queryString).then((res) => {
  105. codeList.value = res.data;
  106. });
  107. };
  108. const onSaveTemplate = async () => {
  109. await formRef.value?.validate();
  110. const res = excelRef.value.getExcelData();
  111. console.log("保存的exccel数据", res);
  112. let p = {
  113. excelData: JSON.stringify(res),
  114. ...formData,
  115. id: currentTemplate.value?.id || null,
  116. };
  117. if (p.id) {
  118. await updateExcelTemplate(p);
  119. } else {
  120. let result = await saveExcelTemplate(p);
  121. }
  122. formRef.value && formRef.value.resetFields();
  123. currentTemplate.value = null;
  124. excelData.value = null;
  125. ElMessage.success("保存成功");
  126. };
  127. // 点击搜索按钮查询 产品编码下的测试数据
  128. const testingDataList = ref<any[]>([]); // 测试数据列表
  129. const onSearchTestingData = async () => {
  130. console.log(formData);
  131. let res = await getTestingDataByCode(
  132. formData.engineeringId,
  133. formData.productCode
  134. );
  135. testingDataList.value = res.data;
  136. };
  137. // 点击测试数据的写入
  138. const onWriteTestingData = (item) => {
  139. let toWriteValue = `{{${item.dataItem}&${item.engineeringProjectId}}}`; //{{温度}
  140. excelRef.value.setCellValue(toWriteValue);
  141. // console.log(
  142. // "onWriteTestingData",
  143. // toWriteValue,
  144. // excelRef.value.setCellValue
  145. // );
  146. };
  147. onMounted(() => {
  148. getTestedProductList({
  149. executeStatus: true,
  150. }).then((res) => {
  151. productAllList.value = res.data;
  152. productList.value = productAllList.value;
  153. });
  154. });
  155. </script>
  156. <template>
  157. <div class="report-template">
  158. <div class="left">
  159. <div class="header">
  160. <div class="header-left">
  161. <div class="blue-btn" @click="onOpenTemplate">
  162. <svg-icon icon-class="save" />
  163. 打开模版
  164. </div>
  165. <div class="blue-btn" @click="onImportTemplate">
  166. <svg-icon icon-class="report-template" />
  167. 导入模版
  168. </div>
  169. <div class="blue-btn" @click="onExportTemplate">
  170. <svg-icon icon-class="save" />
  171. 导出模版
  172. </div>
  173. </div>
  174. <div>
  175. <div class="blue-btn" @click="onSaveTemplate">
  176. <svg-icon icon-class="save" />
  177. 保存模版
  178. </div>
  179. </div>
  180. </div>
  181. <div class="excel-container">
  182. <ExcelView ref="excelRef" v-if="excelData" :data="excelData" />
  183. </div>
  184. </div>
  185. <div class="right">
  186. <div class="title-header">测试项查询</div>
  187. <el-form
  188. ref="formRef"
  189. v-model:model="formData"
  190. :rules="rules"
  191. label-position="top"
  192. >
  193. <el-form-item label="模版名称" prop="formName">
  194. <el-input v-model="formData.formName" placeholder="请输入模版名称" />
  195. </el-form-item>
  196. <el-form-item label="产品" prop="engineeringId">
  197. <el-select-v2
  198. v-model="formData.engineeringId"
  199. filterable
  200. remote
  201. :remote-method="proRemoteMethod"
  202. clearable
  203. :props="proProps"
  204. :options="productList"
  205. :loading="proLoading"
  206. placeholder="请选择产品名称"
  207. @change="onProductChange"
  208. />
  209. </el-form-item>
  210. <el-form-item label="产品编号" prop="productCode">
  211. <el-select-v2
  212. v-model="formData.productCode"
  213. filterable
  214. remote
  215. :remote-method="codeRemoteMethod"
  216. clearable
  217. :props="codeProps"
  218. :options="codeList"
  219. :loading="codeLoading"
  220. placeholder="请选择产品编号"
  221. />
  222. </el-form-item>
  223. </el-form>
  224. <div class="blue-btn" style="width: 100%" @click="onSearchTestingData">
  225. <svg-icon icon-class="search" />
  226. 搜索
  227. </div>
  228. <div class="white-line"></div>
  229. <div class="result-text">搜索结果</div>
  230. <el-scrollbar class="scroll-bottm-height">
  231. <div class="result-box">
  232. <div v-for="item in testingDataList" :key="item.projectName">
  233. <div class="result-title-text">{{ item.projectName }}</div>
  234. <div class="result-bar" v-for="log in item.logList">
  235. <el-icon
  236. size="20"
  237. style="cursor: pointer"
  238. @click.stop="onWriteTestingData(log)"
  239. >
  240. <DocumentAdd
  241. /></el-icon>
  242. <div>{{ log.dataItem }}</div>
  243. <div></div>
  244. </div>
  245. </div>
  246. </div>
  247. </el-scrollbar>
  248. </div>
  249. <el-drawer
  250. v-model="temsDrawerVisible"
  251. :with-header="false"
  252. :append-to-body="true"
  253. :destroy-on-close="true"
  254. size="800"
  255. direction="ltr"
  256. >
  257. <TemplateList
  258. ref="listRef"
  259. @close="temsDrawerVisible = false"
  260. @selected="onSelectTemplate"
  261. ></TemplateList>
  262. </el-drawer>
  263. </div>
  264. </template>
  265. <style scoped lang="scss">
  266. .report-template {
  267. display: flex;
  268. height: calc(100vh - $main-header-height);
  269. .left {
  270. flex: 1;
  271. height: calc(100vh - $main-header-height);
  272. .header {
  273. width: 100%;
  274. height: 64px;
  275. background-color: $hj-black-3;
  276. display: flex;
  277. justify-content: space-between;
  278. align-items: center;
  279. padding: 0 12px;
  280. .header-left {
  281. display: flex;
  282. gap: 10px;
  283. }
  284. }
  285. .excel-container {
  286. height: calc(100vh - $main-header-height - 64px);
  287. width: calc(100vw - 296px - 80px);
  288. position: relative;
  289. }
  290. }
  291. .right {
  292. width: 296px;
  293. height: calc(100vh - $main-header-height);
  294. background-color: $hj-black-2;
  295. padding: 0 24px;
  296. .white-line {
  297. height: 1px;
  298. width: 100%;
  299. background-color: $hj-white-4;
  300. margin-top: 12px;
  301. }
  302. .result-text {
  303. margin-top: 11px;
  304. height: 18px;
  305. font-size: 14px;
  306. color: #ffffff;
  307. line-height: 16px;
  308. text-align: center;
  309. }
  310. .result-box {
  311. margin-top: 12px;
  312. padding: 12px 6px;
  313. //height: calc(100vh - $main-header-height - 64px - 12px - 330px);
  314. //overflow-y: auto;
  315. .result-title-text {
  316. font-size: 14px;
  317. color: #ffffff;
  318. line-height: 16px;
  319. text-align: left;
  320. }
  321. .result-bar {
  322. height: 36px;
  323. line-height: 36px;
  324. background: linear-gradient(180deg, #656565 0%, #555555 100%);
  325. box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.25);
  326. border-radius: 4px 4px 4px 4px;
  327. font-weight: 400;
  328. font-size: 12px;
  329. color: #ffffff;
  330. margin-top: 8px;
  331. text-align: center;
  332. display: flex;
  333. justify-content: space-around;
  334. align-items: center;
  335. padding: 0 12px;
  336. }
  337. }
  338. }
  339. }
  340. .scroll-bottm-height {
  341. height: calc(100vh - $main-header-height - 64px - 12px - 330px);
  342. border-radius: 4px 4px 4px 4px;
  343. border: 1px solid #696969;
  344. }
  345. .blue-btn {
  346. width: 130px;
  347. height: 36px;
  348. line-height: 36px;
  349. margin: 0 auto;
  350. background: var(--fc-color-7);
  351. color: var(--hj-white-1);
  352. text-align: center;
  353. border-radius: 4px 4px 4px 4px;
  354. cursor: pointer;
  355. }
  356. .title-header {
  357. height: 65px;
  358. font-weight: 400;
  359. font-size: 16px;
  360. color: $hj-white-1;
  361. line-height: 65px;
  362. text-align: left;
  363. background-color: $hj-black-2;
  364. }
  365. :deep(.el-form-item--label-top .el-form-item__label) {
  366. height: 18px;
  367. font-weight: 400;
  368. font-size: 14px;
  369. color: #ffffff;
  370. line-height: 16px;
  371. text-align: left;
  372. }
  373. </style>