對象數組中根據某個屬性名的值相同,求某一項的和。


      this.initagdata = [{
        UnitId: "001001",
        UnitName: "修水縣第一人民醫院",
        TeamchkOperatorId: null,
        TeamchkOperator: null,
        FdchkOperatorId: null,
        FdchkOperator: null,
        TeamchkDt: "0001-01-01T00:00:00",
        FdchkDt: "0001-01-01T00:00:00",
        Operator: "000000-32767",
        OperatorName: "超級管理員",
        Summary: null,
        DaylyId: null,
        Checked: 0,
        DaylyTime: "2019-07-16T11:16:27",
        Qrt: 1,
        MinAccountTime: "2019-07-16T11:16:12",
        MaxAccountTime: "2019-07-16T11:16:12",
        CashPay: 45.0
      }, {
        UnitId: "001001",
        UnitName: "修水縣第一人民醫院",
        TeamchkOperatorId: null,
        TeamchkOperator: null,
        FdchkOperatorId: null,
        FdchkOperator: null,
        TeamchkDt: "0001-01-01T00:00:00",
        FdchkDt: "0001-01-01T00:00:00",
        Operator: "000000-32767",
        OperatorName: "超級管理員",
        Summary: null,
        DaylyId: null,
        Checked: 0,
        DaylyTime: "2019-07-16T09:47:20",
        Qrt: 1,
        MinAccountTime: "2019-07-16T09:47:08",
        MaxAccountTime: "2019-07-16T09:47:08",
        CashPay: 54.0
      }, {
        UnitId: "001001",
        UnitName: "修水縣第一人民醫院",
        TeamchkOperatorId: null,
        TeamchkOperator: null,
        FdchkOperatorId: null,
        FdchkOperator: null,
        TeamchkDt: "0001-01-01T00:00:00",
        FdchkDt: "0001-01-01T00:00:00",
        Operator: "000000-32767",
        OperatorName: "超級管理員",
        Summary: null,
        DaylyId: null,
        Checked: 0,
        DaylyTime: "2019-07-16T09:37:33",
        Qrt: 1,
        MinAccountTime: "2019-07-16T09:37:19",
        MaxAccountTime: "2019-07-16T09:37:19",
        CashPay: 92.0
      }, {
        UnitId: "001001",
        UnitName: "修水縣第一人民醫院",
        TeamchkOperatorId: null,
        TeamchkOperator: null,
        FdchkOperatorId: null,
        FdchkOperator: null,
        TeamchkDt: "0001-01-01T00:00:00",
        FdchkDt: "0001-01-01T00:00:00",
        Operator: "000000-32767",
        OperatorName: "超級管理員",
        Summary: null,
        DaylyId: null,
        Checked: 0,
        DaylyTime: "2019-07-16T09:45:41",
        Qrt: 1,
        MinAccountTime: "2016-07-16T09:45:27",
        MaxAccountTime: "2019-11-16T09:45:27",
        CashPay: 45.0
      }, {
        UnitId: "001001",
        UnitName: "修水縣第一人民醫院",
        TeamchkOperatorId: null,
        TeamchkOperator: null,
        FdchkOperatorId: null,
        FdchkOperator: null,
        TeamchkDt: "0001-01-01T00:00:00",
        FdchkDt: "0001-01-01T00:00:00",
        Operator: "000000-32767",
        OperatorName: "超級管理員",
        Summary: null,
        DaylyId: null,
        Checked: 0,
        DaylyTime: "2019-07-16T11:11:49",
        Qrt: 1,
        MinAccountTime: "2019-07-16T11:09:23",
        MaxAccountTime: "2019-07-16T11:09:23",
        CashPay: 46.0
      }, {
        UnitId: "001001",
        UnitName: "修水縣第一人民醫院",
        TeamchkOperatorId: null,
        TeamchkOperator: null,
        FdchkOperatorId: null,
        FdchkOperator: null,
        TeamchkDt: "0001-01-01T00:00:00",
        FdchkDt: "0001-01-01T00:00:00",
        Operator: "001001-8003",
        OperatorName: "程博平",
        Summary: null,
        DaylyId: null,
        Checked: 0,
        DaylyTime: "2019-07-16T11:55:40",
        Qrt: 1,
        MinAccountTime: "2019-07-16T11:55:26",
        MaxAccountTime: "2019-07-16T11:55:26",
        CashPay: 45.0
      }, {
        UnitId: "001001",
        UnitName: "修水縣第一人民醫院",
        TeamchkOperatorId: null,
        TeamchkOperator: null,
        FdchkOperatorId: null,
        FdchkOperator: null,
        TeamchkDt: "0001-01-01T00:00:00",
        FdchkDt: "0001-01-01T00:00:00",
        Operator: "001001-8002",
        OperatorName: "崔勇",
        Summary: null,
        DaylyId: null,
        Checked: 0,
        DaylyTime: "2019-07-16T11:02:04",
        Qrt: 1,
        MinAccountTime: "2019-07-16T10:37:40",
        MaxAccountTime: "2019-07-16T10:38:26",
        CashPay: 92.0
      }, {
        UnitId: "001001",
        UnitName: "修水縣第一人民醫院",
        TeamchkOperatorId: null,
        TeamchkOperator: null,
        FdchkOperatorId: null,
        FdchkOperator: null,
        TeamchkDt: "0001-01-01T00:00:00",
        FdchkDt: "0001-01-01T00:00:00",
        Operator: "001001-8002",
        OperatorName: "崔勇",
        Summary: null,
        DaylyId: null,
        Checked: 0,
        DaylyTime: "2019-07-16T11:38:26",
        Qrt: 1,
        MinAccountTime: "2019-07-16T11:33:49",
        MaxAccountTime: "2019-07-16T11:33:49",
        CashPay: 45.0
      }, {
        UnitId: "001001",
        UnitName: "修水縣第一人民醫院",
        TeamchkOperatorId: null,
        TeamchkOperator: null,
        FdchkOperatorId: null,
        FdchkOperator: null,
        TeamchkDt: "0001-01-01T00:00:00",
        FdchkDt: "0001-01-01T00:00:00",
        Operator: "001001-8001",
        OperatorName: "徐文龍",
        Summary: null,
        DaylyId: null,
        Checked: 0,
        DaylyTime: "2019-07-10T17:17:31",
        Qrt: 1,
        MinAccountTime: "2019-07-10T16:49:37",
        MaxAccountTime: "2019-07-10T17:16:07",
        CashPay: 95.0
      }, {
        UnitId: "001001",
        UnitName: "修水縣第一人民醫院",
        TeamchkOperatorId: null,
        TeamchkOperator: null,
        FdchkOperatorId: null,
        FdchkOperator: null,
        TeamchkDt: "0001-01-01T00:00:00",
        FdchkDt: "0001-01-01T00:00:00",
        Operator: "001001-8001",
        OperatorName: "徐文龍",
        Summary: null,
        DaylyId: null,
        Checked: 0,
        DaylyTime: "2019-07-16T09:28:51",
        Qrt: 1,
        MinAccountTime: "2019-07-16T09:25:37",
        MaxAccountTime: "2019-07-16T09:25:37",
        CashPay: 9.0
      }]
      var temp = {};
      for (var i in this.initagdata) {
        var key = this.initagdata[i].Operator;
        if (temp[key]) {
          temp[key].CashPay += Number(this.initagdata[i].CashPay);
          temp[key].Operator = this.initagdata[i].Operator;
          temp[key].UnitId = this.initagdata[i].UnitId;
          temp[key].UnitName = this.initagdata[i].UnitName;
          // temp[key].TeamchkOperatorId = this.initagdata[i].TeamchkOperatorId; //班組核銷人id
          // temp[key].TeamchkOperator = this.initagdata[i].TeamchkOperator;   //班組核銷人
          // temp[key].FdchkOperatorId = this.initagdata[i].FdchkOperatorId; //財務核銷人id
          // temp[key].FdchkOperator = this.initagdata[i].FdchkOperator;  //財務核銷人
          // temp[key].TeamchkDt = this.initagdata[i].TeamchkDt; //班組核銷時間
          // temp[key].FdchkDt = this.initagdata[i].FdchkDt; //財務核銷時間
          temp[key].OperatorName = this.initagdata[i].OperatorName; //收費員姓名
          // temp[key].Summary = this.initagdata[i].Summary;  //摘要
          // temp[key].DaylyId = this.initagdata[i].DaylyId;  //日報號
          temp[key].Checked = this.initagdata[i].Checked;  //選擇
          // temp[key].DaylyTime = this.initagdata[i].DaylyTime; //日報時間
          temp[key].Qrt += Number(this.initagdata[i].Qrt);  //日報筆數
          temp[key].MinAccountTime = new Date(temp[key].MinAccountTime).getTime() < new Date(this.initagdata[i].MinAccountTime).getTime() ? temp[key].MinAccountTime : this.initagdata[i].MinAccountTime; //第一筆業務時間

          temp[key].MaxAccountTime = new Date(temp[key].MaxAccountTime).getTime() > new Date(this.initagdata[i].MaxAccountTime).getTime() ? temp[key].MaxAccountTime : this.initagdata[i].MaxAccountTime; //最后一筆業務時間

        } else {
          temp[key] = {};
          temp[key].CashPay = Number(this.initagdata[i].CashPay);
          temp[key].Operator = this.initagdata[i].Operator;
          temp[key].UnitId = this.initagdata[i].UnitId;
          temp[key].UnitName = this.initagdata[i].UnitName;
          // temp[key].TeamchkOperatorId = this.initagdata[i].TeamchkOperatorId;
          // temp[key].TeamchkOperator = this.initagdata[i].TeamchkOperator;
          // temp[key].FdchkOperatorId = this.initagdata[i].FdchkOperatorId;
          // temp[key].FdchkOperator = this.initagdata[i].FdchkOperator;
          // temp[key].TeamchkDt = this.initagdata[i].TeamchkDt;
          // temp[key].FdchkDt = this.initagdata[i].FdchkDt;
          temp[key].OperatorName = this.initagdata[i].OperatorName;
          // temp[key].Summary = this.initagdata[i].Summary;
          // temp[key].DaylyId = this.initagdata[i].DaylyId;
          temp[key].Checked = this.initagdata[i].Checked;
          // temp[key].DaylyTime = this.initagdata[i].DaylyTime;
          temp[key].Qrt = Number(this.initagdata[i].Qrt);
          temp[key].MinAccountTime = this.initagdata[i].MinAccountTime;
          temp[key].MaxAccountTime = this.initagdata[i].MaxAccountTime;
        }
      }

      var newArry = [];
      for (var k in temp) {
        newArry.push(temp[k])
      }
      console.log(newArry)

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM