edit-dialog.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <a-modal v-model="visible" title="选择编辑" width="1200px" class="edit-dialog" @cancel="handleCancel">
  3. <template slot="footer">
  4. <a-button key="back" @click="handleCancel">
  5. 取消
  6. </a-button>
  7. <a-button key="submit" type="primary" :loading="loading" @click="handleOk">
  8. 确认
  9. </a-button>
  10. </template>
  11. <div class="dialog-content">
  12. <div class="left">
  13. <div class="header">
  14. <div class="select">
  15. <Select style="margin: 0 10px"
  16. v-model="majorId"
  17. @change="handleMajor"
  18. :hideClear='true'
  19. :selectdata="majorList"
  20. :placeholder="'请选择'"
  21. class="search-select"
  22. width="236" isReadOnly
  23. />
  24. </div>
  25. <div class="search">
  26. <Select
  27. v-model="floorId"
  28. caption="所属楼层:"
  29. @change="chageFloor"
  30. :hideClear='false'
  31. :selectdata="dataFloor"
  32. :placeholder="'请选择'"
  33. class="search-select"
  34. width="236"
  35. />
  36. <a-input-search placeholder="搜索" class="press-enter" @search="onSearch" v-model="keyword"/>
  37. </div>
  38. </div>
  39. <div class="tree">
  40. <searchTree @getTreeId="getTreeId" :treeData="treeData"/>
  41. </div>
  42. <div class="checkbox">
  43. <a-table :pagination="false" :row-key='typeEdit=="Zone"?"location":"assetnum"' :columns="typeEdit=='Image'?columnsSys:columnsLocal" :data-source="tableData" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange,onSelect:onSelect }" :scroll="{ y: 340 }" :loading="loading"/>
  44. <a-pagination v-if="total>0" v-model="page" :total="total" show-less-items style="margin-left: auto;" @change="handleTableChange"/>
  45. </div>
  46. </div>
  47. <div class="right">
  48. <div class="header">
  49. <span class="select-number">已选择 <b>{{arrList.length}}</b>/{{sysNum}}</span>
  50. <a-button type="link" class="link" @click="clearArrList">清空</a-button>
  51. </div>
  52. <div class="list-box">
  53. <p v-for="(item,index) in arrList" :key="index" class="list">{{item.sbjc||item.wzjc}}
  54. <a-icon type="close" class="icon" @click="deleteItem(item,index)"/>
  55. </p>
  56. </div>
  57. </div>
  58. </div>
  59. </a-modal>
  60. </template>
  61. <script>
  62. import searchTree from "@/components/edit/search_tree";
  63. import {queryGlsmsasset ,getQuerySmsxt,getPlazaFloor,getQuerySmsxtBy,queryWzfldl,queryWzflByDl,queryGlsmsLocation} from "@/api/editer";
  64. import bus from "@/bus";
  65. import {getUrlMsg} from '@/components/urlMsg.js'
  66. export default {
  67. name: "edit-dialog",
  68. components: {searchTree},
  69. props:{
  70. typeEdit:String , //用于区分是设备 还是 位置
  71. getmajorId:String, //专业Id
  72. sysNum:Number ,//设备总数
  73. attrCards:Array
  74. },
  75. data() {
  76. return {
  77. loading: false,
  78. visible: false,
  79. model: 'test1',
  80. searchName: '',
  81. floorId:"",//所属楼层
  82. dataFloor: [],
  83. plainOptions: ['福建三明万达-供电系统-6楼-工程信息化中的区域编码ND182472e83742', '福建三明万达-供电系统-6楼-工程信息化中的区域编码ND18247283742'],
  84. majorList: [],
  85. checkedList: [],
  86. keyword:'',
  87. classstructureid:'',
  88. locfl:'',
  89. columnsSys : [
  90. {
  91. title: '设备名称',
  92. dataIndex: 'sbjc',
  93. key: 'sbjc',
  94. width: '75%',
  95. scopedSlots: { customRender: 'sbjc' },
  96. },
  97. {
  98. title: '设备内码',
  99. dataIndex: 'sbjbm',
  100. key: 'sbjbm',
  101. width: '25%',
  102. },
  103. ],
  104. columnsLocal : [
  105. {
  106. title: '位置名称',
  107. dataIndex: 'wzjc',
  108. key: 'wzjc',
  109. width: '75%',
  110. scopedSlots: { customRender: 'wzjc' },
  111. },
  112. {
  113. title: '位置内码',
  114. dataIndex: 'location',
  115. key: 'location',
  116. width: '25%',
  117. },
  118. ],
  119. tableData:[],
  120. loading:false,
  121. page:1,
  122. size:10,
  123. treeData:[],
  124. total:0,
  125. selectedRowKeys :[],
  126. arrList:[],
  127. selectList:[],
  128. }
  129. },
  130. computed:{
  131. majorId(){
  132. return this.typeEdit=='Zone'?'位置区域': this.getmajorId
  133. },
  134. },
  135. watch:{
  136. floorId(val){
  137. if(val==''){
  138. this.queryGlsmsasset();
  139. }
  140. }
  141. },
  142. methods: {
  143. showModal() {
  144. this.visible = true;
  145. },
  146. handleOk(e) {
  147. this.loading = true;
  148. setTimeout(() => {
  149. this.visible = false;
  150. this.loading = false;
  151. const lists = [];
  152. let arr = [];
  153. arr = JSON.parse(JSON.stringify( this.arrList))
  154. arr.map(item =>{
  155. lists.push({id:item.location||item.assetnum,name:item.wzjc||item.sbjc})
  156. })
  157. bus.$emit('changeAttachObjectIds',lists)
  158. bus.$emit('updateAttachMsg',lists)
  159. },1000);
  160. },
  161. handleCancel(e) {
  162. this.visible = false;
  163. let arr = [];
  164. let lists = [];
  165. arr = JSON.parse(JSON.stringify( this.selectList))
  166. arr.map(item =>{
  167. lists.push({id:item.location||item.assetnum,name:item.wzjc||item.sbjc})
  168. })
  169. bus.$emit('changeAttachObjectIds',lists)
  170. },
  171. onSearch(value) {
  172. this.queryGlsmsasset()
  173. },
  174. ChangeCheckbox(val) {
  175. console.log(val)
  176. },
  177. handleMajor(val) {
  178. this.tableData = [];
  179. this.getQuerySmsxtBy(val.id)
  180. },
  181. chageFloor(data) {
  182. this.queryGlsmsasset();
  183. },
  184. pressEnter(e) {
  185. console.log(e)
  186. },
  187. //获取treeId --classstructureid
  188. getTreeId(id) {
  189. if(this.typeEdit=='Image'){
  190. this.classstructureid = id;
  191. }else if(this.typeEdit=='Zone'){
  192. this.locfl = id;
  193. }
  194. this.queryGlsmsasset();
  195. },
  196. //获取表格数据
  197. queryGlsmsasset(){
  198. const data = {
  199. plazaId: getUrlMsg().projectId,//广场id 必填
  200. page: this.page,//页数
  201. size: this.size,//条数
  202. }
  203. if( this.keyword){
  204. data.keyword = this.typeEdit=='Image'? `${this.keyword}:brand`:`${this.keyword}:wzjc`
  205. }
  206. const paramData = {classstructureid: this.classstructureid,gname:this.floorId};
  207. const paramDataLocal = {locfl: this.locfl,gname:this.floorId};
  208. this.loading = true;
  209. if(this.typeEdit=='Image'){
  210. queryGlsmsasset(data,paramData).then(res => {
  211. this.loading = false;
  212. if(res.data.result == 'success'){
  213. this.total = res.data.count;
  214. if(res.data.data){
  215. const data = res.data.data;
  216. data.map(item=>{
  217. item.id = item.sbjbm
  218. })
  219. this.tableData = data;
  220. }else if(res.data.count == 0){
  221. this.tableData = [];
  222. }
  223. }else{
  224. this.$message.error('数据请求失败')
  225. }
  226. })
  227. }else if(this.typeEdit=='Zone'){
  228. queryGlsmsLocation(data,paramDataLocal).then(res => {
  229. this.loading = false;
  230. if(res.data.result == 'success'){
  231. this.total = res.data.count;
  232. if(res.data.data){
  233. this.tableData = res.data.data;
  234. }else if(res.data.count == 0){
  235. this.tableData = [];
  236. }
  237. }else{
  238. this.$message.error('数据请求失败')
  239. }
  240. })
  241. }
  242. },
  243. //分页切换点击
  244. handleTableChange(page, pageSize) {
  245. this.page = page;
  246. this.queryGlsmsasset();
  247. },
  248. onSelect(record, selected, selectedRows, nativeEvent){
  249. if(!selected && this.arrList.length>0){
  250. this.arrList.map((item,index)=>{
  251. if(this.typeEdit=='Zone'&& item.location == record.location ){
  252. this.arrList.splice(index,1);
  253. }else if(this.typeEdit=='Image'&& item.assetnum == record.assetnum ){
  254. this.arrList.splice(index,1);
  255. }
  256. })
  257. }
  258. },
  259. // 中间表格勾选
  260. onSelectChange(selectedRowKeys,selectedRows) {
  261. this.selectedRowKeys = selectedRowKeys;
  262. if(this.selectedRowKeys.length>this.sysNum){
  263. this.selectedRowKeys.pop();
  264. this.$message.error('不能超过设备数')
  265. return false;
  266. }
  267. this.arrList = [...this.arrList,...selectedRows]
  268. const obj = {}
  269. if(this.typeEdit=='Zone'){
  270. this.arrList = this.arrList.reduce (function(item,next){
  271. obj[next.location] ? ' ' : obj[next.location] = true && item.push(next)
  272. return item;
  273. },[])
  274. }else{
  275. this.arrList = this.arrList.reduce (function(item,next){
  276. obj[next.assetnum] ? ' ' : obj[next.assetnum] = true && item.push(next)
  277. return item;
  278. },[])
  279. }
  280. },
  281. //右侧删除
  282. deleteItem(item,index){
  283. this.selectedRowKeys.splice(this.selectedRowKeys.indexOf(item.location||item.assetnum),1);
  284. this.arrList.splice(index,1);
  285. },
  286. //右侧清空
  287. clearArrList(){
  288. this.selectedRowKeys = [];
  289. this.arrList = [];
  290. },
  291. //获取楼层
  292. getPlazaFloor(){
  293. const data = {
  294. plazaId:getUrlMsg().projectId
  295. }
  296. getPlazaFloor(data).then(res =>{
  297. if(res.result == 'success'){
  298. const data = res.data;
  299. data.map(item=>{
  300. item.id = item.gname;
  301. })
  302. this.dataFloor = data;
  303. }
  304. })
  305. },
  306. //获取设备大类和位置大类
  307. getQuerySmsxt(){
  308. if (this.typeEdit=='Image'){
  309. getQuerySmsxt({}).then(res =>{
  310. if(res.result == 'success'){
  311. if(res.data){
  312. const data = res.data;
  313. data.map(item=>{
  314. item.id = item.code;
  315. item.name = item.name;
  316. })
  317. this.majorList = data;
  318. }
  319. }
  320. })
  321. }else if(this.typeEdit =='Zone'){
  322. queryWzfldl({}).then(res =>{
  323. if(res.result == 'success'){
  324. if(res.data){
  325. const data = res.data;
  326. data.map(item=>{
  327. item.id = item.dl;
  328. item.name = item.dl;
  329. })
  330. this.majorList = data;
  331. }
  332. }
  333. })
  334. }
  335. },
  336. // 获取设备大类下的分类和位置大类下的分类
  337. getQuerySmsxtBy(smsxt){
  338. if(this.typeEdit=='Image'){
  339. const data = {
  340. smsxt:smsxt
  341. }
  342. getQuerySmsxtBy(data,{}).then(res =>{
  343. if(res.result == 'success') {
  344. if(res.data){
  345. const data = res.data;
  346. (function recursion(newObj) {
  347. newObj.map(item=>{
  348. item.label = item.gcxxhxtname || item.classqc;
  349. item.id = item.gcxxhxtnum || item.id;
  350. item.children = item.data;
  351. if(item.children){
  352. recursion(item.children);
  353. }
  354. })
  355. })(data)
  356. this.treeData = data;
  357. }
  358. }else{
  359. this.$message.error('获取失败');
  360. }
  361. })
  362. }else if(this.typeEdit=='Zone'){
  363. const data = {
  364. dl:smsxt
  365. }
  366. queryWzflByDl(data,{}).then(res =>{
  367. if(res.result == 'success') {
  368. if(res.data){
  369. const data = res.data;
  370. (function recursion(newObj) {
  371. newObj.map(item=>{
  372. item.label = item.name;
  373. if(item.children){
  374. recursion(item.children);
  375. }
  376. })
  377. })(data)
  378. this.treeData = data;
  379. }
  380. }else{
  381. this.$message.error('获取失败');
  382. }
  383. })
  384. }
  385. }
  386. },
  387. created() {
  388. if(this.attrCards.length){
  389. this.attrCards.map(item=>{
  390. this.selectedRowKeys.push(item.location||item.assetnum)
  391. })
  392. this.arrList = JSON.parse(JSON.stringify(this.attrCards));
  393. this.selectList = JSON.parse(JSON.stringify(this.attrCards));
  394. } else{
  395. this.selectedRowKeys = [];
  396. }
  397. this.getQuerySmsxt();
  398. //如果有专业就带过来
  399. if(this.majorId){
  400. this.getQuerySmsxtBy(this.majorId)
  401. }
  402. this.getPlazaFloor();
  403. }
  404. }
  405. </script>
  406. <style scoped lang="less">
  407. .edit-dialog {
  408. .dialog-content {
  409. width: 1136px;
  410. height: 499px;
  411. background: rgba(255, 255, 255, 1);
  412. border-radius: 3px;
  413. border: 1px solid rgba(239, 240, 241, 1);
  414. display: flex;
  415. /*overflow: auto;*/
  416. .left {
  417. width: 785px;
  418. border-right: 1px solid #EFF0F1;
  419. .header {
  420. width: 785px;
  421. .select {
  422. width: 260px;
  423. border-right: 1px solid #EFF0F1;
  424. display: inline-block;
  425. }
  426. .search {
  427. width: 524px;
  428. display: inline-block;
  429. .search-select {
  430. margin-left: 10px;
  431. position: relative;
  432. top: -2px;
  433. }
  434. .press-enter {
  435. margin-left: 10px;
  436. width: 236px;
  437. }
  438. }
  439. }
  440. .tree {
  441. width: 259px;
  442. height: 441px;
  443. border-right: 1px solid #EFF0F1;
  444. display: inline-block;
  445. float: left;
  446. overflow-y: scroll;
  447. overflow:overlay;
  448. }
  449. .checkbox {
  450. /*margin-top: 17px;*/
  451. /*margin-left: 13px;*/
  452. width: 500px;
  453. height: 441px;
  454. display: inline-block;
  455. display: flex;
  456. flex-direction: column;
  457. justify-content: space-between;
  458. /deep/ .ant-table-selection-column {
  459. .ant-table-header-column{
  460. display: none;
  461. }
  462. }
  463. }
  464. }
  465. .right {
  466. flex-grow: 1;
  467. .list-box{
  468. height: 440px;
  469. overflow-y: scroll;
  470. .list {
  471. background: rgba(239, 240, 241, 1);
  472. border-radius: 2px;
  473. margin: 8px 12px;
  474. position: relative;
  475. padding: 5px;
  476. .icon {
  477. position: absolute;
  478. bottom: 5px;
  479. right: 5px;
  480. cursor: pointer;
  481. }
  482. }
  483. }
  484. .select-number {
  485. margin-left: 12px;
  486. }
  487. .link {
  488. float: right;
  489. line-height: 57px;
  490. }
  491. }
  492. .header {
  493. height: 57px;
  494. line-height: 57px;
  495. border-bottom: 1px solid #EFF0F1;
  496. }
  497. }
  498. /deep/ .ant-input-affix-wrapper .ant-input-suffix {
  499. /*left: 12px;*/
  500. /*padding-right: 12px;*/
  501. }
  502. /deep/ .ant-modal-footer {
  503. border: 0;
  504. }
  505. /deep/ .ant-checkbox-wrapper + .ant-checkbox-wrapper {
  506. margin: 0;
  507. }
  508. }
  509. </style>