123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678 |
- app.controller('manufacturerCtrl', ['$scope', '$http', "$state", '$timeout', 'uiGridConstants', 'i18nService', 'toaster', 'md5', 'FileUploader', function ($scope, $http, $state, $timeout, uiGridConstants, i18nService, toaster, MD5, FileUploader) {
- i18nService.setCurrentLang("zh-cn");
- $scope.gridOptions = {
- data: 'myData',
- showGridFooter: true, //是否显示grid footer
- // rowHeight: 80,
- //-------- 分页属性 ----------------
- paginationPageSizes: [10, 20, 50, 100], //每页显示个数可选项
- paginationCurrentPage: 1, //当前页码
- paginationPageSize: 10, //每页显示个数
- totalItems: 0,// 总数量
- useExternalPagination: true,//是否使用分页按钮
- //过滤
- // enableFiltering: true,
- columnDefs: [],
- //---------------api---------------------
- onRegisterApi: function (gridApi) {
- $scope.gridApi = gridApi;
- gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
- if ($scope.setPagingData) {
- $scope.getPagedDataAsync(newPage, pageSize);
- }
- });
- }
- };
- //枚举常量
- $scope.enum = {};
- $scope.enum.adShow = [
- {value: "", label: "广告状态"},
- {value: false, label: "无广告"},
- {value: true, label: "有广告"}
- ];
- //查询条件
- var condition = $scope.condition = {
- adShow: $.extend({}, $scope.enum.adShow[0]),
- searchKey: "",
- searchType: {value: "", text: "厂商信息"},
- searchTypeList: [
- {value: "", text: "厂商信息"},
- {value: "dealer", text: "经销商查厂商"},
- {value: "agent", text: "代理商查厂商"},
- ],
- };
- //事件
- $scope.event = {
- statusChange: function (key, item) {
- condition[key].value = item.value;
- condition[key].label = item.label;
- this.search()
- },
- search: function () {
- $scope.getPagedDataAsync(1, $scope.gridOptions.paginationPageSize);
- }
- };
- function setColumnDefs() {
- $scope.gridOptions.columnDefs = [
- {
- field: 'nickname', displayName: '厂商名称',
- cellTemplate: '<div class="temp-row"><i class="fa fa-bullhorn text-success" title="已开启广告" ng-if="row.entity.adShow" ></i> {{row.entity.nickname}} </div>',
- },
- {field: 'brandName', displayName: '品牌名称'},
- {field: 'username', displayName: '联系方式'},
- {
- field: 'createdTime',
- displayName: '注册时间',
- cellTemplate: '<div class="temp-row" ng-bind="row.entity.createdTime| date:\'yyyy-MM-dd HH:mm:ss\'"></div>'
- },
- {
- field: 'agentTotal',
- displayName: '代理商总数',
- cellTemplate: '<div class="temp-row" ng-bind="row.entity.agentTotal"></div>'
- },
- {
- field: 'logo',
- displayName: '厂商图标',
- enableFiltering: false,
- cellTemplate: '<img ng-src="{{row.entity.logo}}" class="img-circle center-block" style="max-height: 100%"/>'
- },
- {
- field: 'withdrawFeeRatioCost',
- displayName: '提现费率',
- cellTemplate: '<div class="temp-row">{{row.entity.withdrawFeeRatioCost}}‰</div>'
- },
- {
- field: 'operation',
- displayName: '操作',
- minWidth: 680,
- enableFiltering: false,
- enableSorting: false,
- enableHiding: false,//禁止在列选择器中隐藏
- enableColumnMenu: false,// 是否显示列头部菜单按钮
- cellTemplate: '<div class="grid-button">' +
- '<button class="btn btn-sm btn-rounded btn-danger" ng-if="row.entity.status==\'normal\'" ng-click="grid.appScope.ban(row.entity,false)"><i class="fa fa-ban"></i> 封号</button>' +
- '<button class="btn btn-sm btn-rounded btn-success" ng-if="row.entity.status!==\'normal\'" ng-click="grid.appScope.ban(row.entity,true)"><i class="fa fa-unlock"></i> 解封</button>' +
- // '<button class="btn btn-sm btn-rounded btn-info"ng-click="grid.appScope.unfreeze(row.entity)"><i class="fa fa-smile-o"></i> 解除限制</button>' +
- '<button class="btn btn-sm btn-rounded btn-danger" ng-click="grid.appScope.editFeature(row.entity)"><i class="fa fa-cubes"></i> 特性</button>' +
- '<button class="btn btn-sm btn-rounded btn-dark" ng-click="grid.appScope.editDeviceType(row.entity)"><i class="fa fa-cubes"></i> 设备类型</button>' +
- '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.openLinkPanel(row.entity)"><i class="fa fa-link"></i> 链接生成</button>' +
- '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.checkAgent(row.entity)"><i class="fa fa-user"></i> 代理商</button>' +
- '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.checkDealer(row.entity)"><i class="fa fa-users"></i> 经销商</button>' +
- '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.checkDevice(row.entity)"><i class="glyphicon glyphicon-phone"></i> 设备</button>' +
- '<button class="btn btn-sm btn-rounded btn-default" ng-click="grid.appScope.goLogin(row.entity)"><i class="glyphicon glyphicon-log-in"></i> 去登录</button>' +
- '</div>'
- }
- ];
- var fields = $scope.gridOptions.columnDefs;
- for (var index in fields) {
- var item = fields[index];
- if (item && item['minWidth'] == null) {
- item['minWidth'] = 100;
- }
- }
- }
- $scope.setPagingData = function (data) {
- var pagedData = data.data.dataList;
- $scope.myData = pagedData;
- $scope.gridOptions.totalItems = data.data.total;
- };
- $scope.getPagedDataAsync = function (curPage, pageSize) {
- var params = {
- adShow: condition.adShow.value,
- pageSize: pageSize,
- pageIndex: curPage
- };
- // 查询关键字
- if (condition.searchKey != "") {
- params.searchKey = condition.searchKey
- }
- // 查询类型
- if (condition.searchType.value != "") {
- params.searchType = condition.searchType.value;
- if (condition.searchKey == "") {
- toaster.pop("warning", "提示", "请输入 " + condition.searchType.text + " 信息");
- return
- }
- }
- $http.get('/superadmin/getManagerList', {
- params: params
- }).then(function (data) {
- data = data.data
- $scope.setPagingData(data, curPage, pageSize);
- }).catch(function (data) {
- toaster.pop("error", "提示", "获取数据列表失败");
- });
- };
- function initDataGrid() {
- //首次加载表格
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }
- setColumnDefs();
- initDataGrid();
- //封号|解封
- $scope.ban = function (entity, targetStatus) {
- var url = "/superadmin/toggleManufacturerStatus";
- $.confirm({
- content: '确定这样操作?',
- buttons: {
- ok: {
- btnClass: 'btn-red',
- action: function () {
- $http({
- method: 'POST',
- url: url,
- data: {
- id: entity.id,
- normal: targetStatus
- }
- }).then(function (response) {
- entity.normal = targetStatus;
- console.log(response);
- if (response.data.result) {
- toaster.pop("success", "提示", "修改状态成功!");
- } else {
- toaster.pop("error", "提示", "修改状态失败!");
- }
- }, function (response) {
- toaster.pop("error", "提示", "修改状态失败!");
- });
- }
- },
- }
- });
- };
- function getOneRow() {
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length === 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return false;
- }
- if (rows.length > 1) {
- toaster.pop("info", "提示", "只能选中编辑一条数据");
- return false;
- }
- return rows[0]
- }
- // 解除5次错误限制
- $scope.unfreeze = function (entity) {
- var entity = getOneRow();
- if (!entity) {
- return
- }
- var url = "/superadmin/unfreeze";
- $http({
- method: 'POST',
- url: url,
- data: {
- role: "manager",
- id: entity.id,
- }
- }).then(function (response) {
- if (response.data.result) {
- toaster.pop("success", "提示", "解除限制成功!");
- } else {
- toaster.pop("error", "提示", "解除限制失败!");
- }
- }, function (response) {
- toaster.pop("error", "提示", "解除限制失败!");
- });
- };
- // 必须先声明,否则ui-select无法双绑
- $scope.dialogData = {};
- //添加
- $scope.add = function () {
- //重置表单状态
- $scope.manageForm.$setPristine();
- $scope.manageForm.$setUntouched();
- //重置图片上传控件
- closeUploader();
- $scope.dialogName = "厂商开户";
- $scope.dialogData = {isNew: true};
- $("#manageForm").modal();
- };
- //编辑
- $scope.edit = function () {
- //重置表单状态
- $scope.manageForm.$setPristine();
- $scope.manageForm.$setUntouched();
- //重置图片上传控件
- closeUploader();
- $scope.dialogName = "编辑厂商信息";
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length == 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return;
- }
- if (rows.length > 1) {
- toaster.pop("info", "提示", "只能选中编辑一条数据");
- return;
- }
- var item = rows[0];
- $scope.dialogData = $.extend({}, item);
- $("#manageForm").modal();
- };
- //提交表单保存
- $scope.saveData = function () {
- //表单未校验通过不能提交,上传文件提示
- if ($scope.manageForm.$invalid) {
- return
- }
- var url = "";
- if ($scope.dialogData.id == null) {
- url = "/superadmin/addManager";
- } else {
- url = "/superadmin/editManager";
- }
- var data = {
- nickname: $scope.dialogData.nickname,
- brandName: $scope.dialogData.brandName,
- username: $scope.dialogData.username,
- remarks: $scope.dialogData.remarks,
- logo: $scope.dialogData.logo,
- };
- if ($scope.dialogData.id != null) {
- //编辑
- $.extend(data, {'id': $scope.dialogData.id})
- } else {
- //新建时才会保存密码
- data.password = MD5.createHash($scope.dialogData.password + '');
- // 新增时才会修改首席代理商信息
- data.primaryAgentUsername = $scope.dialogData.primaryAgentUsername;
- data.primaryAgentPassword = MD5.createHash($scope.dialogData.primaryAgentPassword + '');
- data.primaryAgentNickName = $scope.dialogData.primaryAgentNickName;
- data.trafficCardCost = $scope.dialogData.trafficCardCost;
- data.withdrawFeeRatioCost = $scope.dialogData.withdrawFeeRatioCost;
- }
- $http({
- method: 'POST',
- url: url,
- data: data
- }).then(function (response) {
- $('#manageForm').modal('hide');//弹窗消失
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "开户失败!");
- });
- };
- $scope.editAddress = function () {
- //重置表单状态
- $scope.editAddressForm.$setPristine();
- $scope.editAddressForm.$setUntouched();
- $scope.dialogName = "编辑厂商售后收货地址";
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length == 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return;
- }
- if (rows.length > 1) {
- toaster.pop("info", "提示", "只能选中编辑一条数据");
- return;
- }
- var item = rows[0];
- $scope.dialogData = item.exchangeAddress || {};
- $scope.dialogData.managerId = item.id
- $("#editAddressForm").modal();
- };
- $scope.saveAddress = function () {
- //表单未校验通过不能提交,上传文件提示
- if ($scope.editAddressForm.$invalid) {
- return
- }
- var url = "/superadmin/saveFactoryAddress";
- var data = $scope.dialogData
- $http({
- method: 'POST',
- url: url,
- data: data
- }).then(function (response) {
- $('#editAddressForm').modal('hide');
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "保存失败!");
- });
- };
- //查看代理商
- $scope.checkAgent = function (entity) {
- $state.go('app.user.agents', {
- moniAppId: '',
- managerId: entity.id,
- }, {
- reload: true
- });
- };
- //查看经销商
- $scope.checkDealer = function (entity) {
- $state.go('app.user.dealer', {
- managerId: entity.id,
- agentId: "",
- }, {
- reload: true
- });
- };
- //查看设备
- $scope.checkDevice = function (entity) {
- $state.go('app.dev.devManage', {
- managerId: entity.id,
- agentId: "",
- dealerId: "",
- searchKey: "",
- }, {
- reload: true
- });
- };
- $scope.goLogin = function (entity) {
- var username = entity.username;
- var url = "/1.0/index.html?username=" + username + "#/access/signin";
- window.open(url);
- };
- //事件绑定
- $timeout(function () {
- $("#fileUpload").on("change", function () {
- var objUrl = getObjectURL(this.files[0]);
- if (objUrl) {
- $("#previewImg").attr("src", objUrl);
- }
- });
- $("#fileUploadValue").on("focus", function () {
- $(this).blur();
- })
- });
- //建立一個可存取到該file的url
- function getObjectURL(file) {
- var url = null;
- if (window.createObjectURL != undefined) { // basic
- url = window.createObjectURL(file);
- } else if (window.URL != undefined) { // mozilla(firefox)
- url = window.URL.createObjectURL(file);
- } else if (window.webkitURL != undefined) { // webkit or chrome
- url = window.webkitURL.createObjectURL(file);
- }
- return url;
- }
- //图片提交控件
- var uploader = $scope.uploader = new FileUploader({
- url: '/common/upload?type=logo',
- queueLimit: 1, //文件个数
- removeAfterUpload: true //上传后删除文件
- });
- //注册上传事件
- uploader.onCompleteItem = function (fileItem, response, status, headers) {
- if (response.payload) {
- //适配数据
- response.data = response.payload;
- }
- if (response.result) {
- toaster.pop("success", "提示", "上传成功!");
- $scope.dialogData.logo = response.data;
- } else {
- toaster.pop("error", "失败", response.description);
- }
- };
- uploader.onErrorItem = function (fileItem, response, status, headers) {
- toaster.pop("error", "提示", "上传失败,请重试");
- };
- /*关闭上传框窗口后恢复上传框初始状态*/
- function closeUploader() {
- $("#fileUpload").val("");
- $("#previewImg").attr("src", "");
- uploader.clearQueue();
- uploader.cancelAll();
- }
- /********************链接拷贝面板***********************/
- var copyLinkData = $scope.copyLinkData = {};
- var currentDomain = location.protocol + "//" + location.host;
- //生成推广链接
- $scope.openLinkPanel = function (entity) {
- $("#copyLinkPanel").modal();
- //代理商入口
- var url = currentDomain + "/agents/index.html?managerId=" + entity.id;
- copyLinkData.link1 = url;
- };
- // 关闭链接生成器
- $scope.closeCopyLinkPanel = function () {
- $("#copyLinkPanel").modal("hide");
- };
- var clipboard;
- //事件绑定
- $timeout(function () {
- //在弹窗绑定 COPY组件
- clipboard = new ClipboardJS('.copyLinkBtn');
- clipboard.on('success', function (e) {
- e.clearSelection();
- toaster.pop("info", "提示", "复制成功");
- $scope.$apply();
- });
- clipboard.on('error', function (e) {
- toaster.pop("info", "提示", "请选择“拷贝”进行复制!");
- $scope.$apply();
- });
- });
- $scope.$on("$destroy", function () {
- if (clipboard) {
- clipboard.destroy();
- console.log("clipboard destroy");
- }
- });
- // 分配厂商的设备类型弹窗
- $scope.editDeviceType = function (entity) {
- $("#editDeviceTypePanel").modal();
- $scope.dialogName = entity.nickname + "配置设备类型";
- $("#dealerDevList").modal();
- // todo 由于ui-grid 之前隐藏,表格渲染有问题
- setTimeout(function () {
- // 刷新设备
- $scope.$broadcast("initDriverCodeList", {id: entity.id, role: "manager"});
- }, 100);
- };
- $scope.closeDeviceConfig = function (entity) {
- $("#editDeviceTypePanel").modal('hide');
- };
- //------------配置特性--------------------
- $scope.editFeature = function (entity) {
- $scope.dialogData = {
- id: entity.id,
- featureList: entity.featureList,
- specialFeature: entity.specialFeature,
- };
- $("#featureForm").modal();
- }
- $scope.saveFeature = function () {
- if ($scope.featureForm.$invalid) {
- return
- }
- $.confirm({
- content: '确定要变更特性?',
- buttons: {
- ok: {
- btnClass: 'btn-red',
- action: function () {
- var url = "/superadmin/editManagerFeature";
- $http({
- method: 'POST',
- url: url,
- data: {
- id: $scope.dialogData.id,
- featureList: $scope.dialogData.featureList,
- specialFeature: $scope.dialogData.specialFeature,
- }
- }).then(function (response) {
- //保存成功 弹窗消失
- $('#featureForm').modal('hide');
- if (response.data.result) {
- toaster.pop("info", "提示", "成功")
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }
- }, function (response) {
- toaster.pop("error", "提示", "保存失败!");
- });
- }
- },
- }
- });
- };
- //广告开关
- $scope.selectedIds = []
- $scope.editAdShow = function () {
- $scope.dialogData = {};
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length === 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return;
- }
- var ids = [];
- for (var i = 0; i < rows.length; i++) {
- ids.push(rows[i].id);
- }
- $scope.selectedIds = ids;
- $("#editAdForm").modal();
- }
- $scope.saveAdEdit = function () {
- var ids = $scope.selectedIds
- if ($scope.editAdForm.$invalid) {
- return
- }
- $http({
- method: 'POST',
- url: '/superadmin/editAdShow',
- data: {ids: ids, adShow: $scope.dialogData.adShow, role: "manager"}
- }).then(function (response) {
- initDataGrid();
- $('#editAdForm').modal('hide');
- toaster.pop("success", "提示", "保存成功!");
- }, function (response) {
- toaster.pop("error", "提示", "保存失败!");
- });
- }
- //编辑密码 默认123456
- $scope.editPassword = function () {
- //重置表单状态
- $scope.passwordForm.$setPristine();
- $scope.passwordForm.$setUntouched();
- var rows = $scope.gridApi.selection.getSelectedRows();
- if (rows.length == 0) {
- toaster.pop("info", "提示", "请选择数据!");
- return;
- }
- if (rows.length > 1) {
- toaster.pop("info", "提示", "只能选中编辑一条数据");
- return;
- }
- var item = rows[0];
- $scope.passwordData = $.extend({password: 123456}, item);
- $("#passwordPanel").modal();
- };
- //修改密码提交
- $scope.savePassword = function () {
- //表单未校验通过不能提交
- if ($scope.passwordForm.$invalid) {
- return;
- }
- var url = "/superadmin/changeManagerPassword"
- var password = MD5.createHash($scope.passwordData.password + '');
- $http({
- method: 'POST',
- url: url,
- data: {
- id: $scope.passwordData.id,
- password: password,
- }
- }).then(function (response) {
- $('#passwordPanel').modal('hide');//弹窗消失
- $scope.getPagedDataAsync($scope.gridOptions.paginationCurrentPage, $scope.gridOptions.paginationPageSize);
- }, function (response) {
- toaster.pop("error", "提示", "修改密码失败!");
- });
- };
- }]);
|