financeListCtrl.js 33.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
(function (angular) {
  function financeListCtrl(
    $scope,
    $rootScope,
    $state,
    toaster,
    routeConfig,
    DTColumnBuilder,
    DTOptionsBuilder,
    $uibModal,
    $http,
    Utils,
    financeService
  ) {
    // 1-嘀加;2-广汇;3-轩宇
    $scope.channelType = $rootScope.loginUser.channelConfig.channelType;
    // 是否为单店
    $scope.showStatic = $rootScope.loginUser.merchantUserType;

    //分页常量
    let pageSize = 10;
    $scope.previousName = "上一页";
    $scope.nextName = "下一页";
    $scope.currentPage = 1;
    $scope.maxSize = 10;
    $scope.totalItems = 0;

    // 搜索对象
    $scope.searchForm = {};

    // 列表数据
    $scope.dataList = [];
    $scope.tableStaticInfo = {};

    // 统计数据
    $scope.staticInfo = {};

    $scope.showNoCharts = false;

    // 分账方式
    $scope.payTypeList = {
      1: "微信支付",
      2: "4s店支付",
      3: "pos机支付",
      4: "支付宝",
      5: "嘀加收款",
			6: "对公转账",
			7: "其他收款"
    };

    // 分账类型
    $scope.typeList = {
      1: "线下对账",
      2: "线上分账",
    };

    // 分账规则
    $scope.shopProfitTypeList = {
      1: "毛利",
      2: "收入",
      3: "固定金额",
    };

    // 编号类型
    $scope.orderType = "1";

    // 月份
    $scope.monthList = [];
    $scope.staticTime = "";

    // 工厂常量
    $scope.showMerchant = true;
    $scope.factoryMerchantId = "";
    $scope.provinceMerchantId = "";
    $scope.cityMerchantId = "";
    $scope.shopMerchantId = "";

    // 获取参数
    function getParams() {
      let oParams = {};
      let o = JSON.parse(JSON.stringify($scope.searchForm));
      oParams.pageSize = pageSize;
      oParams.pageNum = $scope.currentPage;

      o.merchantId = $scope.factoryMerchantId;

      if ($scope.provinceMerchantId) {
        o.merchantId = $scope.provinceMerchantId;
      }

      if ($scope.cityMerchantId) {
        o.merchantId = $scope.cityMerchantId;
      }

      if ($scope.shopMerchantId) {
        o.merchantId = $scope.shopMerchantId;
      }

      delete o.fixTimeStr;

      oParams.condition = o;

      return oParams;
    }

    // 获取时间参数
    function getTimes(str) {
      let oParams = {};
      // console.log($scope.staticTime);
      let o = $scope.staticTime || str;
      let d = new Date();
      if (o) {
        let s = d.getFullYear() + "-" + (o < 10 ? "0" + o : o) + "-01 00:00:01";
        let e = d.getFullYear() + "-" + (o < 10 ? "0" + o : o) + "-31 23:59:59";
        oParams.payStartDateStr = s;
        oParams.payEndDateStr = e;
      }

      return oParams;
    }

    // 监听汇总切换月份
    $scope.changeMonth = function (e) {
      $scope.staticTime = e;
      $scope.getStatic();
    };

    // 获取财务列表
    $scope.getList = function () {
      let oParams = getParams();
      financeService.getFinanceList(oParams, function (res) {
        // res = {"returnCode":"0","message":null,"errId":null,"data":{"pageNum":1,"pageSize":10,"startRow":0,"endRow":10,"total":577,"pages":58,"list":[{"orderCode":"2107031142308953","subOrderCode":"S210703114230895300","baseThumbUrl":"http://qcimg01.glsx.net:7060/group1/M00/00/1D/wKgD3mC9guKAGPbyAAASiVKSGII236.jpg","allocationMoney":0.99,"subTotalPrice":1,"serviceCharge":0.01,"advanceUserName":null,"sellerName":null,"sellerMerchantName":"门店账号华通雷克萨斯汽车销售服务有限公司一二三四五六七八一二三四五六七八","customerType":null,"carChildsBrandName":null,"standNo":null,"customerSex":null,"customerName":null,"upgradeBrandMerchantName":"","upgradeDiscount":null,"upgradeGoodsName":"测试升级商品","upgradeSapCode":"TEST0002","goodsCost":0.1,"orderTime":"2021-07-03 11:42:30","source":1,"paySuccessDate":"2021-07-03 11:56:52","payType":3,"actualMoney":1,"actualIncomeMoney":null,"outTradeNo":"0120210703412763718905241600","shopMerchantId":44209563,"shopMerchantName":"门店-导流方02发现长寿老人腹泻便秘消化不良等肠胃问题都很少体内益生菌数量显著优于普通老人","shopProfitType":2,"shopProfitPer":10,"shopProfitMoney":0.09,"divisionType":2,"upgradeGoodsType":0,"upgradeGoodsTypeName":"测试","number":1,"upgradeRetailPrice":null,"upgradePrice":1},{"orderCode":"2107031104339637","subOrderCode":"S210703110433963700","baseThumbUrl":"http://qcimg01.glsx.net:7060/group1/M00/00/1D/wKgD3mC9guKAGPbyAAASiVKSGII236.jpg","allocationMoney":0.99,"subTotalPrice":1,"serviceCharge":0.01,"advanceUserName":null,"sellerName":null,"sellerMerchantName":"门店账号华通雷克萨斯汽车销售服务有限公司一二三四五六七八一二三四五六七八","customerType":null,"carChildsBrandName":null,"standNo":null,"customerSex":null,"customerName":null,"upgradeBrandMerchantName":"","upgradeDiscount":null,"upgradeGoodsName":"测试升级商品","upgradeSapCode":"TEST0002","goodsCost":0.1,"orderTime":"2021-07-03 11:29:40","source":1,"paySuccessDate":"2021-07-03 11:28:28","payType":3,"actualMoney":1,"actualIncomeMoney":null,"outTradeNo":"0120210703412760035249364992","shopMerchantId":44209563,"shopMerchantName":"门店-导流方02发现长寿老人腹泻便秘消化不良等肠胃问题都很少体内益生菌数量显著优于普通老人","shopProfitType":2,"shopProfitPer":10,"shopProfitMoney":0.09,"divisionType":2,"upgradeGoodsType":0,"upgradeGoodsTypeName":"测试","number":1,"upgradeRetailPrice":null,"upgradePrice":1},{"orderCode":"2107031007565270","subOrderCode":"S210703100756527000","baseThumbUrl":"http://qcimg01.glsx.net:7060/group1/M00/00/1D/wKgD3mDGtYyAWpY3AACWmwAVvyA847.jpg","allocationMoney":600,"subTotalPrice":600,"serviceCharge":0,"advanceUserName":"员工12301","sellerName":"员工12301","sellerMerchantName":"门店账号华通雷克萨斯汽车销售服务有限公司一二三四五六七八一二三四五六七八","customerType":null,"carChildsBrandName":"本田(进口)","standNo":"ABC00000000000001","customerSex":1,"customerName":"070201现场测试","upgradeBrandMerchantName":"强生/福膜","upgradeDiscount":null,"upgradeGoodsName":"升级商品-桔1","upgradeSapCode":"juzi01001","goodsCost":300,"orderTime":"2021-07-03 10:07:56","source":3,"paySuccessDate":"2021-07-03 10:08:25","payType":2,"actualMoney":2406.04,"actualIncomeMoney":null,"outTradeNo":"CCCC0000000000000000000000000","shopMerchantId":44209560,"shopMerchantName":"门店-导流方忙碌的现代生活背面不规律的作息和不健康的饮食习惯透支着当代人的身体健康越来越多的人","shopProfitType":2,"shopProfitPer":10,"shopProfitMoney":60,"divisionType":1,"upgradeGoodsType":1,"upgradeGoodsTypeName":"太阳膜","number":3,"upgradeRetailPrice":null,"upgradePrice":200},{"orderCode":"2107031007565270","subOrderCode":"S210703100756527001","baseThumbUrl":"http://qcimg01.glsx.net:7060/group1/M00/00/0A/wKgD3l_8DCWAH9wyAACIrraLVH0805.jpg","allocationMoney":1006.04,"subTotalPrice":1006.04,"serviceCharge":0,"advanceUserName":"员工12301","sellerName":"员工12301","sellerMerchantName":"门店账号华通雷克萨斯汽车销售服务有限公司一二三四五六七八一二三四五六七八","customerType":null,"carChildsBrandName":"本田(进口)","standNo":"ABC00000000000001","customerSex":1,"customerName":"070201现场测试","upgradeBrandMerchantName":"强生","upgradeDiscount":null,"upgradeGoodsName":"升级商品-猕猴桃-1","upgradeSapCode":"nihoutao01","goodsCost":200,"orderTime":"2021-07-03 10:07:56","source":3,"paySuccessDate":"2021-07-03 10:08:25","payType":2,"actualMoney":2406.04,"actualIncomeMoney":null,"outTradeNo":"CCCC0000000000000000000000000","shopMerchantId":44209560,"shopMerchantName":"门店-导流方忙碌的现代生活背面不规律的作息和不健康的饮食习惯透支着当代人的身体健康越来越多的人","shopProfitType":2,"shopProfitPer":10,"shopProfitMoney":100.6,"divisionType":1,"upgradeGoodsType":4,"upgradeGoodsTypeName":"车衣","number":1,"upgradeRetailPrice":null,"upgradePrice":1006.04},{"orderCode":"2107031007565270","subOrderCode":"S210703100756527002","baseThumbUrl":"http://qcimg01.glsx.net:7060/group1/M00/00/1D/wKgD3mDGtYyAWpY3AACWmwAVvyA847.jpg","allocationMoney":800,"subTotalPrice":800,"serviceCharge":0,"advanceUserName":"员工12301","sellerName":"员工12301","sellerMerchantName":"门店账号华通雷克萨斯汽车销售服务有限公司一二三四五六七八一二三四五六七八","customerType":null,"carChildsBrandName":"本田(进口)","standNo":"ABC00000000000001","customerSex":1,"customerName":"070201现场测试","upgradeBrandMerchantName":"强生/福膜","upgradeDiscount":null,"upgradeGoodsName":"升级商品-桔2","upgradeSapCode":"juzi01002","goodsCost":400,"orderTime":"2021-07-03 10:07:56","source":3,"paySuccessDate":"2021-07-03 10:08:25","payType":2,"actualMoney":2406.04,"actualIncomeMoney":null,"outTradeNo":"CCCC0000000000000000000000000","shopMerchantId":44209560,"shopMerchantName":"门店-导流方忙碌的现代生活背面不规律的作息和不健康的饮食习惯透支着当代人的身体健康越来越多的人","shopProfitType":2,"shopProfitPer":10,"shopProfitMoney":80,"divisionType":1,"upgradeGoodsType":7,"upgradeGoodsTypeName":"电子烟","number":2,"upgradeRetailPrice":null,"upgradePrice":400},{"orderCode":"2107011504011676","subOrderCode":"S210701150401167600","baseThumbUrl":"http://qcimg01.glsx.net:7060/group1/M00/00/1D/wKgD3mC9guKAGPbyAAASiVKSGII236.jpg","allocationMoney":0.89,"subTotalPrice":1,"serviceCharge":0.01,"advanceUserName":null,"sellerName":null,"sellerMerchantName":"HJ集团1号店","customerType":null,"carChildsBrandName":null,"standNo":null,"customerSex":null,"customerName":null,"upgradeBrandMerchantName":"","upgradeDiscount":null,"upgradeGoodsName":"测试升级商品","upgradeSapCode":"TEST0002","goodsCost":0.1,"orderTime":"2021-07-02 16:12:59","source":1,"paySuccessDate":"2021-07-02 16:19:00","payType":3,"actualMoney":1,"actualIncomeMoney":null,"outTradeNo":"0120210702412469401611411456","shopMerchantId":44209532,"shopMerchantName":"广联赛讯测试4S店","shopProfitType":1,"shopProfitPer":10,"shopProfitMoney":0.08,"divisionType":2,"upgradeGoodsType":0,"upgradeGoodsTypeName":"测试","number":1,"upgradeRetailPrice":null,"upgradePrice":1},{"orderCode":"2107021013021093","subOrderCode":"S210702101302109301","baseThumbUrl":"http://qcimg01.glsx.net:7060/group1/M00/00/0A/wKgD3l_8DCWAH9wyAACIrraLVH0805.jpg","allocationMoney":1006.04,"subTotalPrice":1006.04,"serviceCharge":0,"advanceUserName":"员工12301","sellerName":"员工12301","sellerMerchantName":"门店账号华通雷克萨斯汽车销售服务有限公司一二三四五六七八一二三四五六七八","customerType":null,"carChildsBrandName":"本田(进口)","standNo":"ABC00000000000001","customerSex":1,"customerName":"070201现场测试","upgradeBrandMerchantName":"强生","upgradeDiscount":null,"upgradeGoodsName":"升级商品-猕猴桃-1","upgradeSapCode":"nihoutao01","goodsCost":200,"orderTime":"2021-07-02 10:13:02","source":3,"paySuccessDate":"2021-07-02 11:01:14","payType":2,"actualMoney":2406.04,"actualIncomeMoney":null,"outTradeNo":"BBBBB123456789012345678901234567","shopMerchantId":44209560,"shopMerchantName":"门店-导流方忙碌的现代生活背面不规律的作息和不健康的饮食习惯透支着当代人的身体健康越来越多的人","shopProfitType":2,"shopProfitPer":10,"shopProfitMoney":100.6,"divisionType":1,"upgradeGoodsType":4,"upgradeGoodsTypeName":"车衣","number":1,"upgradeRetailPrice":null,"upgradePrice":1006.04},{"orderCode":"2107021013021093","subOrderCode":"S210702101302109302","baseThumbUrl":"http://qcimg01.glsx.net:7060/group1/M00/00/1D/wKgD3mDGtYyAWpY3AACWmwAVvyA847.jpg","allocationMoney":800,"subTotalPrice":800,"serviceCharge":0,"advanceUserName":"员工12301","sellerName":"员工12301","sellerMerchantName":"门店账号华通雷克萨斯汽车销售服务有限公司一二三四五六七八一二三四五六七八","customerType":null,"carChildsBrandName":"本田(进口)","standNo":"ABC00000000000001","customerSex":1,"customerName":"070201现场测试","upgradeBrandMerchantName":"强生/福膜","upgradeDiscount":null,"upgradeGoodsName":"升级商品-桔2","upgradeSapCode":"juzi01002","goodsCost":400,"orderTime":"2021-07-02 10:13:02","source":3,"paySuccessDate":"2021-07-02 11:01:14","payType":2,"actualMoney":2406.04,"actualIncomeMoney":null,"outTradeNo":"BBBBB123456789012345678901234567","shopMerchantId":44209560,"shopMerchantName":"门店-导流方忙碌的现代生活背面不规律的作息和不健康的饮食习惯透支着当代人的身体健康越来越多的人","shopProfitType":2,"shopProfitPer":10,"shopProfitMoney":80,"divisionType":1,"upgradeGoodsType":7,"upgradeGoodsTypeName":"电子烟","number":2,"upgradeRetailPrice":null,"upgradePrice":400},{"orderCode":"2107021013021093","subOrderCode":"S210702101302109300","baseThumbUrl":"http://qcimg01.glsx.net:7060/group1/M00/00/1D/wKgD3mDGtYyAWpY3AACWmwAVvyA847.jpg","allocationMoney":600,"subTotalPrice":600,"serviceCharge":0,"advanceUserName":"员工12301","sellerName":"员工12301","sellerMerchantName":"门店账号华通雷克萨斯汽车销售服务有限公司一二三四五六七八一二三四五六七八","customerType":null,"carChildsBrandName":"本田(进口)","standNo":"ABC00000000000001","customerSex":1,"customerName":"070201现场测试","upgradeBrandMerchantName":"强生/福膜","upgradeDiscount":null,"upgradeGoodsName":"升级商品-桔1","upgradeSapCode":"juzi01001","goodsCost":300,"orderTime":"2021-07-02 10:13:02","source":3,"paySuccessDate":"2021-07-02 11:01:14","payType":2,"actualMoney":2406.04,"actualIncomeMoney":null,"outTradeNo":"BBBBB123456789012345678901234567","shopMerchantId":44209560,"shopMerchantName":"门店-导流方忙碌的现代生活背面不规律的作息和不健康的饮食习惯透支着当代人的身体健康越来越多的人","shopProfitType":2,"shopProfitPer":10,"shopProfitMoney":60,"divisionType":1,"upgradeGoodsType":1,"upgradeGoodsTypeName":"太阳膜","number":3,"upgradeRetailPrice":null,"upgradePrice":200},{"orderCode":"2107011637336527","subOrderCode":"S210701163733652700","baseThumbUrl":"http://qcimg01.glsx.net:7060/group1/M00/00/13/wKgD3mCFOLCAeu9AAABUH7Qqcfs310.png","allocationMoney":0.97,"subTotalPrice":4,"serviceCharge":0.03,"advanceUserName":"胡庚美","sellerName":"胡庚美","sellerMerchantName":"HJ集团1号店","customerType":null,"carChildsBrandName":null,"standNo":"","customerSex":1,"customerName":"呼吸都是空气","upgradeBrandMerchantName":"","upgradeDiscount":null,"upgradeGoodsName":"测试基础商品","upgradeSapCode":"TEST0001","goodsCost":3,"orderTime":"2021-07-01 16:37:33","source":3,"paySuccessDate":"2021-07-01 16:38:35","payType":3,"actualMoney":4,"actualIncomeMoney":null,"outTradeNo":"0120210701412113281931812864","shopMerchantId":44209532,"shopMerchantName":"广联赛讯测试4S店","shopProfitType":1,"shopProfitPer":10,"shopProfitMoney":0.09,"divisionType":1,"upgradeGoodsType":0,"upgradeGoodsTypeName":"测试","number":1,"upgradeRetailPrice":null,"upgradePrice":4}],"condition":null,"needCount":true}};
        const PAYTYPEOBJ = {
          1: "微信支付",
          2: "4S店支付",
          3: "POS机收款",
          4: "支付宝支付",
          5: "嘀加收款",
					6: "对公转账",
					7: "其他收款"
        };
        const appendZero = (int) => {
          if (int < 10) {
            return "0" + `${int}`;
          } else {
            return int;
          }
        };
        const dateFormat = function (dateTime, format = "YYYY-MM-DD") {
          const date = new Date(dateTime);
          const config = {
            YYYY: date.getFullYear(),
            MM: appendZero(date.getMonth() + 1), //getMonth() 方法根据本地时间返回指定日期的月份(从 0 到 11)
            DD: appendZero(date.getDate()),
            HH: appendZero(date.getHours()),
            mm: appendZero(date.getMinutes()),
            ss: appendZero(date.getSeconds()),
          };
          for (const key in config) {
            format = format.replace(key, config[key]);
          }
          return format;
        };
        console.log("res", res);
        res.list = res && res.data ? res.data.list : [];
        console.log("res.list", res.list);
        let tableData = [];
        // const TYPELIST = ["--", "毛利", "收入", "固定"];
        const TYPELIST = {
          0: "--",
          1: "毛利",
          2: "收入",
          3: "固定",
          4: "(产值-流量成本)",
          5: "(产值-流量成本-其他费用不包含产品成本)",
          6: "(产值-流量成本-其他费用包含产品成本)",
          8: "(收入-自定义其他费用)",
          9: "(收入-其他费用)",
          10: "按固定金额*购买数量"
        };
        res.list.forEach((item) => {
          const packageOrderList = item.packageOrderList || [];
          const orderRuleObj = item.mainProfitAllocation || {};

          packageOrderList.forEach((subItem, sunIdx) => {
            const subOrderList = subItem.subOrderList || [];

            const packageName = item.packageName || ''
            subOrderList.forEach((ele, eleIdx) => {
              const {
                id,
                subOrderCode,
                subTotalPrice,
                upgradeGoodsCommodityCode,
                upgradeGoodsName,
                upgradeGoodsTypeName,
                subProfitAllocation,
                profitAllocationRule,
              } = ele;
              console.log(subItem,subItem.profitAllocationRule,profitAllocationRule)
              const setMealRuleObj =  subItem.profitAllocationRule||{}
              console.log(setMealRuleObj,'setMealRuleObj')
              let {
                shopTrafficMoneyCalculateType,
                shopTrafficMoneyCalculateValue,
                purchaseNum
              } =profitAllocationRule||{}
              //   ? subItem.profitAllocationRule
              //   : profitAllocationRule || {};
              // console.log(shopTrafficMoneyCalculateType,shopTrafficMoneyCalculateValue)

              const { goodsCost, virtualAccountCost, actualIncomeMoney } =
                subProfitAllocation || {};
              let ruleType = TYPELIST[shopTrafficMoneyCalculateType] || "--";
              let setMealRuleType =
                TYPELIST[setMealRuleObj.shopTrafficMoneyCalculateType|| ''] || "--";
              let orderRuleType =
                TYPELIST[orderRuleObj.shopTrafficMoneyCalculateType] || "--";
              console.log(setMealRuleType != "--" && eleIdx == 0 ,setMealRuleType,'setMealRuleType')
              const _obj = {
                ...item,
                ...ele,
                rowspan: 1,
                setMealRowspan: setMealRuleType == "--"?1:  eleIdx == 0 ? subOrderList.length : 0,
                // setMealRowspan: setMealRuleType != "--" && sunIdx == 0 ? subOrderList.length : 1,
                id,
                subOrderCode,
                subTotalPrice,
                packageName,
                upgradeGoodsCommodityCode,
                upgradeGoodsName,
                upgradeGoodsTypeName,
                actualIncomeMoney,
                realityShopMerchantName: orderRuleObj.shopMerchantName,
                shopTrafficMoney: orderRuleObj.shopTrafficMoney,
                goodsCost: virtualAccountCost || goodsCost,
                rule: `${ruleType}${
                  !shopTrafficMoneyCalculateType
                    ? ""
                    : shopTrafficMoneyCalculateValue
                }${
                  !shopTrafficMoneyCalculateType
                    ? ""
                    : shopTrafficMoneyCalculateType == 3
                    ? "元"
                    : "%"
                }`,
                orderRule: `${orderRuleType}${
                  !orderRuleObj.shopTrafficMoneyCalculateType
                    ? ""
                    : orderRuleObj.shopTrafficMoneyCalculateValue
                }${
                  !orderRuleObj.shopTrafficMoneyCalculateType
                    ? ""
                    : orderRuleObj.shopTrafficMoneyCalculateType == 3
                    ? "元"
                    : "%"
                }`,
                setMealRule: `${setMealRuleType}${
                  !setMealRuleObj.shopTrafficMoneyCalculateType
                    ? ""
                    : setMealRuleObj.shopTrafficMoneyCalculateValue
                }${
                  !setMealRuleObj.shopTrafficMoneyCalculateType
                    ? ""
                    : setMealRuleObj.shopTrafficMoneyCalculateType == 3
                    ? "元"
                    : "%"
                }`,
                divisionTypeName:
                  item.divisionType == 1 ? "线下对账" : "线上分账",
                payTypeName: PAYTYPEOBJ[item.payType],
                paySuccessDate: dateFormat(
                  item.paySuccessDate,
                  "YYYY-MM-DD HH:mm:ss"
                ),
              };
              // 按固定金额*购买数量特殊处理
              if (shopTrafficMoneyCalculateType == 10) {
                _obj.rule = `按固定金额${shopTrafficMoneyCalculateValue}元*${purchaseNum || ''}`
              }
              if (orderRuleObj.shopTrafficMoneyCalculateType == 10) {
                _obj.orderRule = `按固定金额${orderRuleObj.shopTrafficMoneyCalculateValue}元*${orderRuleObj.purchaseNum || ''}`
              }
              if (setMealRuleObj.shopTrafficMoneyCalculateType == 10) {
                _obj.setMealRule = `按固定金额${setMealRuleObj.shopTrafficMoneyCalculateValue}元*${setMealRuleObj.purchaseNum || ''}`
              }
              tableData.push(_obj);
            });
          });
        });
        let codeList = tableData.map((item) => item.orderCode);
        // this.tableData
        let obj = res.data || {};
        // let list = obj.list || [];
        $scope.dataList = tableData.map((item, index) => {
          const rowspan =
            codeList?.filter((ele) => ele == item.orderCode)?.length || 1;
          item.rowspan =
            codeList.indexOf(item.orderCode) == index
              ? rowspan
              : rowspan > 1
              ? 0
              : 1;
          return item;
        });
        console.log($scope.dataList, "$scope.dataList");
        $scope.totalItems = obj.total;
        // console.log(list);
        if (obj.total) {
          $scope.totalPage =
            obj.total / pageSize < 1 ? 1 : Math.ceil(obj.total / pageSize);
        }
      });
    };

    //显示时间
    $scope.showTime = function (row) {
      let o = "";
      if (!row.goodsOrder) {
        return o;
      }
      if (!row.goodsOrder.payOrder) {
        return o;
      }
      o = row.goodsOrder.payOrder.successDate;
      return o;
    };

    // 查看明细
    $scope.lookDetail = function (row) {
      $uibModal.open({
        templateUrl: "biz/finance/view/detail.html",
        controller: "detailCtrl",
        size: "lg",
        resolve: {
          parentData: function () {
            return {
              // type: 'readonly',
              // id: id,
              // activityStatus: activityStatus,
              // activityStatusEdit: activityStatusEdit,
              data: row,
            };
          },
        },
      });
    };

    //
    function inserAt(str, sub, index) {
      return str.substr(0, index) + sub + str.substr(index);
    }

    // 获取统计数据
    $scope.getStatic = function () {
      let oParams = getTimes();
      financeService.getFinanceStatic(oParams, function (res) {
        let obj = res.data || {};
        let list = obj.countList || [];
        //let list = [{"nums":44,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":810613.53,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44187815,"shopMerchantName":"门店账号华通雷克萨斯汽车销售服务有限公司一二三四五六七八一二三四五六七八","subNums":58},{"nums":226,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":39763.47,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44187812,"shopMerchantName":"工厂账号","subNums":357},{"nums":5,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":12918.42,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44187651,"shopMerchantName":"最新华南片区名称","subNums":11},{"nums":16,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":6519.26,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44209410,"shopMerchantName":"fenrun02","subNums":19},{"nums":7,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":3354.00,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44209416,"shopMerchantName":"chenxiaokaitest","subNums":7},{"nums":6,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":1374.05,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44209247,"shopMerchantName":"testMD","subNums":7},{"nums":11,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":1182.00,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44209390,"shopMerchantName":"明明塘朗4s店A","subNums":12},{"nums":11,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":807.00,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44209391,"shopMerchantName":"明明塘朗4s店B","subNums":11},{"nums":1,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":298.20,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44209408,"shopMerchantName":"fenrun01","subNums":1},{"nums":6,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":160.00,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44209543,"shopMerchantName":"乔的嘀加渠道门店","subNums":6},{"nums":12,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":47.87,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44209481,"shopMerchantName":"测试4S店","subNums":14},{"nums":11,"totalPrice":null,"totalYqGrossProfit":null,"totalShopGrossProfit":null,"totalShopProfitMoney":37.68,"totalYqProfitMoney":null,"totalFranchiseeProfitMoney":null,"totalGlProfitMoney":null,"yqMerchantId":null,"yqMerchantName":null,"shopMerchantId":44209510,"shopMerchantName":"test4s1","subNums":18}];
        if (!list || list.length <= 0) {
          $scope.showNoCharts = true;
        } else {
          $scope.showNoCharts = false;
        }
        obj.shopName = list[0] ? list[0].shopMerchantName : "";
        $scope.staticInfo = obj;
        let nList = [];
        if (list) {
          nList = list.splice(0, 10);
        }

        if ($scope.showStatic != 2) {
          initEcharts(nList);
        }

        //drawLine(nList);
      });
    };

    // 获取本年度所有的月份,截止到当前月
    let getMonth = function () {
      let o = new Date();
      let y = o.getFullYear();
      let m = o.getMonth() + 1;
      let arr = [];
      for (var i = m; i >= 1; i--) {
        let k = {
          name: y + "年" + i + "月",
          id: i.toString(),
        };
        arr.push(k);
      }
      $scope.monthList = arr;
      //$scope.staticTime = arr[0].id;
    };

    // 导出excel
    $scope.downExcel = function () {
      let params = getParams();
      let oParams = params.condition;
      oParams.sdctag = true

      //Utils.exportExcel2(
      //  "orderProfitAllocation/exportGoodsOrderProfitAllocationPage",
      // oParams,
      //  "财务列表"
      //);

      financeService.exportProfitAllocationList(oParams, function (res) {
        var data = JSON.parse(res.data);
        aToExport(data.data);
      });
    };

    function aToExport(url) {
      var a = document.createElement("a");
      a.setAttribute("id", "exportToExport");
      a.setAttribute("href", url);
      a.setAttribute("target", "_blank");
      document.body.appendChild(a);
      a.click();
    }
    // 导出excel统计报表
    $scope.downStaticExcel = function () {
      let params = getTimes();
      console.log($scope.staticTime);
      Utils.exportExcel2(
        "orderProfitAllocation/exportCount",
        params,
        "财务统计列表"
      );
    };

    // 重置
    $scope.rest = function () {
      $scope.searchForm = {};
      $scope.factoryMerchantId = "";
      $scope.provinceMerchantId = "";
      $scope.cityMerchantId = "";
      $scope.shopMerchantId = "";

      $scope.$broadcast("reset");
      //$scope.getList();
      $scope.onSearch();
    };

    // 查看门店详情
    $scope.lookStoreList = function () {
      let o = $scope.staticTime;
      $uibModal.open({
        templateUrl: "biz/finance/view/storeList.html",
        controller: "storeListCtrl",
        size: "lg",
        resolve: {
          parentData: function () {
            return {
              // type: 'readonly',
              // id: id,
              // activityStatus: activityStatus,
              // activityStatusEdit: activityStatusEdit,
              data: { time: o },
            };
          },
        },
      });
    };

    // 日期选择处理
    $scope.dateOptions = {
      opens: "right",
      eventHandlers: {
        "apply.daterangepicker": function (ev, picker) {
          $scope.searchForm.payStartDateStr = picker.startDate.format(
            "YYYY-MM-DD HH:mm:ss"
          );
          $scope.searchForm.payEndDateStr = picker.endDate.format(
            "YYYY-MM-DD HH:mm:ss"
          );
          $scope.searchForm.fixTimeStr = {
            startDate: picker.startDate.format("YYYY-MM-DD") + " 00:00:00",
            endDate: picker.endDate.format("YYYY-MM-DD") + " 23:59:59",
          };
          $scope.$apply();
        },
        "cancel.daterangepicker": function (ev, picker) {
          $scope.searchForm.payStartDateStr = "";
          $scope.searchForm.payEndDateStr = "";
          $scope.searchForm.fixTimeStr = {};
          $scope.$apply();
        },
      },
    };

    // 搜索
    $scope.onSearch = function () {
      $scope.getList();
      $scope.getTableStatic();
    };

    // 初始化图表
    var initEcharts = function (data) {
      var chartDom = document.getElementById("lossOfClues");
      var myChart = echarts.init(chartDom);
      let arr = [];
      let nums = [];

      if (!data && data.length <= 0) {
        return false;
      }

      data.map((k) => {
        arr.unshift(k.shopMerchantName);
        nums.unshift(k.totalShopProfitMoney);
      });

      var option = {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
          formatter(params) {
            console.log(params);
            let o = params[0];
            return o.axisValue + "</br>" + o.marker + o.data + "元";
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "value",
          boundaryGap: [0, 0.01],
        },
        yAxis: {
          type: "category",
          axisLabel: {
            formatter: function (value) {
              if (value.length > 8) {
                return value.substring(0, 8) + "...";
              } else {
                return value;
              }
            },
          },
          data: arr,
        },
        series: [
          {
            type: "bar",
            data: nums,
          },
        ],
      };
      myChart.setOption(option);
    };

    // 监听编号变化
    $scope.onChange = function (e) {
      if ($scope.orderType == 1) {
        delete $scope.searchForm.tradeNo;
      } else {
        delete $scope.searchForm.orderCode;
      }
    };

    // 获取列表顶部统计数据
    $scope.getTableStatic = function (time) {
      let m = getTimes(time);
      let o = JSON.parse(JSON.stringify($scope.searchForm));
      let oParams = {};

      o.merchantId = $scope.factoryMerchantId;

      if ($scope.provinceMerchantId) {
        o.merchantId = $scope.provinceMerchantId;
      }

      if ($scope.cityMerchantId) {
        o.merchantId = $scope.cityMerchantId;
      }

      if ($scope.shopMerchantId) {
        o.merchantId = $scope.shopMerchantId;
      }

      delete o.fixTimeStr;
      delete oParams.pageSize;
      delete oParams.pageNum;

      Object.assign(oParams, m, o);
      financeService.getFinanceStatic(oParams, function (res) {
        let obj = res.data || {};
        let list = obj.countList || [];
        $scope.tableStaticInfo = obj;
      });
    };

    // 展示冠军店名称
    $scope.getShopName = function (row) {
      if (!row) {
        return "";
      }
      if (!row.shopName) {
        return "";
      }
      if (row.shopName.length > 7) {
        return row.shopName.substring(0, 7) + "...";
      } else {
        return row.shopName;
      }
    };

    // 初始化函数
    $scope.init = function () {
      $scope.getList();
      // 单店不显示统计
      $scope.getStatic();
      $scope.getTableStatic();
      getMonth();
    };

    $scope.init();
  }

  angular.module("finance").controller("financeListCtrl", financeListCtrl);
})(angular);