bms.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <div class="charge-box">
  3. <div class="charge-tools">
  4. <el-form :inline="true" :model="queryParams">
  5. <el-form-item label="日志范围:" style="margin-left: 35px">
  6. <el-select
  7. multiple
  8. v-model="robotValue"
  9. clearable
  10. placeholder="请选择"
  11. @change="changeSelect"
  12. collapse-tags
  13. @remove-tag="removeTag"
  14. >
  15. <el-option label="全选" value="全选" @click.native="selectAll"></el-option>
  16. <el-option
  17. v-for="item in logOptions"
  18. :key="item.alarmCode"
  19. :label="item.alarmName"
  20. :value="item.alarmCode"
  21. />
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="充电机ID:" style="margin-left: 35px">
  25. <el-select v-model="queryParams.deviceNo" clearable placeholder="请选择">
  26. <el-option
  27. v-for="item in chargerArr"
  28. :key="item.value"
  29. :label="item+'号充电机'"
  30. :value="item"
  31. />
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="电池编号:" style="margin-left: 50px;">
  35. <el-input v-model.trim="queryParams.sn" placeholder="请输入电池编号" clearable />
  36. </el-form-item>
  37. <el-form-item label="时间范围:" style="margin-left: 50px">
  38. <el-date-picker
  39. v-model="dateTime"
  40. class="times"
  41. type="datetimerange"
  42. range-separator="至"
  43. start-placeholder="开始时间"
  44. end-placeholder="结束时间"
  45. format="yyyy-MM-dd HH:mm:ss"
  46. />
  47. </el-form-item>
  48. <el-form-item>
  49. <el-button type="primary" class="serch actve" @click="handleQuery">查询</el-button>
  50. <el-button type="primary" class="serch" @click="resetForm">重置</el-button>
  51. </el-form-item>
  52. </el-form>
  53. </div>
  54. <div class="charge-table">
  55. <div class="charge-table-top">
  56. <el-button type="primary" class="daochu" @click="chargeExport">导出结果</el-button>
  57. </div>
  58. <div class="charge-table-bottom">
  59. <el-table
  60. :data="datalist"
  61. :header-cell-style="{
  62. background: '#1d283e',
  63. borderColor: '#2f3c86',
  64. height: '36px',
  65. lineHeight: '36px',
  66. color:'white',
  67. fontSize: '15px',
  68. }"
  69. stripe
  70. fit
  71. :height="tableheight"
  72. style="width: 100%"
  73. ref="tblist"
  74. >
  75. <el-table-column
  76. prop="time"
  77. label="发生时间"
  78. fixed
  79. width="150">
  80. </el-table-column>
  81. <el-table-column
  82. prop="deviceNo"
  83. label="充电机ID"
  84. fixed
  85. width="150"
  86. v-if="logheader.length"
  87. >
  88. </el-table-column>
  89. <el-table-column
  90. prop="sn"
  91. label="电池编号"
  92. fixed
  93. width="150">
  94. </el-table-column>
  95. <el-table-column v-for="log in logheader" :key="log.alarmCode" :label="log.alarmName" :render-header="labelHead">
  96. <template slot-scope="scope">
  97. {{ scope.row[log.alarmCode] }}
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. </div>
  102. <div class="pageblock">
  103. <el-pagination
  104. :current-page="queryParams.page"
  105. :page-sizes="[10, 20, 30, 40]"
  106. :page-size="queryParams.pageSize"
  107. layout="total, sizes, prev, pager, next, jumper"
  108. :total="total"
  109. @size-change="handleSizeChange"
  110. @current-change="handleCurrentChange"
  111. />
  112. </div>
  113. </div>
  114. <!--导出弹窗-->
  115. <div class="rolemanage chargeshow">
  116. <el-dialog
  117. title="生成导出任务"
  118. :visible.sync="dialogExportVisible"
  119. :destroy-on-close="true"
  120. >
  121. <div class="setExport">
  122. <el-form :model="ruleForm" :rules="rules" ref="ExportForm">
  123. <el-form-item label="任务名称" prop="exportName">
  124. <el-input v-model="ruleForm.exportName" placeholder="请输入任务名称"></el-input>
  125. </el-form-item>
  126. <el-form-item>
  127. <el-button type="primary" @click="AddExport">生成</el-button>
  128. </el-form-item>
  129. </el-form>
  130. <div class="descript">说明:导出任务生成后,你可以在数据导出列表中进行查询和下载</div>
  131. </div>
  132. </el-dialog>
  133. </div>
  134. <!--导出弹窗结束-->
  135. </div>
  136. </template>
  137. <script>
  138. import './log.scss'
  139. import { BmsModel,bmsList,exportFile } from '@/api/log'
  140. import { getChargeCode } from '@/api/records'
  141. export default {
  142. name: 'Bms',
  143. components: {},
  144. data() {
  145. return {
  146. // 查询时间数组
  147. dateTime: '',
  148. // 充电机ID下拉列表
  149. chargerArr: null,
  150. // 数据列表
  151. datalist: [],
  152. // 查询参数
  153. queryParams: {
  154. page: 1, // 当前页
  155. pageSize: 10, // 每页条数
  156. deviceNo: undefined,
  157. endTime: undefined, // 电池编号
  158. signals: undefined, // 排序字段
  159. startTime: undefined, // 排序方式
  160. sn: undefined,
  161. sort: 1,
  162. },
  163. total: 0, // 总条数,
  164. tableheight: 0, // 表格高度设置
  165. dialogExportVisible: false, // 弹窗显示
  166. checked: false,
  167. indeterminate: false,
  168. robotValue:'',
  169. logOptions: [],
  170. logheader:[],
  171. heightTimer:false,
  172. loading: false,
  173. ruleForm:{
  174. exportName:undefined,
  175. },
  176. rules:{
  177. exportName: [
  178. { required: true, message: '请输入任务名称', trigger: 'blur' },
  179. { min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
  180. ],
  181. }
  182. }
  183. },
  184. mounted() {
  185. this.getChargeCode()
  186. this.onLoadHeight()
  187. this.changeWindow()
  188. this.getLogModel()
  189. this.getrobotList()
  190. },
  191. methods: {
  192. labelHead(h,{column,index}){
  193. let l = column.label.length
  194. let f = 20
  195. if(l <= 3){
  196. f = 30
  197. }else if(l >= 14){
  198. f = 15
  199. }
  200. column.minWidth = f*l
  201. return h('div',{class:'table-head',style:{minWidth:'100%'}},[column.label])
  202. },
  203. selectAll() {
  204. if (this.robotValue.length < this.logOptions.length) {
  205. this.robotValue = [];
  206. this.logOptions.map((item) => {
  207. this.robotValue.push(item.alarmCode);
  208. });
  209. this.robotValue.unshift("全选");
  210. } else {
  211. this.robotValue = [];
  212. }
  213. },
  214. changeSelect(val) {
  215. if (!val.includes("全选") && val.length === this.logOptions.length) {
  216. this.robotValue.unshift("全选");
  217. } else if (val.includes("全选") && val.length - 1 < this.logOptions.length) {
  218. this.robotValue = this.robotValue.filter((item) => {
  219. return item !== "全选";
  220. });
  221. }
  222. },
  223. removeTag(val) {
  224. if (val === "全选") {
  225. this.robotValue = [];
  226. }
  227. },
  228. // 获取充电机ID
  229. getChargeCode() {
  230. getChargeCode().then(res => {
  231. this.chargerArr = res.data
  232. })
  233. },
  234. //获取BMS日志列表
  235. getrobotList(){
  236. this.loading=true;
  237. bmsList(this.queryParams).then( res =>{
  238. this.datalist= res.data.list
  239. this.total=res.data.total
  240. this.$nextTick(()=>{
  241. this.$refs.tblist.doLayout();
  242. })
  243. this.loading=false
  244. })
  245. },
  246. //获取日志数据字典
  247. getLogModel(){
  248. BmsModel().then( res =>{
  249. this.logOptions= res.data
  250. this.logheader=res.data
  251. this.$nextTick(()=>{
  252. this.$refs.tblist.doLayout();
  253. })
  254. })
  255. },
  256. /** 分页下一页 */
  257. handleSizeChange(val) {
  258. this.queryParams.pageSize = val
  259. this.getrobotList()
  260. },
  261. /** 分页选择页数 */
  262. handleCurrentChange(val) {
  263. this.queryParams.page = val
  264. this.getrobotList()
  265. },
  266. // 搜索
  267. handleQuery() {
  268. console.log(this.queryParams.sn)
  269. if (this.dateTime || this.robotValue.length > 0 || this.queryParams.sn || this.queryParams.deviceNo != undefined) {
  270. if (this.dateTime) {
  271. this.queryParams.startTime = this.$moment(this.dateTime[0]).format(
  272. "YYYY-MM-DD HH:mm:ss"
  273. );
  274. this.queryParams.endTime = this.$moment(this.dateTime[1]).format(
  275. "YYYY-MM-DD HH:mm:ss"
  276. );
  277. }
  278. if (this.robotValue.length > 0) {
  279. this.queryParams.signals = this.robotValue;
  280. let differenceABSet = Array.from(
  281. new Set(
  282. [...this.logOptions].filter((x) =>
  283. this.robotValue.includes(x.alarmCode)
  284. )
  285. )
  286. );
  287. this.logheader = differenceABSet;
  288. }
  289. this.getrobotList();
  290. }else{
  291. this.$message({
  292. message: "请选择查询条件!",
  293. type: "warning",
  294. duration: 1000,
  295. offset: 20,
  296. });
  297. }
  298. },
  299. // 搜索重置
  300. resetForm() {
  301. this.queryParams.startTime = undefined;
  302. this.queryParams.endTime = undefined;
  303. this.queryParams.signals = undefined;
  304. this.queryParams.batteryNum = undefined;
  305. this.queryParams.deviceNo = undefined;
  306. this.queryParams.sn = "";
  307. this.robotValue = "";
  308. this.dateTime = "";
  309. this.queryParams.page = 1;
  310. this.queryParams.pageSize = 10;
  311. this.getrobotList();
  312. this.getLogModel();
  313. },
  314. // 导出结果
  315. chargeExport() {
  316. this.dialogExportVisible=true
  317. },
  318. //生成报表
  319. AddExport(){
  320. this.$refs.ExportForm.validate((valid) => {
  321. if (valid) {
  322. let addParams={
  323. exportName:this.ruleForm.exportName,
  324. signals:this.robotValue,
  325. sn:this.queryParams.sn,
  326. startTime:this.queryParams.startTime,
  327. endTime:this.queryParams.endTime,
  328. exportLogType:3
  329. }
  330. exportFile(addParams).then( res =>{
  331. console.log(res)
  332. if(res.code === 0){
  333. this.dialogExportVisible = false;
  334. this.$router.push({path:"/manage-log/data-export"})
  335. }else{
  336. this.$message({
  337. message: res.msg,
  338. type: "warning",
  339. duration: 1000,
  340. offset: 20,
  341. });
  342. }
  343. })
  344. } else {
  345. return false;
  346. }
  347. });
  348. }
  349. }
  350. }
  351. </script>