index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <script setup>
  2. import { getDeviceList, getDrawerData } from '@/api/report/lab';
  3. import { dayjs } from 'element-plus';
  4. const { proxy } = getCurrentInstance();
  5. const route = useRoute();
  6. const queryParams = ref({
  7. deviceNo: '',
  8. pageNum: 1,
  9. pageSize: 10
  10. });
  11. const datePieckerValue = ref([dayjs(new Date()).format('YYYY-MM-DD'), dayjs(new Date()).format('YYYY-MM-DD')]);
  12. let firstDeviceNo = '';
  13. const total = ref(0);
  14. const tableData = ref([]);
  15. const loading = ref(false);
  16. const options = ref([]);
  17. const columns = [
  18. {
  19. label: '基本资料',
  20. children: [
  21. { label: "化验开始时间", prop: 'assayTime', width: 180 },
  22. // { label: "设备名称", prop: 'deviceName', width: 180 },
  23. // { label: "设备名称", prop: 'deviceNo', width: 180 },
  24. { label: "所属水厂", prop: 'worksName', width: 180 },
  25. // { label: "样品名称", prop: 'assayTypeName', width: 180 }
  26. ]
  27. },
  28. {
  29. label: '高COD',
  30. children: [
  31. { label: "标称值", prop: 'highCodStandardVal', width: 100 },
  32. { label: "化验值", prop: 'highCodResultConcentration', width: 100 },
  33. { label: "偏差度", prop: 'highCodDeviationRate', width: 100 }
  34. ]
  35. },
  36. {
  37. label: '低COD',
  38. children: [
  39. { label: "标称值", prop: 'lowCodStandardVal', width: 100 },
  40. { label: "化验值", prop: 'lowCodResultConcentration', width: 100 },
  41. { label: "偏差度", prop: 'lowCodDeviationRate', width: 100 }
  42. ]
  43. },
  44. {
  45. label: '氨氮',
  46. children: [
  47. { label: "标称值", prop: 'anDanStandardVal', width: 100 },
  48. { label: "化验值", prop: 'anDanResultConcentration', width: 100 },
  49. { label: "偏差度", prop: 'anDanDeviationRate', width: 100 }
  50. ]
  51. },
  52. {
  53. label: '总氮',
  54. children: [
  55. { label: "标称值", prop: 'tnStandardVal', width: 100 },
  56. { label: "化验值", prop: 'tnResultConcentration', width: 100 },
  57. { label: "偏差度", prop: 'tnDeviationRate', width: 100 }
  58. ]
  59. },
  60. {
  61. label: '总磷',
  62. children: [
  63. { label: "标称值", prop: 'tpStandardVal', width: 100 },
  64. { label: "化验值", prop: 'tpResultConcentration', width: 100 },
  65. { label: "偏差度", prop: 'tpDeviationRate', width: 100 }
  66. ]
  67. },
  68. {
  69. label: '硝酸盐',
  70. children: [
  71. { label: "标称值", prop: 'xsydStandardVal', width: 100 },
  72. { label: "化验值", prop: 'xsydResultConcentration', width: 100 },
  73. { label: "偏差度", prop: 'xsydDeviationRate', width: 100 }
  74. ]
  75. },
  76. {
  77. label: '亚硝酸盐',
  78. children: [
  79. { label: "标称值", prop: 'yxsyStandardVal', width: 100 },
  80. { label: "化验值", prop: 'yxsyResultConcentration', width: 100 },
  81. { label: "偏差度", prop: 'yxsyDeviationRate', width: 100 }
  82. ]
  83. },
  84. {
  85. label: '正磷酸盐',
  86. children: [
  87. { label: "标称值", prop: 'zlsyStandardVal', width: 100 },
  88. { label: "化验值", prop: 'zlsyResultConcentration', width: 100 },
  89. { label: "偏差度", prop: 'zlsyDeviationRate', width: 100 }
  90. ]
  91. }
  92. ]
  93. const finalyColumns = ref([]);
  94. const initPageData = async () => {
  95. loading.value = true;
  96. const [ timeBegin, timeEnd ] = datePieckerValue.value;
  97. const { total: tableTotal, rows } = await getDrawerData({ ...queryParams.value, timeBegin, timeEnd, type: route.query.t });
  98. const arr = [];
  99. for (let index = 1; index < columns.length; index++) {
  100. const children = columns[index].children;
  101. const tempArr = [];
  102. for (let i = 1; i < children.length; i++) {
  103. const item = children[i];
  104. tempArr.push(item.prop);
  105. }
  106. arr.push( tempArr );
  107. }
  108. const tempColumns = [];
  109. arr.forEach((item, index) => {
  110. const [k1] = item;
  111. const isExits = rows.some((val) => val[k1]);
  112. if ( isExits ) {
  113. tempColumns.push(columns[index + 1]);
  114. }
  115. })
  116. finalyColumns.value = rows.length ? [columns[0]].concat(tempColumns) : [];
  117. tableData.value = rows;
  118. total.value = tableTotal;
  119. loading.value = false;
  120. }
  121. // 查询
  122. const handleQuery = async() => {
  123. initPageData();
  124. }
  125. // 重置
  126. const handleReset = () => {
  127. datePieckerValue.value = [dayjs(new Date()).format('YYYY-MM-DD'), dayjs(new Date()).format('YYYY-MM-DD')];
  128. queryParams.value.pageNum = 1;
  129. queryParams.value.pageSize = 10;
  130. queryParams.value.deviceNo = firstDeviceNo;
  131. initPageData();
  132. }
  133. // 导出
  134. const handleExport = () => {
  135. const [ timeBegin, timeEnd ] = datePieckerValue.value;
  136. proxy.getDownload("/business/exportAssayPageListByDeviceNoAndDate", {
  137. timeBegin, timeEnd, deviceNo: queryParams.value.deviceNo, type: route.query.t
  138. }, `${new Date().getTime()}.xlsx`);
  139. }
  140. const test = (key, item) => {
  141. let color = '#606266';
  142. const whitelist = [
  143. 'highCodDeviationRate',
  144. 'lowCodDeviationRate',
  145. 'anDanDeviationRate',
  146. 'tnDeviationRate',
  147. 'tpDeviationRate',
  148. 'xsydDeviationRate',
  149. 'yxsyDeviationRate',
  150. 'zlsyDeviationRate',
  151. ]
  152. if ( whitelist.includes(key) ) {
  153. const n = item[key + 'Number'];
  154. if ( (n || n == 0) && Math.abs( n ) > 0.1 ) {
  155. color = 'red'
  156. }
  157. }
  158. return {color};
  159. }
  160. onMounted(async () => {
  161. await getDeviceList({ type: route.query.t }).then(({ data }) => {
  162. const [ item ] = data;
  163. queryParams.value.deviceNo = item?.deviceNo;
  164. firstDeviceNo = item?.deviceNo;
  165. options.value = data
  166. });
  167. await initPageData();
  168. })
  169. </script>
  170. <template>
  171. <div class="space-y-[10px]">
  172. <el-card shadow="never" :body-style="{ border: '0px' }">
  173. <template #header>
  174. <p class="space-x-[10px]">
  175. <span class="font-bold">数据筛选</span>
  176. </p>
  177. </template>
  178. <el-row class="pt-[5px]" justify="space-between" :gutter="20">
  179. <el-col :span="6">
  180. <el-form-item label="设备名称">
  181. <el-select v-model="queryParams.deviceNo" placeholder="请选择" filterable clearable>
  182. <el-option v-for="item in options" :key="item.deviceNo" :label="item.deviceName" :value="item.deviceNo" />
  183. </el-select>
  184. </el-form-item>
  185. </el-col>
  186. <el-col :span="6">
  187. <el-form-item>
  188. <template #label>
  189. <span class="font-bold">化验日期</span>
  190. </template>
  191. <el-date-picker
  192. :clearable="false"
  193. v-model="datePieckerValue"
  194. type="daterange"
  195. range-separator="-"
  196. start-placeholder="开始日期"
  197. end-placeholder="结束日期"
  198. :editable="false"
  199. value-format="YYYY-MM-DD"
  200. />
  201. </el-form-item>
  202. </el-col>
  203. <el-col :span="6" :offset="6">
  204. <div class="flex justify-end">
  205. <el-button type="primary" @click="handleQuery" :loading="loading">查询</el-button>
  206. <el-button @click="handleReset" :loading="loading">重置</el-button>
  207. </div>
  208. </el-col>
  209. </el-row>
  210. </el-card>
  211. <el-card shadow="never" :body-style="{ padding: '20px' }">
  212. <div class="flex justify-between items-center mb-[10px]">
  213. <h4 class="font-bold">化验记录</h4>
  214. <el-button type="warning" plain icon="Download" @click="handleExport">导出</el-button>
  215. </div>
  216. <el-table :data="tableData" style="width: 100%" v-loading="loading">
  217. <el-table-column :label="col.label" :min-width="col.width" :fixed="col.fixed" align="center" v-for="col in finalyColumns">
  218. <el-table-column :prop="child.prop" :label="child.label" :min-width="child.width" v-for="child in col.children">
  219. <template #default="scope">
  220. <span :style="test(child.prop, scope.row)">{{ scope.row[child.prop] }}</span>
  221. </template>
  222. </el-table-column>
  223. </el-table-column>
  224. </el-table>
  225. <div class="">
  226. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
  227. v-model:limit="queryParams.pageSize" @pagination="initPageData" />
  228. </div>
  229. </el-card>
  230. </div>
  231. </template>
  232. <style lang="less" scoped></style>