shopRemind.js 17.2 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
(function (angular) {
  function shopRemind ($scope, $rootScope, localStorageService, aiNicheService, $uibModal, DTOptionsBuilder, DTColumnBuilder, $compile, Utils, toaster) {
    // 跳转 活动列表 保养线索 流失线索 拦截
    $scope.activityFlag = false
    $scope.jumpLink = function (name, target) {
      checkPermission(name, $scope.menuList, target)
      if ($scope[target]) {
        // 跳往一件营销
        $scope.jumpActivity()
      } else {
        toaster.pop({
          type: 'error',
          body: '您暂未开通该服务,请联系客服处理',
          showCloseButton: true,
          timeout: 3000
        })
      }
    }
    function checkPermission (pageTitle, data, name) {
      angular.forEach(data, function (e) {
        if (e.children) {
          checkPermission(pageTitle, e.children, name)
        } else {
          if (e.pageTitle == pageTitle) {
            $scope[name] = true
          }
        }
      })
    }
    // 图表
    $scope.chartActive = 1
    $scope.chartCbk = function (chartActive) {
      $scope.chartActive = chartActive
      if (chartActive == 1) {
        console.log(1212);
        if (chart7) chart7.destroy()
      } else if (chartActive == 2) {
        if (chart6) chart6.destroy()
      }
    }
    var chart6
    var chart7
    $scope.data6 = []
    $scope.data7 = []
    $scope.bgColor = [{}, {}, {}, {}, {}, {}]
    var rankColor = ['#01C292', '#3090FF', '#00B0FF', '#12DCAA', '#FFAB00', '#FFD600']
    $scope.$watch('chartActive', function () {
      if ($scope.chartActive == 1) {
        $scope.loss.lossSelect = ''
        // 到店线索,忠诚客户分析
        aiNicheService.getClassifyYearBackCount(function (res) {
          var total = '- -'
          if (res.returnCode == '0') {
            $scope.data6 = res.data
            total = res.data[0].total
          } else {
            $scope.data6 = [{
              number: 0,
              total: '- -',
              name: 0
            }]
          }
          var chart6 = new G2.Chart({
            container: 'loyalCustomer',
            forceFit: true,
            height: 200,
            padding: [30],
            options: {
              legends: false
            }
          })
          // var total = res.data.length == 0 ? 0 : res.data[0].total
          drawChart($scope.data6, chart6, '总人数', total)
        })
      } else if ($scope.chartActive == 2) {
        console.log('我切换了')
        $scope.loss.lossSelect = '1'
      }
    })

    $scope.loss = {}
    $scope.$watch('loss.lossSelect', function (newVal, oldVal) {
      console.log(2222, newVal, oldVal)
      if (newVal != '' && oldVal != '') {
        if (chart7) chart7.destroy()
      }
      if ($scope.loss.lossSelect == '1') {
        console.log($scope.loss.lossSelect)
        getCountClassifyDistance()
      } else if ($scope.loss.lossSelect == '2') {
        getNoCountTotalMileageClassify()
      }
    }, true)
    function getCountClassifyDistance () {
      $scope.data7 = []
      // 未返厂客户分析
      aiNicheService.getCountClassifyDistance(function (res) {
        var total = '- -'
        if (res.returnCode == '0') {
          $scope.data7 = res.data
          total = res.data[0].total
        }
        drawShop(res.data, total)
      })
    }
    function getNoCountTotalMileageClassify () {
      $scope.data7 = []
      var total = '- -'
      aiNicheService.getNoCountTotalMileageClassify(function (res) {
        if (res.returnCode == '0') {
          $scope.data7 = res.data
          total = res.data[0].total
        }
        drawShop(res.data, total)
      })
    }
    function drawShop (data, total) {
      if ($scope.data7.length == 0) {
        $scope.data7 = [{
          number: 0,
          total: '- -',
          name: 0
        }]
      }
      chart7 = new G2.Chart({
        container: document.getElementById('notReturned'),
        forceFit: true,
        height: 200,
        padding: [30],
        options: {
          legends: false
        }
      })
      // var total = data.length == 0 ? $scope.data7[0].total : data[0].total
      drawChart($scope.data7, chart7, '总人数', total)
    }

    var sliceNumber = 0.005
    // 自定义 other 的图形,增加两条线
    G2.Shape.registerShape('interval', 'sliceShape', {
      draw: function draw (cfg, container) {
        var points = cfg.points
        var path = []
        path.push(['M', points[0].x, points[0].y])
        path.push(['L', points[1].x, points[1].y - sliceNumber])
        path.push(['L', points[2].x, points[2].y - sliceNumber])
        path.push(['L', points[3].x, points[3].y])
        path.push('Z')
        path = this.parsePath(path)
        return container.addShape('path', {
          attrs: {
            fill: cfg.color,
            path: path
          }
        })
      }
    })
    function drawChart (data, chart, totalName, total) {
      var bgColor = ['#3090FF', '#00B0FF', '#58CA79', '#14DCAA', '#FFAB00', '#FFD600']
      angular.forEach(data, function (item, index) {
        $scope.bgColor[index]['background-color'] = rankColor[index]
      })
      if (total == 0 || total == '- -') {
        var info = [{
          number: 1,
          name: 1
        }]
        chart.source(info)
        bgColor = ['#CFD3D5']
        chart.tooltip(false)
      } else {
        chart.source(data)
        chart.tooltip({
          showTitle: false
        })
      }
      chart.coord('theta', {
        innerRadius: 0.75
      })
      chart.guide().html({
        position: ['50%', '50%'],
        html: `<div class="g2-guide-html"><div class="value">${total}</div><div class="title">${totalName}</div></div>`
      })
      chart.intervalStack().position('number').color('name', bgColor).shape('sliceShape')
      chart.render()
    }
    $scope.warnInfoBox = false
    var curMerchantId = $rootScope.loginUser.merchantId
    var checkFlag = localStorageService.get('address.check' + curMerchantId)
    if ('Y' != checkFlag) {
      aiNicheService.getAddressCheck(function (response) {
        if (response.returnCode == 0) {
          if (response.data) {
            $scope.warnInfoBox = false
            localStorageService.set('address.check' + curMerchantId, 'Y')
          } else {
            $scope.warnInfoBox = true
          }
        } else {
          $scope.warnInfoBox = true
        }
      })
    }

    $scope.hasAddress = true
    $scope.mid = null
    aiNicheService.getUserMerchant(function (response) {
      if (response.returnCode == 0) {
        $scope.mid = response.data.detail.id
        if (response.data.address == null || response.data.address == '') {
          $scope.hasAddress = false
        }
      }
    })

    $scope.merchant = {
      lat: '',
      lng: '',
      cityName: '',
      provinceName: '',
      areaName: '',
      address: ''
    }

    var showMinutes = (function () {
      return function (e, dt, node, config) {
        var results = null
        if (node.minutes < 0) {
          results = 0
        }else {
          results = node.minutes
        }
        return results
      }
    })()

    var showDays = (function () {
      return function (e, dt, node, config) {
        var results = null
        if (node.bindingDays < 0) {
          results = 0
        }else {
          results = node.bindingDays
        }
        return results
      }
    })()

    $scope.dtColumns = [
      DTColumnBuilder.newColumn('enterTimeStr').withOption('width', 120).withTitle('到店时间'),
      DTColumnBuilder.newColumn('standNo').withOption('width', 100).withTitle('车架号'),
      // DTColumnBuilder.newColumn('lastTimeDistance').withOption('width',120).withTitle('距上次到店已行驶(KM)').renderWith(showDistance),
      // DTColumnBuilder.newColumn('lastTimeDay').withOption('width',70).withTitle('距上次到店时间间隔(天)').renderWith(showDay),
      DTColumnBuilder.newColumn('minutes').withOption('width', 70).withTitle('停留时长(min)').renderWith(showMinutes),
      DTColumnBuilder.newColumn('numberOfShops').withOption('width', 70).withTitle('到店次数'),
      DTColumnBuilder.newColumn('name').withOption('width', 80).withTitle('客户姓名'),
      DTColumnBuilder.newColumn('mobile').withOption('width', 90).withTitle('手机'),
      DTColumnBuilder.newColumn('bindingTimeStr').withOption('width', 120).withTitle('绑定客户时间'),
      DTColumnBuilder.newColumn('bindingDays').withOption('width', 90).withTitle('绑定客户时长(天)').renderWith(showDays),
      DTColumnBuilder.newColumn('merchantName').withOption('width', 120).withTitle('店面名称'),
      DTColumnBuilder.newColumn(null).withTitle(function () {
        return '操作'
      }).withOption('width', 220).withClass('text-center').renderWith(function (data, type, full, oSettings) {
        var str = '<div class="form-inline">'
          + '<div class="form-group"><a class="btn btn-link" ng-click="details(' + data.id + ',\'' + data.sn + '\')">详情</a></div>'
          + '<div class="form-group"><a class="btn btn-link" ng-click="shopRecord(\'' + data.standNo + '\',\'' + data.sn + '\')">到店记录</a></div><div class="form-group"><a class="btn btn-link" ng-click="followRecord(\'' + data.standNo + '\',\'' + data.sn + '\')">跟进记录</a></div>'
        str += '</div>'
        return str
      })
    ]
    $scope.dtOptions = DTOptionsBuilder.newOptions()
      .withOption('id', 'id')
      .withFixedColumns({
        leftColumns: 1,
        rightColumns: 0
      })
      .withOption('num', true)
      .withOption('completeCb', function () {
        // 使table头部自定义内容能够绑定到当前scope
        setTimeout(function () {
          $compile(angular.element('.dt-head-ctrl').contents())($scope)
        }, 0)
      })

    $scope.dtInstance = {
      serverData: aiNicheService.getShopWarnListInfo
    }

    // table搜索
    $scope.tableSearch = function () {
      var params = getParams()
      $scope.dtInstance.query(params)
    }

    $scope.monthSelects = []
    aiNicheService.shopQueryMonthList(function (response) {
      $scope.monthSelects = response.data
      if ($scope.monthSelects == null) {
        $scope.monthSelects = []
      }
      $scope.monthSelects.unshift({
        name: '全部'
      })
    })

    if (!angular.equals({}, $scope.createTime)) {
      $scope.createTime = {
        startDate: null,
        endDate: null
      }
    }

    function getParams () {
      var obj = {}
      if ($scope.selectCondition && $scope.conditionText) {
        obj.searchKey = $scope.selectCondition
        obj.searchValue = $scope.conditionText
      }

      if ($scope.followResult) {
        obj.followResult = $scope.followResult
      }

      if ($scope.createTime.startDate && $scope.createTime.endDate) {
        obj.sTime = $scope.createTime.startDate.format('YYYY-MM-DD HH:mm:ss')
        obj.eTime = $scope.createTime.endDate.format('YYYY-MM-DD HH:mm:ss')
      }

      // if($scope.warnTimes1){
      obj.warnTimesStart = $scope.warnTimes1
      // }
      // if($scope.warnTimes2){
      obj.warnTimesEnd = $scope.warnTimes2
      // }
      // if($scope.stopTime1){
      obj.stopTimeStart = $scope.stopTime1
      // }
      // if($scope.stopTime2){
      obj.stopTimeEnd = $scope.stopTime2
      // }
      if ($scope.monthSelectsDate) {
        obj.monthSelectsDate = $scope.monthSelectsDate.id
      }
      return obj
    }

    $scope.warnInfoBoxHidden = function () {
      $scope.warnInfoBox = false
      var mid = $rootScope.loginUser.merchantId
      localStorageService.set('address.check' + mid, 'Y')
      aiNicheService.addAddressCheck(function (response) {})
      $scope.tableSearch()
    }


    function open (url, controller, defaultData, result, size) {
      $uibModal.open({
        templateUrl: url,
        controller: controller,
        size: size || 'md',
        resolve: {
          data: () => {
            return {
            defaultData}
          }
        }
      }).result.then(result)
    }
    $scope.openMapDialog = function () {
      var position = {
        lat: $scope.merchant.lat,
        lng: $scope.merchant.lng
      }
      var oAddr = {
        city: $scope.merchant.cityName,
        province: $scope.merchant.provinceName,
        district: $scope.merchant.areaName,
        address: $scope.merchant.address,
        mid: $scope.mid,
        position: position
      }
      open('biz/AIniche/view/chooseAddress.html', 'chooseAddress', {
        oAddress: oAddr
      }, function (oAddr) {
        $scope.merchant.cityName = oAddr.city
        $scope.merchant.provinceName = oAddr.province
        $scope.merchant.areaName = oAddr.district
        $scope.merchant.lat = oAddr.position.lat
        $scope.merchant.lng = oAddr.position.lng
        $scope.merchant.address = oAddr.address; // concatAddr(province,city,district,address)

        var obj = {}
        obj.merchantId = $rootScope.loginUser.merchantId
        obj.address = oAddr.address
        obj.lat = oAddr.position.lat
        obj.lng = oAddr.position.lng
        obj.id = $scope.mid
        aiNicheService.addOrUpdateMerchant(obj, function (res) {
          if (res.returnCode == 0) {
            swal({
              type: 'success',
              title: '',
              html: true,
              text: '操作成功',
              timer: 1000
            })
            $uibModalInstance.close('cancel')
          }else {
            swal({
              type: 'error',
              title: '',
              html: true,
              text: '操作失败 ' + (res.message || ''),
              confirmButtonText: '确定'
            })
          }
        })
        $scope.hasAddress = true
        $scope.warnInfoBox = false
        var mid = $rootScope.loginUser.merchantId
        localStorageService.set('address.check' + mid, 'Y')
        aiNicheService.addAddressCheck(function (response) {})
        $scope.tableSearch()
      }, 'lg')
    }

    $scope.getAddress = function () {
      aiNicheService.getUserMerchant(function (response) {
        if (response.returnCode == 0) {
          $scope.mid = response.data.detail.id
          $scope.merchant.lat = response.data.detail.lat
          $scope.merchant.lng = response.data.detail.lng
          $scope.merchant.cityName = response.data.detail.cityName
          $scope.merchant.provinceName = response.data.detail.provinceName
          $scope.merchant.areaName = response.data.detail.areaName
          $scope.merchant.address = response.data.detail.address

          aiNicheService.addAddressCheck(function (response) {
            var mid = $rootScope.loginUser.merchantId
            localStorageService.set('address.check' + mid, 'Y')
            $scope.warnInfoBox = false
          })
          $scope.openMapDialog()
        }
      })
    }

    $scope.exportExcel = function () {
      if ($scope.isExporting) return
      var params = getParams()
      $scope.isExporting = true
      var shopTitle = '客户到店分析'
      Utils.exportExcel3('shop/exportShop', params, shopTitle, 'GET', function () {
        $scope.isExporting = false
      })
    /*
            var options={
                url:"shop/exportShop"
            }
            Utils.exportExcel(options, params, function(){
                $scope.$apply(function(){
                    $scope.isExporting = false
                })
            })
            */
    }

    // 跟进记录
    $scope.followRecord = function (standNo, sn) {
    	if (null == standNo || '' == standNo || 'null' == standNo) {
       	 standNo = null
         }
      var modalInstance = $uibModal
        .open({
          templateUrl: 'biz/AIniche/view/shopFollowRecord.html',
          controller: 'shopFollowRecordInfo',
          size: 'md',
          resolve: {
            param: function () {
              return {
                standNo: standNo,
                sn:sn
              }
            }
          }
        })
      // 弹窗返回值
      modalInstance.result.then(function (data) {
        if (data) {
          // $scope.dtInstance.query(data)
          $scope.tableSearch()
        }
      })
    }

    // 详情
    $scope.details = function (item, sn) {
      var modalInstance = $uibModal
        .open({
          templateUrl: 'biz/AIniche/view/shopDetails.html',
          controller: 'shopDetailsInfoDefine',
          size: 'lg',
          resolve: {
            param: function () {
              return {
                id: item,
                sn: sn
              }
            }
          }
        })
      // 弹窗返回值
      modalInstance.result
        .then(function (data) {
          if (data) {
            // $scope.dtInstance.query(data)
          }
        })
    }

    // 到店记录
    $scope.shopRecord = function (standNo, sn) {
    	console.log(standNo, sn)
      if (null == standNo || '' == standNo || 'null' == standNo) {
    	 standNo = null
      }
      var modalInstance = $uibModal
        .open({
          templateUrl: 'biz/AIniche/view/shopRecords.html',
          controller: 'shopRecordInfoDefine',
          size: 'md',
          resolve: {
            param: function () {
              return {
                standNo: standNo,
                sn:sn
              }
            }
          }
        })
      // 弹窗返回值
      modalInstance.result
        .then(function (data) {
          if (data) {
            // $scope.dtInstance.query(data)
          }
        })
    }
  }
  angular.module('AIniche').controller('shopRemind', shopRemind)
})(angular)