ApplicationEquip.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <template>
  2. <div class="content-main common-scroll">
  3. <div class="content-body">
  4. <Row :gutter="8" style="width:100%;height:100%">
  5. <i-col span="5" style="height:100%">
  6. <div class="station-tree">
  7. <div class="station-tree-body">
  8. <div class="station-tree-top">
  9. <Input suffix="ios-search" placeholder="请输入关键字查询" clearable search v-model="currentStation" class="common-search" @on-search="iconChange" @on-clear="clearChange"/>
  10. </div>
  11. <div class="station-tree-center">
  12. <div class="station-tree-left common-scroll" v-show="showTree">
  13. <tree-list :defaultData="stationData" :currentStaData="currentStaData" :clickAllNode="true" secondCalssName="icon-shebei1" thirdCalssName="icon-shebei" v-if="stationData && stationData.length>0" @treeChange="treeChange" ref="tree"></tree-list>
  14. </div>
  15. <div class="station-tree-left-notree" v-show="!showTree">
  16. 关键字输入错误!
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. </i-col>
  22. <i-col span="19" style="height:100%">
  23. <div class="right-main">
  24. <div class="manage-main-top">
  25. <Button icon="ios-add" class="common-add-btn" @click="addClick">新增关联</Button>
  26. </div>
  27. <div class="manage-main-center">
  28. <Table :columns="columns" :data="tableData" class="common-table" no-data-text="" :row-class-name="rowClassName" :loading="loading">
  29. <template slot="loading">
  30. <Loading-animation></Loading-animation>
  31. </template>
  32. <template slot-scope="{ row }" slot="action">
  33. <Tooltip content="解绑" placement="top">
  34. <i class="iconfont icon-guanlian" style="cursor:pointer;color:#E92E2E;fontSize:20px;marginRight:6px" @click="boundClick(row)"></i>
  35. </Tooltip>
  36. </template>
  37. </Table>
  38. </div>
  39. <div class="common-page">
  40. <div class="common-page-total">
  41. 共<span>{{tablePage}}</span>页 / <span>{{tableTotal}}</span>条数据
  42. </div>
  43. <Page :total="tableTotal" :current="tableParams.pageNum" :page-size="tableParams.pageSize" @on-change="changePage" @on-page-size-change="sizeChange" show-elevator />
  44. </div>
  45. <!-- <Page :total="tableTotal" :current="tableParams.pageNum" :page-size="tableParams.pageSize" @on-change="changePage" @on-page-size-change="sizeChange" show-elevator class="common-page"/> -->
  46. </div>
  47. </i-col>
  48. </Row>
  49. </div>
  50. <Modal
  51. v-model="showModal"
  52. :title="title"
  53. width="25"
  54. ref="modalGrag"
  55. draggable
  56. reset-drag-position
  57. :mask-closable="false"
  58. @on-visible-change="modalChange"
  59. class-name="common-modal">
  60. <Form class="common-form" ref="formOption" :model="formOption" :rules="ruleValidate" :label-width="120">
  61. <FormItem label="应用名称:" prop="applicationId">
  62. <Select v-model="formOption.applicationId" placeholder="应用名称">
  63. <Option v-for="item in appNameList" :value="(item.id)" :key="item.value">{{ item.appName }}</Option>
  64. </Select>
  65. </FormItem>
  66. <FormItem label="设备类型:" prop="equipmentTypeId">
  67. <Select v-model="formOption.equipmentTypeId" placeholder="设备类型">
  68. <Option v-for="item in equipTypeData" :value="(item.id)" :key="item.id">{{ item.name }}</Option>
  69. </Select>
  70. </FormItem>
  71. </Form>
  72. <div slot="footer">
  73.     <Button @click="modalCancel">取消</Button>
  74.     <Button type="primary" @click="modalOk('formOption')">确定</Button>
  75.   </div>
  76. </Modal>
  77. <Modal
  78. v-model="modalStatus"
  79. title="确认解绑"
  80. width="25"
  81. ref="modalGrag"
  82. draggable
  83. reset-drag-position
  84. :mask-closable="false"
  85. class-name="common-modal">
  86. <Icon type="ios-information-circle" class="modal-icon" style="color:#E92E2E"></Icon>
  87. <span class="modal-text">删除的同时将解绑所有运营数据,且数据不可恢复。请慎重操作。</span>
  88. <div slot="footer">
  89.     <Button @click="commonCancel">取消</Button>
  90.     <Button type="primary" @click="commonOk">确定</Button>
  91.   </div>
  92. </Modal>
  93. </div>
  94. </template>
  95. <script>
  96. import _ from 'lodash'
  97. export default {
  98. name: "ApplicationEquip",
  99. components:{
  100. },
  101. data() {
  102. return {
  103. currentStation: '',
  104. currentStaData: [], // 当前搜索框搜索的站台数组对象,传给子组件,用来判断单选站台名当前选中状态
  105. showTree: true,// 是否显示树形组件
  106. stationData: [],
  107. tableTotal: 0,
  108. tablePage: 0,
  109. tableParams: {
  110. applicationId:'',
  111. equipmentTypeId: '',
  112. keywords: '',
  113. pageNum: 1,
  114. pageSize: 10
  115. },
  116. loading: true,
  117. tableData: [],
  118. columns: [
  119. {
  120. title: '应用名称',
  121. key: 'appName',
  122. align: 'center'
  123. },
  124. {
  125. title: '设备类型',
  126. key: 'equipmentName',
  127. align: 'center'
  128. },
  129. {
  130. title: '接入设备数量',
  131. key: 'equipmentNum',
  132. align: 'center'
  133. },
  134. {
  135. title: '操作',
  136. align: 'center',
  137. slot: 'action',
  138. }
  139. ],
  140. rowObj: {},
  141. formOption: {applicationId: '',equipmentTypeId:''},
  142. ruleValidate: {
  143. applicationId: [{
  144. required: true,
  145. type: 'number',
  146. message: '请选择应用名称',
  147. trigger: 'change'
  148. }],
  149. equipmentTypeId: [{
  150. required: true,
  151. type: 'number',
  152. message: '请选择设备类型',
  153. trigger: 'change'
  154. }],
  155. },
  156. equipTypeData: [],
  157. showModal: false,
  158. title: '新增关联',
  159. modalStatus: false,
  160. appNameObj: {
  161. level: '',
  162. lineId: '',
  163. stationId: '',
  164. equipmentCheck: '',
  165. instrumentCheck: '',
  166. pageNum: 1,
  167. pageSize: 9999
  168. },
  169. appNameList: []
  170. };
  171. },
  172. mounted() {
  173. document.querySelector(".common-scroll").scrollTo(0, 0)
  174. this.getMetroLevel()
  175. },
  176. methods: {
  177. // 获取树形数据
  178. getMetroLevel () {
  179. this.$get('metroapi/application/appEquipmentTypeTree').then(res => {
  180. if (res.httpCode == 1) {
  181. this.stationData = res.data
  182. }
  183. })
  184. },
  185. // 递归函数 每层数组的第一个对象里的属性expand 全展开(true)
  186. getTree(arr) {
  187. return arr.map((v,index) => {
  188. if (index==0) {
  189. v.expand = true
  190. }
  191. if (v.children) v.children = this.getTree(v.children);
  192. return v;
  193. });
  194. },
  195. iconChange: _.throttle(function() {
  196. this.currentStaData = []
  197. this.treeName = []
  198. this.$nextTick(()=> {
  199. this.getTableData()
  200. })
  201. if(this.currentStation != ''){
  202. this.showTree = false
  203. document.querySelector(".common-scroll").scrollTo(0, 0); // 滚动条回到顶部
  204. } else {
  205. document.querySelector(".common-scroll").scrollTo(0, 0); // 滚动条回到顶部
  206. this.showTree = true
  207. this.stationData = this.getTree(this.stationData)
  208. return
  209. }
  210. this.getSelectedItem()
  211. }, 500),
  212. clearChange () {
  213. this.getSelectedItem()
  214. this.$nextTick(()=> {
  215. this.getTableData()
  216. })
  217. },
  218. getSelectedItem () {
  219. this.stationData.forEach((item, index,itemArr) => {
  220. item.expand = false;
  221. item.disabled = false;
  222. item.selected = false;
  223. if (item.title == this.currentStation) {
  224. item.selected = true;
  225. item.disabled = true; // disabled 是否禁止选中
  226. item.expand = true;
  227. this.currentStaData.push(item)
  228. this.showTree = true
  229. }
  230. if (this.currentStation == '' && index == 0) {
  231. item.expand = true
  232. }
  233. item.children.forEach((val, i,valArr) => {
  234. val.expand = false; //expand 是否展开直子节点
  235. val.disabled = false; // disabled 是否禁止选中
  236. val.selected = false;
  237. if (val.title == this.currentStation) {
  238. val.selected = true;
  239. val.disabled = true; // disabled 是否禁止选中
  240. val.expand = true;
  241. item.expand = true;
  242. this.currentStaData.push(val)
  243. this.showTree = true
  244. }
  245. if (this.currentStation == '' && i==0) {
  246. val.expand = true
  247. }
  248. if (val.children) {
  249. val.children.forEach ((lastVal,lastIndex) => {
  250. lastVal.selected = false; //expand 是否展开直子节点
  251. lastVal.disabled = false;
  252. lastVal.expand = false;
  253. if (lastVal.title == this.currentStation) {
  254. lastVal.selected = true;
  255. lastVal.disabled = true; // disabled 是否禁止选中
  256. lastVal.expand = true;
  257. val.expand = true
  258. item.expand = true
  259. this.currentStaData.push(lastVal)
  260. this.showTree = true
  261. }
  262. })
  263. }
  264. });
  265. });
  266. },
  267. treeChange(val,arr,level) {
  268. this.currentStation = val
  269. this.$nextTick(()=> {
  270. this.getTableData(arr,level)
  271. })
  272. },
  273. rowClassName(row, index) {
  274. if (index % 2 == 0) {
  275. return "ivu-table-stripe-even";
  276. } else {
  277. return "ivu-table-stripe-odd";
  278. }
  279. },
  280. // 分页
  281. changePage (val) {
  282. this.tableParams.pageNum = val
  283. this.getTableData()
  284. },
  285. //跳转
  286. sizeChange (val) {
  287. this.tableParams.pageSize = val
  288. this.getTableData()
  289. },
  290. getTableData (arr,level) {
  291. if (level) {
  292. this.tableParams.keywords = ''
  293. if (level == 2) {
  294. this.tableParams.applicationId = arr[arr.length-1]
  295. this.tableParams.equipmentTypeId = ''
  296. } else if (level == 3) {
  297. this.tableParams.applicationId = arr[arr.length-2]
  298. this.tableParams.equipmentTypeId = arr[arr.length-1]
  299. } else {
  300. this.tableParams.applicationId = ''
  301. this.tableParams.applicationId = ''
  302. }
  303. } else {
  304. this.tableParams.applicationId = ''
  305. this.tableParams.equipmentTypeId = ''
  306. if (this.currentStation == '合肥轨道交通' || this.currentStation == '') {
  307. this.tableParams.keywords = ''
  308. } else {
  309. this.tableParams.keywords = this.currentStation
  310. }
  311. // if (this.$route.params.type) {
  312. // this.currentStation = '合肥轨道交通'
  313. // }
  314. }
  315. this.loading = true
  316. this.$get('metroapi/application/equipmentTypeInfo', this.tableParams).then(res=>{
  317. this.loading = false
  318. if ( res.httpCode == 1 ){
  319. this.tableData = res.data.data
  320. this.tableTotal = res.data.count
  321. if (res.data.data.length==0) {
  322. this.tablePage = 0
  323. } else {
  324. this.tablePage = res.data.count<= 10 ? 1: Math.ceil(res.data.count/this.tableParams.pageSize)
  325. }
  326. if (res.data.data.length==0 && this.tableParams.pageNum>1) {
  327. this.tableParams.pageNum--
  328. return this.getTableData()
  329. }
  330. } else {
  331. this.tableData = []
  332. this.tableTotal = 0
  333. }
  334. })
  335. },
  336. getType () {
  337. // 获取设备类型
  338. this.$get('metroapi/equipment/queryEquipmentType', {name:''}).then(res=>{
  339. if (res.httpCode == 1 ){
  340. this.equipTypeData = res.data
  341. } else {
  342. this.equipTypeData = []
  343. }
  344. })
  345. // 获取应用名称
  346. this.$get('metroapi/application/info/list', this.appNameObj).then(res=>{
  347. if (res.httpCode == 1 ){
  348. this.appNameList = res.data.data
  349. } else {
  350. this.appNameList = []
  351. }
  352. })
  353. },
  354. addClick () {
  355. this.showModal = true
  356. },
  357. boundClick (row) {
  358. this.rowObj = row
  359. this.modalStatus = true
  360. },
  361. modalChange (modalStatus) {
  362. if (!modalStatus) {
  363. this.$refs.formOption.resetFields();
  364. this.equipTypeData = []
  365. }
  366. },
  367. modalOk (formName) {
  368. this.$refs[formName].validate((valid) => {
  369. if (valid) {
  370. this.$post('metroapi/application/addEquipmentType', this.formOption).then(res=>{
  371. if (res.httpCode == 1 ){
  372. this.showModal = false
  373. this.$Message.info(res.msg)
  374. this.getTableData()
  375. this.getMetroLevel()
  376. } else {
  377. this.$Message.info(res.msg)
  378. }
  379. })
  380. } else {
  381. this.showModal = true
  382. }
  383. })
  384. },
  385. modalCancel () {
  386. this.showModal = false
  387. },
  388. commonOk () {
  389. this.$post('metroapi/application/deleteEquipmentType',{appEquipmentTypeId:this.rowObj.appEquipmentTypeId}).then(res=>{
  390. if (res.httpCode == 1 ){
  391. this.modalStatus = false
  392. this.getTableData()
  393. this.getMetroLevel()
  394. this.$Message.info(res.msg)
  395. } else {
  396. this.$Message.info(res.msg)
  397. }
  398. })
  399. },
  400. commonCancel () {
  401. this.modalStatus = false
  402. },
  403. }
  404. };
  405. </script>
  406. <style scoped lang="stylus">
  407. .content-main {
  408. width: 100%;
  409. height: calc(100% - 50px);
  410. overflow: auto;
  411. }
  412. .common-search {
  413. width: 100%;
  414. }
  415. >>> .common-search .ivu-input {
  416. background-color: #06214D;
  417. border: 1px solid #2355A6;
  418. border-radius: 15px;
  419. color: #fff;
  420. height: 32px;
  421. }
  422. >>> .common-search .ivu-input:focus {
  423. border-color: #0185ea;
  424. }
  425. .content-body {
  426. width: 100%;
  427. height: 100%;
  428. background: #06214D;
  429. }
  430. .station-tree {
  431. height: 100%;
  432. padding: 10px;
  433. }
  434. .station-tree-body {
  435. border: 1px solid #204384;
  436. height: 100%;
  437. padding: 10px;
  438. }
  439. .station-tree-center {
  440. height: calc(100% - 32px);
  441. padding-top: 10px;
  442. // display: flex;
  443. }
  444. .station-tree-left {
  445. height: 100%;
  446. overflow: auto;
  447. }
  448. .station-tree-left-notree {
  449. height: 100%;
  450. display: flex;
  451. align-items: center;
  452. justify-content: center;
  453. color: #fff;
  454. fon-size: 14px;
  455. }
  456. .right-main {
  457. height: 100%;
  458. padding: 10px 0;
  459. position: relative;
  460. // padding: 16px;
  461. }
  462. .manage-main-top {
  463. padding: 12px 0;
  464. display: flex;
  465. justify-content: flex-end;
  466. }
  467. .manage-main-center {
  468. width: 100%;
  469. height: calc(100% - 100px);
  470. }
  471. .common-table {
  472. max-height: 100%;
  473. }
  474. >>> .common-table .ivu-table th {
  475. height: 54px;
  476. }
  477. >>> .common-table .ivu-table td {
  478. height: 54px;
  479. }
  480. >>> .common-table .ivu-spin-fix {
  481. top: 54px;
  482. height: calc(100vh - 350px);
  483. }
  484. >>> .common-table .ivu-table-tip {
  485. background: url('../../../assets/images/noData.png') no-repeat center;
  486. height: calc(100vh - 350px);
  487. }
  488. >>> .common-table .ivu-table-tip table {
  489. display: none;
  490. }
  491. .common-page {
  492. margin-top: 15px;
  493. display: flex;
  494. align-items: center;
  495. justify-content: flex-end;
  496. position: absolute;
  497. bottom: 0;
  498. right: 0;
  499. }
  500. .common-page-total {
  501. color: #fff;
  502. padding-right: 10px;
  503. font-size: 14px;
  504. span {
  505. color #409EFF;
  506. }
  507. }
  508. </style>