customerDeviceCtrl.js 10.9 KB
(function (angular) {
  function customerDeviceCtrl($scope, customerService, DTColumnBuilder, DTOptionsBuilder, $http, $state, $uibModal, Utils) {
    $scope.fieldName = 'merchantId';
    $scope.fieldName2 = 'createdBy';

    $scope.dtColumns = [
      DTColumnBuilder.newColumn('imei').withOption('width', 60).withTitle('IMEI/SN号'),
      DTColumnBuilder.newColumn('deviceTypeId').withOption('width', 60).withTitle('设备类型').renderWith(function (data, type, full, oSettings) {
        return {
          1: 'OBD',
          2: '云导航',
          3: '电子狗',
          5: 'TBOX(2G)',
          6: '记录仪',
          7: 'BBOX',
          8: 'GPS',
          9: '车载wifi',
          12134: '后视镜',
          12501: '智能蓝牙耳机车充'
        } [data] || '--'
      }),
      DTColumnBuilder.newColumn('merchantName').withOption('width', 60).withTitle('商户名称'),
      DTColumnBuilder.newColumn('merchantId').withOption('width', 60).withTitle('商户号'),
      DTColumnBuilder.newColumn('isAuth').withOption('width', 50).withTitle('实名认证').renderWith(function (data, type, full, oSettings) {
        if (data === 1 || data == "1") {
          return "已实名"
        } else {
          return "未实名"
        }
      }),
      DTColumnBuilder.newColumn('source').withOption('width', 80).withTitle('来源').renderWith(function (data, type, full, oSettings) {
        if (data === 1 || data == "1") {
          return "手机端录入"
        } else if (data === 2 || data == "2") {
          return "PC后台导入"
        }  else if (data === 3 || data == "3") {
          return "PC后台添加"
        } else if (data === 4 || data == "4") {
          return "系统预录"
        } else {
          return "--"
        }
      }),
      DTColumnBuilder.newColumn('phone').withOption('width', 100).withTitle('客户电话'),
      DTColumnBuilder.newColumn('name').withOption('width', 60).withTitle('客户姓名'),
      DTColumnBuilder.newColumn('gender').withOption('width', 60).withTitle('性别').renderWith(function (data, type, full, oSettings) {
        if(data === 1 || data == '1'){
          return "男"
        } else if(data === 2 || data == '2'){
          return "女"
        } else {
          return "- -"
        }
      }),
      DTColumnBuilder.newColumn('plateNum').withOption('width', 60).withTitle('车牌号'),
      DTColumnBuilder.newColumn('standNo').withOption('width', 100).withTitle('车架号'),
      DTColumnBuilder.newColumn(null).withOption('width', 60).withTitle('车型').renderWith(data => {
        let str = data.vehicleBrand ? `<div>${data.vehicleBrand}<br/></div>` : '<div>- -</div>'
        return str
      }),
    DTColumnBuilder.newColumn('installMileage').withOption('width', 100).withTitle('设备安装时车辆里程'),
        DTColumnBuilder.newColumn('nextMaintainMileage').withOption('width', 80).withTitle('下次保养里程'),
        DTColumnBuilder.newColumn('nextMaintainTime').withOption('width', 100).withTitle('下次保养时间').renderWith(function (data, type, full, oSettings) {
          if (data) {
            return data.split(" ")[0];
          }
          return "";
        }),
        DTColumnBuilder.newColumn('lastMaintainMileage').withOption('width', 80).withTitle('上次保养里程'),
        DTColumnBuilder.newColumn('lastMaintainTime').withOption('width', 100).withTitle('上次保养时间').renderWith(function (data, type, full, oSettings) {
          if (data) {
            return data.split(" ")[0];
          }
          return "";
        }),
        DTColumnBuilder.newColumn('iccid').withOption('width', 110).withTitle('ICCID').renderWith(function (data, type, full, oSettings) {
          if (data) {
            return data;
          }
          return "";
        }),
        DTColumnBuilder.newColumn('dispatchOrderCode').withOption('width',100).withTitle('订单号'),
        DTColumnBuilder.newColumn('createdDate').withOption('width', 90).withTitle('操作时间'),
        DTColumnBuilder.newColumn('employeeName').withOption('width', 80).withTitle('录入员工'),
        DTColumnBuilder.newColumn('createdBy').withOption('width', 80).withTitle('操作人登录账号'),
        DTColumnBuilder.newColumn('isChange').withOption('width', 80).withTitle('是否更换设备').renderWith(function (data, type, full, oSettings) {
          if(data === 1 || data == '1'){
            return "保修更换-免费"
          } else if(data == 2 || data == '2'){
            return "维修更换"
          } else if(data == 3 || data == '3'){
            return "购买"
          } else {
            return "- -"
          }
        }),
    DTColumnBuilder.newColumn(null).withTitle('操作').withOption('width', 100).renderWith((data, type, full, oSettings) => {
      let {
        id,
        vehicleBrand,
        vehicleBrandId,
        vehicleChildsBrandName,
        vehicleChildsBrandId,
        vehicleSeriesName,
        vehicleSeriesId,
        vehicleTypeId,
        vehicleTypeName,
        imei,
        phone,
        name,
        gender,
        plateNum,
        standNo,
        isAuth,
        isChange
        
      } = data
      let _data = JSON.stringify({
        id,
        vehicleBrand,
        vehicleBrandId,
        vehicleChildsBrandName,
        vehicleChildsBrandId,
        vehicleSeriesName,
        vehicleSeriesId,
        vehicleTypeId,
        vehicleTypeName,
        imei,
        phone,
        name,
        gender,
        plateNum,
        standNo,
        isAuth,
        isChange

      })
      let str = `<a class="btn-link" style="padding:0 5px;" ng-click='change(${_data})' >修改用户信息</a>`
      return str
    })
  ];

    $scope.dtOptions = DTOptionsBuilder.newOptions()
        .withOption('id', 'id')
        .withFixedColumns({
          leftColumns: 1,
          rightColumns: 1
        })
        .withOption('lengthMenu', [10, 20, 40, 60, 100])
        .withOption('num', true);

    $scope.dtInstance = {
      serverData: customerService.listCustomerDevicePage
    };
    $scope.change = data => {
      $uibModal.open({
        templateUrl: 'biz/customer/view/updateDeviceModel.html',
        controller: 'updateDeviceModelCtrl',
        size: 'xs',
        resolve: {
          parentData: function () {
            return data
          }
        }
      }).result.then(function (data) {
        $scope.select()
      })
    }
    //查询条件
    $scope.filter = {
      time: moment(),
      factoryMerchantId:''
    };
    $scope.drOptions = {
      opens: 'right',
      eventHandlers: {
        'apply.daterangepicker': function (ev, picker) {
          $scope.filter.time.startDate = picker.startDate;
          $scope.filter.time.endDate = picker.endDate;
        },
        'cancel.daterangepicker': function (ev, picker) {
          $scope.filter.time = {}
          $scope.filter.time.startDate = null;
          $scope.filter.time.endDate = null;
          $scope.$apply()
        }
      }
    };

    $scope.getParam = function () {
      var param = {};
      if ($scope.imei) {
        param.imei = $scope.imei;
      }

      var factoryMerchantId = $scope.factoryMerchantId;
      var provinceMerchantId = $scope.provinceMerchantId;
      var cityMerchantId = $scope.cityMerchantId;
      var shopMerchantId = $scope.shopMerchantId;
      if(factoryMerchantId) {
        param.factoryMerchantId = $scope.factoryMerchantId;
      }
      if(provinceMerchantId) {
        param.provinceMerchantId = $scope.provinceMerchantId;
      }
      if(cityMerchantId) {
        param.cityMerchantId = $scope.cityMerchantId;
      }
      if(shopMerchantId) {
        param.shopMerchantId = $scope.shopMerchantId;
      }

      if ($scope.isBind) {
        param.isBind = $scope.isBind
      }
      if ($scope.fieldName && $scope.fieldValue) {
        if ($scope.fieldName == 'merchantId') {
          var m = -1;
          if (/^[1-9]\d*$/.test($scope.fieldValue)) {
            m = parseInt($scope.fieldValue) || -1;
            if (m > 2147483647) {
              m = -1;
            }
          }
          param[$scope.fieldName] = m;
        } else {
          param[$scope.fieldName] = $scope.fieldValue;
        }
      }
      if ($scope.fieldName2 && $scope.fieldValue2) {
        param[$scope.fieldName2] = $scope.fieldValue2;
      }
      if ($scope.deviceTypeId) {
        param.deviceTypeId = $scope.deviceTypeId;
      }
      if ($scope.createdBy) {
        param.createdBy = $scope.createdBy;
      }
      if ($scope.filter.time) {
        if ($scope.filter.time.startDate) {
          param.startDate = $scope.filter.time.startDate.format('YYYY-MM-DD') + " 00:00:00";
        }
        if ($scope.filter.time.endDate) {
          param.endDate = $scope.filter.time.endDate.format('YYYY-MM-DD') + " 23:59:59";
        }
        if ($scope.isAuth) {
          param.isAuth= $scope.isAuth
        }
        if ($scope.source) {
          param.source = $scope.source;
        }
      }
      var obj = {
        condition: param
      };
      return obj;
    }

    $scope.select = function () {
      var param = $scope.getParam();
      $scope.dtInstance.query(param);
    }

    $scope.importExcel = function () {
      $uibModal.open({
        templateUrl: 'biz/customer/view/customerImportModal.html',
        controller: 'customerImportModalCtrl',
        size: 'md',
        scope: $scope,
        resolve: {
          importConfig: function () {
            return {
              pageTitle: '设备录入', //弹框标题
              ajaxUrl: 'customer/customerDevice/import', //导入服务地址
              downloadType: '13', //下载导入模板类型
              importTemplate: '设备录入-模版', //下载导入模板文件名
              errorDown: '设备录入报错下载.xlsx'
            };
          }
        }
      }).result.then(function () {
        //关闭弹框后执行方法
      }, function () {
        $scope.select();
      });
    };

    // 添加设备
    $scope.handleAdd = function () {
      $uibModal.open({
        templateUrl: 'biz/customer/view/addDeviceModel.html',
        controller: 'addDeviceModelCtrl',
        size: 'md',
        resolve: function() {
          return {}
        }
      }).result.then(function(isRefresh) {
        if(isRefresh) {
          $scope.select()
        }
      }, function () {})
    };

    // 添加设备
    $scope.handleUpdate = function () {
      $uibModal.open({
        templateUrl: 'biz/customer/view/updateDeviceModel.html',
        controller: 'updateDeviceModelCtrl',
        size: 'md',
        resolve: function() {
          return {}
        }
      }).result.then(function(isRefresh) {
        if(isRefresh) {
          $scope.select()
        }
      }, function () {})
    };
    $scope.exportExcel = function () {
      var options = $scope.getParam().condition;
      Utils.exportExcel2('customer/customerDevice/export', options, '设备录入');
    };
  }

  angular.module('customer').controller('customerDeviceCtrl', customerDeviceCtrl);
})(angular);