这是本文档旧的修订版!

import { Component, } from '@angular/core';

import { IonicPage, ViewController, ModalController, AlertController, ItemSliding, NavParams } from 'ionic-angular';

import { ZequiplocEdit } from './ZequiplocEdit/ZequiplocEdit';

import { ZEquipAL } from './ZEquipAL/ZEquipAL';

import { AITopoServer } from '../../../providers/aitopo.server';

import { GlobalFunction } from '../../GlobalFunction/GlobalFunction';

import { WindEditPage } from "../../Tfeng/equipment/windEdit";

import { gMapGlobal } from '../../map/mapClass/gMapGlobal';

import { SystemSel } from '../../../providers/system.serve';

import { EquipsServe } from '../../../providers/strata/EquipsServe';

import { ZwarnServe } from '../../../providers/strata/ZwarnServe';

import { WorkInfo } from '../../../providers/ZworkInfo.serve';


@IonicPage()

@Component({

 selector: 'gs_Zequiploc',

 templateUrl: 'Zequiploc.html',

 providers: [GlobalFunction],

})

export class Zequiploc {

 枚举值处理

 stat = ce9178;">'0', '未使用'], ['1', '使用中'], ['2', '已废弃';状态 cstatus

 showData = [];

 nrid = '';列表的下文读取

 mZsearchValue = '';搜索内容

 option = { f: '', gridid: '', nrid: '' }搜索框设置

 isBusy = false;忙碌

 mZnextMsg = '';下一页的标识内容

 sOpt = [false, true, true, true, true, true, true, true, true, true];是否显示搜索框

 sData: Array<any> = [];

 addModal: any;其他组件的调用

 areaID: string;区域id

 workID: string;工作面id

 name: string = '';区域名称

 rootData;原始数据

 father;宿主指针

 globalStyle;

 sys;

 mZwideLevel = 0;

 Ptype = '0';

 reSizeFun;

 firstRun = true;

 settings = {

   columns: {

     id: {

       title: 'ID'

     },

     name: {

       title: 'Full Name'

     },

     username: {

       title: 'User Name'

     },

     email: {

       title: 'Email'

     }

   }

 };


 constructor(

   navP: NavParams,

   system: SystemSel,

   private serve: AITopoServer,

   private modalCtrl: ModalController,

   private alertCtrl: AlertController,  用于超级用户的弹出框

   private vCtrl: ViewController,

   private gF: GlobalFunction,

   private gMapGlobal: gMapGlobal,

   private equSer: EquipsServe,

   private warn: ZwarnServe,

   workInfo: WorkInfo

 ) {

   let data = navP.get('data');

   if (!data) return;

   this.Ptype = data.p || '0';

   this.father = system.globalComp.map;

   this.father.mCdFormComp = this;

   this.areaID = workInfo.nowAreaID;

   this.workID = workInfo.nowWorkID;

   this.name = workInfo.getWorkName();

   this.mZsearchValue = data.filters;

   this.sys = data.t || 1;

   建立窗口调整功能

   this.gF.setLayerLevel([800, 600, 400, 200]);

   this.reSizeFun = () => { this.mZwideLevel = this.gF.reLayer(); }

   window.addEventListener("resize", this.reSizeFun);

   this.reSizeFun();

   this.mZwideLevel = this.gF.reLayer();

   this.fnZreload();

 }

 helpDiv = 'unshowDiv';

 showDiv() { this.helpDiv = 'showDiv'; }

 cancelDiv() { this.helpDiv = 'unshowDiv'; }


 /

  * 设置设备的过滤内容,对外接口

  * @param str 过滤值

  */

 setFilters(str) {

   str = str || '';

   this.sOpt[0] = true;

   this.mZsearchValue = str;

   this.getItems('1');

 }


