repairConfig.js 3.22 KB
(function (angular) {
  function repairConfig($scope, aiNicheService, Utils, $uibModal, DTOptionsBuilder, DTColumnBuilder, $q, common, $resource) {

    $scope.searchForm = {}
    $scope.selcetList = [{
      label: '请选择',
      value: ''
    }, {
      label: '商户名称',
      value: 'merchantName'
    }, {
      label: '商户号',
      value: 'merchantId'
    }, {
      label: '登录账号',
      value: 'remark'
    }]
    $scope.select = {
      type: '',
      value: ''
    }
    $scope.markLastSelect = ''

    // 表格
    $scope.dtColumns = [
      DTColumnBuilder.newColumn('merchantName').withOption('width', 150).withTitle('商户名称'),
      DTColumnBuilder.newColumn('merchantId').withOption('width', 150).withTitle('商户号'),
      DTColumnBuilder.newColumn('remark').withOption('width').withTitle('登陆账号'),
      DTColumnBuilder.newColumn('counselorName').withTitle('送修顾问名字'),
      DTColumnBuilder.newColumn('collisionPhone').withTitle('送修顾问联系电话'),
      DTColumnBuilder.newColumn('sparePhones').withTitle('备用联系电话'),
    ]

    $scope.dtOptions = DTOptionsBuilder.newOptions().withOption('num', false)
    $scope.dtInstance = {
      serverData: function (param) {
        return aiNicheService.getConfigList(param);
      }
    }

    function getParams() {
      $scope.markLastSelect && (delete $scope.searchForm[$scope.markLastSelect])
      var regNum = /^[0-9]*$/
      if ($scope.select.type) {
        $scope.markLastSelect = $scope.select.type
        if ($scope.select.type == 'merchantId' && !regNum.test($scope.select.value)) {
          $scope.searchForm[$scope.select.type] = -1
        } else {
          $scope.searchForm[$scope.select.type] = $scope.select.value
        }
      }
    };

    $scope.handleSearch = function () {
      getParams()
      $scope.dtInstance.query({
        condition: $scope.searchForm
      })
    };

    $scope.handleReset = function () {
      $scope.searchForm = {}
      $scope.select = {
        type: '',
        value: ''
      }
      $scope.markLastSelect = ''
      $scope.dtInstance.query()
    };

    $scope.handleExport = function () {
      var maintainTitle = '送修配置列表'
      // // url, params, filename, method
      getParams()
      Utils.exportExcel2('collisionNoticeConfig/export', $scope.searchForm, maintainTitle, 'GET')
    };

    $scope.handleImport = function () {
      $uibModal.open({
        templateUrl: 'biz/AIniche/view/aiImportModal.html',
        controller: 'aiImportModalCtrl',
        size: 'md',
        resolve: {
          importConfig: function () {
            return {
              pageTitle: '批量导入', //弹框标题
              ajaxUrl: 'collisionNoticeConfig/importCollisionConfig', //导入服务地址
              downloadType: '21', //下载导入模板类型
              importTemplate: '送修配置管理模板', //下载导入模板文件名
              errorDown: '送修配置管理报错下载.xlsx'
            }
          }
        }
      }).result.then(function () {}, function () {
        $scope.dtInstance.query({
          condition: $scope.searchForm
        })
      });
    };

  }

  angular.module('AIniche').controller('repairConfig', repairConfig);

})(angular);