|
|
@@ -0,0 +1,718 @@
|
|
|
+define(['app/app', 'jquery-uploadify'], function(app) {
|
|
|
+ 'use strict';
|
|
|
+ app.register.controller('singleEntryCtrl', ['$scope', 'Loading', '$rootScope', 'Material', 'toaster', 'ComponentActive', 'Enterprise', '$q', 'NumberService', '$location', '$stateParams', 'Search', '$modal', 'ComponentActiveAPI', 'BrandSubmit', 'BrandActiveAPI', 'DistributionRule', 'prodRepositoryService', 'AuthenticationService', 'StoreInfo', 'ProductServiceQuery', 'StoreCms', 'ByteCountService', 'Goods', 'UASBatchPutOnPropertyServices', '$filter', '$upload', '$http', function($scope, Loading, $rootScope, Material, toaster, ComponentActive, Enterprise, $q, NumberService, $location, $stateParams, Search, $modal, ComponentActiveAPI, BrandSubmit, BrandActiveAPI, DistributionRule, prodRepositoryService, AuthenticationService, StoreInfo, ProductServiceQuery, StoreCms, ByteCountService, Goods, UASBatchPutOnPropertyServices, $filter, $upload, $http) {
|
|
|
+ $rootScope.active = 'product_upload';
|
|
|
+ document.title = '买家产品库-单个录入';
|
|
|
+ $scope.tab = 'single_entry';
|
|
|
+ $scope.packageArray = ["Bulk-散装", "Reel-卷装", "Tape/Reel-编带", "Tray-盘装", "Tube-管装", "盒装", "袋装", "罐装", "瓶装", "桶装", "箱装", "其他"];
|
|
|
+ $scope.batch = {};
|
|
|
+
|
|
|
+ function initInfo() {
|
|
|
+ $scope.Regul = {
|
|
|
+ packaging: '其他',
|
|
|
+ Regulpic: 'static/img/vendor/images/upload.png',
|
|
|
+ Ischange: false,
|
|
|
+ iniUrlImg: 'static/img/vendor/images/upload.png',
|
|
|
+ RegulImg: 'static/img/vendor/images/upload.png',
|
|
|
+ prices: [{'start': 1, rMBPrice: ''}],
|
|
|
+ minPackQty: 1,
|
|
|
+ minDelivery: 1,
|
|
|
+ maxDelivery: 10,
|
|
|
+ dateArea: 'formMe',
|
|
|
+ minBuyQty: 1,
|
|
|
+ breakUp: false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ function initError() {
|
|
|
+ $scope.objError = {
|
|
|
+ pbranden: false,
|
|
|
+ kind: false,
|
|
|
+ pcmpcode: false,
|
|
|
+ spec: false,
|
|
|
+ minDelivery: false,
|
|
|
+ maxDelivery: false,
|
|
|
+ OnePrice: false,
|
|
|
+ minPackQty: false
|
|
|
+ }
|
|
|
+ for (var i = 0; i < $scope.Regul.prices.length; i++) {
|
|
|
+ $scope.Regul.prices[i].priceInvalid = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ initInfo()
|
|
|
+ initError()
|
|
|
+
|
|
|
+ //获取登录的信息
|
|
|
+ var getAuthentication = function () {
|
|
|
+ return AuthenticationService.getAuthentication().success(function(data) {
|
|
|
+ if(data && data.enterprises) {
|
|
|
+ data.enterprise = data.enterprises[data.enterprises.length - 1];
|
|
|
+ if(data.enterprises.length > 1) {
|
|
|
+ var enSelect = [];
|
|
|
+ angular.forEach(data.enterprises, function(e){
|
|
|
+ if(e.current)
|
|
|
+ data.enterprise = e;
|
|
|
+ else
|
|
|
+ enSelect.push(e);
|
|
|
+ });
|
|
|
+ data.enSelect = enSelect;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $rootScope.userInfo = data;
|
|
|
+ }).error(function(response) {
|
|
|
+ toaster.pop('info', '获取定单的信息' + response);
|
|
|
+ });
|
|
|
+ };
|
|
|
+ //判断是否是商城管理公司,是否可以选择自营。
|
|
|
+ $q.all([getAuthentication()]).then(function() {
|
|
|
+ //获取店铺的信息
|
|
|
+ StoreInfo.getStoreInfoByEnuu({enUU : $rootScope.userInfo.enterprise.uu}, function(data) {
|
|
|
+ $scope.storeInfo = data;
|
|
|
+ if(!data.uuid || data.storeName.indexOf('优软测试二') > -1 || data.storeName.indexOf('优软商城') > -1) {
|
|
|
+ $scope.batch.sellType = 'UAS';
|
|
|
+ $scope.batch.selfSellEabled = false;
|
|
|
+ }else {
|
|
|
+ $scope.batch.sellType = 'self';
|
|
|
+ $scope.batch.selfSellEabled = true;
|
|
|
+ }
|
|
|
+ var selfSale = ($scope.storeInfo.uuid != 'undefind' && $scope.storeInfo.uuid !== '33069557578d44e69bd91ad12d28a8d4' && ($scope.storeInfo.storeName && $scope.storeInfo.storeName.indexOf('优软测试二') < 0 && $scope.storeInfo.storeName.indexOf('优软商城') < 0)) ? 1: 0
|
|
|
+ $scope.Regul.dateArea = selfSale === 1 ? 'formMe' : 'autoMonth' // 自营还是销售
|
|
|
+ // 销售方式
|
|
|
+
|
|
|
+ $scope.Regul.selfSale = selfSale
|
|
|
+ }, function(response) {
|
|
|
+ toaster.pop('error', '获取店铺的信息失败, ' + response.data);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // 品牌change事件
|
|
|
+ $scope.onBrandChange = function(brand, index) {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ $scope.objError.pbranden = false
|
|
|
+ if (index === undefined) {
|
|
|
+ if (brand === '') {
|
|
|
+ $scope.Regul.BrandList = []
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ $scope.Regul.BrandList = $scope.getSimilarBrands(brand).$$state
|
|
|
+ } else {
|
|
|
+ if (brand && getRealLen(brand) > 50) {
|
|
|
+ $scope.replaceMaterialList[index].ptrBranden = cutOutString(brand,
|
|
|
+ 50);
|
|
|
+ } else if ((/[^\x00-\xff]/g).test(brand)) {
|
|
|
+ var chineseIndex = -1;
|
|
|
+ for (var i = 0; i < brand.length; i++) {
|
|
|
+ if ((/[^\x00-\xff]/g).test(brand.charAt(i))
|
|
|
+ && !(/[\u4e00-\u9fa5]/).test(brand.charAt(i))) {
|
|
|
+ chineseIndex = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (chineseIndex > -1) {
|
|
|
+ $scope.replaceMaterialList[index].ptrBranden = brand.substring(0,
|
|
|
+ chineseIndex);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!brand) {
|
|
|
+ $scope.setShowSimilarBrandList(false, index);
|
|
|
+ } else {
|
|
|
+ $scope.getSimilarBrand(brand, index);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.RegulKindBlur = function() {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ $scope.objError.kind = false
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 物料编辑品牌输入框失去焦点
|
|
|
+ *
|
|
|
+ * @param name 品牌名称
|
|
|
+ */
|
|
|
+ $scope.RegulonBrandBlur = function(name) {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ // setTimeout(function() {
|
|
|
+ if (name === '') {
|
|
|
+ $scope.Regul.BrandList = []
|
|
|
+ } else {
|
|
|
+ $scope.Regul.pbranden = $scope.Regul.BrandList && $scope.Regul.BrandList.value && $scope.Regul.BrandList.value[0].nameEn || name
|
|
|
+ $scope.Regul.BrandList = []
|
|
|
+ }
|
|
|
+ // }, 300)
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.stopMounseDown = function(e) {
|
|
|
+ var _e = e || window.event
|
|
|
+ _e.preventDefault()
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.setBrand = function(brand, index) {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ if (index === undefined) {
|
|
|
+ $scope.Regul.pbranden = brand
|
|
|
+ $scope.Regul.BrandList = []
|
|
|
+ } else {
|
|
|
+ $scope.replaceMaterialList[index].ptrBranden = brand;
|
|
|
+ $scope.setShowSimilarBrandList(false, index);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取品牌联想词
|
|
|
+ $scope.getSimilarBrands = function(keyword) {
|
|
|
+ if (keyword) {
|
|
|
+ return Search.getSimilarBrands({
|
|
|
+ keyword: keyword
|
|
|
+ }).$promise.then(function(data) {
|
|
|
+ return data.map(function(item) {
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ;
|
|
|
+
|
|
|
+ $scope.onCodeChange = function(code, index) {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ $scope.objError.pcmpcode = false
|
|
|
+ if (index === undefined) {
|
|
|
+ if (code === '') {
|
|
|
+ $scope.Regul.CodeList = []
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if ((/[^\x00-\xff]/g).test(code)) {
|
|
|
+ $scope.Regul.pcmpcode = ''
|
|
|
+ $scope.Regul.CodeList = []
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ $scope.Regul.CodeList = getSimilarCode(code).$$state
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 编辑物料型号输入框失去焦点
|
|
|
+ *
|
|
|
+ * @param name 型号名称
|
|
|
+ */
|
|
|
+ $scope.RegulonCodeBlur = function(name) {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ if (name === '') {
|
|
|
+ $scope.Regul.CodeList = []
|
|
|
+ } else {
|
|
|
+ $scope.Regul.pcmpcode = $scope.Regul.CodeList.value && $scope.Regul.CodeList.value[0].pcmpcode || name
|
|
|
+ $scope.Regul.pbranden = $scope.Regul.CodeList.value && $scope.Regul.CodeList.value[0].pbranden || $scope.Regul.pbranden
|
|
|
+ $scope.Regul.spec = $scope.Regul.CodeList.value && $scope.Regul.CodeList.value[0].pbranden || $scope.Regul.spec
|
|
|
+ $scope.Regul.kind = $scope.Regul.CodeList.value && $scope.Regul.CodeList.value[0].pbranden || $scope.Regul.kind
|
|
|
+ $scope.Regul.CodeList = []
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $scope.setCode = function(code, index) {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ $scope.Regul.pcmpcode = code.pcmpcode
|
|
|
+
|
|
|
+ $scope.Regul.pbranden = code.pbranden
|
|
|
+ $scope.Regul.spec = code.spec
|
|
|
+ $scope.Regul.kind = code.kind
|
|
|
+ $scope.Regul.CodeList = []
|
|
|
+ }
|
|
|
+
|
|
|
+ var countLength = function(string) {
|
|
|
+ return string.replace(/[^\x00-\xff]/g, '**').length;
|
|
|
+ };
|
|
|
+ /**
|
|
|
+ * 获取型号联想词
|
|
|
+ *
|
|
|
+ * @param name 品牌名称
|
|
|
+ */
|
|
|
+ function getSimilarCode(name) {
|
|
|
+ if (name) {
|
|
|
+ return Material.getSimilarComponents({keyword: name}).$promise.then(
|
|
|
+ function (data) {
|
|
|
+ console.log(data)
|
|
|
+ return data.map(function (item) {
|
|
|
+ return item;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var cutOutString = function(str, length) {
|
|
|
+ for (var i = 1; i <= str.length; i++) {
|
|
|
+ if (countLength(str.substr(0, i)) > length) {
|
|
|
+ str = str.substr(0, i - 1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return str;
|
|
|
+ };
|
|
|
+
|
|
|
+ $scope.showClickText = function(goods, item) {
|
|
|
+ goods.packaging = item;
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.setPriceMinPackAmount = function(num) {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ if (num && num.indexOf('.') > -1) {
|
|
|
+ toaster.pop('warning', '提示', '最小包装数不能存在小数点')
|
|
|
+ $scope.Regul.minPackQty = 1
|
|
|
+ } else {
|
|
|
+ $scope.Regul.minPackQty = num
|
|
|
+ }
|
|
|
+ $scope.objError.minPackQty = false
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $scope.setReserve = function(num) {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ if (num && num.indexOf('.') > -1) {
|
|
|
+ toaster.pop('warning', '提示', '库存数量不能存在小数点')
|
|
|
+ $scope.Regul.reserve = 1
|
|
|
+ } else {
|
|
|
+ $scope.Regul.reserve = num
|
|
|
+ }
|
|
|
+ $scope.objError.reserve = false
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.setOnePrice = function(num) {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ $scope.Regul.OnePrice = num
|
|
|
+ $scope.objError.OnePrice = false
|
|
|
+ }
|
|
|
+ // 修改规格书
|
|
|
+ $scope.onUploadSuccess = function(data) {
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ $scope.Regul.Regulpic = data.path;
|
|
|
+ $scope.Regul.Ischange = true
|
|
|
+ };
|
|
|
+
|
|
|
+ // 删除规格书
|
|
|
+ $scope.deleteRegulImg = function(pom) {
|
|
|
+ $scope.Regul[pom] = 'static/img/vendor/images/upload.png'
|
|
|
+ $scope.Regul.Ischange = false
|
|
|
+ }
|
|
|
+
|
|
|
+ // 修改物料图片
|
|
|
+ $scope.onUploadSuccessProduct = function(data) {
|
|
|
+ $scope.Regul.RegulImg = data.path;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*查看大图*/
|
|
|
+ $scope.showImg = function(imgUrl, event) {
|
|
|
+ console.log(1)
|
|
|
+ var src = imgUrl, box = $('#image-box'), modal = $('.modal-content');
|
|
|
+ box.show();
|
|
|
+ box.find('img').attr('src', src);
|
|
|
+ box.find('a').click(function(){
|
|
|
+ box.hide();
|
|
|
+ });
|
|
|
+ box.dblclick(function(){
|
|
|
+ box.hide();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最小起订量修改 梯度1的值等于最小起订量
|
|
|
+ $scope.ProductupdateStartNumber = function(productUpOff) {
|
|
|
+ if (parseInt(productUpOff) >= parseInt($scope.Regul.prices[0].start)) {
|
|
|
+ $scope.Regul.prices[0].start = $scope.Regul.minPackQty
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ $scope.Regul.prices[0].start = parseInt(productUpOff)
|
|
|
+ }
|
|
|
+ // 最小起订量失去焦点
|
|
|
+ $scope.ProductblurMinBuyQty = function(MinBuyQty) {
|
|
|
+ if (!MinBuyQty) return
|
|
|
+ if (!$scope.Regul.minBuyQty || $scope.Regul.minBuyQty === '') {
|
|
|
+ toaster.pop('warning', '提示', '最小包装数未编辑导致无法上架');
|
|
|
+ return
|
|
|
+ }
|
|
|
+ $rootScope.singleEntryInfo = true
|
|
|
+ if (!$scope.Regul.breakUp && $scope.Regul.minBuyQty !== $scope.Regul.minPackQty) {
|
|
|
+ if ($scope.Regul.minBuyQty % $scope.Regul.minPackQty !== 0) {
|
|
|
+ $scope.Regul.minBuyQty = $scope.Regul.minPackQty
|
|
|
+ toaster.pop('warning', '提示', '不可拆卖时,起订量必须是包装数量的倍数');
|
|
|
+ $scope.ProductupdateStartNumber($scope.Regul.minBuyQty)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param min 最小值
|
|
|
+ * @param max 最大值
|
|
|
+ * @param isMin 传入的是否是最小值
|
|
|
+ * @param commodity 批次信息
|
|
|
+ */
|
|
|
+ $scope.isInt = /^[0-9]*[1-9][0-9]*$/;
|
|
|
+ $scope.changeDelivery = function(min, max, isMin) {
|
|
|
+ var day = -1;
|
|
|
+ if (isMin) {
|
|
|
+ if (min && $scope.isInt.test(min)) {
|
|
|
+ day = min;
|
|
|
+ } else {
|
|
|
+ if (typeof min == 'undefined') {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!$scope.isInt.test(min)) {
|
|
|
+ toaster.pop('warning', '提示', '交期请输入1-999的整数');
|
|
|
+ $scope.objError.minDelivery = true;
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (max && $scope.isInt.test(max)) {
|
|
|
+ day = max;
|
|
|
+ } else {
|
|
|
+ if (typeof max == 'undefined') {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!$scope.isInt.test(max)) {
|
|
|
+ toaster.pop('warning', '提示', '交期只能填写1-999之间的整数值');
|
|
|
+ $scope.objError.maxDelivery = true;
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (day > 999 || day < 1) {
|
|
|
+ if (isMin) {
|
|
|
+ $scope.objError.minDelivery = true;
|
|
|
+ } else {
|
|
|
+ $scope.objError.maxDelivery = true;
|
|
|
+ }
|
|
|
+ toaster.pop('warning', '提示', '交期的值必须在1-999天');
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (Number(min) > Number(max)) {
|
|
|
+ $scope.objError.minDelivery = true;
|
|
|
+ $scope.objError.maxDelivery = true;
|
|
|
+ toaster.pop('warning', '提示', '最短交期应小于等于最长交期');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $scope.objError.minDelivery = false;
|
|
|
+ $scope.objError.maxDelivery = false;
|
|
|
+ }
|
|
|
+ ;
|
|
|
+
|
|
|
+ // 可拆卖 上下架开关
|
|
|
+ $scope.productToggleIsBreadUp = function(pom) {
|
|
|
+ $scope.Regul[pom] = !$scope.Regul[pom]
|
|
|
+ if (pom === 'breakUp') {
|
|
|
+ // 重置最小起订量
|
|
|
+ $scope.ProductblurMinBuyQty($scope.Regul.minBuyQty)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 选择寄售还是自营
|
|
|
+ $scope.productChangeSelfType = function(num, _type) {
|
|
|
+ if ((!$scope.storeInfo.uuid || $scope.storeInfo.uuid === '33069557578d44e69bd91ad12d28a8d4') && _type === 'formMe'){
|
|
|
+ toaster.pop('warning','提示','您还未开店铺,不能选择自营')
|
|
|
+ $scope.Regul.dateArea = 'autoMonth'
|
|
|
+ return
|
|
|
+ }
|
|
|
+ $scope.Regul.dateArea = _type
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断价格是否合理,只设置验证的结果
|
|
|
+ * @param prices 分段价格
|
|
|
+ * @param price 对应的价格
|
|
|
+ * @param index 索引
|
|
|
+ */
|
|
|
+ $scope.changePrices = function(prices, price, index) {
|
|
|
+ prices[index].priceInvalid = false;
|
|
|
+ if (!prices || !prices[index] || !price) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isNaN(price)) {
|
|
|
+ prices[index].priceInvalid = true;
|
|
|
+ toaster.pop('warning', '提示', '单价必须是大于0的数字');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (new Number(price) <= 0) {
|
|
|
+ prices[index].priceInvalid = true;
|
|
|
+ toaster.pop('warning', '提示', '单价必须是大于0的数字');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (price.toString().indexOf('.') > -1) {
|
|
|
+ var arr = price.toString().split(".");
|
|
|
+ if (arr[0].length > 4 || arr[1].length > 6) {
|
|
|
+ prices[index].priceInvalid = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (price.toString().toString().length > 4) {
|
|
|
+ prices[index].priceInvalid = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ;
|
|
|
+ /**
|
|
|
+ * 删除对应的分段.
|
|
|
+ * @param commodity
|
|
|
+ */
|
|
|
+ $scope.productDeleteFragment = function(goods, index) {
|
|
|
+ if (index > -1 && index < goods.length) {
|
|
|
+ if (goods.length < 2) {
|
|
|
+ toaster.pop('warning', "提示", "商品至少需要一个分段");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var price = goods.splice(index, 1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增加对应的分段。
|
|
|
+ * @param commodity
|
|
|
+ */
|
|
|
+ $scope.productAddFragment = function(goods) {
|
|
|
+ if (goods.length > 2) {
|
|
|
+ toaster.pop('warning', "提示", "商品最多只能有三个分段");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ goods.push({rMBPrice: '', start: ''})
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 分段失去焦点。
|
|
|
+ * @param commodity
|
|
|
+ */
|
|
|
+ $scope.productPriceInfoBlur = function(index, val) {
|
|
|
+ if (index > 0) {
|
|
|
+ if ($scope.Regul.prices[index].start <= $scope.Regul.prices[index - 1].start) {
|
|
|
+ toaster.pop('warning', '提示', '输入值会导致梯度重叠,请重新修改')
|
|
|
+ $scope.Regul.prices[index].start = ''
|
|
|
+ return
|
|
|
+ }
|
|
|
+ $scope.Regul.prices[index].start = val
|
|
|
+ } else {
|
|
|
+ $scope.Regul.prices[index].start = val
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // $scope.objError = {
|
|
|
+ // pbranden: false,
|
|
|
+ // kind: false,
|
|
|
+ // pcmpcode: false,
|
|
|
+ // spec: false,
|
|
|
+ // minDelivery: false,
|
|
|
+ // maxDelivery: false
|
|
|
+ // minBuyQty: false
|
|
|
+ // }
|
|
|
+ // 编辑上下架保存按钮
|
|
|
+ $scope.productSave = function() {
|
|
|
+ initError()
|
|
|
+
|
|
|
+ if ($scope.Regul.pbranden === '' || !$scope.Regul.pbranden) {
|
|
|
+ toaster.pop('warning','提示', '品牌为必填项')
|
|
|
+ $scope.objError.pbranden = true
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ($scope.Regul.kind === '' || !$scope.Regul.kind) {
|
|
|
+ toaster.pop('warning','提示', '物料名称为必填项')
|
|
|
+ $scope.objError.kind = true
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ($scope.Regul.pcmpcode === '' || !$scope.Regul.pcmpcode) {
|
|
|
+ toaster.pop('warning','提示', '型号为必填项')
|
|
|
+ $scope.objError.pcmpcode = true
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ($scope.Regul.reserve === '' || !$scope.Regul.reserve) {
|
|
|
+ toaster.pop('warning','提示', '库存数量不能为空')
|
|
|
+ $scope.objError.reserve = true
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($scope.Regul.reserve <= 0) {
|
|
|
+ toaster.pop('warning','提示', '库存数量必须大于等于1')
|
|
|
+ $scope.objError.reserve = true
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (/\D/.test($scope.Regul.reserve)) {
|
|
|
+ toaster.pop('warning','提示', '库存数量只能为正整数')
|
|
|
+ $scope.objError.reserve = true
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($scope.Regul.minPackQty && /\D/.test($scope.Regul.minPackQty)) {
|
|
|
+ toaster.pop('warning','提示', '最小包装数输入不正确')
|
|
|
+ $scope.objError.minPackQty = true
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($scope.Regul.OnePrice && !/^\d+(\.\d+)?$/.test($scope.Regul.OnePrice.trim())) {
|
|
|
+ toaster.pop('warning','提示', '成本单价输入不正确')
|
|
|
+ $scope.objError.OnePrice = true
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$scope.Regul.minBuyQty || $scope.Regul.minBuyQty === 0) {
|
|
|
+ toaster.pop('warning','提示', '最小起订量必须是大于0的数字')
|
|
|
+ $scope.objError.minBuyQty = true
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!$scope.Regul.minDelivery || !$scope.Regul.maxDelivery) {
|
|
|
+ toaster.pop('warning','提示', '交期不能为空')
|
|
|
+ if (!$scope.Regul.minDelivery) {
|
|
|
+ $scope.objError.minDelivery = true
|
|
|
+ }
|
|
|
+ if (!$scope.Regul.maxDelivery) {
|
|
|
+ $scope.objError.maxDelivery = true
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if ($scope.Regul.minDelivery > $scope.Regul.maxDelivery) {
|
|
|
+ toaster.pop('warning','提示','最小交期不能大于最大交期')
|
|
|
+ $scope.objError.minDelivery = true
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var flag = true
|
|
|
+ for (var i = 0; i < $scope.Regul.prices.length; i++) {
|
|
|
+ // if (!$scope.Regul.prices[i].start
|
|
|
+ // || !$scope.Regul.prices[i].rMBPrice && $scope.storeInfo.enType !== 'HK' ) {
|
|
|
+ // toaster.pop('warning', '提示', '价格梯度不能为空')
|
|
|
+ // flag = false
|
|
|
+ // $scope.Regul.prices[i].priceInvalid = true
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // else if (!$scope.Regul.prices[i].start
|
|
|
+ // || !$scope.Regul.prices[i].uSDPrice && $scope.storeInfo.enType === 'HK') {
|
|
|
+ // toaster.pop('warning', '提示', '价格梯度不能为空')
|
|
|
+ // flag = false
|
|
|
+ // $scope.Regul.prices[i].priceInvalid = true
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ if ($scope.Regul.prices[i + 1] && Number($scope.Regul.prices[i].start) > Number($scope.Regul.prices[i + 1].start)) {
|
|
|
+ toaster.pop('warning','提示','输入值会导致梯度重叠,请重新修改')
|
|
|
+ flag = false
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!flag) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if ($scope.Regul.prices.length === 1) {
|
|
|
+ if ($scope.storeInfo.enType === 'HK') {
|
|
|
+ $scope.Regul.prices[0].uSDNTPrice = ''
|
|
|
+ $scope.Regul.prices[0].end = '999999999'
|
|
|
+ }else {
|
|
|
+ $scope.Regul.prices[0].rMBNTPrice = ''
|
|
|
+ $scope.Regul.prices[0].end = '999999999'
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (var i = 0; i < $scope.Regul.prices.length; i++) {
|
|
|
+ if ($scope.storeInfo.enType === 'HK') {
|
|
|
+ $scope.Regul.prices[i].uSDNTPrice = ''
|
|
|
+ $scope.Regul.prices[i].end = '999999999'
|
|
|
+ }else {
|
|
|
+ $scope.Regul.prices[i].rMBNTPrice = ''
|
|
|
+ $scope.Regul.prices[i].end = '999999999'
|
|
|
+ }
|
|
|
+ if ($scope.Regul.prices[i + 1]) {
|
|
|
+ $scope.Regul.prices[i].end = parseInt(
|
|
|
+ $scope.Regul.prices[i + 1].start) - 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先判断是自营店铺 还是 寄售店铺
|
|
|
+ // var _selfSale = $scope.productUpOff.goods.selfSale
|
|
|
+ if ($scope.storeInfo.uuid !== '33069557578d44e69bd91ad12d28a8d4') { // 如果是自营店铺
|
|
|
+ if ($scope.Regul.dateArea === 'formMe') { // 用户选择了自营
|
|
|
+ $scope.Regul.selfSale = 1
|
|
|
+ } else if ($scope.Regul.dateArea === 'autoMonth') { // 用户选择了寄售
|
|
|
+ $scope.Regul.selfSale = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var jsonObject = {
|
|
|
+ isPcb: $rootScope.isPcbStore ? 1 : 0,
|
|
|
+ goods: {},
|
|
|
+ product: {}
|
|
|
+ }
|
|
|
+ jsonObject.product = {
|
|
|
+ spec: $scope.Regul.spec, // 规格
|
|
|
+ minPackQty: $scope.Regul.minPackQty, // 最小包装量
|
|
|
+ erpReserve: $scope.Regul.reserve, //库存
|
|
|
+ cmpCode: $scope.Regul.pcmpcode, //型号
|
|
|
+ brand: $scope.Regul.pbranden,//品牌
|
|
|
+ prodName: $scope.Regul.kind, // 名称
|
|
|
+ price: $scope.Regul.OnePrice, // 成本单价
|
|
|
+ attachment: $scope.Regul.Ischange ? $scope.Regul.Regulpic : '', // 规格书
|
|
|
+ cmpImg: $scope.Regul.RegulImg !== $scope.Regul.iniUrlImg ? $scope.Regul.RegulImg : '',// 图片
|
|
|
+ packaging: $scope.Regul.packaging // 包装方式
|
|
|
+ }
|
|
|
+ jsonObject.goods = {
|
|
|
+ minBuyQty: $scope.Regul.minBuyQty, // 最小起订量
|
|
|
+ //分段报价信息
|
|
|
+ prices: $scope.Regul.prices,
|
|
|
+ breakUp: $scope.Regul.breakUp, // 是否拆卖
|
|
|
+ minDelivery: $scope.Regul.minDelivery, // 最短交期
|
|
|
+ maxDelivery: $scope.Regul.maxDelivery,// 最长交期
|
|
|
+ selfSale: $scope.Regul.selfSale, // 销售方式
|
|
|
+ }
|
|
|
+ $rootScope.singleEntryInfo = false
|
|
|
+ Material.importOneMaterail({}, jsonObject, function(data) {
|
|
|
+ if (data.code == 1) {
|
|
|
+ toaster.pop('success', '保存成功');
|
|
|
+ $scope.showProductInfo = true
|
|
|
+ } else {
|
|
|
+ toaster.pop('error', '失败', data.message);
|
|
|
+ }
|
|
|
+ }, function(response) {
|
|
|
+ toaster.pop('error', '失败', response.data);
|
|
|
+ });
|
|
|
+ // Goods.updateGoods(null, $scope.productUpOff.goods, function(data) {
|
|
|
+ // if (data.code == 1) {
|
|
|
+ // toaster.pop('success', '保存成功');
|
|
|
+ // loadData()
|
|
|
+ // } else {
|
|
|
+ // toaster.pop('error', '失败', data.message);
|
|
|
+ // }
|
|
|
+ // }, function(response) {
|
|
|
+ // toaster.pop('error', '失败', response.data);
|
|
|
+ // });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增物料
|
|
|
+ $scope.initProduct = function() {
|
|
|
+ resetPageInfo()
|
|
|
+ $scope.showProductInfo = false
|
|
|
+ }
|
|
|
+
|
|
|
+ // 取消编辑
|
|
|
+ $scope.clearCheckBox = function() {
|
|
|
+ if ($rootScope.singleEntryInfo === true ) {
|
|
|
+ if (confirm('是否放弃本次编辑')) {
|
|
|
+ $rootScope.singleEntryInfo = false
|
|
|
+ resetPageInfo()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ resetPageInfo()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 重置页面数据
|
|
|
+ function resetPageInfo() {
|
|
|
+ initInfo()
|
|
|
+ initError()
|
|
|
+ var selfSale = ($scope.storeInfo.uuid != 'undefind' && $scope.storeInfo.uuid !== '33069557578d44e69bd91ad12d28a8d4' && ($scope.storeInfo.storeName && $scope.storeInfo.storeName.indexOf('优软测试二') < 0 && $scope.storeInfo.storeName.indexOf('优软商城') < 0)) ? 1: 0
|
|
|
+ $scope.Regul.dateArea = selfSale === 1 ? 'formMe' : 'autoMonth' // 自营还是销售
|
|
|
+ // 销售方式
|
|
|
+ $scope.Regul.selfSale = selfSale
|
|
|
+ }
|
|
|
+
|
|
|
+ // document.addEventListener('click', function() {
|
|
|
+ // $scope.Regul.pcmpcode = $scope.Regul.CodeList&& $scope.Regul.CodeList.value && $scope.Regul.CodeList.value[0].code || name
|
|
|
+ // $scope.Regul.CodeList = []
|
|
|
+ // $scope.Regul.pbranden = $scope.Regul.BrandList && $scope.Regul.BrandList.value[0].nameEn
|
|
|
+ // $scope.Regul.BrandList = []
|
|
|
+ // }, false)
|
|
|
+
|
|
|
+
|
|
|
+ }])
|
|
|
+});
|