淘先锋技术网

首页 1 2 3 4 5 6 7
html
 <nz-table #colSpanTable [nzData]="data" nzBordered [nzShowPagination]="false" [nzFrontPagination]="false" [nzScroll]="{ x: '1200px', y: '500px' }">
    <thead>
      <tr>
        <th nzLeft nzWidth="100px">序号</th>
        <th nzLeft nzWidth="150px">大区</th>
        <th nzWidth="150px">风场</th>
        <th nzWidth="150px">机型</th>
        <th nzWidth="150px">机位</th>
        <th nzWidth="150px">维护项</th>
        <th nzWidth="180px">耗品物料编码</th>
        <th nzWidth="180px">耗品物料描述</th>
        <th nzWidth="150px">耗品型号</th>
        <th nzWidth="150px">单车用量/</th>
        <th nzWidth="150px">单位</th>
        <th nzWidth="150px">创建人</th>
        <th nzWidth="150px">更新人</th>
        <th nzWidth="180px">更新时间</th>
        <th nzWidth="180px">创建时间</th>
        <!-- <th nzWidth="180px" *ngFor="let column of tableColumnItems">
          {{column.title}}
        </th> -->
        <th nzRight nzWidth="100px">操作</th>
      </tr>


    </thead>
    <tbody>
      <tr *ngFor="let data of colSpanTable.data; index as i">
        <td nzLeft>{{i + 1}}</td>
        <!-- <td [rowspan]="data.count" >{{data.fanModel}}</td> -->
        <!-- <td*ngFor="let column of tableColumnItems" title="{{data[column.field]}}">
          <div class="content">{{data[column.field]}}</div>
         </td> -->
         <td nzLeft [attr.rowspan]="data.wfFarmRegionNumber" *ngIf="data.wfFarmRegionNumber">{{data.wfFarmRegion}}</td>
         <td [attr.rowspan]="data.wfFarmNameNumber" *ngIf="data.wfFarmNameNumber">{{data.wfFarmName}}</td>
         <td [attr.rowspan]="data.fanModelNumber" *ngIf="data.fanModelNumber">{{data.fanModel}}</td>
         <td [attr.rowspan]="data.fanSeatStrNumber" *ngIf="data.fanSeatStrNumber">{{data.fanSeatStr}}</td>
         <td>{{data.maintenanceItem}}</td>
         <td>{{data.materialCode}}</td>
         <td>{{data.materialDescription}}</td>
         <td>{{data.materialModel}}</td>
         <td>{{data.costYear}}</td>
         <td>{{data.unit}}</td>
         <td>{{data.createUserNickName}}</td>
         <td>{{data.updateUserNickName}}</td>
         <td>{{data.updateTime | date: 'yyyy-MM-dd HH:mm:ss'}}</td>
         <td>{{data.createTime | date: 'yyyy-MM-dd HH:mm:ss'}}</td>
        <td nzRight>
          <span  nz-popconfirm
          nzPopconfirmTitle="是否确认删除?"
          nzPopconfirmPlacement="top"
          (nzOnConfirm)="del(data)" style="color: #329DFF; font-size:12px;cursor: pointer;">删除</span>
        </td>
      </tr>
    </tbody>
  </nz-table>

ts
  searchAction = (params): Observable<any> => {
    return  this.dataSrv.search({...params}).pipe(
      tap((res) => {
        if(res['data']) {
          let arr = []
           arr = this.handleSpan(res.data, 'wfFarmRegion','wfFarmRegionNumber');
           arr = this.handleSpan(res.data, 'wfFarmName','wfFarmNameNumber');
           arr = this.handleSpan(res.data, 'fanModel','fanModelNumber');
           arr = this.handleSpan(res.data, 'fanSeatStr','fanSeatStrNumber');
          this.data = arr
          console.log(res.data,'列表数据')
        }
      })
    );

  };
  // 记录文字出现的次数
  handleSpan(result,name,type) {
    result.forEach((ele) => {
    //给每行数据的count为1
      // ele[number] = 1;
      if(type == 'wfFarmRegionNumber') {
        ele.wfFarmRegionNumber = 1
      }else if(type == 'wfFarmNameNumber'){
        ele.wfFarmNameNumber = 1
      }else if ( type == 'fanModelNumber') {
        ele.fanModelNumber = 1
      }else if (type == 'fanSeatStrNumber') {
        ele.fanSeatStrNumber = 1
      }
      // arr = this.handleSpan(res.data, 'wfFarmRegion',wfFarmRegionNumber);
      // arr = this.handleSpan(res.data, 'wfFarmName',wfFarmNameNumber);
      // arr = this.handleSpan(res.data, 'fanModel',fanModelNumber);
      // arr = this.handleSpan(res.data, 'fanSeatStr',fanSeatStrNumber);
    });
    //关键==>遍历
    for (let i = 0; i < result.length; i++) {
      const element = result[i];
      for (let j = i + 1; j < result.length; j++) {
      //1、如果上一行与下一行address相等则合并(即将上一行的count+1,下一行的的count为0),count就是rowSpan的值
        if (element[name]=== result[j][name]) {
          if(type == 'wfFarmRegionNumber') {
            element.wfFarmRegionNumber++;
            result[j].wfFarmRegionNumber = 0;
          } else if(type == 'wfFarmNameNumber') {
            element.wfFarmNameNumber++;
            result[j].wfFarmNameNumber = 0;
          }else if(type == 'fanModelNumber') {
            element.fanModelNumber++;
            result[j].fanModelNumber = 0;
          }else if (type == 'fanSeatStrNumber') {
            element.fanSeatStrNumber++;
            result[j].fanSeatStrNumber = 0;
          }
          //3、这里是因为遍历到最后一条,不能跳出去,所以我们要结束所有的遍历
          if(j==result.length-1){
            return result;
          }
        } else {
        //2、如果到了不相等的一行则跳出j的遍历
        //这里减1是因为i的循环会+1,
          i = j - 1;
          break;
        }
      }
    }
    return result;
  }
  /**
   * 删除
   * @param item 
   */
  del(item) {
    this.appListPage.loading = true;
    let params = {
      wfFarmSheId: item.wfFarmSheId,
      maintenanceItemDictSheId: item.maintenanceItemDictSheId,
      mdMaterialSheId: item.mdMaterialSheId,
      fanSeatStr: item.fanSeatStr
    }
    this.dataSrv.delete(params).pipe(
      finalize(() => this.appListPage.loading = false),
    ).subscribe((res) => {
      if (res && res['success']) {
        this._message.success('删除成功~');
        this.appListPage.search();
      }
    });
  }