 firstFilter() {

   if (this.mZsearchValue != undefined) {

     this.sOpt[0] = true;

     for (var k in this.rootData) {

       if (this.rootData.hasOwnProperty(k)) {

         let r = false;

         坐标

         if (this.sOpt[1] && this.rootData[k][25] == '') r = true;

         else if (this.sOpt[2] && this.rootData[k][25] != '') r = true;

         if (r == false) continue;

         状态

         r = false;

         if (this.sOpt[3] && this.rootData[k][16] == '0') r = true;

         else if (this.sOpt[4] && this.rootData[k][16] == '1') r = true;

         else if (this.sOpt[5] && this.rootData[k][16] == '2') r = true;

         if (r == false) continue;

         else this.sData.push(this.rootData[k]);

       }

     }

     this.getItems(undefined);


   };

   this.firstRun = false;

 }


 changePos() {

   if (this.serve.gZlockPosition) this.serve.gZlockPosition = false;

   else this.serve.gZlockPosition = true;

   this.serve.fZsaveGlobal();

 }


 读取下一页

 doInfinite(infiniteScroll?) {

   如果其他通信进行中

   if (this.isBusy == true) {

     this.serve.msgShow(1, 'high', '信息', '其他操作进行中,请稍后再试');

     if (infiniteScroll) infiniteScroll.complete();

     return;

   }

   如果已经没有内容,说明不需要再次进行读取

   if (this.option.nrid == '') {

     this.mZnextMsg = '';

     if (infiniteScroll) infiniteScroll.complete();

     return;

   }

   this.isBusy = true;

   this.mZnextMsg = '读取中';

   this.fZread().then) => {

     this.isBusy = false;

     if (infiniteScroll) infiniteScroll.complete();

   }).catch((err) => {

     this.isBusy = false;

     if (infiniteScroll) infiniteScroll.complete();

     this.mZnextMsg = err.msg;

     this.errorProcess(err);

   });

 }


 读取

 fZread() {

   return this.equSer.get(this.areaID, this.workID).then(data => {

     this.rootData = data;

     this.reLoadData();

     return Promise.resolve();

   }).catch(err => Promise.reject(err));

 }


 删除

 delete(item: string, items?) {

   if (this.isBusy == true) return this.serve.msgShow(1, 'high', '错误', '其他操作正在进行中!');

   let ids = [];

   if (items != undefined) ids = items;

   else ids.push(item);

   this.equSer.del(this.areaID, ids).then(() => {

     this.reLoadData();

     this.isBusy = false;

     this.serve.msgShow(1, 'high', '信息', '删除成功!');

     this.serve.synCdInforInServer(this.areaID, '396', 'syn');强制同步

     if (this.father.equLocAUD) return this.father.equLocAUD(this.workID, 3, item);

     return;

   }).catch(err => this.errorProcess(err));

 }


 错误处理

 errorProcess(err) {

   console.log(err);

   this.isBusy = false;

   if (err.errCode == '1002') return this.serve.msgShow(3, 'low', '错误', '超时或者账户在其他地点登陆!');

   this.serve.msgShow(3, 'high', '错误', err.msg);

 }

 仅仅高亮点击行

 forcueLine(item1) {

   if (this.globalStyle && this.delAllItem == false) this.globalStyle[-1] = '';

   if (this.delAllItem == false) this.globalStyle = item1;

   item1[-1] = 'selected';

 }


 是否处于全部删除的状态

 delAllItem = false;

 delAllName = '删除';


 delAll() {

   if (this.globalStyle) {

     this.globalStyle[-1] = '';

     this.globalStyle = undefined;

   }

   if (this.delAllItem == false) {

     this.delAllItem = true;

     this.delAllName = '确认';

   }

   else {

     let ids = [];

     this.delAllItem = false;

     this.delAllName = '删除';

     for (let i = 0; i < this.showData.length; i++) {

       const e = this.showData[i].data;

       if (e[-1] == 'selected') ids.push(e[0])

     }

     if (ids.length > 0) this.delete('', ids);

   }

 }


 /添加批量数据 */

 addSome() {

   this.addModal = this.modalCtrl.create('ZEquipAL', { areaID: this.areaID, workID: this.workID, t: this.sys, father: this.father }, { cssClass: 'Zequloc' });

   this.addModal.onDidDismiss(() => this.fnZreload(;

   this.addModal.present();

 }


 添加或者编辑

 fZaddEdit(item1: any, mZisData: boolean, slidingItem?: ItemSliding, ) {

   if (slidingItem) slidingItem.close();

   if (this.isBusy == true) return this.serve.msgShow(1, '', '信息', '其他处理正在进行中,请稍后');

   if (this.globalStyle) this.globalStyle[-1] = '';

   this.globalStyle = item1;

   this.globalStyle[-1] = 'selected';

   if (this.Ptype == '1') {

     this.addModal = this.modalCtrl.create('WindEditPage', { data: { typeName: item1[3], rid: this.areaID, hid: item1[0], gid: this.workID, father: this.father } }, { cssClass: 'Zequloc' });

     this.addModal.onDidDismiss) => this.fnZreload(;

     this.addModal.present();

     return;

   }

   this.addModal = this.modalCtrl.create('ZequiplocEdit', { father: this.father, data: item1, isData: mZisData, areaID: this.areaID, workID: this.workID, allData: this.showData }, { cssClass: 'Zequloc' });

   this.addModal.onDidDismiss(res => {

     if (!res) return;

     if (res.del == true) return this.delete(item1[0]);

     else { this.fnZreload(); }

   });

   this.addModal.present();

 }


 过滤选项

 showSearch(n) {

   let cell = ['', '无坐标信息', '有坐标信息', '未使用', '使用中', '已废弃',]

   let alertT = this.alertCtrl.create({ cssClass: 'Zequloc' });

   alertT.setTitle('过滤选项:');

   alertT.setMessage('请选择需要显示的仪表:');

   for (let i = n; i < n + 3; i++) {

     if (cell[i] == '') continue;

     alertT.addInput({

       type: 'checkbox',

       label: cell[i],

       value: i.toString(),

       checked: this.sOpt[i],

     });

   }

   alertT.addButton({

     text: '确定',

     handler: data => {

       for (let i = n; i < n + 3; i++)this.sOpt[i] = false;

       for (let i = 0; i < data.length; i++)this.sOpt[parseInt(data[i])] = true;

       this.creatFilter();

     }

   });

   alertT.present();

 }


 creatFilter() {

   this.sData.splice(0, this.sData.length);

   for (var k in this.rootData) {

     if (this.rootData.hasOwnProperty(k)) {

       let r = false;

       坐标

       if (this.sOpt[1] && this.rootData[k][25] == '') r = true;

       else if (this.sOpt[2] && this.rootData[k][25] != '') r = true;

       if (r == false) continue;

       状态

       r = false;

       if (this.sOpt[3] && this.rootData[k][16] == '0') r = true;

       else if (this.sOpt[4] && this.rootData[k][16] == '1') r = true;

       else if (this.sOpt[5] && this.rootData[k][16] == '2') r = true;

       if (r == false) continue;

       else this.sData.push(this.rootData[k]);

     }

   }

   if (this.sOpt[0]) this.getItems('1');

   else this.getItems('');

 }


 重新读取内容

 async fnZreload() {

   if (this.isBusy == true) return;

   else this.isBusy = true;

   try {

     await this.fZread();

     this.creatFilter();

     if (this.firstRun) this.firstFilter();

   } catch (error) {

     this.mZnextMsg = error.msg;

     this.errorProcess(error);

   }

   this.isBusy = false;

 }


 findNoGoem() {

   this.showData = [];

   for (let k in this.rootData) {

     let t;

     if (this.rootData[k][25].length == 0) {

       if (this.Ptype == '0') {

         if this.gMapGlobal.mFPropHash[this.rootData[k][2]].type & 2) != 0) {测点配置属性

           if (this.rootData[k][25] == '' || this.rootData[k][25] == 'null') t = false;

           else t = true;

           this.showData.push({ data: this.rootData[k], locat: t });

         }

       } else if (this.Ptype == '1') {

         if ((this.gMapGlobal.mFPropHash[this.rootData[k][2]].type & 1) != 0) {设备

           if (this.rootData[k][25] == '' || this.rootData[k][25] == 'null') t = false;

           else t = true;

           this.showData.push({ data: this.rootData[k], locat: t });

         }

       }

     }

   }

 }


 过滤

 getItems($event) {

   this.showData = [];

   let ser = this.mZsearchValue.split(' ');

   if (ser && ser.length != 0) {

     for (let i = 0; i < ser.length;) {

       const e = ser[i];

       if (e == '') ser.splice(i, 1);

       else i++

     }

   }

   for (let k = 0; k < this.sData.length; k++) {

     let needJump = false;

     for (let i = 1; i < this.sData[k].length; i++) {

       如果空,或者抖索框为空,那么全部添加

       if ($event == '' || this.mZsearchValue == undefined || this.mZsearchValue == '') {

         let t;

         if (this.Ptype == '0') {

           if ((this.gMapGlobal.mFPropHash[this.sData[k][2]].type & 2) != 0) {测点配置属性

             if (this.sData[k][25] == '' || this.sData[k][25] == 'null') t = false;

             else t = true;

             this.showData.push({ data: this.sData[k], locat: t });

           }

         } else if (this.Ptype == '1') {

           if ((this.gMapGlobal.mFPropHash[this.sData[k][2]].type & 1) != 0) {基本属性

             if (this.sData[k][25] == '' || this.sData[k][25] == 'null') t = false;

             else t = true;

             this.showData.push({ data: this.sData[k], locat: t });

           }

         }

         break;

       }

       不为空的话,进行逐个添加

       for (let j = 0; j < ser.length; j++) {

         const e = ser[j];

         if (e[0] == 't' && e[1] == '=') continue;

         let t;

          console.log('查找信息', this.sData[k][i]);


         if (this.sData[k][i].indexOf(e) < 0) continue;

         if (this.sData[k][25] == '' || this.sData[k][25] == 'null') t = false;

         else t = true;

         this.currentItems.push({ data: this.sData[k], locat: t });

         if (this.Ptype == '0') {

           if ((this.gMapGlobal.mFPropHash[this.sData[k][2]].type & 2) != 0) {测点配置属性

             if (this.sData[k][25] == '' || this.sData[k][25] == 'null') t = false;

             else t = true;

             this.showData.push({ data: this.sData[k], locat: t });

           }

         } else if (this.Ptype == '1') {

           if ((this.gMapGlobal.mFPropHash[this.sData[k][2]].type & 1) != 0) {基本设备

             if (this.sData[k][25] == '' || this.sData[k][25] == 'null') t = false;

             else t = true;

             this.showData.push({ data: this.sData[k], locat: t });

           }

         }

         needJump = true;

         break;

       }

       if (needJump == true) break;

     }

   }


   通信地址过滤

   let decs = [];

   for (let j = 0; j < ser.length; j++) {

     const e = ser[j];

     if (e[0] == 't' && e[1] == '=') { decs.push(e.replace(/t\=/g, '' }

   }

   if (decs && decs.length != 0) {

     for (let i = 0; i < decs.length; i++) decs[i] = decs[i].replace(/t\=/g, '');

     console.log('过滤', decs);

     for (let i = 0; i < this.showData.length;) {

       let needDel = true;

       const e = this.showData[i].data;

       每个过滤关键字

       for (let k = 0; k < decs.length; k++) {

         needDel = true;

         const f = decs[k];

         通信地址判断

         if (e[5].indexOf(f) < 0) continue;

         else { needDel = false; break; }

       }

       if (needDel) this.showData.splice(i, 1);

       else i++;

     }

   }

   this.equSer.equs

   this.sortData();

 }


 sortData() {

   this.showData.sorta, b) => {

     let [aNum, bNum] = [Number(a.data[16]), Number(b.data[16])];

     if (aNum != 1 && bNum == 1) return 1;

     else if (aNum == 1 && bNum != 1) return -1;

     if (a.data[2] > b.data[2]) return 1;

     else if (a.data[2] < b.data[2]) return -1;

     if (this.getNumber(a.data[15]) > this.getNumber(b.data[15] return 1;

     return -1

   });

 }



 getNumber(t: string) {

   let res: any = t.match(/[0-9]+/);

   if (res) res = res[0];

   else return t;

   return Number(res);

 }


 reLoadData() {

   this.showData = [];.splice(0, this.showData.length);

   let t;

   for (var k in this.rootData) {

     if (this.Ptype == '0') {

       if ((this.gMapGlobal.mFPropHash[this.rootData[k][2]].type & 2) != 0) {测点配置属性

         if (this.rootData[k][25] == '' || this.rootData[k][25] == 'null') t = false;

         else t = true;

         this.showData.push({ data: this.rootData[k], locat: t });

       }

     } else if (this.Ptype == '1') {

       if this.gMapGlobal.mFPropHash[this.rootData[k][2]].type & 1) != 0) {基本属性

         if (this.rootData[k][25] == '' || this.rootData[k][25] == 'null') t = false;

         else t = true;

         this.showData.push({ data: this.rootData[k], locat: t });

       }

     }

   }

   this.sortData();

   if (this.sOpt[0]) {

     this.creatFilter();

     this.getItems('1');

   }

 }

 cancel() { this.vCtrl.dismiss(); }


 locat(item) { if (this.father.equLocPosition) this.father.equLocPosition(item); }


 ngOnDestroy() {

   window.removeEventListener("resize", this.reSizeFun);

   if (this.globalStyle && this.delAllItem == false) this.globalStyle[-1] = '';

   if (this.addModal != undefined) this.addModal.dismiss();

   if (this.father) this.father.onCompDismiss(4);

 }

 将工作面设备配置默认值

 theAreaTitle = "1301胶带";

 intevalTime;

 addNum = 0;

 addCont = 1;50

 areaCont = 1;

 1 深 2 浅 3 综

 organizedData() {

   console.log("全部的值", this.showData);

   let arr = [];

   for (let i = 0; i < this.showData.length; i++) {

     arr[i] = this.showData[i];

   }

   冒泡排序

    for(let i=0;i<this.currentItems.length;i++){

      arr[i]=this.currentItems[i];

    }

      for(var a=0;a<arr.length;a++){

        for(var b=0;b<arr.length;b++){

            var c;

            var t = arr[a]["data"][18].split("‖");

            var k = arr[b]["data"][18].split("‖");

            if(t[2]<k[2]){

                c = arr[a];

                arr[a] = arr[b];

                arr[b] = c;

            }

          }

        }

   this.editAlert("轮询区域名称", [{ name: "name", type: 'text', placeholder: "区域名" },

     {name:"start",type: 'text',placeholder:"距工作面起点"},

     {name:"end",type: 'text',placeholder:"距工作面终点"}

   ],

     arr);

 }

 isbusyAdd = false;

 tianjiafangfa(resText) {

   if (this.isbusyAdd) return;

   this.isbusyAdd = true;

   console.log("添加结果", resText);


   this.equSer.update(this.areaID, resText).then((data) => {

     console.log("添加结果", data);

     this.isbusyAdd = false;

     this.addNum++;

     this.addCont++;

        this.serve.synCdInforInServer(this.areaID, '396', 'syn');强制同步

        this.viewCtrl.dismiss({ w: this.workID, g: this.form.get('geom').value, i: this.form.get('cid').value });

   })

 }

 organizedAlarmPlan() {

   console.log("全部的值", this.showData);

   let arr = [];

   for (let i = 0; i < this.showData.length; i++) {

     arr[i] = this.showData[i];

   }

   this.warn.get().then(v => {

     console.log("预案解果", v);

     let brr = [];

     for (let i = 0; i < v.length; i++) {

       brr.push({ name: "name", type: 'radio', label: v[i][1], value: v[i][0] });

     }

     brr.push({name:"type",type: 'radio',label:"深孔",value:"sk"});

     brr.push({name:"type",type: 'radio',label:"浅孔",value:"qk"});

     this.editAlert("报警预案设置", brr, arr);

   });



 }

 /

  * 仪表修改弹框

  */

 editAlert(title, content, arr) {

   console.log(title, content);

   let alert = this.alertCtrl.create({

     title: title,

     inputs: content,

     buttons: [

       { text: '取消', },

       {

         text: '确定',

         handler: data => {

           switch (title) {

             case "报警预案设置":

               this.addPlanInfo(arr, data);

               break;

             case "轮询区域名称":

               this.addAreaInfo(arr, data);

               break;

             case "按距离筛选":

               this.selectEquipment(arr, data);

               break;

             case "按深浅孔筛选":

               this.selectType(arr, data);

               break;

           }

         }

       }

     ]

   });

   alert.present();

 }

 /

  * 添加预案信息

  */

 addPlanInfo(arr, data) {

   console.log("调整后的全部的值", arr);

   this.intevalTime = setInterval(() => {

     if (!arr[this.addNum]) {

       clearInterval(this.intevalTime);

       this.serve.synCdInforInServer(this.areaID, '396', 'syn');强制同步

       return;

     }

     let brr = arr[this.addNum]["data"];

     brr[26] = "1$" + data;


     this.tianjiafangfa(brr)


   }, 500);

 }

 addAreaInfo(arr, data) {

   this.intevalTime = setInterval(() => {

     if (!arr[this.addNum]) {

       clearInterval(this.intevalTime);

       this.serve.synCdInforInServer(this.areaID, '396', 'syn');强制同步

       return;

     }

     let brr = arr[this.addNum]["data"];

     brr[14] = data["name"];

     this.tianjiafangfa(brr)


   }, 500);

 }

 /**

  * 设备的筛选

  * 目前只有按照工作面距离筛选

  */

 selectEquip() {

   let arr = [];

   for (let i = 0; i < this.showData.length; i++) {

     arr[i] = this.showData[i];

   }

   this.editAlert("按距离筛选", [{ name: "start", type: 'text', placeholder: "起始距离" }, { name: "end", type: 'text', placeholder: "结束距离" }], arr);

 }

 selectEquipment(arr, data) {

   console.log("选择条件", data);

   let b = [];

   for (let i = 0; i < arr.length; i++) {

     let a = arr[i]["data"][18].split("‖");

     console.log(a[2], a[2] >= Number(data["start"]), a[2] < Number(data["end"]), a[2]);


     if (a[2] >= Number(data["start"]) && a[2] < Number(data["end"])) {

       b.push(arr[i]);

     }

   }

   if (!data["start"] || !data["end"]) {

     b = this.showData;

   }

   this.showData = b;

   this.editAlert("按深浅孔筛选", [{ name: "type", type: 'radio', label: "深孔", value: "sk" }, { name: "type", type: 'radio', label: "浅孔", value: "qk" }], b);

 }

 selectType(arr, data) {

   console.log(data);

   let s = [];

   let q = [];

   for (let i = 0; i < arr.length; i++) {

     let b = arr[i]["data"][18].split("‖");

     if (b[0] <= 10) {浅孔

       q.push(arr[i]);

     }

     else {

       s.push(arr[i]);

     }

   }

   if (data == "sk") {

     this.showData = s;

   }

   if (data == "qk") {

     this.showData = q;

   }

 }

}