index.vue 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058
  1. <template>
  2. <div v-if="showReportData" style="width: 100%; height: calc(100% - 70px);">
  3. <div class="cy-report-content">
  4. <div class="cy-div0">
  5. <div class="cy-report-ruler-unit">mm</div>
  6. </div>
  7. <div class="cy-div1">
  8. <div class="cy-ruler-top">
  9. <ruler-view ruler-position="horizontal"></ruler-view>
  10. </div>
  11. <div class="cy-box">
  12. <div class="cy-ruler-left">
  13. <ruler-view ruler-position="vertical"></ruler-view>
  14. </div>
  15. <div class="cy-box-main">
  16. <el-input type="text" placeholder="请输入报表模板名称" v-model="templateName" maxlength="20" size="mini"
  17. show-word-limit></el-input>
  18. <div id="luckysheet"
  19. style="margin:0px;padding:0px;position:relative;height:calc(100% - 40px);width:100%;left: 0px;top: 0px;bottom:0px;">
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="cy-div2">
  25. <input ref="importFileNode" class="import-file-node" type="file" @change="loadExcel"
  26. style="display: none;"></input>
  27. <div v-if="templateId && templateId != 0 && templateId != -999" class="cy-chart-div"
  28. @click="saveReportTemplate('saveAs')">
  29. <svg-icon icon-class="report_saveas" style="width: 35px; height: 35px; margin-bottom: 6px;"/>
  30. <span>另存为</span>
  31. </div>
  32. <div class="cy-chart-div" @click="saveReportTemplate">
  33. <svg-icon icon-class="report_save" style="width: 35px; height: 35px; margin-bottom: 6px;"/>
  34. <span>保存</span>
  35. </div>
  36. <div class="cy-chart-div" @click="printExcel()">
  37. <svg-icon icon-class="cy-print" style="width: 30px; height: 30px; margin-bottom: 8px;"/>
  38. <span>打印</span>
  39. </div>
  40. <div class="cy-chart-div" @click="resetReport(false)">
  41. <svg-icon icon-class="report_reset" style="width: 30px; height: 30px; margin-bottom: 8px;"/>
  42. <span>重置</span>
  43. </div>
  44. <div class="cy-chart-div" @click="closeReport">
  45. <svg-icon icon-class="report_cancel" style="width: 30px; height: 30px; margin-bottom: 8px;"/>
  46. <span>关闭</span>
  47. </div>
  48. <el-divider></el-divider>
  49. <div class="cy-chart-div" @click="templateEvent()" v-if="templateReportType != 2 && templateReportType != 5">
  50. <svg-icon icon-class="report_template" style="width: 35px;"/>
  51. <span>模板库</span>
  52. </div>
  53. <div class="cy-chart-div" @click="dataEvent(1)" v-if="templateReportType != 2 && templateReportType != 5">
  54. <svg-icon icon-class="report_basedata" style="width: 35px;"/>
  55. <span>基础数据项</span>
  56. </div>
  57. <div class="cy-chart-div" @click="dataEvent(2)">
  58. <svg-icon icon-class="report_data_u" style="width: 35px;"/>
  59. <span>附属属性</span>
  60. </div>
  61. <div class="cy-chart-div" @click="dataEvent(3)">
  62. <svg-icon icon-class="report_data" style="width: 35px;"/>
  63. <span>数据项</span>
  64. </div>
  65. <div class="cy-chart-div" @click="updateDataEvent()" v-if="templateReportType != 5">
  66. <svg-icon icon-class="report_data" style="width: 35px;"/>
  67. <span>修改策略</span>
  68. </div>
  69. <div class="cy-chart-div" @click="barEvent('bar')" v-if="templateReportType != 2 && templateReportType != 5">
  70. <svg-icon icon-class="bar_chart"/>
  71. <span>柱状图</span>
  72. </div>
  73. <div class="cy-chart-div" @click="barEvent('line')" v-if="templateReportType != 2 && templateReportType != 5">
  74. <svg-icon icon-class="line_chart"/>
  75. <span>折线图</span>
  76. </div>
  77. <div class="cy-chart-div" @click="barEvent('pie')" v-if="templateReportType != 2 && templateReportType != 5">
  78. <svg-icon icon-class="pie_chart"/>
  79. <span>饼状图</span>
  80. </div>
  81. </div>
  82. </div>
  83. <!-- 图表右键操作 -->
  84. <ul v-show="visibleChartMenu"
  85. :style="{ left: menuLeft + 'px', top: menuTop + 'px' }"
  86. class="contextmenu contextmenu-black">
  87. <li @click="updateChartItem">修改</li>
  88. <li @click="delChartItem">删除</li>
  89. </ul>
  90. <!-- 弹出层:图配置 -->
  91. <el-drawer
  92. :title="chartConfigTitle"
  93. :visible.sync="dialogBarChartVisible"
  94. :show-close="false"
  95. :close-on-press-escape="false"
  96. :wrapperClosable="false"
  97. size="30%"
  98. :before-close="dialogClose">
  99. <el-form ref="barChartForm" :model="barChartForm" label-position="top" size="mini" style="margin: 0 20px 20px;">
  100. <el-form-item label="图表标题:" prop="title" class="label-title1">
  101. <el-input type="text" placeholder="请输入标题" v-model="barChartForm.title" maxlength="80" show-word-limit>
  102. </el-input>
  103. </el-form-item>
  104. <el-form-item label="图表副标题:" prop="subtitle" class="label-title1">
  105. <el-input type="text" placeholder="请输入副标题" v-model="barChartForm.subtitle" maxlength="60"
  106. show-word-limit>
  107. </el-input>
  108. </el-form-item>
  109. <el-form-item label="是否显示图表标题:" prop="showTitle">
  110. <el-radio v-model="barChartForm.showTitle" label="1">是</el-radio>
  111. <el-radio v-model="barChartForm.showTitle" label="0">否</el-radio>
  112. </el-form-item>
  113. <el-form-item label="是否显示图例:" prop="showLegend">
  114. <el-radio v-model="barChartForm.showLegend" label="1">是</el-radio>
  115. <el-radio v-model="barChartForm.showLegend" label="0">否</el-radio>
  116. </el-form-item>
  117. <!-- <el-form-item label="图例:" prop="legendType" v-if="barChartForm.type != 'pie'">-->
  118. <!-- <el-radio v-model="barChartForm.legendType" label="1">数据项</el-radio>-->
  119. <!-- <el-radio v-model="barChartForm.legendType" label="0">值</el-radio>-->
  120. <!-- </el-form-item>-->
  121. <el-form-item label="数据组:">
  122. <el-select filterable
  123. v-model="chooseDataGroup"
  124. placeholder="请选择数据组"
  125. @change="dataSourceChange"
  126. style="width: calc(100% - 110px);">
  127. <el-option
  128. v-for="dict in dataGroupList"
  129. :key="dict.id"
  130. :label="dict.groupName"
  131. :value="dict.id"
  132. ></el-option>
  133. </el-select>
  134. <el-button size="mini" @click="addDataItem" style="float: right;width: 100px;">选择数据项</el-button>
  135. <el-tag size="mini" v-if="chooseItemData.length > 0"
  136. style="margin-top: 10px;"
  137. class="cy-item-tag">已选择({{ chooseItemData.length }})项
  138. </el-tag>
  139. </el-form-item>
  140. <template v-if="chooseItemData.length > 0">
  141. <el-form-item label="取值类型:" prop="valueType">
  142. <el-radio v-for="item in valueTypeList"
  143. v-model="barChartForm.valueType"
  144. :label="item.value">{{ item.label }}
  145. </el-radio>
  146. </el-form-item>
  147. <el-form-item label="取值模式:" prop="valueTakingMode" v-if="templateReportType == 1">
  148. <el-radio v-for="item in valueTakingModeList"
  149. v-model="barChartForm.valueTakingMode"
  150. :label="item.value">{{ item.label }}
  151. </el-radio>
  152. </el-form-item>
  153. <template v-if="templateReportType == 1">
  154. <el-divider content-position="left">取值周期设置</el-divider>
  155. <div class="cy-line" style="margin-bottom: 20px;">
  156. <el-form-item label="时间单位:" prop="bucketType">
  157. <el-radio v-for="item in bucketTypeList"
  158. v-model="barChartForm.bucketType"
  159. :label="item.value">{{ item.label }}
  160. </el-radio>
  161. </el-form-item>
  162. <el-form-item label="数据切换周期:" prop="bucketValue">
  163. <el-input-number label="请输入周期值"
  164. v-model="barChartForm.bucketValue"
  165. :precision="0"
  166. :min="1"
  167. :max="100"></el-input-number>
  168. </el-form-item>
  169. </div>
  170. </template>
  171. </template>
  172. <!-- <el-button type="warning" size="mini" @click="insertBarChartForm(0)">应用</el-button>-->
  173. <el-button type="primary" size="mini" @click="insertBarChartForm(1)">保存</el-button>
  174. <el-button size="mini" @click="cancelBarChartForm">取消</el-button>
  175. </el-form>
  176. </el-drawer>
  177. <!-- 数据组选择 -->
  178. <el-dialog
  179. title="选择数据项"
  180. width="600px"
  181. top="10vh"
  182. center
  183. v-dialog-drag-and-zoom
  184. v-if="dialogDataItemVisible"
  185. :before-close="dialogItemClose"
  186. :visible.sync="dialogDataItemVisible"
  187. :close-on-click-modal="false"
  188. :append-to-body="true">
  189. <div>
  190. <div style="margin-bottom: 10px;">
  191. <span>组名称:{{ itemDataListByGroupName }}(共 {{ itemDataListByTree.length }} 项)</span>
  192. <el-checkbox v-model="isSelectAllItem" @change="selectAllItem" style="float: right;">全选</el-checkbox>
  193. </div>
  194. <el-input placeholder="请输入关键字进行过滤" @input="itemChangeEvent" v-model="filterItemData"></el-input>
  195. <div style="height: 50vh; margin-top: 10px; overflow: auto;">
  196. <!-- <el-tree class="cy-item-tree"-->
  197. <!-- ref="itemTree"-->
  198. <!-- :data="itemDataListByTree"-->
  199. <!-- :indent="10"-->
  200. <!-- node-key="id"-->
  201. <!-- show-checkbox-->
  202. <!-- :check-on-click-node="true"-->
  203. <!-- :filter-node-method="filterItemDataNode"-->
  204. <!-- :highlight-current="true"-->
  205. <!-- :default-expand-all="true"-->
  206. <!-- @check-change="handleItemCheckChange">-->
  207. <!-- <span class="custom-tree-node" slot-scope="{ node, data }">-->
  208. <!-- <svg-icon v-if="!data.children || data.children.length == 0" icon-class="file"/>-->
  209. <!-- <svg-icon v-else-if="node.expanded" icon-class="folder-open"/>-->
  210. <!-- <svg-icon v-else icon-class="folder"/>-->
  211. <!-- <span :title='data.itemName || "-"' style="margin-left: 2px;">-->
  212. <!-- {{-->
  213. <!-- data.describe-->
  214. <!-- ? ((data.itemName ? data.itemName : '') + '(' + data.describe + ')')-->
  215. <!-- : data.itemName ? data.itemName : ''-->
  216. <!-- }}-->
  217. <!-- </span>-->
  218. <!-- </span>-->
  219. <!-- </el-tree>-->
  220. <p-virtual-check ref="pvcChoose"
  221. :data-sources="itemDataListByTree"
  222. @check-change-all="checkChangeAllChoose"
  223. @check-change="checkChangeChoose"></p-virtual-check>
  224. </div>
  225. </div>
  226. <div style="width: 100%;text-align: center;">
  227. <el-button type="primary"
  228. @click="chooseItemTreeEvent"
  229. style="margin-top: 20px;">确定
  230. </el-button>
  231. </div>
  232. </el-dialog>
  233. <!-- 数据组选择(设备报表) -->
  234. <el-dialog
  235. title="选择条件数据项"
  236. width="600px"
  237. top="10vh"
  238. center
  239. v-dialog-drag-and-zoom
  240. v-if="dialogDeviceDataItemVisible"
  241. :before-close="dialogItemClose"
  242. :visible.sync="dialogDeviceDataItemVisible"
  243. :close-on-click-modal="false"
  244. :append-to-body="true">
  245. <div>
  246. <div style="margin-bottom: 10px;">
  247. <span>组名称:{{ itemDataListByGroupName }}(共 {{ itemDeviceDataListByTree.length }} 项)</span>
  248. </div>
  249. <el-input placeholder="请输入关键字进行过滤" v-model="filterDeviceItemData"></el-input>
  250. <div style="height: 50vh; margin-top: 10px; overflow: auto;">
  251. <el-tree class="cy-item-tree"
  252. ref="deviceItemTree"
  253. :data="itemDeviceDataListByTree"
  254. :indent="10"
  255. node-key="id"
  256. show-checkbox
  257. :check-on-click-node="true"
  258. :filter-node-method="filterItemDataNode"
  259. :highlight-current="true"
  260. :default-expand-all="true">
  261. <span class="custom-tree-node" slot-scope="{ node, data }">
  262. <svg-icon v-if="!data.children || data.children.length == 0" icon-class="file"/>
  263. <svg-icon v-else-if="node.expanded" icon-class="folder-open"/>
  264. <svg-icon v-else icon-class="folder"/>
  265. <span :title='data.itemName || "-"' style="margin-left: 2px;">
  266. {{
  267. data.describe
  268. ? ((data.itemName ? data.itemName : '') + '(' + data.describe + ')')
  269. : data.itemName ? data.itemName : ''
  270. }}
  271. </span>
  272. </span>
  273. </el-tree>
  274. </div>
  275. </div>
  276. <div style="width: 100%;text-align: center;">
  277. <el-button type="primary"
  278. @click="chooseDeviceItemTreeEvent"
  279. style="margin-top: 20px;">确定
  280. </el-button>
  281. </div>
  282. </el-dialog>
  283. <!-- 选择基础数据项 -->
  284. <el-dialog
  285. title="选择基础数据项"
  286. width="500px"
  287. center
  288. v-dialog-drag
  289. v-if="dialogBaseDataVisible"
  290. :before-close="dialogBaseDataClose"
  291. :visible.sync="dialogBaseDataVisible"
  292. :close-on-click-modal="false"
  293. :append-to-body="true">
  294. <el-select v-model="chooseBaseData" filterable placeholder="请选择数据项" style="width: 100%;">
  295. <el-option
  296. v-for="item in this.baseDataList"
  297. :key="item.id"
  298. :label="item.dictKey"
  299. :value="item.dictValue">
  300. </el-option>
  301. </el-select>
  302. <div style="width: 100%; text-align: center; margin-top: 20px;">
  303. <el-button type="warning" @click="baseItemEvent(0)">应用</el-button>
  304. <el-button type="primary" @click="baseItemEvent(1)">确定</el-button>
  305. <el-button @click="dialogBaseDataClose">取消</el-button>
  306. </div>
  307. </el-dialog>
  308. <el-dialog
  309. title="选择表达式"
  310. width="500px"
  311. top="10vh"
  312. center
  313. :before-close="dialogDataModelClose"
  314. :visible.sync="dialogDataModelVisible"
  315. :close-on-click-modal="false"
  316. :append-to-body="true">
  317. <el-select v-model="chooseDataModel" filterable placeholder="请选择表达式" style="width: 100%;">
  318. <el-option
  319. v-for="item in this.dataModelList"
  320. :key="item.id"
  321. :label="item.operationRule"
  322. :value="item.id">
  323. </el-option>
  324. </el-select>
  325. <div style="width: 100%; text-align: center; margin-top: 20px;">
  326. <el-button type="primary" @click="saveDataModelEvent">确定</el-button>
  327. <el-button @click="dialogDataModelClose">取消</el-button>
  328. </div>
  329. </el-dialog>
  330. <!-- 公共模板报表类型选择 -->
  331. <el-dialog
  332. title="选择模板报表"
  333. width="60vw"
  334. center
  335. v-dialog-drag-and-zoom
  336. v-if="dialogCommReportVisible"
  337. :before-close="dialogClose"
  338. :visible.sync="dialogCommReportVisible"
  339. :close-on-click-modal="false"
  340. :append-to-body="true">
  341. <div style="height: 60vh; overflow: auto;">
  342. <div style="height: 50px; display: flex;">
  343. <div style="width: 50%;">
  344. <label style="margin-right: 15px;">模板名称</label>
  345. <el-input placeholder="请输入报表模板名称进行过滤"
  346. v-model="searchReportTxt"
  347. @input="handleReportTypeInputChange"
  348. style="width: calc(100% - 100px); margin-bottom: 10px;">
  349. </el-input>
  350. </div>
  351. <div style="width: 50%;">
  352. <label style="margin-right: 15px;">所属行业</label>
  353. <el-input placeholder="请选择所属行业"
  354. @click.native="clickCascader"
  355. v-model="reportTypeInputName"
  356. readonly
  357. style="width: calc(100% - 100px); z-index: 1;">
  358. </el-input>
  359. <el-cascader v-model="reportType"
  360. ref="reportType"
  361. :options="reportTypes"
  362. style="width: calc(100% - 100px); width: 40px; margin-left: calc(-100% + 100px);"
  363. :props="{ value: 'id', label: 'dictKey', emitPath: true, multiple: false }"
  364. clearable
  365. @change="handleReportTypeChange"
  366. @expand-change="handleReportTypeNodeChange"></el-cascader>
  367. </div>
  368. </div>
  369. <div style="height: calc(100% - 50px); overflow: auto;">
  370. <el-empty v-if="commTemplateList.length == 0" description="暂无数据"></el-empty>
  371. <div v-else style="margin-top: 10px;">
  372. <div v-for="item in commTemplateList"
  373. style="float: left;width: 30%;display: flex;flex-direction: column;align-items: center;margin-top: 10px;">
  374. <el-image v-if="item.logo == 'zsxt.png'" :src="require('@/assets/images/template/zsxt.png')" fit="contain"
  375. style="height: 80px;"></el-image>
  376. <el-image v-else-if="item.logo == 'jcscs.png'" :src="require('@/assets/images/template/jcscs.png')"
  377. fit="contain" style="height: 80px;"></el-image>
  378. <el-image v-else-if="item.logo == 'ncs.png'" :src="require('@/assets/images/template/ncs.png')"
  379. fit="contain" style="height: 80px;"></el-image>
  380. <el-image v-else :src="require('@/assets/images/template/muban.png')" fit="contain"
  381. style="height: 80px;"></el-image>
  382. <el-radio v-model="commTemplate" :label="item"
  383. style="margin-top: 5px;width: 100%;text-overflow: ellipsis;white-space: nowrap;overflow: hidden;text-align: center;">
  384. {{ item.templateName }}
  385. </el-radio>
  386. </div>
  387. </div>
  388. </div>
  389. </div>
  390. <div style="text-align: center; margin-top: 40px;">
  391. <el-button type="warning" @click="commReportEvent(0)">应用</el-button>
  392. <el-button type="primary" @click="commReportEvent(1)">确定</el-button>
  393. <el-button @click="dialogClose">取消</el-button>
  394. </div>
  395. </el-dialog>
  396. <!-- 选择数据组数据 -->
  397. <el-dialog
  398. :title="hasBelongDataFlag ? '附属属性配置' : '数据项配置'"
  399. width="80%"
  400. top="10vh"
  401. center
  402. v-dialog-drag-and-zoom
  403. v-if="dialogGroupItemVisible"
  404. :before-close="dialogClose"
  405. :visible.sync="dialogGroupItemVisible"
  406. :close-on-click-modal="false"
  407. :append-to-body="true">
  408. <div style="height: 60vh; overflow: auto;">
  409. <div>
  410. <label v-if="templateReportType != 2 || (!isUpdateShow && templateReportType == 2)">数据组:</label>
  411. <el-select filterable
  412. v-if="templateReportType != 2 || (!isUpdateShow && templateReportType == 2)"
  413. v-model="chooseDataGroup"
  414. @change="getGroupById"
  415. placeholder="请选择数据组"
  416. style="width: 330px;">
  417. <el-option
  418. v-for="dict in dataGroupList"
  419. :key="dict.id"
  420. :label="dict.groupName"
  421. :value="dict.id"
  422. ></el-option>
  423. </el-select>
  424. <!-- <label style="margin-left: 10px;">数据类型:</label>-->
  425. <!-- <el-select filterable-->
  426. <!-- v-model="chooseDataGroupType"-->
  427. <!-- placeholder="请选择数据类型"-->
  428. <!-- style="width: 150px;">-->
  429. <!-- <el-option-->
  430. <!-- v-for="dict in dataGroupTypeList"-->
  431. <!-- :key="dict.value"-->
  432. <!-- :label="dict.label"-->
  433. <!-- :value="dict.value"-->
  434. <!-- ></el-option>-->
  435. <!-- </el-select>-->
  436. <el-button v-if="templateReportType != 2 || (!isUpdateShow && templateReportType == 2)" size="mini" @click="addDataItem" style="width: 100px;margin-top: 4px; margin-left: 10px;">
  437. 选择数据项
  438. </el-button>
  439. <template v-if="!hasBelongDataFlag">
  440. <el-button size="mini" type="primary" @click="multipleDataItemEvent"
  441. style="width: 100px;margin-top: 4px;">设置数据条件
  442. </el-button>
  443. <!-- <el-button v-if="templateReportType==2" size="mini" type="primary" @click="setDriverCondition"-->
  444. <!-- style="width: 100px;margin-top: 4px;">配置驱动条件-->
  445. <!-- </el-button>-->
  446. </template>
  447. </div>
  448. <div v-if="chooseDataGroup && !hasBelongDataFlag && templateReportType == 2"
  449. style="margin-top: 10px; display: flex;">
  450. <label>条件:</label>
  451. <div style="color: #a5a5a5;">
  452. <span>{{ this.conditionObj.itemName }}</span>&nbsp;&nbsp;
  453. <span>{{ this.conditionObj.eventModeName }}</span>&nbsp;&nbsp;
  454. <span>{{ this.conditionObj.modeValue }}</span>
  455. </div>
  456. </div>
  457. <div style="height: 30vh; margin-top: 10px; overflow: auto;">
  458. <template v-if="!hasBelongDataFlag">
  459. <u-table ref="plConditionTable"
  460. row-key="label"
  461. use-virtual
  462. :height="250"
  463. :data="chooseGroupItemList"
  464. @selection-change="selectionLineChangeHandle"
  465. :big-data-checkbox="true"
  466. showBodyOverflow="title"
  467. showHeaderOverflow="title"
  468. style="margin-top: 10px;"
  469. border>
  470. <u-table-column type="selection" width="55" align="center"/>
  471. <u-table-column type="index" label="序号" width="60" fixed align="center"/>
  472. <u-table-column label="数据项名称" prop="itemName" sortable="custom" align="center"/>
  473. <u-table-column prop="valueType" label="取值类型" align="center">
  474. <template slot-scope="scope">
  475. {{ getValByProp(valueTypeList, scope.row.valueType) }}
  476. </template>
  477. </u-table-column>
  478. <u-table-column v-if="templateReportType == 1" prop="valueTakingMode" label="取值模式" align="center">
  479. <template slot-scope="scope">
  480. {{ getValByProp(valueTakingModeList, scope.row.valueTakingMode) }}
  481. </template>
  482. </u-table-column>
  483. <u-table-column v-if="templateReportType == 1" prop="bucketType" label="取值时间单位" align="center">
  484. <template slot-scope="scope">
  485. {{ getValByProp(bucketTypeList, scope.row.bucketType) }}
  486. </template>
  487. </u-table-column>
  488. <u-table-column v-if="templateReportType == 1" prop="bucketValue" label="数据切换周期" align="center">
  489. </u-table-column>
  490. <template v-if="false">
  491. <u-table-column prop="startTime" label="取值时段范围" align="center">
  492. <template slot-scope="scope">
  493. {{ scope.row.startTime }}
  494. {{ scope.row.startTime ? ',' : '' }}
  495. {{ scope.row.endTime }}
  496. </template>
  497. </u-table-column>
  498. </template>
  499. <u-table-column label="操作" align="center" width="80">
  500. <template slot-scope="scope">
  501. <el-button
  502. type="text"
  503. size="mini"
  504. style="color: red;"
  505. @click="handleItemDelete(scope.$index, scope.row)">删除
  506. </el-button>
  507. </template>
  508. </u-table-column>
  509. </u-table>
  510. </template>
  511. <template v-else>
  512. <u-table ref="plConditionTable"
  513. row-key="label"
  514. use-virtual
  515. :height="250"
  516. :data="chooseGroupItemList"
  517. @selection-change="selectionLineChangeHandle"
  518. :big-data-checkbox="true"
  519. showBodyOverflow="title"
  520. showHeaderOverflow="title"
  521. style="margin-top: 10px;"
  522. border>
  523. <u-table-column type="selection" width="55" align="center"/>
  524. <u-table-column type="index" label="序号" width="60" fixed align="center"/>
  525. <u-table-column label="数据项名称" prop="itemName" sortable="custom" align="center"/>
  526. <u-table-column prop="dataValue" label="值" align="center">
  527. </u-table-column>
  528. <u-table-column label="操作" align="center" width="80">
  529. <template slot-scope="scope">
  530. <el-button
  531. type="text"
  532. size="mini"
  533. style="color: red;"
  534. @click="handleItemDelete(scope.$index, scope.row)">删除
  535. </el-button>
  536. </template>
  537. </u-table-column>
  538. </u-table>
  539. </template>
  540. </div>
  541. <!-- 设备报表 -->
  542. <div v-if="templateReportType == 5">
  543. <el-divider content-position="left">设备报表条件配置</el-divider>
  544. <div class="cy-line custom-tree" style="display: flex; flex-direction: column;">
  545. <div class="device-condition">
  546. <label>条件类型:</label>
  547. <el-radio v-model="deviceReportCondition.variableType" label="1">单变量</el-radio>
  548. <el-radio v-model="deviceReportCondition.variableType" label="2">双变量</el-radio>
  549. </div>
  550. <div class="device-condition">
  551. <label>状态1:</label>
  552. <template v-if="deviceReportCondition.variableType == 2">
  553. <el-button size="mini" @click="addDataItemByDevice(1)">
  554. 选择状态1
  555. </el-button>
  556. </template>
  557. <template v-else>
  558. <el-button size="mini" @click="addDataItemByDevice(0)">
  559. 选择变量
  560. </el-button>
  561. </template>
  562. <div v-if="deviceReportCondition.startItemId" style="margin-left: 20px;">
  563. <span>{{ deviceReportCondition.startItemName }}</span>&nbsp;&nbsp;
  564. <span><b>等于</b></span>&nbsp;&nbsp;
  565. <!-- <el-input-number v-model="deviceReportCondition.startValue" placeholder="请输入值"-->
  566. <!-- :min="0" :max="99999" :controls="false" :precision="0"-->
  567. <!-- style="width: 120px;margin-right: 50px;"></el-input-number>-->
  568. <el-input v-model="deviceReportCondition.startValue" placeholder="请输入值"
  569. style="width: 120px;margin-right: 50px;"></el-input>
  570. </div>
  571. </div>
  572. <div class="device-condition">
  573. <label>状态2:</label>
  574. <el-button v-if="deviceReportCondition.variableType == 2"
  575. size="mini" @click="addDataItemByDevice(2)">
  576. 选择状态2
  577. </el-button>
  578. <div v-if="deviceReportCondition.endItemId" style="margin-left: 20px;">
  579. <span>{{ deviceReportCondition.endItemName }}</span>&nbsp;&nbsp;
  580. <span><b>等于</b></span>&nbsp;&nbsp;
  581. <!-- <el-input-number v-model="deviceReportCondition.endValue" placeholder="请输入值"-->
  582. <!-- :min="0" :max="99999" :controls="false" :precision="0"-->
  583. <!-- style="width: 120px;margin-right: 50px;"></el-input-number>-->
  584. <el-input v-model="deviceReportCondition.endValue" placeholder="请输入值"
  585. style="width: 120px;margin-right: 50px;"></el-input>
  586. </div>
  587. </div>
  588. <div class="device-condition">
  589. <label>是否自动计算运行时间:</label>
  590. <el-radio v-model="deviceReportCondition.isGenCountTime" label="0">不计算</el-radio>
  591. <el-radio v-model="deviceReportCondition.isGenCountTime" label="1">计算</el-radio>
  592. </div>
  593. </div>
  594. </div>
  595. <div v-if="chooseGroupItemList.length > 0 && templateReportType != 2 && templateReportType != 5">
  596. <template>
  597. <el-divider content-position="left">{{ hasBelongDataFlag ? '显示方式' : '数据项排列方式' }}</el-divider>
  598. <div class="cy-line custom-tree">
  599. <el-radio-group v-model="itemShowParams.fieldType" @input="showDataTypeEvent">
  600. <el-radio label="1">横向</el-radio>
  601. <el-radio label="2">纵向</el-radio>
  602. </el-radio-group>
  603. </div>
  604. </template>
  605. <template v-if="!hasBelongDataFlag && templateReportType != 0">
  606. <el-divider content-position="left">值显示数量</el-divider>
  607. <div class="cy-line custom-tree" style="display: flex; align-items: center;">
  608. <div style="width: 50%;display: none;">
  609. <label>显示方式:</label>
  610. <el-radio v-model="itemShowParams.valType" label="1">横向</el-radio>
  611. <el-radio v-model="itemShowParams.valType" label="2">纵向</el-radio>
  612. </div>
  613. <div style="width: 50%;">
  614. <!-- <label>值显示数量:</label>-->
  615. <el-input-number label="请输入显示数量"
  616. v-model="itemShowParams.valLine"
  617. :min="1"
  618. :max="50"></el-input-number>
  619. </div>
  620. </div>
  621. </template>
  622. </div>
  623. </div>
  624. <div style="width: 100%;text-align: center;">
  625. <template v-if="!hasBelongDataFlag">
  626. <el-button type="warning" style="margin-top: 20px;" @click="itemEvent(0)">应用</el-button>
  627. <el-button type="primary" style="margin-top: 20px;" @click="itemEvent(1)">确定</el-button>
  628. </template>
  629. <template v-else>
  630. <el-button type="warning" style="margin-top: 20px;" @click="belongItemEvent(0)">应用</el-button>
  631. <el-button type="primary" style="margin-top: 20px;" @click="belongItemEvent(1)">确定</el-button>
  632. </template>
  633. <el-button style="margin-top: 20px;" @click="dialogClose">取消</el-button>
  634. </div>
  635. </el-dialog>
  636. <!-- 配置数据项取值条件 -->
  637. <el-dialog
  638. title="设置数据条件"
  639. width="600px"
  640. top="10vh"
  641. center
  642. v-dialog-drag
  643. v-if="dialogDataItemConfigVisible"
  644. :before-close="dialogDataItemConfigClose"
  645. :visible.sync="dialogDataItemConfigVisible"
  646. :close-on-click-modal="false"
  647. :append-to-body="true">
  648. <el-form label-width="120px" ref="itemConditionForm" :model="itemConditionForm" :rules="itemConditionFormRules">
  649. <el-form-item label="取值类型:" prop="valueType">
  650. <el-radio v-for="item in valueTypeList"
  651. v-model="itemConditionForm.valueType"
  652. :label="item.value">{{ item.label }}
  653. </el-radio>
  654. </el-form-item>
  655. <el-form-item label="取值模式:" prop="valueTakingMode" v-if="templateReportType == 1">
  656. <el-radio v-for="item in valueTakingModeList"
  657. v-model="itemConditionForm.valueTakingMode"
  658. :label="item.value">{{ item.label }}
  659. </el-radio>
  660. </el-form-item>
  661. <template v-if="false">
  662. <el-form-item label="取值时间:" prop="dateRange">
  663. <el-date-picker
  664. v-model="itemConditionForm.dateRange"
  665. type="datetimerange"
  666. :clearable="false"
  667. range-separator="至"
  668. start-placeholder="开始时间"
  669. end-placeholder="结束时间"
  670. placeholder="选择取值时间范围"
  671. :picker-options="{
  672. format: 'yyyy-MM-dd HH:mm:ss'
  673. }"
  674. value-format="yyyy-MM-dd HH:mm:ss"
  675. :default-time="['09:00:00', '18:00:00']">
  676. </el-date-picker>
  677. </el-form-item>
  678. </template>
  679. <template v-if="templateReportType == 1">
  680. <el-divider content-position="left">取值周期设置</el-divider>
  681. <div class="cy-line">
  682. <el-form-item label="时间单位:" prop="bucketType">
  683. <el-radio v-for="item in bucketTypeList"
  684. v-model="itemConditionForm.bucketType"
  685. :label="item.value">{{ item.label }}
  686. </el-radio>
  687. </el-form-item>
  688. <el-form-item label="数据切换周期:" prop="bucketValue">
  689. <el-input-number label="请输入周期值"
  690. v-model="itemConditionForm.bucketValue"
  691. :precision="0"
  692. :min="1"
  693. :max="100"></el-input-number>
  694. </el-form-item>
  695. </div>
  696. </template>
  697. </el-form>
  698. <span slot='footer'>
  699. <el-button type="primary" @click="chooseDataItemConfigEvent" style="margin-top: 20px;">确定</el-button>
  700. <el-button @click="dialogDataItemConfigClose" style="margin-top: 20px;">取消</el-button>
  701. </span>
  702. </el-dialog>
  703. <!-- 配置驱动条件 -->
  704. <el-dialog
  705. title="配置驱动条件"
  706. width="600px"
  707. top="10vh"
  708. center
  709. v-dialog-drag
  710. v-if="dialogDriverConditionVisible"
  711. :before-close="dialogDriverConditionClose"
  712. :visible.sync="dialogDriverConditionVisible"
  713. :close-on-click-modal="false"
  714. :append-to-body="true">
  715. <el-form label-width="100px">
  716. <el-form-item label="驱动条件:">
  717. <el-radio v-for="item in driverConditionList"
  718. v-model="eventMode"
  719. :label="item.value">{{ item.label }}
  720. </el-radio>
  721. </el-form-item>
  722. <el-form-item label="驱动值:">
  723. <el-input-number label="请输入条件值"
  724. v-model="modeValue"
  725. :precision="0"
  726. :controls="false"
  727. :min="1"
  728. :max="99999"></el-input-number>
  729. </el-form-item>
  730. <el-form-item label="选择驱动项:">
  731. <el-radio v-for="item in chooseGroupItemList"
  732. v-model="isDriverItemId"
  733. :label="item.id">{{ item.itemName }}
  734. </el-radio>
  735. </el-form-item>
  736. </el-form>
  737. <span slot='footer'>
  738. <el-button type="primary" @click="chooseDriverCondition" style="margin-top: 20px;">确定</el-button>
  739. <el-button @click="dialogDriverConditionClose" style="margin-top: 20px;">取消</el-button>
  740. </span>
  741. </el-dialog>
  742. <!-- 模板报表类型选择 -->
  743. <el-dialog
  744. title="选择模板报表类型"
  745. width="600px"
  746. center
  747. v-dialog-drag
  748. v-if="dialogReportTypeVisible"
  749. :before-close="dialogClose"
  750. :visible.sync="dialogReportTypeVisible"
  751. :close-on-click-modal="false"
  752. :append-to-body="true">
  753. <div>
  754. <label>报表类型:</label>
  755. <el-radio v-model="templateReportType" label="0">手动报表</el-radio>
  756. <el-radio v-model="templateReportType" label="1">自动报表</el-radio>
  757. <el-radio v-model="templateReportType" label="2">事件驱动报表</el-radio>
  758. <el-radio v-model="templateReportType" label="5">设备报表</el-radio>
  759. </div>
  760. <div v-if="templateReportType == 2 || templateReportType == 5" style="margin-top: 20px;">
  761. <label>记录数量:</label>
  762. <el-input-number label="请输入事件驱动显示记录数量"
  763. v-model="templateEventReportNum"
  764. :min="1"
  765. :max="100"></el-input-number>
  766. </div>
  767. <div style="text-align: center; margin-top: 40px;">
  768. <el-button type="primary" @click="chooseTemplateReportTypeEvent">确定</el-button>
  769. </div>
  770. </el-dialog>
  771. <div id="print-area"
  772. style="display: none;position: absolute;z-index: 0;top: 0;width: 100%;height: 100vh;overflow: hidden;">
  773. <div id="print-html" ref="printPayFeeNew"></div>
  774. </div>
  775. </div>
  776. <div v-else></div>
  777. </template>
  778. <script>
  779. import RulerView from '@/components/RulerView'
  780. import PVirtualCheck from "@/components/PVirtualCheck"
  781. import LuckyExcel from 'luckyexcel'
  782. import {
  783. getAllDataModel,
  784. getAllItemGroup, getItemGroupById, getSysTableTemplate, getSysTableTemplateById,
  785. getTableItemGroupById,
  786. getTableTemplateById,
  787. saveReportTemplate,
  788. updateReportTemplate
  789. } from "@/api/datasource";
  790. import {
  791. getLuckysheetConfig, goPage,
  792. handleTree, showAlertMsgWin,
  793. showAlertWin, showConfirmWin,
  794. showLoading, showPromptWin,
  795. traverseNode,
  796. traverseVisible
  797. } from "@/utils/cqcy";
  798. import {getDictByKey} from "@/api/basic";
  799. import {exportExcel} from "@/utils/export";
  800. import {exportSheetExcel} from "@/utils/sheetToXls";
  801. import {insertLuckysheetEChart, cellValueFormat, toLuckySheetJson, toExcelColumn} from "@/utils/luckysheettool";
  802. import Print from "print-js";
  803. import {print} from '@/utils/print'
  804. export default {
  805. name: 'index',
  806. components: {
  807. RulerView,
  808. "p-virtual-check": PVirtualCheck,
  809. },
  810. data() {
  811. return {
  812. isUpdateShow: false,
  813. newItemId: 0,
  814. ctrlxstatus: false,
  815. sheetAxis: [],
  816. showReportData: true,
  817. dialogBarChartVisible: false,
  818. dialogDataItemVisible: false,
  819. dialogDeviceDataItemVisible: false,
  820. dialogDataModelVisible: false,
  821. dialogCommReportVisible: false,
  822. dialogGroupItemVisible: false,
  823. dialogBaseDataVisible: false,
  824. dialogReportTypeVisible: false,
  825. dialogDataItemConfigVisible: false,
  826. dialogDriverConditionVisible: false,
  827. isSelectAllItem: false,
  828. menuLeft: 0,
  829. menuTop: 0,
  830. visibleChartMenu: false,
  831. templateReportType: null,
  832. hasBelongDataFlag: false,
  833. eventMode: null,
  834. modeValue: null,
  835. isDriverItemId: null,
  836. templateEventReportNum: 100,
  837. chooseChartClz: '',
  838. chartConfigTitle: '',
  839. barChartForm: {
  840. title: '',
  841. type: '',
  842. subtitle: '',
  843. showTitle: '1',
  844. showLegend: '1',
  845. legendType: '1',
  846. legendData: ['模板数据1', '模板数据2'],
  847. xAxisData: ['数据1', '数据2', '数据3'],
  848. valueType: 0, // 0原始值1计算值
  849. valueTakingMode: 0, // 取值模式0平均值,1最大值,2最小值,3瞬时值
  850. bucketType: 1, // 时段类型0天,1时,2分,3秒
  851. bucketValue: 1
  852. },
  853. barChartOption: {},
  854. valueTypeList: [
  855. {'label': '原始值', 'value': 0},
  856. {'label': '计算值', 'value': 1}
  857. ],
  858. bucketTypeList: [
  859. {'label': '天', 'value': 0},
  860. {'label': '时', 'value': 1},
  861. {'label': '分', 'value': 2},
  862. {'label': '秒', 'value': 3},
  863. ],
  864. valueTakingModeList: [
  865. {'label': '平均值', 'value': 0},
  866. {'label': '最大值', 'value': 1},
  867. {'label': '最小值', 'value': 2},
  868. {'label': '瞬时值', 'value': 3},
  869. ],
  870. driverConditionList: [
  871. {'label': '大于', 'value': 0},
  872. {'label': '小于', 'value': 1},
  873. {'label': '等于', 'value': 2}
  874. ],
  875. // 条件值
  876. conditionObj: {
  877. itemName: '',
  878. eventModeName: '',
  879. modeValue: ''
  880. },
  881. // 设备报表条件
  882. deviceReportCondition: {
  883. type: null,
  884. variableType: '1',
  885. isGenCountTime: '0',
  886. startItemId: null,
  887. startItemName: null,
  888. startValue: '',
  889. endItemId: null,
  890. endItemName: null,
  891. endValue: ''
  892. },
  893. // 数据项取值条件
  894. itemConditionForm: {
  895. valueType: 0, // 0原始值1计算值
  896. valueTakingMode: 0, // 取值模式0平均值,1最大值,2最小值,3瞬时值
  897. bucketType: 1, // 时段类型0天,1时,2分,3秒
  898. bucketValue: 1, // 时段值
  899. dateRange: [], // 取值时间范围,手动报表必填
  900. },
  901. itemConditionFormRules: {
  902. valueType: [
  903. {required: true, message: '请选择取值类型', trigger: 'change'}
  904. ],
  905. valueTakingMode: [
  906. {required: true, message: '请选择取值模式', trigger: 'change'}
  907. ],
  908. bucketType: [
  909. {required: true, message: '请选择时间单位', trigger: 'change'}
  910. ],
  911. bucketValue: [
  912. {required: true, message: '请输入周期值', trigger: 'change'}
  913. ]
  914. },
  915. itemShowParams: {
  916. fieldType: '1',
  917. valType: '2',
  918. valLine: 1,
  919. dataId: new Date().getTime()
  920. },
  921. baseDataList: [],
  922. chooseBaseData: null,
  923. dataGroupList: [],
  924. dataGroupTypeList: [
  925. {'label': '所有', 'value': -1},
  926. {'label': '附属项', 'value': 0},
  927. {'label': '数据项', 'value': 1}
  928. ],
  929. itemDeviceDataListByTree: [],
  930. itemDataListByTree: [],
  931. itemDataListByGroupName: '',
  932. itemDataListByCalc: [],
  933. chooseGroupItemList: [],
  934. selectionDataItems: [],
  935. dataModelList: [],
  936. chooseDataModel: null,
  937. chooseDataItemIndex: null,
  938. bomCheckKey: 0,
  939. bomItemKey: 0,
  940. chooseDataGroup: null,
  941. chooseDataGroupType: null,
  942. chooseItemData: [],
  943. filterItemData: '',
  944. filterDeviceItemData: '',
  945. searchReportTxt: '',
  946. keyType: 'report_template',
  947. reportTypes: [],
  948. reportType: null,
  949. reportTypeInputName: '所有',
  950. reportTypeInputId: [],
  951. commTemplate: null,
  952. commTemplateList: [],
  953. templateName: '',
  954. templateId: '',
  955. templateVersion: '',
  956. reportTemplateItem: this.$store.getters.sessionName.REPORT_TEMPLATE_ITEM,
  957. reportInterval: null,
  958. toolItemChart: [],
  959. toolItemTable: [],
  960. luckysheetOption: {
  961. container: 'luckysheet', // 设定 DOM 容器的 id
  962. title: '报表模板', // 设定表格名称
  963. lang: 'zh', // 设定表格语言
  964. showinfobar: false, // 是否显示顶部信息栏
  965. showtoolbar: false, // 是否显示工具栏
  966. showtoolbarConfig: {
  967. paintFormat: true, //格式刷
  968. moreFormats: true, // 单元格格式
  969. font: true, // 字体
  970. fontSize: true, // 字号大小
  971. bold: true, // 粗体 (Ctrl+B)
  972. italic: true, // 斜体 (Ctrl+I)
  973. strikethrough: true, // 删除线 (Alt+Shift+5)
  974. underline: true, // 下划线 (Alt+Shift+6)
  975. textColor: true, // 文本颜色
  976. fillColor: true, // 单元格颜色
  977. border: true, // 边框
  978. mergeCell: true, // 合并单元格
  979. horizontalAlignMode: true, // 水平对齐方式
  980. verticalAlignMode: true, // 垂直对齐方式
  981. function: true, // 公式
  982. // image: true
  983. // chart: true
  984. },
  985. showsheetbar: false, // 是否显示底部 sheet 页按钮
  986. sheetFormulaBar: false, // 是否显示公式
  987. row: 120, // 是否显示底部 sheet 页按钮
  988. data: [{
  989. "name": "统计报表", //工作表名称
  990. }],
  991. cellRightClickConfig: { // 自定义配置单元格右击菜单
  992. copy: true, // 复制
  993. copyAs: false, // 复制为
  994. paste: true, // 粘贴
  995. insertRow: true, // 插入行
  996. insertColumn: true, // 插入列
  997. deleteRow: true, // 删除选中行
  998. deleteColumn: true, // 删除选中列
  999. deleteCell: false, // 删除单元格
  1000. hideRow: false, // 隐藏选中行和显示选中行
  1001. hideColumn: false, // 隐藏选中列和显示选中列
  1002. rowHeight: true, // 行高
  1003. columnWidth: true, // 列宽
  1004. clear: false, // 清除内容
  1005. matrix: false, // 矩阵操作选区
  1006. sort: false, // 排序选区
  1007. filter: false, // 筛选选区
  1008. chart: true, // 图表生成
  1009. image: false, // 插入图片
  1010. link: false, // 插入链接
  1011. data: false, // 数据验证
  1012. cellFormat: false // 设置单元格格式
  1013. },
  1014. plugins: ['chart'],
  1015. printId:null
  1016. }
  1017. }
  1018. },
  1019. watch: {
  1020. '$route.query.t': {
  1021. handler(now, old) {
  1022. this.initLuckysheet(this.$route.query.id, this.$route.query.type)
  1023. }
  1024. },
  1025. // filterItemData(val) {
  1026. // this.$refs.itemTree.filter(val)
  1027. // },
  1028. filterDeviceItemData(val) {
  1029. this.$refs.deviceItemTree.filter(val)
  1030. },
  1031. visibleChartMenu(value) {
  1032. if (value) {
  1033. document.body.addEventListener('click', this.closeMenu)
  1034. } else {
  1035. document.body.removeEventListener('click', this.closeMenu)
  1036. }
  1037. }
  1038. },
  1039. mounted() {
  1040. let _this = this
  1041. $(function () {
  1042. if (_this.showReportData) {
  1043. let tempId = _this.$route.query.id
  1044. let type = _this.$route.query.type
  1045. _this.initLuckysheet(tempId, type)
  1046. }
  1047. })
  1048. document.onkeyup = function (event) {
  1049. let e = event || window.event || arguments.callee.caller.arguments[0]
  1050. if (!e) return
  1051. const {key, keyCode} = e
  1052. if (keyCode === 46 || keyCode === 8) {
  1053. _this.forceRefreshLuckysheet()
  1054. }
  1055. if (event.ctrlKey && event.keyCode == 67) {
  1056. _this.$data.ctrlxstatus = false;
  1057. setTimeout(()=> {
  1058. navigator.clipboard.writeText(cellValueFormat(luckysheet.getRangeHtml()))
  1059. }, 100)
  1060. } else if (event.ctrlKey && event.keyCode == 88) {
  1061. _this.$data.ctrlxstatus = true;
  1062. _this.$data.sheetAxis = luckysheet.getRange();
  1063. console.log(luckysheet.getRangeAxis())
  1064. setTimeout(()=> {
  1065. navigator.clipboard.writeText(cellValueFormat(luckysheet.getRangeHtml()))
  1066. }, 100)
  1067. }
  1068. }
  1069. },
  1070. created() {
  1071. let _this = this
  1072. // 强制关闭自定义图表右键菜单
  1073. document.body.oncontextmenu = (e) => {
  1074. setTimeout(() => {
  1075. if ($('#luckysheet-rightclick-menu') && 'block' == $('#luckysheet-rightclick-menu').css('display')) {
  1076. _this.closeMenu()
  1077. }
  1078. }, 500)
  1079. }
  1080. },
  1081. destroyed() {
  1082. localStorage.removeItem('REPORT_LEN')
  1083. luckysheet.destroy()
  1084. if (this.reportInterval) {
  1085. clearInterval(this.reportInterval)
  1086. }
  1087. },
  1088. methods: {
  1089. /** 初始化操作 */
  1090. initLuckysheet(tempId, type) {
  1091. let _this = this
  1092. this.selectionDataItems = []
  1093. this.templateReportType = null
  1094. let f = localStorage.getItem('IMPORT_FILE_FLAG')
  1095. if (type === 'import' && f === 'true') { // 报表模板导入
  1096. this.templateReportType = null
  1097. this.dialogReportTypeVisible = true
  1098. console.log('导入报表')
  1099. return
  1100. }
  1101. if (tempId && tempId != -999) {
  1102. _this.getTableTemplate(tempId, type)
  1103. return
  1104. }
  1105. let expand = localStorage.getItem('EXPAND_REPORT_FLAG')
  1106. if (expand === 'true') {
  1107. localStorage.removeItem('EXPAND_REPORT_FLAG')
  1108. this.showInitLuckysheet()
  1109. return
  1110. }
  1111. this.templateReportType = null
  1112. this.dialogReportTypeVisible = true
  1113. },
  1114. /** 显示表格数据信息 */
  1115. showInitLuckysheet() {
  1116. let _this = this
  1117. this.templateId = null
  1118. this.templateVersion = null
  1119. this.templateName = ''
  1120. this.toolItemChart = []
  1121. this.toolItemTable = []
  1122. luckysheet.destroy()
  1123. let locItem = localStorage.getItem(_this.reportTemplateItem)
  1124. if (locItem && JSON.parse(locItem).data && Array.isArray(JSON.parse(locItem).data)) {
  1125. let option = JSON.parse(JSON.stringify(_this.luckysheetOption))
  1126. option.data = JSON.parse(locItem).data
  1127. _this.toolItemChart = JSON.parse(locItem).charts
  1128. _this.toolItemTable = JSON.parse(locItem).tables
  1129. option.hook = {
  1130. workbookCreateAfter() {
  1131. for (let i in _this.toolItemChart) {
  1132. _this.insertEChartTool(JSON.parse(_this.toolItemChart[i].standby), false)
  1133. }
  1134. _this.autoSaveReportInfo()
  1135. let _len = getLuckysheetConfig() ? getLuckysheetConfig().length : 0
  1136. localStorage.setItem('REPORT_LEN', String(_len))
  1137. },
  1138. cellUpdated(r, c, newV, oldV) {
  1139. if (!(r === 49 && c === 0)) {
  1140. _this.forceRefreshLuckysheet()
  1141. }
  1142. },
  1143. rangePasteBefore(r, d) {
  1144. if (_this.$data.ctrlxstatus) {
  1145. _this.$data.ctrlxstatus = false;
  1146. luckysheet.clearRange({range: _this.$data.sheetAxis})
  1147. }
  1148. }
  1149. }
  1150. luckysheet.create(option)
  1151. _this.templateName = localStorage.getItem(_this.reportTemplateItem + '_TITLE')
  1152. } else {
  1153. let option = JSON.parse(JSON.stringify(_this.luckysheetOption))
  1154. option.hook = {
  1155. workbookCreateAfter() {
  1156. // 定时本地存储
  1157. _this.autoSaveReportInfo()
  1158. },
  1159. cellUpdated(r, c, newV, oldV) {
  1160. if (!(r === 49 && c === 0)) {
  1161. _this.forceRefreshLuckysheet()
  1162. }
  1163. },
  1164. rangePasteBefore(r, d) {
  1165. if (_this.$data.ctrlxstatus) {
  1166. _this.$data.ctrlxstatus = false;
  1167. luckysheet.clearRange({range: _this.$data.sheetAxis})
  1168. }
  1169. }
  1170. }
  1171. luckysheet.create(option)
  1172. }
  1173. },
  1174. getValByProp(lists = [], val) {
  1175. let result = ''
  1176. lists.forEach((list) => {
  1177. if (list.value === val) {
  1178. result = list.label
  1179. }
  1180. })
  1181. return result
  1182. },
  1183. /** 多选事件 */
  1184. selectionLineChangeHandle(val) {
  1185. this.selectionDataItems = val
  1186. },
  1187. /** 删除临时数据项 */
  1188. handleItemDelete(index, row) {
  1189. let _this = this
  1190. showConfirmWin(_this, null, '您确定要删除该数据项吗?', () => {
  1191. _this.chooseGroupItemList.forEach((item, i) => {
  1192. if (row.id == item.id) {
  1193. _this.chooseGroupItemList.splice(i, 1)
  1194. }
  1195. })
  1196. })
  1197. },
  1198. /** 多选事件 */
  1199. multipleDataItemEvent() {
  1200. // 事件驱动报表
  1201. // if (this.templateReportType == 2) {
  1202. // showAlertMsgWin(this, null, '事件驱动报表不需要设置取值条件!')
  1203. // return
  1204. // }
  1205. if (!this.selectionDataItems || this.selectionDataItems.length == 0) {
  1206. showAlertMsgWin(this, null, '请至少选择一项数据!')
  1207. return
  1208. }
  1209. this.dialogDataItemConfigVisible = true
  1210. },
  1211. setDataCondition(data) {
  1212. data.valueTakingMode = this.itemConditionForm.valueTakingMode
  1213. data.bucketType = this.itemConditionForm.bucketType
  1214. data.valueType = this.itemConditionForm.valueType
  1215. data.bucketValue = this.itemConditionForm.bucketValue
  1216. if (this.templateReportType == 0) {
  1217. data.startTime = this.itemConditionForm.dateRange[0]
  1218. data.endTime = this.itemConditionForm.dateRange[1]
  1219. }
  1220. },
  1221. /** 数据项配置结果集事件 */
  1222. chooseDataItemConfigEvent() {
  1223. // if (this.templateReportType == 0 && (!this.itemConditionForm.dateRange || this.itemConditionForm.dateRange.length == 0)) {
  1224. // showAlertMsgWin(this, null, '取值时间范围不能为空!')
  1225. // return
  1226. // }
  1227. this.$refs['itemConditionForm'].validate((valid) => {
  1228. if (valid) {
  1229. this.$nextTick(() => {
  1230. let _this = this
  1231. const loading = showLoading(_this, '保存中,请稍候···')
  1232. if (_this.chooseGroupItemList.length == _this.selectionDataItems.length) {
  1233. _this.chooseGroupItemList.forEach((data) => {
  1234. _this.setDataCondition(data)
  1235. })
  1236. } else {
  1237. _this.selectionDataItems.forEach((item) => {
  1238. if (item.checked || item.isFlag == 'update') {
  1239. _this.chooseGroupItemList.forEach((data) => {
  1240. if (data.id === item.id) {
  1241. _this.setDataCondition(data)
  1242. }
  1243. })
  1244. }
  1245. })
  1246. }
  1247. loading.close()
  1248. _this.dialogDataItemConfigClose()
  1249. _this.dialogDataItemConfigVisible = false
  1250. _this.$refs.plConditionTable.clearSelection()
  1251. _this.selectionDataItems = []
  1252. _this.bomItemKey++
  1253. })
  1254. }
  1255. })
  1256. },
  1257. /** 配置驱动条件 */
  1258. setDriverCondition() {
  1259. if (this.chooseGroupItemList.length == 0) {
  1260. showAlertMsgWin(this, null, '请选择数据组项!')
  1261. return
  1262. }
  1263. this.dialogDriverConditionVisible = true;
  1264. },
  1265. /** 选择事件驱动结果集 */
  1266. chooseDriverCondition() {
  1267. if (this.isDriverItemId == null || this.eventMode == null || this.modeValue == null) {
  1268. showAlertMsgWin(this, null, '请配置驱动条件、驱动值、驱动项!')
  1269. return
  1270. }
  1271. this.chooseGroupItemList.forEach((item, i) => {
  1272. item.isDriverItem = null;
  1273. if (item.id == this.isDriverItemId) {
  1274. item.isDriverItem = 1;
  1275. }
  1276. })
  1277. this.dialogDriverConditionVisible = false;
  1278. },
  1279. /** 关闭配置驱动条件界面 */
  1280. dialogDriverConditionClose() {
  1281. this.eventMode = null
  1282. this.modeValue = null
  1283. this.isDriverItemId = null
  1284. this.dialogDriverConditionVisible = false
  1285. },
  1286. /** 选择模板报表类型 */
  1287. chooseTemplateReportTypeEvent() {
  1288. if (!this.templateReportType) {
  1289. showAlertMsgWin(this, null, '请选择模板报表类型!')
  1290. return
  1291. }
  1292. this.dialogReportTypeVisible = false
  1293. let f = localStorage.getItem('IMPORT_FILE_FLAG')
  1294. if (f === 'true') {
  1295. this.resetReport(true)
  1296. this.$refs.importFileNode.dispatchEvent(new MouseEvent('click'))
  1297. localStorage.removeItem('IMPORT_FILE_FLAG')
  1298. return
  1299. }
  1300. localStorage.removeItem(this.reportTemplateItem)
  1301. this.showInitLuckysheet()
  1302. },
  1303. /** 实现类似刷新效果 */
  1304. forceRefreshLuckysheet() {
  1305. if (luckysheet) {
  1306. luckysheet.setCellValue(49, 0, luckysheet.getCellValue(49, 0))
  1307. }
  1308. },
  1309. checkChangeChoose(datas) {
  1310. this.itemDataListByTree = datas
  1311. },
  1312. checkChangeAllChoose(flag) {
  1313. this.isSelectAllItem = flag
  1314. },
  1315. /** 数据项搜索条件 */
  1316. itemChangeEvent(value) {
  1317. let arr = JSON.parse(JSON.stringify(this.itemDataListByTree))
  1318. if (!value || !value.trim()) {
  1319. this.itemDataListByTree = arr
  1320. return
  1321. }
  1322. let filterList = arr.filter(v => {
  1323. return v.itemName.indexOf(value) !== -1
  1324. })
  1325. this.itemDataListByTree = filterList
  1326. },
  1327. /** 数据项全选事件 */
  1328. selectAllItem(val) {
  1329. // const data = traverseNode(this.$refs.itemTree.store.root.childNodes)
  1330. // if (this.isSelectAllItem) {
  1331. // // this.$refs.itemTree.setCheckedNodes(this.itemDataListByTree)
  1332. // let arr = traverseVisible(data)
  1333. // let ids = Array.from(arr, ({id}) => id)
  1334. // this.$refs.itemTree.setCheckedKeys(ids)
  1335. // } else {
  1336. // this.$refs.itemTree.setCheckedNodes([])
  1337. // }
  1338. this.$refs.pvcChoose.checkedAll(val)
  1339. },
  1340. /**数据项单项选择判断 */
  1341. handleItemCheckChange(data, checked, indeterminate) {
  1342. const tdata = traverseNode(this.$refs.itemTree.store.root.childNodes)
  1343. let arr = traverseVisible(tdata)
  1344. if (arr.length == this.$refs.itemTree.getCheckedNodes().length) {
  1345. this.isSelectAllItem = true
  1346. } else {
  1347. this.isSelectAllItem = false
  1348. }
  1349. },
  1350. /** 处理日期显示数字问题 */
  1351. withDateData(excelData) {
  1352. if (!excelData) {
  1353. return
  1354. }
  1355. excelData.map((item) => {
  1356. if (item) {
  1357. item.map((ll) => {
  1358. if (ll && ll.ct && ll.ct.t && ll.ct.t === 'd') {
  1359. ll.m = ll.m,
  1360. ll.v = ll.m,
  1361. ll.ct = {
  1362. fa: "@",
  1363. t: "s",
  1364. }
  1365. }
  1366. })
  1367. }
  1368. })
  1369. },
  1370. /** 保存模版信息 */
  1371. saveReportTemplate(type) {
  1372. let _templateName = this.templateName
  1373. let _title = '保存'
  1374. if (type == 'saveAs') {
  1375. this.templateName = '副本_' + _templateName
  1376. _title = '另存为'
  1377. showPromptWin(this, _title, '请输入/确认报表模板名称', this.templateName, (val) => {
  1378. if (!val) {
  1379. return '模板名称不能为空'
  1380. }
  1381. if (val.length > 20) {
  1382. return '模板名称必须在20字以内'
  1383. }
  1384. }, (value) => {
  1385. this.saveReportTemplateData(type, value, _templateName, _title)
  1386. }, () => {
  1387. this.templateName = _templateName
  1388. })
  1389. return
  1390. }
  1391. if (!this.templateName || this.templateName.length > 20) {
  1392. showAlertMsgWin(this, null, '模板名称不能为空且必须在20字以内!')
  1393. return
  1394. }
  1395. this.saveReportTemplateData(type, this.templateName, _templateName, _title)
  1396. },
  1397. saveReportTemplateData(type, templateName, _templateName, _title) {
  1398. const loading = showLoading(this, '保存中,请稍候···')
  1399. let option = JSON.parse(JSON.stringify(this.luckysheetOption))
  1400. let _data = JSON.parse(getLuckysheetConfig())
  1401. if (!_data) {
  1402. loading.close()
  1403. showAlertMsgWin(this, null, '保存失败!')
  1404. return
  1405. }
  1406. let excelData = _data[0].data
  1407. // 处理日期显示数字问题
  1408. this.withDateData(excelData)
  1409. // 检查数据项设置的字段值是否被改变
  1410. this.checkToItemTable()
  1411. let result = {
  1412. 'option': option,
  1413. 'data': _data
  1414. }
  1415. let data = {
  1416. 'templateType': this.templateReportType,
  1417. 'templateName': templateName,
  1418. 'templateData': JSON.stringify(result),
  1419. 'tableTemplateItemList': this.toolItemTable,
  1420. 'tableTemplateChartList': this.toolItemChart
  1421. }
  1422. // 事件驱动模板
  1423. if (this.templateReportType == 2) {
  1424. data.eventNum = this.templateEventReportNum;
  1425. if (this.eventMode == null || this.modeValue == null) {
  1426. // showAlertMsgWin(this, null, '保存失败!驱动条件或驱动值未设置')
  1427. // return
  1428. }
  1429. data.eventMode = this.eventMode;
  1430. data.modeValue = this.modeValue;
  1431. }
  1432. // 设备报表模板
  1433. if (this.templateReportType == 5) {
  1434. data.eventNum = this.templateEventReportNum
  1435. data.isGenCountTime = this.deviceReportCondition.isGenCountTime
  1436. data.variableType = this.deviceReportCondition.variableType
  1437. data.startItemId = this.deviceReportCondition.startItemId
  1438. data.endItemId = this.deviceReportCondition.endItemId
  1439. data.startValue = this.deviceReportCondition.startValue
  1440. data.endValue = this.deviceReportCondition.endValue
  1441. let _temp = null
  1442. data.tableTemplateItemList.forEach((_t) => {
  1443. // 单变量
  1444. if (data.variableType == 1) {
  1445. if (data.startItemId == _t.itemId) {
  1446. _t.timeItemType = 0
  1447. _temp = JSON.parse(JSON.stringify(_t))
  1448. }
  1449. } else {
  1450. if (data.startItemId == _t.itemId) {
  1451. _t.timeItemType = 0
  1452. }
  1453. if (data.endItemId == _t.itemId) {
  1454. _t.timeItemType = 1
  1455. }
  1456. }
  1457. })
  1458. if (_temp) {
  1459. _temp.timeItemType = 1
  1460. data.tableTemplateItemList.push(_temp)
  1461. }
  1462. }
  1463. if (this.templateId && type != 'saveAs') {
  1464. data.id = this.templateId
  1465. data.version = this.templateVersion
  1466. updateReportTemplate(data).then(res => {
  1467. loading.close()
  1468. let msg = res.data ? '修改成功!' : '修改失败!'
  1469. showAlertMsgWin(this, null, msg, () => {
  1470. this.resetReport(true)
  1471. this.getTableTemplate(this.$route.query.id, this.$route.query.type)
  1472. this.$emit('refreshReportTemplateData', new Date().getTime())
  1473. })
  1474. }).catch((e) => {
  1475. loading.close()
  1476. this.templateName = _templateName
  1477. showAlertWin(this, null, e)
  1478. })
  1479. } else {
  1480. saveReportTemplate(data).then(res => {
  1481. loading.close()
  1482. let msg = res.data ? _title + '成功!' : _title + '失败!'
  1483. showAlertMsgWin(this, null, msg)
  1484. this.resetReport(true)
  1485. this.$emit('refreshReportTemplateData', new Date().getTime())
  1486. }).catch((e) => {
  1487. loading.close()
  1488. this.templateName = _templateName
  1489. showAlertWin(this, null, e)
  1490. })
  1491. }
  1492. },
  1493. /** 关闭报表 */
  1494. closeReport() {
  1495. goPage(this, '/index')
  1496. },
  1497. /** 重置报表信息 */
  1498. resetReport(clearFlag) {
  1499. let _this = this
  1500. localStorage.removeItem(this.reportTemplateItem)
  1501. if (clearFlag) {
  1502. this.templateId = null
  1503. this.templateVersion = null
  1504. this.templateName = ''
  1505. }
  1506. this.toolItemChart = []
  1507. this.toolItemTable = []
  1508. luckysheet.destroy()
  1509. let option = JSON.parse(JSON.stringify(this.luckysheetOption))
  1510. option.hook = {
  1511. workbookCreateAfter() {
  1512. _this.autoSaveReportInfo()
  1513. },
  1514. cellUpdated(r, c, newV, oldV) {
  1515. if (!(r === 49 && c === 0)) {
  1516. _this.forceRefreshLuckysheet()
  1517. }
  1518. },
  1519. rangePasteBefore(r, d) {
  1520. if (_this.$data.ctrlxstatus) {
  1521. _this.$data.ctrlxstatus = false;
  1522. luckysheet.clearRange({range: _this.$data.sheetAxis})
  1523. }
  1524. }
  1525. }
  1526. luckysheet.create(option)
  1527. },
  1528. /** 导入报表 */
  1529. loadExcel(evt) {
  1530. console.log(evt)
  1531. let _this = this
  1532. const files = evt.target.files
  1533. if (files == null || files.length == 0) {
  1534. showAlertMsgWin(_this, null, '请选择文件!')
  1535. return
  1536. }
  1537. console.log(files)
  1538. // 获取文件名
  1539. let name = files[0].name
  1540. // 获取文件后缀
  1541. let suffixArr = name.split("."),
  1542. suffix = suffixArr[suffixArr.length - 1]
  1543. if (suffix != 'xlsx') {
  1544. showAlertMsgWin(_this, null, '只能导入xlsx格式文件!')
  1545. return
  1546. }
  1547. const loading = showLoading(this, '文件导入中,请稍候···')
  1548. // 转换导入的excel
  1549. LuckyExcel.transformExcelToLucky(files[0], function (exportJson, luckysheetfile) {
  1550. if (exportJson.sheets == null || exportJson.sheets.length == 0) {
  1551. loading.close()
  1552. showAlertMsgWin(_this, null, '无法读取excel文件的内容,当前不支持xls文件!')
  1553. return
  1554. }
  1555. console.log('exportJson', exportJson)
  1556. // 销毁之前的表格
  1557. window.luckysheet.destroy()
  1558. // 创建新的表格
  1559. let option = JSON.parse(JSON.stringify(_this.luckysheetOption))
  1560. option.data = exportJson.sheets
  1561. option.title = exportJson.info.name
  1562. // option.data = toLuckySheetJson(exportJson.sheets)
  1563. option.hook = {
  1564. workbookCreateAfter() {
  1565. _this.autoSaveReportInfo()
  1566. toLuckySheetJson(luckysheet)
  1567. },
  1568. cellUpdated(r, c, newV, oldV) {
  1569. if (!(r === 49 && c === 0)) {
  1570. _this.forceRefreshLuckysheet()
  1571. }
  1572. },
  1573. rangePasteBefore(r, d) {
  1574. if (_this.$data.ctrlxstatus) {
  1575. _this.$data.ctrlxstatus = false;
  1576. luckysheet.clearRange({range: _this.$data.sheetAxis})
  1577. }
  1578. }
  1579. }
  1580. window.luckysheet.create(option)
  1581. document.getElementsByClassName('import-file-node')[0].value = ''
  1582. loading.close()
  1583. })
  1584. },
  1585. /** 生成唯一 ID 字符串 */
  1586. generateRandomKey(prefix) {
  1587. if (prefix == null) {
  1588. prefix = 'chart'
  1589. }
  1590. let userAgent = window.navigator.userAgent
  1591. .replace(/[^a-zA-Z0-9]/g, '')
  1592. .split('')
  1593. let mid = ''
  1594. for (let i = 0; i < 12; i++) {
  1595. mid += userAgent[Math.round(Math.random() * (userAgent.length - 1))]
  1596. }
  1597. let time = new Date().getTime()
  1598. return prefix + '_' + mid + '_' + time
  1599. },
  1600. /** 向 Excel 插入图表 */
  1601. insertEChartTool(info, flag, item, chartInfo) {
  1602. let _this = this
  1603. let _self = this
  1604. // 数据参数
  1605. if (flag) {
  1606. let params = {
  1607. 'chartName': chartInfo.title,
  1608. 'chartType': chartInfo.type,
  1609. 'valueTakingMode': chartInfo.valueTakingMode,
  1610. 'valueType': chartInfo.valueType,
  1611. 'bucketType': chartInfo.bucketType,
  1612. 'bucketValue': chartInfo.bucketValue,
  1613. 'startTime': null,
  1614. 'endTime': null,
  1615. 'standby': JSON.stringify(info),
  1616. 'tableTemplateChartItemList': []
  1617. }
  1618. item.forEach((t) => {
  1619. params.tableTemplateChartItemList.push({
  1620. 'itemId': t.id,
  1621. 'itemName': t.itemName,
  1622. 'itemReadName': t.itemReadName,
  1623. 'itemGroupId': t.itemGroupId
  1624. })
  1625. })
  1626. console.log(params)
  1627. if (!_this.toolItemChart) _this.toolItemChart = []
  1628. _this.toolItemChart.push(params)
  1629. }
  1630. setTimeout(() => {
  1631. const sheet = luckysheet.getLuckysheetfile()[0]
  1632. let optionData = sheet.data
  1633. try {
  1634. insertLuckysheetEChart({
  1635. selector: '#luckysheet',
  1636. info,
  1637. sheet,
  1638. optionData,
  1639. echarts,
  1640. luckysheet,
  1641. $,
  1642. _self
  1643. })
  1644. } catch (e) {
  1645. console.error(e)
  1646. }
  1647. // 图表事件监听
  1648. $('.' + info.className).mousedown(function (e) {
  1649. if (3 == e.which) {
  1650. _this.closeMenu()
  1651. _this.menuTop = e.pageY
  1652. _this.menuLeft = e.pageX / 2
  1653. _this.visibleChartMenu = true
  1654. _this.chooseChartClz = info.className
  1655. setTimeout(() => {
  1656. $('#luckysheet-rightclick-menu').css('display', 'none')
  1657. }, 100)
  1658. }
  1659. })
  1660. }, 200)
  1661. },
  1662. /** 获取右侧数据组列表 */
  1663. getDataGroupList(callback) {
  1664. getAllItemGroup(this.templateReportType).then(res => {
  1665. this.dataGroupList = res.data
  1666. if (callback) callback()
  1667. }).catch((e) => {
  1668. showAlertWin(this, null, e)
  1669. })
  1670. },
  1671. /** 选择数据源值改变事件 */
  1672. dataSourceChange(val) {
  1673. this.chooseDataGroup = val
  1674. this.chooseItemData = []
  1675. },
  1676. /** 数据项搜索过滤 */
  1677. filterItemDataNode(value, data) {
  1678. if (!value) return true
  1679. return data.itemName.indexOf(value) !== -1
  1680. },
  1681. /** 添加数据项 */
  1682. addDataItem() {
  1683. let id = this.chooseDataGroup
  1684. // let _type = this.chooseDataGroupType
  1685. if (!id) {
  1686. showAlertMsgWin(this, null, '请选择数据组!')
  1687. return
  1688. }
  1689. this.isSelectAllItem = false
  1690. this.itemDataListByTree = []
  1691. const loading = showLoading(this, '加载中,请稍候···')
  1692. const itemType = this.newItemId == 1 ? 1 : (this.hasBelongDataFlag ? 0 : null);
  1693. getTableItemGroupById(id, itemType).then(res => {
  1694. loading.close()
  1695. this.itemDataListByGroupName = res.data.groupName
  1696. let flag = this.chooseGroupItemList.length == 0
  1697. let tempList = flag ? this.chooseItemData : this.chooseGroupItemList
  1698. let _data = res.data.itemList ? res.data.itemList : []
  1699. _data.forEach((t) => {
  1700. t.label = t.itemName
  1701. t.value = t.itemReadName
  1702. t.checked = false
  1703. })
  1704. this.itemDataListByTree = _data ? _data : []
  1705. if (this.$refs.itemTree) this.$refs.itemTree.setCheckedKeys([])
  1706. if (tempList.length > 0) {
  1707. let idList = Array.from(tempList, ({id}) => id)
  1708. setTimeout(() => {
  1709. if (this.$refs.itemTree) {
  1710. if (flag) this.$refs.itemTree.setCheckedKeys([])
  1711. else this.$refs.itemTree.setCheckedKeys(idList)
  1712. }
  1713. if (this.itemDataListByTree.length == this.chooseGroupItemList.length) {
  1714. this.isSelectAllItem = true
  1715. } else {
  1716. this.isSelectAllItem = false
  1717. }
  1718. }, 100)
  1719. }
  1720. this.dialogDataItemVisible = true
  1721. }).catch((e) => {
  1722. loading.close()
  1723. showAlertWin(this, null, e)
  1724. })
  1725. },
  1726. /** 添加数据项(设备报表条件数据项) */
  1727. addDataItemByDevice(type) {
  1728. if (!this.deviceReportCondition.variableType) {
  1729. showAlertMsgWin(this, null, '请选择条件类型!')
  1730. return
  1731. }
  1732. this.deviceReportCondition.type = type
  1733. this.filterDeviceItemData = ''
  1734. let _data = this.chooseGroupItemList
  1735. this.itemDeviceDataListByTree = _data ? _data : []
  1736. this.dialogDeviceDataItemVisible = true
  1737. },
  1738. /** 选择的数据项:第一步 */
  1739. chooseItemTreeEvent() {
  1740. let _temp = JSON.parse(JSON.stringify(this.itemDataListByTree))
  1741. if (!_temp || _temp.length == 0) {
  1742. showAlertMsgWin(this, null, '请选择数据项!')
  1743. return
  1744. }
  1745. for (let i = _temp.length - 1; i >= 0; i --) {
  1746. if (!_temp[i].checked) {
  1747. _temp.splice(i, 1)
  1748. }
  1749. }
  1750. if (_temp.length == 0) {
  1751. showAlertMsgWin(this, null, '请选择数据项!')
  1752. return
  1753. }
  1754. // if (_temp.length > 100) {
  1755. // showAlertMsgWin(this, null, '报表数据项选择超过上限100!')
  1756. // return
  1757. // }
  1758. // let flag = this.chooseGroupItemList.length == 0
  1759. // let tempList = flag ? this.chooseItemData : this.chooseGroupItemList
  1760. // let _tempList = JSON.parse(JSON.stringify(tempList))
  1761. // let chooseList = []
  1762. // for (let i in checkedNodes) {
  1763. // let checkedNode = checkedNodes[i]
  1764. // if (checkedNode.children && checkedNode.children.length > 0) {
  1765. // continue
  1766. // }
  1767. // // 优化数据项选择条件后重新选择数据项时条件会消失
  1768. // for (let j in _tempList) {
  1769. // if (_tempList[j].id == checkedNode.id) {
  1770. // checkedNode.valueTakingMode = _tempList[j].valueTakingMode
  1771. // checkedNode.valueType = _tempList[j].valueType
  1772. // checkedNode.bucketType = _tempList[j].bucketType
  1773. // checkedNode.bucketValue = _tempList[j].bucketValue
  1774. // }
  1775. // }
  1776. // console.log(checkedNode)
  1777. // chooseList.push(checkedNode)
  1778. // }
  1779. // this.chooseItemData = chooseList
  1780. console.log(this.chooseItemData)
  1781. console.log(_temp)
  1782. this.chooseItemData = _temp
  1783. this.dialogDataItemVisible = false
  1784. if (this.dialogGroupItemVisible) {
  1785. this.initGroupItem()
  1786. }
  1787. this.filterItemData = ''
  1788. // this.getAllDataModel(chooseList)
  1789. },
  1790. /** 选择的设备报表数据 */
  1791. chooseDeviceItemTreeEvent() {
  1792. let checkedNodes = this.$refs.deviceItemTree.getCheckedNodes(false, true)
  1793. if (checkedNodes.length != 1) {
  1794. showAlertMsgWin(this, null, '请选择一项数据项!')
  1795. return
  1796. }
  1797. // 单变量
  1798. if (this.deviceReportCondition.type == 0) {
  1799. this.deviceReportCondition.startItemId = checkedNodes[0].id
  1800. this.deviceReportCondition.startItemName = checkedNodes[0].itemName
  1801. this.deviceReportCondition.endItemId = checkedNodes[0].id
  1802. this.deviceReportCondition.endItemName = checkedNodes[0].itemName
  1803. }
  1804. // 双变量:开始
  1805. else if (this.deviceReportCondition.type == 1) {
  1806. this.deviceReportCondition.startItemId = checkedNodes[0].id
  1807. this.deviceReportCondition.startItemName = checkedNodes[0].itemName
  1808. }
  1809. // 双变量:结束
  1810. else if (this.deviceReportCondition.type == 2) {
  1811. this.deviceReportCondition.endItemId = checkedNodes[0].id
  1812. this.deviceReportCondition.endItemName = checkedNodes[0].itemName
  1813. }
  1814. this.deviceReportCondition.type = null
  1815. this.dialogDeviceDataItemVisible = false
  1816. },
  1817. initGroupItem() {
  1818. let group = null
  1819. for (let i = 0; i < this.dataGroupList.length; i++) {
  1820. if (this.dataGroupList[i].id == this.chooseDataGroup) {
  1821. group = this.dataGroupList[i]
  1822. break
  1823. }
  1824. }
  1825. if (!this.isUpdateShow) {
  1826. this.chooseGroupItemList = this.chooseGroupItemList.filter(function (item, index) {
  1827. return item.itemGroupId != group.id;
  1828. })
  1829. }
  1830. for (let j = 0; j < this.chooseItemData.length; j++) {
  1831. this.chooseItemData[j].groupName = group.groupName
  1832. this.chooseGroupItemList.push(this.chooseItemData[j])
  1833. }
  1834. let obj = {};
  1835. this.chooseGroupItemList = this.chooseGroupItemList.reduce(function (item, next) {
  1836. obj[next.id] ? '' : obj[next.id] = true && item.push(next)
  1837. return item;
  1838. }, [])
  1839. },
  1840. /** 查询所有数据模型 */
  1841. getAllDataModel(itemList) {
  1842. let loading = showLoading(this, '数据加载中,请稍候···')
  1843. let params = {
  1844. 'page': 1,
  1845. 'limit': 1000
  1846. }
  1847. getAllDataModel(params).then(res => {
  1848. loading.close()
  1849. if (!res.data) {
  1850. this.chooseItemData = itemList
  1851. return
  1852. }
  1853. this.dataModelList = res.data.dataModelList
  1854. this.itemDataListByCalc = JSON.parse(JSON.stringify(itemList))
  1855. for (let i in this.itemDataListByCalc) {
  1856. let temp = this.itemDataListByCalc[i]
  1857. temp.rule = {
  1858. 'operationRule': '默认值'
  1859. }
  1860. }
  1861. }).catch((e) => {
  1862. loading.close()
  1863. showAlertWin(this, null, e)
  1864. })
  1865. },
  1866. /** 选择数据模型 */
  1867. handleChoose(index, row) {
  1868. this.chooseDataItemIndex = index
  1869. this.chooseDataModel = null
  1870. this.dialogDataModelVisible = true
  1871. },
  1872. /** 保存数据模型事件 */
  1873. saveDataModelEvent() {
  1874. if (!this.chooseDataModel) {
  1875. showAlertMsgWin(this, null, '请选择表达式!')
  1876. return
  1877. }
  1878. let item = {}
  1879. for (let i in this.dataModelList) {
  1880. if (this.chooseDataModel == this.dataModelList[i].id) {
  1881. item = this.dataModelList[i]
  1882. }
  1883. }
  1884. this.$nextTick(() => {
  1885. this.itemDataListByCalc[this.chooseDataItemIndex].rule = item
  1886. this.bomCheckKey++
  1887. })
  1888. this.dialogDataModelVisible = false
  1889. },
  1890. /** 报表模板库 */
  1891. templateEvent() {
  1892. this.commTemplateList = []
  1893. this.reportTypes = []
  1894. this.reportType = null
  1895. // 获取报表类别
  1896. getDictByKey({
  1897. 'keyType': 'report_template'
  1898. }).then(res => {
  1899. this.reportTypes.push({
  1900. 'id': -1,
  1901. 'dictKey': '所有',
  1902. 'dictValue': ''
  1903. })
  1904. let t = handleTree(res.data, 'id', 'parentId', 'children')
  1905. this.reportTypes = this.reportTypes.concat(t)
  1906. this.dialogCommReportVisible = true
  1907. this.handleReportTypeChange([-1])
  1908. }).catch((e) => {
  1909. showAlertWin(this, null, e)
  1910. })
  1911. },
  1912. clickCascader() {
  1913. this.$refs.reportType.$el.click()
  1914. this.reportType = null
  1915. },
  1916. searchDictTree(nodes, searchKey) {
  1917. for (let _i = 0; _i < nodes.length; _i++) {
  1918. if (nodes[_i].id === searchKey) {
  1919. return nodes[_i].dictKey
  1920. } else {
  1921. if (nodes[_i].children && nodes[_i].children.length > 0) {
  1922. let res = this.searchDictTree(nodes[_i].children, searchKey)
  1923. if (res) {
  1924. return res
  1925. }
  1926. }
  1927. }
  1928. }
  1929. return null
  1930. },
  1931. handleReportTypeInputChange() {
  1932. let arr = this.reportTypeInputId.length == 0 ? [-1] : this.reportTypeInputId
  1933. this.handleReportTypeChange(arr)
  1934. },
  1935. /** 报表行业选择 */
  1936. handleReportTypeNodeChange(val) {
  1937. this.handleReportTypeChange(val)
  1938. },
  1939. /** 报表行业选择 */
  1940. handleReportTypeChange(val) {
  1941. if (!val || val.length == 0) {
  1942. return
  1943. }
  1944. let nameArr = []
  1945. val.forEach(v => {
  1946. let name = this.searchDictTree(this.reportTypes, v)
  1947. nameArr.push(name)
  1948. })
  1949. this.reportTypeInputName = nameArr.join(' / ')
  1950. this.reportTypeInputId = val
  1951. let id = val[val.length - 1]
  1952. if (id === -1) {
  1953. this.reportTypeInputName = '所有'
  1954. this.reportTypeInputId = []
  1955. id = null
  1956. }
  1957. let params = {
  1958. 'keyType': this.keyType,
  1959. 'dictId': id
  1960. }
  1961. if (this.searchReportTxt && this.searchReportTxt.trim()) {
  1962. params.templateName = this.searchReportTxt.trim()
  1963. }
  1964. getSysTableTemplate(params).then(res => {
  1965. if (!res.data) {
  1966. return
  1967. }
  1968. this.commTemplateList = res.data
  1969. }).catch((e) => {
  1970. showAlertWin(this, null, e)
  1971. })
  1972. },
  1973. /** 选择模板报表 */
  1974. commReportEvent(flag) {
  1975. let _this = this
  1976. if (!_this.commTemplate) {
  1977. showAlertMsgWin(_this, null, '请选择模板!')
  1978. return
  1979. }
  1980. const loading = showLoading(_this, '加载中,请稍候···')
  1981. getSysTableTemplateById(_this.commTemplate.id).then(res => {
  1982. if (!res || !res.data) {
  1983. loading.close()
  1984. return
  1985. }
  1986. let locItem = res.data.templateData
  1987. luckysheet.destroy()
  1988. let option = JSON.parse(JSON.stringify(_this.luckysheetOption))
  1989. option.data = JSON.parse(locItem).data
  1990. this.toolItemChart = JSON.parse(locItem).charts
  1991. option.hook = {
  1992. workbookCreateAfter() {
  1993. loading.close()
  1994. if (flag == 1) _this.dialogClose()
  1995. },
  1996. cellUpdated(r, c, newV, oldV) {
  1997. if (!(r === 49 && c === 0)) {
  1998. _this.forceRefreshLuckysheet()
  1999. }
  2000. },
  2001. rangePasteBefore(r, d) {
  2002. if (_this.$data.ctrlxstatus) {
  2003. _this.$data.ctrlxstatus = false;
  2004. luckysheet.clearRange({range: _this.$data.sheetAxis})
  2005. }
  2006. }
  2007. }
  2008. luckysheet.create(option)
  2009. }).catch((e) => {
  2010. loading.close()
  2011. showAlertWin(_this, null, e)
  2012. })
  2013. },
  2014. /** 数据项 */
  2015. dataEvent(type) {
  2016. this.isUpdateShow = false
  2017. let rangeWithFlatten = luckysheet.getRangeWithFlatten()
  2018. if (!rangeWithFlatten || rangeWithFlatten.length != 1) {
  2019. showAlertMsgWin(this, null, '请选择一项单元格!')
  2020. return
  2021. }
  2022. this.newItemId = 0;
  2023. // 基础数据项
  2024. if (type == 1) {
  2025. this.getBaseDataItem()
  2026. return
  2027. } else if (type == 3) {
  2028. this.newItemId = 1;
  2029. }
  2030. // 初始化数据显示方式
  2031. this.itemShowParams = {
  2032. fieldType: '1',
  2033. valType: '2',
  2034. valLine: 1,
  2035. dataId: new Date().getTime()
  2036. }
  2037. this.deviceReportCondition = {
  2038. type: null,
  2039. variableType: '1',
  2040. isGenCountTime: '0',
  2041. startItemId: null,
  2042. startItemName: null,
  2043. startValue: '',
  2044. endItemId: null,
  2045. endItemName: null,
  2046. endValue: ''
  2047. }
  2048. this.hasBelongDataFlag = false
  2049. if (type == 2) this.hasBelongDataFlag = true
  2050. this.chooseDataGroup = null
  2051. this.getDataGroupList()
  2052. this.dialogGroupItemVisible = true
  2053. },
  2054. /** 查询字典表:基础数据项 */
  2055. getBaseDataItem() {
  2056. getDictByKey({
  2057. 'keyType': 'base_data_item'
  2058. }).then(res => {
  2059. this.dialogBaseDataVisible = true
  2060. this.baseDataList = res.data
  2061. }).catch((e) => {
  2062. showAlertWin(this, null, e)
  2063. })
  2064. },
  2065. /** 基础数据项插入 */
  2066. baseItemEvent(flag) {
  2067. if (!this.chooseBaseData) {
  2068. showAlertMsgWin(this, null, '请选择基础数据项!')
  2069. return
  2070. }
  2071. let rangeWithFlatten = luckysheet.getRangeWithFlatten()
  2072. let c = rangeWithFlatten[0].c
  2073. let r = rangeWithFlatten[0].r
  2074. luckysheet.setCellValue(r, c, this.chooseBaseData)
  2075. if (flag == 1) this.dialogBaseDataClose()
  2076. },
  2077. /** 动态数据项插入 */
  2078. itemEvent(flag) {
  2079. if (this.chooseGroupItemList.length == 0) {
  2080. showAlertMsgWin(this, null, '请选择数据组项!')
  2081. return
  2082. }
  2083. // 检查是否设置数据读取条件
  2084. let condCount = 0
  2085. this.chooseGroupItemList.forEach((item, i) => {
  2086. if (this.templateReportType != 2
  2087. && (item.valueTakingMode == null || item.bucketType == null
  2088. || item.bucketValue == null)) {
  2089. condCount++
  2090. }
  2091. })
  2092. if (condCount > 0) {
  2093. showAlertMsgWin(this, null, '请设置数据条件!')
  2094. return
  2095. }
  2096. // 设备报表
  2097. if (this.templateReportType == 5) {
  2098. if (!this.deviceReportCondition.startItemId || !this.deviceReportCondition.endItemId) {
  2099. showAlertMsgWin(this, null, '请设置设备报表条件!')
  2100. return
  2101. }
  2102. if (this.deviceReportCondition.startItemId == this.deviceReportCondition.endItemId
  2103. && this.deviceReportCondition.startValue == this.deviceReportCondition.endValue) {
  2104. showAlertMsgWin(this, null, '设备报表开始和结束变量条件不合法!')
  2105. return
  2106. }
  2107. }
  2108. let c, r
  2109. condCount = 0;
  2110. let rangeWithFlatten = luckysheet.getRangeWithFlatten()
  2111. c = rangeWithFlatten[0].c
  2112. r = rangeWithFlatten[0].r
  2113. // 事件驱动报表格式设置
  2114. if (this.templateReportType == 2) {
  2115. this.chooseGroupItemList.forEach((item, i) => {
  2116. if (item.valueType == null) {
  2117. condCount++
  2118. }
  2119. })
  2120. if (condCount > 0) {
  2121. showAlertMsgWin(this, null, '请设置数据条件!')
  2122. return
  2123. }
  2124. // 清空之前选择的数据组、数据项信息
  2125. let tempItem = JSON.parse(JSON.stringify(this.toolItemTable))
  2126. tempItem.forEach((t, i) => {
  2127. if (i == 0) {
  2128. luckysheet.setCellValue(t.xaxis - 1, t.yaxis - 1, '')
  2129. }
  2130. luckysheet.setCellValue(t.xaxis - 1, t.yaxis, '')
  2131. luckysheet.setCellValue(t.xaxis, t.yaxis, '')
  2132. })
  2133. this.toolItemTable = []
  2134. luckysheet.setCellValue(r, c, '数据时间')
  2135. r++
  2136. c++
  2137. }
  2138. // 设备报表
  2139. else if (this.templateReportType == 5) {
  2140. console.log(this.deviceReportCondition)
  2141. luckysheet.setCellValue(r, c, '序号')
  2142. luckysheet.setCellValue(r + 1, c, '${index}')
  2143. c++
  2144. luckysheet.setCellValue(r, c, '开始时间')
  2145. luckysheet.setCellValue(r + 1, c, '${startTime}')
  2146. c++
  2147. luckysheet.setCellValue(r, c, '停止时间')
  2148. luckysheet.setCellValue(r + 1, c, '${stopTime}')
  2149. if (this.deviceReportCondition.isGenCountTime == 1) {
  2150. c++
  2151. luckysheet.setCellValue(r, c, '运行时间(分钟)')
  2152. luckysheet.setCellValue(r + 1, c, '${runMinute}')
  2153. }
  2154. r++
  2155. c++
  2156. }
  2157. // 值显示数量
  2158. let addrObj = {}
  2159. let startX = 0;
  2160. let startY = 0;
  2161. console.log(this.chooseGroupItemList)
  2162. for (let n = 0; n < this.itemShowParams.valLine; n++) {
  2163. for (let i = 0; i < this.chooseGroupItemList.length; i++) {
  2164. let item = this.chooseGroupItemList[i]
  2165. // this.chooseGroupItemList.forEach((item, i) => {
  2166. let groupId = item.itemGroupId
  2167. let name = item.itemName
  2168. let describe = item.describe
  2169. // name = name.substring(name.lastIndexOf('.') + 1)
  2170. let v = '${' + groupId + '.' + name + '}'
  2171. if (item.itemReadName) {
  2172. v = '${' + item.dataSourceName + '.' + item.itemReadName + '}'
  2173. // v = item.dataSourceName + "." + item.itemReadName
  2174. }
  2175. if (!item.placeHolder) {
  2176. item.placeHolder = v
  2177. } else {
  2178. v = item.placeHolder
  2179. }
  2180. item.standby = JSON.stringify({
  2181. 'index': n,
  2182. 'fieldType': this.itemShowParams.fieldType
  2183. })
  2184. let p_c = parseInt(c)
  2185. let p_r = parseInt(r)
  2186. // fieldType:1 横向 2 纵向
  2187. if (this.itemShowParams.fieldType == '2') {
  2188. p_r += i
  2189. p_c += n
  2190. } else {
  2191. p_c += i
  2192. p_r += n
  2193. }
  2194. item.xaxis = p_r
  2195. item.yaxis = p_c
  2196. if (i == 0 && n == 0) {
  2197. startX = p_r;
  2198. startY = p_c;
  2199. }
  2200. // 事件驱动报表和设备报表格式设置
  2201. if (this.templateReportType == 2 || this.templateReportType == 5) {
  2202. // luckysheet.setCellValue((p_r > 1 ? (p_r - 1) : 0), p_c, describe ? describe : name)
  2203. addrObj[(p_r > 1 ? (p_r - 1) : 0) + "_" + p_c] = describe ? describe : name
  2204. if (i == 0 && n == 0) {
  2205. startX = (p_r > 1 ? (p_r - 1) : 0) ;
  2206. }
  2207. }
  2208. // luckysheet.setCellValue(p_r, p_c, v)
  2209. addrObj[p_r + "_" +p_c] = v
  2210. if (n == 0) this.pushToItemTable(item)
  2211. // })
  2212. }
  2213. }
  2214. // console.log(addrObj)
  2215. // 拼接数据项二位数组
  2216. let cloumn = [];
  2217. let addX = 0;
  2218. while (true) {
  2219. let x = startX + addX;
  2220. let y = startY;
  2221. let addY = 0;
  2222. let row = [];
  2223. while (true) {
  2224. if (addrObj[x+"_"+(y + addY)] != null) {
  2225. // console.log(x+"_"+(y + addY))
  2226. row.push(addrObj[x+"_"+(y + addY)])
  2227. } else {
  2228. break;
  2229. }
  2230. addY++;
  2231. }
  2232. cloumn.push(row);
  2233. if (addrObj[x+"_"+y] == null) {
  2234. break;
  2235. }
  2236. addX++;
  2237. }
  2238. luckysheet.setValueBatch(cloumn, {
  2239. sr: startY,
  2240. sc: startX,
  2241. er: cloumn[0].length + startY - 1,
  2242. ec: cloumn.length + startX - 1
  2243. })
  2244. if (flag == 1) {
  2245. this.chooseGroupItemList = []
  2246. this.chooseDataGroup = null
  2247. this.chooseItemData = []
  2248. this.dialogGroupItemVisible = false
  2249. }
  2250. },
  2251. /** 附属属性值 */
  2252. belongItemEvent(flag) {
  2253. if (this.chooseGroupItemList.length == 0) {
  2254. showAlertMsgWin(this, null, '请选择数据组项!')
  2255. return
  2256. }
  2257. let rangeWithFlatten = luckysheet.getRangeWithFlatten()
  2258. let c = rangeWithFlatten[0].c
  2259. let r = rangeWithFlatten[0].r
  2260. this.chooseGroupItemList.forEach((item, i) => {
  2261. let dataValue = item.dataValue
  2262. dataValue = dataValue ? (dataValue + '') : ''
  2263. let p_c = parseInt(c)
  2264. let p_r = parseInt(r)
  2265. // fieldType:1 横向 2 纵向
  2266. if (this.itemShowParams.fieldType == '2') {
  2267. p_r += i
  2268. } else {
  2269. p_c += i
  2270. }
  2271. luckysheet.setCellValue(p_r, p_c, dataValue)
  2272. })
  2273. // 应用
  2274. if (flag == 1) {
  2275. this.chooseGroupItemList = []
  2276. this.chooseDataGroup = null
  2277. this.chooseItemData = []
  2278. this.dialogGroupItemVisible = false
  2279. }
  2280. },
  2281. /** 向数据表格增加数据(重复判断) */
  2282. pushToItemTable(item) {
  2283. console.log(item)
  2284. let itemInfo = {
  2285. 'itemId': item.id,
  2286. 'isDriverItem': item.isDriverItem,
  2287. 'placeHolder': item.placeHolder,
  2288. 'xaxis': item.xaxis,
  2289. 'yaxis': item.yaxis,
  2290. 'valueTakingMode': item.valueTakingMode,
  2291. 'bucketType': item.bucketType,
  2292. 'valueType': item.valueType,
  2293. 'bucketValue': item.bucketValue,
  2294. 'standby': item.standby,
  2295. 'itemName': item.itemName,
  2296. 'itemReadName': item.itemReadName,
  2297. 'dataSourceName': item.dataSourceName,
  2298. 'itemGroupId': item.itemGroupId,
  2299. 'itemType': item.itemType,
  2300. 'checked': item.checked
  2301. }
  2302. if (item.dataSourceId) {
  2303. itemInfo.dataSourceId = item.dataSourceId
  2304. }
  2305. if (item.itemId) {
  2306. itemInfo.itemId = item.itemId
  2307. }
  2308. itemInfo.startTime = null
  2309. itemInfo.endTime = null
  2310. // 当前是手动报表
  2311. if (this.templateReportType == 0) {
  2312. itemInfo.startTime = item.startTime
  2313. itemInfo.endTime = item.endTime
  2314. }
  2315. // 检查同一位置是否被替换
  2316. let index = -1
  2317. this.toolItemTable.forEach((info, i) => {
  2318. if (itemInfo.xaxis === info.xaxis && itemInfo.yaxis === info.yaxis) {
  2319. index = i
  2320. }
  2321. })
  2322. if (index > -1) {
  2323. this.toolItemTable[index] = itemInfo
  2324. } else {
  2325. this.toolItemTable.push(itemInfo)
  2326. }
  2327. },
  2328. /** 检查数据项设置的字段值是否被改变 */
  2329. checkToItemTable() {
  2330. let i = this.toolItemTable.length
  2331. let sheetData = luckysheet.getSheetData(0)
  2332. while (i--) {
  2333. let info = this.toolItemTable[i]
  2334. // let v = luckysheet.getCellValue(info.xaxis, info.yaxis)
  2335. let v = sheetData[info.xaxis][info.yaxis]
  2336. console.log(v, info.placeHolder)
  2337. if (v) {
  2338. if ((v + "") != info.placeHolder) {
  2339. if (v.v) {
  2340. if (v.v != info.placeHolder) {
  2341. this.toolItemTable.splice(i, 1)
  2342. }
  2343. } else {
  2344. this.toolItemTable.splice(i, 1)
  2345. }
  2346. }
  2347. } else {
  2348. this.toolItemTable.splice(i, 1)
  2349. }
  2350. }
  2351. },
  2352. uniqueFunc(arr, uniId) {
  2353. try {
  2354. const res = new Map()
  2355. return arr.filter((item) => !res.has(item.showType[uniId]) && res.set(item.showType[uniId], 1))
  2356. } catch (e) {
  2357. return arr
  2358. }
  2359. },
  2360. /** 柱状图 */
  2361. barEvent(type) {
  2362. let _this = this
  2363. // 当前选择范围
  2364. let rangeWithFlatten = luckysheet.getRangeWithFlatten()
  2365. if (!rangeWithFlatten || rangeWithFlatten.length <= 1) {
  2366. showAlertMsgWin(_this, null, '请选择多项单元格!')
  2367. return
  2368. }
  2369. this.barChartForm = {
  2370. title: '',
  2371. type: '',
  2372. subtitle: '',
  2373. showTitle: '1',
  2374. showLegend: '1',
  2375. legendType: '1',
  2376. legendData: ['模板数据1', '模板数据2'],
  2377. xAxisData: ['数据1', '数据2', '数据3'],
  2378. valueType: 0, // 0原始值1计算值
  2379. valueTakingMode: 0, // 取值模式0平均值,1最大值,2最小值,3瞬时值
  2380. bucketType: 1, // 时段类型0天,1时,2分,3秒
  2381. bucketValue: 1
  2382. }
  2383. this.chooseDataGroup = null
  2384. this.getDataGroupList()
  2385. if (!type) {
  2386. type = 'bar'
  2387. }
  2388. if (type == 'bar') {
  2389. this.chartConfigTitle = '柱状图配置'
  2390. } else if (type == 'line') {
  2391. this.chartConfigTitle = '折线图配置'
  2392. } else if (type == 'pie') {
  2393. this.chartConfigTitle = '饼状图配置'
  2394. }
  2395. this.barChartForm.type = type
  2396. // 显示柱状图配置信息
  2397. this.dialogBarChartVisible = true
  2398. },
  2399. /** 柱状图图表插入 */
  2400. insertBarChartForm(flag) {
  2401. if (this.barChartForm.showTitle == '1' && !this.barChartForm.title) {
  2402. showAlertMsgWin(this, null, '标题不能为空!')
  2403. return
  2404. }
  2405. if (!this.chooseDataGroup) {
  2406. showAlertMsgWin(this, null, '请选择数据组!')
  2407. return
  2408. }
  2409. if (this.chooseItemData.length == 0) {
  2410. showAlertMsgWin(this, null, '请选择数据组项!')
  2411. return
  2412. }
  2413. if ((this.barChartForm.legendType == '0' && this.chooseItemData.length > 1)
  2414. || (this.barChartForm.type == 'pie' && this.chooseItemData.length > 1)) {
  2415. showAlertMsgWin(this, null, '饼图仅支持选择一项数据项!')
  2416. return
  2417. }
  2418. // 图表参数
  2419. this.barChartOption = {
  2420. title: {
  2421. show: this.barChartForm.showTitle == '1',
  2422. text: this.barChartForm.title,
  2423. subtext: this.barChartForm.subtitle,
  2424. left: 'center'
  2425. },
  2426. grid: {
  2427. },
  2428. tooltip: {
  2429. top: 0
  2430. },
  2431. legend: {
  2432. show: this.barChartForm.showLegend == '1',
  2433. orient: 'vertical',
  2434. left: 0,
  2435. bottom: 0,
  2436. data: []
  2437. },
  2438. series: []
  2439. }
  2440. if (this.barChartForm.type != 'pie') {
  2441. this.barChartOption.xAxis = {
  2442. data: this.barChartForm.xAxisData
  2443. }
  2444. this.barChartOption.yAxis = {}
  2445. // 图表图例类型:1 数据项 0 值
  2446. if (this.barChartForm.legendType == '1') {
  2447. let legendNameList = []
  2448. for (let i in this.chooseItemData) {
  2449. let name = this.chooseItemData[i].describe
  2450. name = name ? name : this.chooseItemData[i].itemName
  2451. legendNameList.push(name)
  2452. }
  2453. this.barChartOption.legend.data = legendNameList
  2454. } else {
  2455. this.barChartOption.legend.data = ['值', '运算值']
  2456. }
  2457. // this.barChartOption.legend.data = this.barChartForm.legendData
  2458. for (let i in this.barChartOption.legend.data) {
  2459. let seriesName = this.barChartOption.legend.data[i]
  2460. let dataList = []
  2461. for (let j in this.barChartForm.xAxisData) {
  2462. dataList.push(Math.ceil(Math.random() * 10))
  2463. }
  2464. let series = {
  2465. name: seriesName,
  2466. type: this.barChartForm.type,
  2467. data: dataList
  2468. }
  2469. this.barChartOption.series.push(series)
  2470. }
  2471. } else {
  2472. this.barChartOption.legend = null
  2473. let seriesName = this.barChartForm.legendData[0]
  2474. let dataList = []
  2475. for (let i in this.barChartForm.xAxisData) {
  2476. dataList.push({
  2477. value: Math.ceil(Math.random() * 10),
  2478. name: this.barChartForm.xAxisData[i]
  2479. })
  2480. }
  2481. let series = {
  2482. name: seriesName,
  2483. type: this.barChartForm.type,
  2484. radius: '50%',
  2485. data: dataList
  2486. }
  2487. this.barChartOption.series.push(series)
  2488. }
  2489. if (this.barChartForm.uid) {
  2490. this.delChartItem()
  2491. }
  2492. // 合并当前选择范围
  2493. luckysheet.setRangeMerge('all')
  2494. // 图表插入的 x、y 轴坐标获取
  2495. let range = luckysheet.getRange()
  2496. let x = range[0].column[0]
  2497. let y = range[0].row[0]
  2498. // 随机类名称
  2499. let clz = this.generateRandomKey('chart_clz')
  2500. let info = {
  2501. id: this.generateRandomKey('chart'), // 唯一 id
  2502. pos: [y, x], // eCharts 插入的单元格横、纵坐标
  2503. className: clz, // 给定eCharts容器的 className,自定义
  2504. chart: null, // 创建的 eCharts 实例
  2505. option: this.barChartOption // eCharts 图形配置选项
  2506. }
  2507. this.insertEChartTool(info, true, this.chooseItemData, this.barChartForm)
  2508. this.chooseDataGroup = null
  2509. if (flag == 0) {
  2510. setTimeout(() => {
  2511. this.chooseChartClz = clz
  2512. this.updateChartItem()
  2513. }, 1000)
  2514. return
  2515. }
  2516. this.$refs.barChartForm.resetFields()
  2517. this.chooseItemData = []
  2518. this.dialogBarChartVisible = false
  2519. },
  2520. /** 取消图表插入 */
  2521. cancelBarChartForm() {
  2522. this.$refs.barChartForm.resetFields()
  2523. this.chooseDataGroup = null
  2524. this.chooseItemData = []
  2525. this.dialogBarChartVisible = false
  2526. },
  2527. /** 图表修改 */
  2528. updateChartItem() {
  2529. let chartInfo = {}
  2530. for (let i in this.toolItemChart) {
  2531. if (JSON.parse(this.toolItemChart[i].standby).className == this.chooseChartClz) {
  2532. chartInfo = this.toolItemChart[i]
  2533. }
  2534. }
  2535. const chartData = JSON.parse(chartInfo.standby)
  2536. let temp = chartData.option
  2537. luckysheet.setRangeShow((toExcelColumn(chartData.pos[1] + 1) + (chartData.pos[0] + 1)) + ":" + (toExcelColumn(chartData.pos[1] + 1) + (chartData.pos[0] + 1)))
  2538. this.barChartForm.uid = new Date().getTime()
  2539. this.barChartForm.title = temp.title.text
  2540. this.barChartForm.subtitle = temp.title.subtext
  2541. this.barChartForm.showTitle = temp.title.show ? '1' : '0'
  2542. this.barChartForm.showLegend = temp.legend.show ? '1' : '0'
  2543. this.barChartForm.type = temp.series[0].type
  2544. this.barChartForm.legendType = '1'
  2545. this.barChartForm.bucketType = chartInfo.bucketType
  2546. this.barChartForm.bucketValue = chartInfo.bucketValue
  2547. this.barChartForm.valueTakingMode = chartInfo.valueTakingMode
  2548. this.barChartForm.valueType = chartInfo.valueType
  2549. this.chooseItemData = chartInfo.tableTemplateChartItemList
  2550. this.getDataGroupList(() => {
  2551. this.chooseDataGroup = chartInfo.tableTemplateChartItemList[0].itemGroupId
  2552. })
  2553. this.dialogBarChartVisible = true
  2554. },
  2555. /** 图表删除 */
  2556. delChartItem() {
  2557. if (!this.chooseChartClz) {
  2558. return
  2559. }
  2560. $('.' + this.chooseChartClz).remove()
  2561. luckysheet.cancelRangeMerge()
  2562. for (let i in this.toolItemChart) {
  2563. if (JSON.parse(this.toolItemChart[i].standby).className == this.chooseChartClz) {
  2564. this.toolItemChart.splice(i, 1)
  2565. }
  2566. }
  2567. },
  2568. /** 自动存储报表信息 */
  2569. autoSaveReportInfo() {
  2570. let _this = this
  2571. if (this.reportInterval) {
  2572. clearInterval(this.reportInterval)
  2573. }
  2574. let time = setInterval(() => {
  2575. if (!this.templateId) {
  2576. let result = {
  2577. 'charts': _this.toolItemChart,
  2578. 'tables': _this.toolItemTable,
  2579. 'data': JSON.parse(getLuckysheetConfig())
  2580. }
  2581. localStorage.setItem(_this.reportTemplateItem, JSON.stringify(result))
  2582. localStorage.setItem(_this.reportTemplateItem + '_TITLE', _this.templateName)
  2583. console.log(new Date().getTime(), 'auto save report template success.')
  2584. }
  2585. }, 5 * 1000)
  2586. this.reportInterval = time
  2587. },
  2588. /** 获取模板报表信息 */
  2589. getTableTemplate(id, type) {
  2590. let _this = this
  2591. this.printId=id
  2592. if (!id || id == -999) {
  2593. this.resetReport(true)
  2594. return
  2595. }
  2596. getTableTemplateById(id).then(res => {
  2597. if (!res.data) {
  2598. return
  2599. }
  2600. localStorage.removeItem('REPORT_LEN')
  2601. luckysheet.destroy()
  2602. this.templateName = res.data.templateName
  2603. this.templateId = res.data.id
  2604. this.templateVersion = res.data.version
  2605. this.templateReportType = res.data.templateType
  2606. this.templateEventReportNum = res.data.eventNum ? res.data.eventNum : 100
  2607. this.toolItemTable = res.data.tableTemplateItemList
  2608. this.toolItemChart = res.data.tableTemplateChartList
  2609. let templateData = res.data.templateData
  2610. let option = JSON.parse(JSON.stringify(this.luckysheetOption))
  2611. option.data = JSON.parse(templateData).data
  2612. option.hook = {
  2613. workbookCreateAfter() {
  2614. for (let i in _this.toolItemChart) {
  2615. _this.insertEChartTool(JSON.parse(_this.toolItemChart[i].standby), false)
  2616. }
  2617. // 报表模板导出
  2618. if (type === 'export' && type === localStorage.getItem('__export')) {
  2619. localStorage.setItem('__export', '')
  2620. exportExcel(luckysheet.getAllSheets(), _this.templateName)
  2621. }
  2622. let _len = getLuckysheetConfig() ? getLuckysheetConfig().length : 0
  2623. localStorage.setItem('REPORT_LEN', String(_len))
  2624. },
  2625. cellUpdated(r, c, newV, oldV) {
  2626. if (!(r === 49 && c === 0)) {
  2627. _this.forceRefreshLuckysheet()
  2628. }
  2629. },
  2630. rangePasteBefore(r, d) {
  2631. if (_this.$data.ctrlxstatus) {
  2632. _this.$data.ctrlxstatus = false;
  2633. luckysheet.clearRange({range: _this.$data.sheetAxis})
  2634. }
  2635. }
  2636. }
  2637. luckysheet.create(option)
  2638. }).catch((e) => {
  2639. showAlertWin(this, null, e)
  2640. })
  2641. },
  2642. /** 数据值显示类型事件 */
  2643. showDataTypeEvent(val) {
  2644. if (val == 1) {
  2645. this.itemShowParams.valType = '2'
  2646. } else {
  2647. this.itemShowParams.valType = '1'
  2648. }
  2649. },
  2650. /** 根据ID查询组信息 */
  2651. getGroupById(val) {
  2652. if (this.templateReportType == 2 || this.templateReportType == 5) {
  2653. this.chooseGroupItemList = []
  2654. }
  2655. if (this.templateReportType != 2) {
  2656. return
  2657. }
  2658. const loading = showLoading(this, '加载中,请稍候···')
  2659. getItemGroupById(val, null).then(res => {
  2660. loading.close()
  2661. let data = res.data
  2662. let itemList = data.itemList
  2663. let itemName = ''
  2664. itemList.forEach((item) => {
  2665. if (item.isDriverItem == 1) {
  2666. itemName = item.itemName
  2667. }
  2668. })
  2669. let list = [
  2670. {'label': '大于', 'value': 0},
  2671. {'label': '小于', 'value': 1},
  2672. {'label': '等于', 'value': 2},
  2673. {'label': '动态大于', 'value': 3},
  2674. {'label': '动态小于', 'value': 4}
  2675. ]
  2676. this.conditionObj = {
  2677. itemName: itemName,
  2678. eventModeName: this.getValByProp(list, data.eventMode),
  2679. modeValue: data.modeValue
  2680. }
  2681. }).catch((e) => {
  2682. loading.close()
  2683. showAlertWin(this, null, e)
  2684. })
  2685. },
  2686. /** 打印操作 */
  2687. printExcel() {
  2688. const loading = showLoading(this, '请稍候···')
  2689. // exportSheetExcel(luckysheet.getLuckysheetfile(), "报表模板", loading)
  2690. document.querySelector('#print-area').style = "display:block";
  2691. window.luckysheet.hideGridLines();
  2692. //获取当前选中区域
  2693. let currentSelected = luckysheet.getRange()
  2694. //如果当前选中区只是一个单元格,则认为选取无效。
  2695. if (currentSelected[0] != null && (currentSelected[0].row[1] - currentSelected[0].row[0] >= 1 || currentSelected[0].column[1] - currentSelected[0].column[0] >= 1)) {
  2696. // 将打印区域生成base64图片(*将生成的base64编码复制粘贴到浏览器地址框,是可以预览图片样式的),生成后执行的后续打印操作,取用匿名委托函数做为参数传入
  2697. luckysheet.getScreenshotNew((imgSrc) => {
  2698. window.luckysheet.showGridLines();
  2699. // * Lodop中的ADD_PRINT_IMAGE,也可以直接输出base64码图片,不用加img标签(如果加了img标签,会被当做超文本对待,受浏览器引擎解析的影响)
  2700. let $img = `<img src=${imgSrc} style="" />`
  2701. this.$nextTick(() => {
  2702. document.querySelector('#print-html').innerHTML = $img;
  2703. setTimeout(() => {
  2704. Print({
  2705. printable: 'print-html',
  2706. type: 'html',
  2707. documentTitle: '文档标题',
  2708. maxWidth: 1150, // 最大宽度
  2709. header: '',
  2710. headerStyle: 'font-weight:400;text-align:center;',
  2711. style: '', // 不打印页眉和页脚
  2712. honorColor: true, // 是否打印彩色文本
  2713. targetStyles: ['*'] // 允许打印所有样式属性
  2714. }) // Print.js插件
  2715. // print(this.printId)
  2716. if (document.querySelector('#print-area'))
  2717. document.querySelector('#print-area').style = "display:none";
  2718. loading.close()
  2719. }, 1000);
  2720. })
  2721. });
  2722. }
  2723. else {
  2724. // 获取打印区域的行列
  2725. let RowColumn = this.getPrintSheetArea();
  2726. // 因需要打印左边的边框,需重新设置第一列
  2727. //RowColumn.column[0] = 0;
  2728. // 进行选区操作
  2729. luckysheet.setRangeShow(RowColumn);
  2730. // 将打印区域生成base64图片(*将生成的base64编码复制粘贴到浏览器地址框,是可以预览图片样式的),生成后执行的后续打印操作,取用匿名委托函数做为参数传入
  2731. luckysheet.getScreenshotNew((imgSrc) => {
  2732. window.luckysheet.showGridLines();
  2733. // * Lodop中的ADD_PRINT_IMAGE,也可以直接输出base64码图片,不用加img标签(如果加了img标签,会被当做超文本对待,受浏览器引擎解析的影响)
  2734. let $img = `<img src=${imgSrc} style="" />`
  2735. this.$nextTick(() => {
  2736. document.querySelector('#print-html').innerHTML = $img;
  2737. setTimeout(() => {
  2738. Print({
  2739. printable: 'print-html',
  2740. type: 'html',
  2741. documentTitle: '文档标题',
  2742. maxWidth: 1150, // 最大宽度
  2743. header: '',
  2744. headerStyle: 'font-weight:400;text-align:center;',
  2745. style: '', // 不打印页眉和页脚
  2746. honorColor: true, // 是否打印彩色文本
  2747. targetStyles: ['*'] // 允许打印所有样式属性
  2748. }) // Print.js插件
  2749. // print(this.printId)
  2750. if (document.querySelector('#print-area'))
  2751. document.querySelector('#print-area').style = "display:none";
  2752. loading.close()
  2753. }, 1000);
  2754. })
  2755. });
  2756. }
  2757. },
  2758. getPrintSheetArea() {
  2759. const sheetData = luckysheet.getSheetData();
  2760. let objRowColumn = {
  2761. row: [0, 0], //行
  2762. column: [0, 0], //列
  2763. };
  2764. // * item是行、index是行索引、it是一行里的一格、itemIndex是这一格在这一行里的列索引
  2765. sheetData.forEach((item, index) => {
  2766. //行数
  2767. item.forEach((it, itemIndex) => {
  2768. if (it !== null && it.v) {
  2769. console.log(index, it)
  2770. if (objRowColumn.row[1] < index) {
  2771. objRowColumn.row[1] = index; //row第二位
  2772. }
  2773. if (objRowColumn.column[1] < itemIndex) {
  2774. objRowColumn.column[1] = itemIndex; //column第二位
  2775. }
  2776. }
  2777. });
  2778. });
  2779. return objRowColumn;
  2780. },
  2781. clearRt() {
  2782. this.reportTypeInputName = '所有'
  2783. this.reportTypeInputId = []
  2784. this.reportType = null
  2785. this.searchReportTxt = ''
  2786. },
  2787. /** 弹出层关闭事件 */
  2788. dialogClose(done) {
  2789. this.chooseDataGroup = null
  2790. this.chooseItemData = []
  2791. this.chooseGroupItemList = []
  2792. this.filterItemData = ''
  2793. this.filterDeviceItemData = ''
  2794. this.clearRt()
  2795. this.commTemplate = null
  2796. if (typeof (done) === 'function') {
  2797. done()
  2798. } else {
  2799. this.dialogBarChartVisible = false
  2800. this.dialogDataItemVisible = false
  2801. this.dialogDataModelVisible = false
  2802. this.dialogCommReportVisible = false
  2803. this.dialogGroupItemVisible = false
  2804. this.dialogReportTypeVisible = false
  2805. this.dialogDriverConditionVisible = false;
  2806. }
  2807. },
  2808. /** 弹出层关闭事件 */
  2809. dialogItemClose(done) {
  2810. this.itemDataListByTree = []
  2811. this.filterItemData = ''
  2812. this.filterDeviceItemData = ''
  2813. if (typeof (done) === 'function') {
  2814. done()
  2815. } else {
  2816. this.dialogDataItemVisible = false
  2817. this.dialogDeviceDataItemVisible = false
  2818. }
  2819. },
  2820. /** 弹出层关闭事件 */
  2821. dialogDataModelClose() {
  2822. if (typeof (done) === 'function') {
  2823. done()
  2824. } else {
  2825. this.dialogDataModelVisible = false
  2826. }
  2827. },
  2828. /** 弹出层关闭事件 */
  2829. dialogBaseDataClose() {
  2830. this.chooseBaseData = null
  2831. if (typeof (done) === 'function') {
  2832. done()
  2833. } else {
  2834. this.dialogBaseDataVisible = false
  2835. }
  2836. },
  2837. /** 数据项取值配置弹出层关闭事件 */
  2838. dialogDataItemConfigClose(done) {
  2839. this.itemConditionForm = {
  2840. valueType: 0, // 0原始值1计算值
  2841. valueTakingMode: 0, // 取值模式0平均值,1最大值,2最小值,3瞬时值
  2842. bucketType: 1, // 时段类型0天,1时,2分,3秒
  2843. bucketValue: 1, // 时段值
  2844. dateRange: [], // 取值时间范围,手动报表必填
  2845. }
  2846. if (typeof (done) === 'function') {
  2847. done()
  2848. } else {
  2849. this.dialogDataItemConfigVisible = false
  2850. }
  2851. },
  2852. /** 关闭右键弹出层 */
  2853. closeMenu() {
  2854. this.visibleChartMenu = false
  2855. },
  2856. updateDataEvent() {
  2857. let rangeWithFlatten = luckysheet.getRangeWithFlatten()
  2858. if (!rangeWithFlatten) {
  2859. showAlertMsgWin(this, null, '请选择要修改的数据项!')
  2860. return
  2861. }
  2862. const sheetData = luckysheet.getSheet(0).data
  2863. let flattenObj = {}
  2864. let status = false;
  2865. for (let i = 0; i < rangeWithFlatten.length; i++) {
  2866. const val = sheetData[rangeWithFlatten[i].r][rangeWithFlatten[i].c]
  2867. if (!status) {
  2868. if (val) {
  2869. status = true;
  2870. }
  2871. }
  2872. flattenObj[rangeWithFlatten[i].c + "_" + rangeWithFlatten[i].r] = val
  2873. }
  2874. console.log(flattenObj)
  2875. if (!status) {
  2876. showAlertMsgWin(this, null, '选择区域未包含有效数据项!')
  2877. return
  2878. }
  2879. const items = this.toolItemTable;
  2880. let arr = []
  2881. for (let i = 0; i < items.length; i++) {
  2882. const key = items[i].yaxis + "_" + items[i].xaxis
  2883. if (flattenObj[key]) {
  2884. items[i].isFlag = 'update'
  2885. arr.push(items[i])
  2886. }
  2887. }
  2888. if (!arr.length) {
  2889. showAlertMsgWin(this, null, '选择区域未包含有效数据项!')
  2890. return
  2891. }
  2892. console.log(arr)
  2893. this.chooseGroupItemList = arr
  2894. this.isUpdateShow = true
  2895. // 初始化数据显示方式
  2896. this.itemShowParams = {
  2897. fieldType: '1',
  2898. valType: '2',
  2899. valLine: 1,
  2900. dataId: new Date().getTime()
  2901. }
  2902. this.deviceReportCondition = {
  2903. type: null,
  2904. variableType: '1',
  2905. isGenCountTime: '0',
  2906. startItemId: null,
  2907. startItemName: null,
  2908. startValue: '',
  2909. endItemId: null,
  2910. endItemName: null,
  2911. endValue: ''
  2912. }
  2913. this.getDataGroupList()
  2914. this.hasBelongDataFlag = false
  2915. // this.chooseDataGroup = null
  2916. this.dialogGroupItemVisible = true
  2917. },
  2918. }
  2919. }
  2920. </script>
  2921. <style rel="stylesheet/scss" lang="scss">
  2922. .cy-report-content {
  2923. width: 100%;
  2924. height: 100%;
  2925. padding-left: 6px;
  2926. color: #FFFFFF;
  2927. font-size: 14px;
  2928. background-color: #2c3e50;
  2929. display: flex;
  2930. flex-direction: row;
  2931. flex-wrap: nowrap;
  2932. }
  2933. .cy-div0 {
  2934. width: 30px;
  2935. height: 30px;
  2936. background: #767676;
  2937. }
  2938. .cy-div1 {
  2939. width: calc(100% - 90px);
  2940. height: 100%;
  2941. }
  2942. .cy-div2 {
  2943. width: 70px;
  2944. height: 100%;
  2945. z-index: 1;
  2946. background: #2c3e50;
  2947. overflow: auto;
  2948. }
  2949. .cy-report-ruler-unit {
  2950. width: 30px;
  2951. height: 30px;
  2952. display: flex;
  2953. justify-content: center;
  2954. align-items: center;
  2955. float: left;
  2956. border-right: 1px solid #2c3e50;
  2957. border-bottom: 1px solid #2c3e50;
  2958. }
  2959. .cy-ruler-top {
  2960. background: #767676;
  2961. width: 100%;
  2962. height: 30px;
  2963. }
  2964. .cy-box {
  2965. height: calc(100% - 50px);
  2966. width: calc(100% + 30px);
  2967. display: flex;
  2968. margin-left: -30px;
  2969. overflow: hidden;
  2970. .cy-ruler-left {
  2971. background: #767676;
  2972. width: 30px;
  2973. height: 100%;
  2974. }
  2975. .cy-box-main {
  2976. width: 100%;
  2977. height: 100%;
  2978. margin: 10px;
  2979. background: #FFFFFF;
  2980. }
  2981. }
  2982. .cy-chart-div {
  2983. display: flex;
  2984. flex-direction: column;
  2985. align-items: center;
  2986. cursor: pointer;
  2987. margin-bottom: 15px;
  2988. .svg-icon {
  2989. width: 50px;
  2990. height: 50px;
  2991. }
  2992. span {
  2993. font-size: 12px;
  2994. margin-top: -5px;
  2995. }
  2996. }
  2997. .label-title {
  2998. display: block !important;
  2999. .el-form-item__content {
  3000. width: calc(100% - 100px);
  3001. }
  3002. }
  3003. .el-transfer-panel {
  3004. width: 300px !important;
  3005. }
  3006. .device-condition {
  3007. margin: 5px;
  3008. }
  3009. </style>