customerDeviceFsyncCountCtrl.js 4 KB
(function (angular) {
  function customerDeviceFsyncCountCtrl($scope, customerService, DTColumnBuilder, DTOptionsBuilder, $http, $state, $uibModal, Utils) {
    $scope.fieldName = 'merchantId';

    $scope.dtColumns = [
      DTColumnBuilder.newColumn('merchantName').withOption('width', 60).withTitle('商户名称'),
      DTColumnBuilder.newColumn('merchantId').withOption('width', 60).withTitle('商户号'),
      DTColumnBuilder.newColumn('count').withOption('width', 60).withTitle('预录设备量'),
      DTColumnBuilder.newColumn('activeSum').withOption('width', 60).withTitle('激活设备量'),
      DTColumnBuilder.newColumn('salesSum').withOption('width', 60).withTitle('系统撤销量'),
      DTColumnBuilder.newColumn('createdDate').withOption('width', 60).withTitle('操作时间'),
      DTColumnBuilder.newColumn(null).withTitle('操作').withOption('width', 100).renderWith((data, type, full, oSettings) => {
        let str = `<a class="btn-link" style="padding:0 5px;" ng-click='delete(${data.merchantId})' >删除</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.listCustomerDeviceFsyncPage
    };

    $scope.delete = function (merchantId) {
      swal({
        title: "确定删除吗?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnConfirm: false
      }, function () {
        deleteByMerchantId(merchantId);
      });
    }

    /**
     * 删除已退单服务订单
     */
    function deleteByMerchantId(merchantId) {
      //swal({title: '删除中', text: "请稍候...", showConfirmButton: false});
      customerService.deleteByMerchantId( merchantId, function (result) {
        if (result.returnCode == '0') {
          swal({
            type: 'success',
            title: '',
            html: true,
            text: '删除成功',
            showConfirmButton: false,
            timer: 1000
          });
          $scope.select()
        } else {
          swal({
            type: 'error',
            title: '',
            html: true,
            text: '删除失败 ' + (result.errId || ''),
            confirmButtonText: "确定"
          });
        }
      });
    }

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

    $scope.getParam = function () {
      var param = {};
      if ($scope.fieldName && $scope.fieldValue) {
        param[$scope.fieldName] = $scope.fieldValue;
      }
      var obj = {
        condition: param
      };
      return obj;
    }

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

    $scope.exportExcel = function () {
      var options = $scope.getParam().condition;
      Utils.exportExcel2('customer/customerDeviceFsyncCount/exportFsyncCount', options, '预录商户');
    };
  }

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