|
|
@@ -2,435 +2,513 @@
|
|
|
* Created by yujia on 2017/3/19.
|
|
|
* 求购的控制器
|
|
|
*/
|
|
|
-define(['app/app'], function(app) {
|
|
|
- 'use strict';
|
|
|
- app.register.controller('seekPurchaseCtrl', ['$scope', '$rootScope','seekPurchase','toaster','BaseService','ngTableParams', function($scope, $rootScope, seekPurchase, toaster, BaseService, ngTableParams) {
|
|
|
- $rootScope.active = 'seek_purchase';
|
|
|
- document.title = '我的求购-优软商城';
|
|
|
+define(['app/app'], function (app) {
|
|
|
+ 'use strict';
|
|
|
+ app.register.controller('seekPurchaseCtrl',
|
|
|
+ ['$scope', '$rootScope', 'seekPurchase', 'toaster', 'BaseService',
|
|
|
+ 'ngTableParams', 'Order', 'SessionService', '$filter',
|
|
|
+ function ($scope, $rootScope, seekPurchase, toaster, BaseService,
|
|
|
+ ngTableParams, Order, SessionService, $filter) {
|
|
|
+ $rootScope.active = 'seek_purchase';
|
|
|
+ document.title = '我的求购-优软商城';
|
|
|
+ var enIdFilter = $filter('EncryptionFilter');
|
|
|
|
|
|
+ $scope.applyObj = {
|
|
|
+ code: '',
|
|
|
+ brand: '',
|
|
|
+ unitPrice: '',
|
|
|
+ currency: 'RMB',
|
|
|
+ encapsulation: '',
|
|
|
+ produceDate: '',
|
|
|
+ amount: '',
|
|
|
+ deadline: ''
|
|
|
+ };
|
|
|
+ $scope.validObj = {
|
|
|
+ code: true,
|
|
|
+ brand: true,
|
|
|
+ unitPrice: true,
|
|
|
+ amount: true,
|
|
|
+ deadline: true
|
|
|
+ };
|
|
|
|
|
|
- $scope.applyObj = {
|
|
|
- code: '',
|
|
|
- brand: '',
|
|
|
- unitPrice: '',
|
|
|
- currency: 'RMB',
|
|
|
- encapsulation: '',
|
|
|
- produceDate: '',
|
|
|
- amount: '',
|
|
|
- deadline: ''
|
|
|
- };
|
|
|
- $scope.validObj = {
|
|
|
- code: true,
|
|
|
- brand: true,
|
|
|
- unitPrice: true,
|
|
|
- amount: true,
|
|
|
- deadline: true
|
|
|
- };
|
|
|
-
|
|
|
- $scope.checkCode = function () {
|
|
|
- $scope.validObj.code = $scope.applyObj.code && $scope.applyObj.code !== '';
|
|
|
- return this.validObj.code;
|
|
|
- }
|
|
|
- $scope.checkBrand = function () {
|
|
|
- $scope.validObj.brand = $scope.applyObj.brand && $scope.applyObj.brand !== '';
|
|
|
- return $scope.validObj.brand;
|
|
|
- }
|
|
|
- $scope.checkUnitPrice = function () {
|
|
|
- $scope.validObj.unitPrice = $scope.applyObj.unitPrice === '' ? true : $scope.applyObj.unitPrice > 0 && $scope.applyObj.unitPrice < 100000000;
|
|
|
- return $scope.validObj.unitPrice;
|
|
|
- }
|
|
|
- $scope.checkAmount = function () {
|
|
|
- $scope.validObj.amount = $scope.applyObj.amount === '' ? true : $scope.applyObj.amount > 0 && $scope.applyObj.amount < 100000000;
|
|
|
- return $scope.validObj.amount;
|
|
|
- }
|
|
|
- $scope.checkAll = function () {
|
|
|
- return $scope.checkCode() && $scope.checkBrand() && $scope.checkUnitPrice() && $scope.checkAmount() && $scope.checkDeadline();
|
|
|
- }
|
|
|
- $scope.checkDeadline = function () {
|
|
|
- $scope.validObj.deadline = $scope.applyObj.deadline && $scope.applyObj.deadline !== '';
|
|
|
- return $scope.validObj.deadline;
|
|
|
- }
|
|
|
- $scope.emptyForm = function () {
|
|
|
- for (var attr in $scope.applyObj) {
|
|
|
- $scope.applyObj[attr] = attr === 'currency' ? 'RMB' : '';
|
|
|
+ $scope.checkCode = function () {
|
|
|
+ $scope.validObj.code = $scope.applyObj.code && $scope.applyObj.code
|
|
|
+ !== '';
|
|
|
+ return this.validObj.code;
|
|
|
+ }
|
|
|
+ $scope.checkBrand = function () {
|
|
|
+ $scope.validObj.brand = $scope.applyObj.brand
|
|
|
+ && $scope.applyObj.brand !== '';
|
|
|
+ return $scope.validObj.brand;
|
|
|
+ }
|
|
|
+ $scope.checkUnitPrice = function () {
|
|
|
+ $scope.validObj.unitPrice = $scope.applyObj.unitPrice === '' ? true
|
|
|
+ : $scope.applyObj.unitPrice > 0 && $scope.applyObj.unitPrice
|
|
|
+ < 100000000;
|
|
|
+ return $scope.validObj.unitPrice;
|
|
|
+ }
|
|
|
+ $scope.checkAmount = function () {
|
|
|
+ $scope.validObj.amount = $scope.applyObj.amount === '' ? true
|
|
|
+ : $scope.applyObj.amount > 0 && $scope.applyObj.amount
|
|
|
+ < 100000000;
|
|
|
+ return $scope.validObj.amount;
|
|
|
+ }
|
|
|
+ $scope.checkAll = function () {
|
|
|
+ return $scope.checkCode() && $scope.checkBrand()
|
|
|
+ && $scope.checkUnitPrice() && $scope.checkAmount()
|
|
|
+ && $scope.checkDeadline();
|
|
|
+ }
|
|
|
+ $scope.checkDeadline = function () {
|
|
|
+ $scope.validObj.deadline = $scope.applyObj.deadline
|
|
|
+ && $scope.applyObj.deadline !== '';
|
|
|
+ return $scope.validObj.deadline;
|
|
|
}
|
|
|
- }
|
|
|
- // 发布求购
|
|
|
- $scope.release = function() {
|
|
|
+ $scope.emptyForm = function () {
|
|
|
+ for (var attr in $scope.applyObj) {
|
|
|
+ $scope.applyObj[attr] = attr === 'currency' ? 'RMB' : '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 发布求购
|
|
|
+ $scope.release = function () {
|
|
|
// 校验
|
|
|
- if ($scope.checkAll()) {
|
|
|
- seekPurchase.saveOneSeekPurchase($scope.applyObj, function (data) {
|
|
|
- $scope.showUseFlag = false;
|
|
|
- $scope.seekPurchaseTableParams.reload();
|
|
|
- $scope.emptyForm();
|
|
|
- toaster.pop('success', '求购发布成功');
|
|
|
- }, function (res) {
|
|
|
- toaster.pop('error', res.data);
|
|
|
- });
|
|
|
- } else {
|
|
|
- toaster.pop('error', '请输入正确的信息');
|
|
|
+ if ($scope.checkAll()) {
|
|
|
+ seekPurchase.saveOneSeekPurchase($scope.applyObj,
|
|
|
+ function (data) {
|
|
|
+ $scope.showUseFlag = false;
|
|
|
+ $scope.seekPurchaseTableParams.reload();
|
|
|
+ $scope.emptyForm();
|
|
|
+ toaster.pop('success', '求购发布成功');
|
|
|
+ }, function (res) {
|
|
|
+ toaster.pop('error', res.data);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ toaster.pop('error', '请输入正确的信息');
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- // 买家求购列表
|
|
|
- $scope.searchStatus = 0;
|
|
|
- $scope.seekPurchaseTableParams = new ngTableParams({
|
|
|
- page : 1,
|
|
|
- count : 10
|
|
|
- }, {
|
|
|
- total : 0,
|
|
|
- getData : function ($defer, params) {
|
|
|
- const param = BaseService.parseParams(params.url());
|
|
|
- param.isMallGoods = $scope.isMallGoods;
|
|
|
- param.deadline = $scope.deadline;
|
|
|
- param.keyWord = $scope.keyWord;
|
|
|
- param.status = $scope.searchStatus;
|
|
|
- param.minReleaseDate = $scope.startDate ? $scope.startDate.getTime() : null;
|
|
|
- param.maxReleaseDate = $scope.endDate ? $scope.endDate.getTime() : null;
|
|
|
- seekPurchase.getUserSeekPageInfo(param, function (data) {
|
|
|
- params.total(data.totalElements);
|
|
|
- $defer.resolve(data.content);
|
|
|
- $scope.seekListData = data;
|
|
|
- }, function (response) {
|
|
|
- toaster.pop('error', response.data);
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
+ // 立即购买
|
|
|
+ $scope.purchase = function (go, index) {
|
|
|
+ var goodsObj = {};
|
|
|
+ goodsObj.batchCode = go.batchCode;
|
|
|
+ goodsObj.currencyName = go.currencyName;
|
|
|
+ goodsObj.minPackQty = go.minPackQty;
|
|
|
+ goodsObj.number = $scope.fragments[index].num;
|
|
|
+ goodsObj.storeUuid = go.storeid;
|
|
|
+ goodsObj.storeid = go.storeid;
|
|
|
+ var goodsList = [];
|
|
|
+ goodsList.push(goodsObj);
|
|
|
+ if(go.minBuyQty > 0) {
|
|
|
+ var newWidow = window.open(rootPath + '/product#/cart');
|
|
|
+ // 1、生成订单
|
|
|
+ Order.buyNowInStore({spId: $scope.currentSeek.spId}, goodsList, function(data){
|
|
|
+ if(data.message) {
|
|
|
+ toaster.pop('info', data.message);
|
|
|
+ }
|
|
|
+ // 控制订单确认页,直接购买不显示进度条
|
|
|
+ SessionService.set("buyNow", true);
|
|
|
+ // 2、跳转到订单确认页面,进行付款操作
|
|
|
+ newWidow.location.href = rootPath + '/user#/order/pay/'+ enIdFilter(data.data.orderid);
|
|
|
+ }, function(res){
|
|
|
+ newWindow.close();
|
|
|
+ toaster.pop('error', '警告', res.data);
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ toaster.pop('warning', '提示', '该商品库存为0,请等待上货或咨询客服');
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- // 搜索
|
|
|
- $scope.onSearch = function(searchStatus){
|
|
|
- if (searchStatus) {
|
|
|
- $scope.searchStatus = searchStatus;
|
|
|
- }
|
|
|
- $scope.seekPurchaseTableParams.reload();
|
|
|
- }
|
|
|
+ // 买家求购列表
|
|
|
+ $scope.searchStatus = 0;
|
|
|
+ $scope.seekPurchaseTableParams = new ngTableParams({
|
|
|
+ page: 1,
|
|
|
+ count: 10
|
|
|
+ }, {
|
|
|
+ total: 0,
|
|
|
+ getData: function ($defer, params) {
|
|
|
+ const param = BaseService.parseParams(params.url());
|
|
|
+ param.isMallGoods = $scope.isMallGoods;
|
|
|
+ param.deadline = $scope.deadline;
|
|
|
+ param.keyWord = $scope.keyWord;
|
|
|
+ param.status = $scope.searchStatus;
|
|
|
+ param.minReleaseDate = $scope.startDate
|
|
|
+ ? $scope.startDate.getTime() : null;
|
|
|
+ param.maxReleaseDate = $scope.endDate ? $scope.endDate.getTime()
|
|
|
+ : null;
|
|
|
+ seekPurchase.getUserSeekPageInfo(param, function (data) {
|
|
|
+ params.total(data.totalElements);
|
|
|
+ $defer.resolve(data.content);
|
|
|
+ $scope.seekListData = data;
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', response.data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- // 采纳报价
|
|
|
- $scope.adopt = function (){
|
|
|
- seekPurchase.updateSeekPurchaseStatus({spId: $scope.currentOffer.spId, ofId: $scope.currentOffer.id, purchaseQuantity: $scope.purchaseQuantity},{}, function (data) {
|
|
|
- $scope.currentOffer = null;
|
|
|
- $scope.seekPurchaseTableParams.reload();
|
|
|
- $scope.showUseFlag = false;
|
|
|
- toaster.pop('success', '采纳报价成功');
|
|
|
- }, function (response) {
|
|
|
- toaster.pop('error', response.data);
|
|
|
- });
|
|
|
- }
|
|
|
+ // 搜索
|
|
|
+ $scope.onSearch = function (searchStatus) {
|
|
|
+ if (searchStatus) {
|
|
|
+ $scope.searchStatus = searchStatus;
|
|
|
+ }
|
|
|
+ $scope.seekPurchaseTableParams.reload();
|
|
|
+ }
|
|
|
|
|
|
- $scope.offerCount = 0;
|
|
|
- $scope.goodsCount = 0;
|
|
|
- $scope.setSeekStatus = function (seek, status) {
|
|
|
- $scope.offerCount = seek.offerAmount;
|
|
|
- $scope.goodsCount = seek.goodsAmount;
|
|
|
- // 查看报价
|
|
|
- if (status == 2 && $scope.offerCount != 0) {
|
|
|
- seekPurchase.getSeekPurchaseOfferPageInfo({count:100,page:1,spId:seek.spId},function(data) {
|
|
|
- $scope.offer = data.content;
|
|
|
- clearSeekStatus();
|
|
|
- seek.$status = status;
|
|
|
+ // 采纳报价
|
|
|
+ $scope.adopt = function () {
|
|
|
+ seekPurchase.updateSeekPurchaseStatus({
|
|
|
+ spId: $scope.currentOffer.spId,
|
|
|
+ ofId: $scope.currentOffer.id,
|
|
|
+ purchaseQuantity: $scope.purchaseQuantity
|
|
|
+ }, {}, function (data) {
|
|
|
+ $scope.currentOffer = null;
|
|
|
+ $scope.seekPurchaseTableParams.reload();
|
|
|
+ $scope.showUseFlag = false;
|
|
|
+ toaster.pop('success', '采纳报价成功');
|
|
|
+ }, function (response) {
|
|
|
+ toaster.pop('error', response.data);
|
|
|
});
|
|
|
- } else if (status == 1 && $scope.goodsCount != 0) {// 查看现货
|
|
|
- seekPurchase.getMallGoodsList({spId: seek.spId}, function(data) {
|
|
|
+ }
|
|
|
+
|
|
|
+ $scope.offerCount = 0;
|
|
|
+ $scope.goodsCount = 0;
|
|
|
+ $scope.currentSeek = {};
|
|
|
+ $scope.setSeekStatus = function (seek, status) {
|
|
|
+ $scope.offerCount = seek.offerAmount;
|
|
|
+ $scope.goodsCount = seek.goodsAmount;
|
|
|
+ $scope.currentSeek = seek;
|
|
|
+ // 查看报价
|
|
|
+ if (status == 2 && $scope.offerCount != 0) {
|
|
|
+ seekPurchase.getSeekPurchaseOfferPageInfo(
|
|
|
+ {count: 100, page: 1, spId: seek.spId}, function (data) {
|
|
|
+ $scope.offer = data.content;
|
|
|
+ clearSeekStatus();
|
|
|
+ seek.$status = status;
|
|
|
+ });
|
|
|
+ } else if (status == 1 && $scope.goodsCount != 0) {// 查看现货
|
|
|
+ seekPurchase.getMallGoodsList({spId: seek.spId}, function (data) {
|
|
|
$scope.goods = data;
|
|
|
clearSeekStatus();
|
|
|
initFragments();
|
|
|
seek.$status = status;
|
|
|
- });
|
|
|
- } else if (status == 0){ // 收起
|
|
|
- seek.$status = status;
|
|
|
+ });
|
|
|
+ } else if (status == 0) { // 收起
|
|
|
+ seek.$status = status;
|
|
|
+ }
|
|
|
+ $scope.selectAmount = 0;
|
|
|
+ $scope.selectPrice = 0;
|
|
|
}
|
|
|
- $scope.selectAmount = 0;
|
|
|
- $scope.selectPrice = 0;
|
|
|
- }
|
|
|
-
|
|
|
- var clearSeekStatus = function () {
|
|
|
- angular.forEach($scope.seekListData.content, function (item) {
|
|
|
- item.$status = 0;
|
|
|
- })
|
|
|
- }
|
|
|
|
|
|
- $scope.condition = {endDateOpen:false, startDateOpen: false, deadlineOpen: false};
|
|
|
- // 打开日期选择框
|
|
|
- $scope.openDatePicker = function ($event, item, openParam,status) {
|
|
|
- if (status != null) {
|
|
|
- if (status == 1) {
|
|
|
- if ($scope.startDate != null) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ var clearSeekStatus = function () {
|
|
|
+ angular.forEach($scope.seekListData.content, function (item) {
|
|
|
+ item.$status = 0;
|
|
|
+ })
|
|
|
}
|
|
|
- if (status == 2) {
|
|
|
- if ($scope.endDate != null) {
|
|
|
- return;
|
|
|
+
|
|
|
+ $scope.condition = {
|
|
|
+ endDateOpen: false,
|
|
|
+ startDateOpen: false,
|
|
|
+ deadlineOpen: false
|
|
|
+ };
|
|
|
+ // 打开日期选择框
|
|
|
+ $scope.openDatePicker = function ($event, item, openParam, status) {
|
|
|
+ if (status != null) {
|
|
|
+ if (status == 1) {
|
|
|
+ if ($scope.startDate != null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (status == 2) {
|
|
|
+ if ($scope.endDate != null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
+ $event.preventDefault();
|
|
|
+ $event.stopPropagation();
|
|
|
+ item[openParam] = !item[openParam];
|
|
|
+ if (openParam == 'startDateOpen') {
|
|
|
+ if (item['endDateOpen']) {
|
|
|
+ item['endDateOpen'] = !item['endDateOpen'];
|
|
|
+ }
|
|
|
+ } else if (openParam == 'endDateOpen') {
|
|
|
+ if (item['startDateOpen']) {
|
|
|
+ item['startDateOpen'] = !item['startDateOpen'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ $scope.changeEndDate = function () {
|
|
|
+ if ($scope.condition.endDateOpen) {
|
|
|
+ $scope.endDate = $scope.endDate.toString().replace(
|
|
|
+ /[0-9]{2}:[0-9]{2}:[0-9]{2}/g, '23:59:59');//;'23.59';//DateUtil.yyyyMmDd($scope.endDate.getTime() + 86399000);
|
|
|
+ $scope.endDate = new Date(
|
|
|
+ formatDateTime(new Date($scope.endDate.toString())));
|
|
|
+ }
|
|
|
+ $scope.vaildDate(false);
|
|
|
+ };
|
|
|
+ $scope.vaildDate = function (isStart) {
|
|
|
+ if ($scope.endDate !== null && $scope.startDate > $scope.endDate) {
|
|
|
+ if (isStart) {
|
|
|
+ alert("开始日期大于结束日期,请重新输入!");
|
|
|
+ $scope.startDate = null;
|
|
|
+ } else {
|
|
|
+ alert("开始日期大于结束日期,请重新输入!");
|
|
|
+ $scope.endDate = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ var formatDateTime = function (date) {
|
|
|
+ var y = date.getFullYear();
|
|
|
+ var m = date.getMonth() + 1;
|
|
|
+ m = m < 10 ? ('0' + m) : m;
|
|
|
+ var d = date.getDate();
|
|
|
+ d = d < 10 ? ('0' + d) : d;
|
|
|
+ var h = date.getHours();
|
|
|
+ var minute = date.getMinutes();
|
|
|
+ var sec = date.getSeconds();
|
|
|
+ minute = minute < 10 ? ('0' + minute) : minute;
|
|
|
+ return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + sec;
|
|
|
+ };
|
|
|
+ // 选择查找日期
|
|
|
+ $scope.onDateCondition = function () {
|
|
|
+ $scope.param.page = 1;
|
|
|
+ $scope.orderTableParams.page(1);
|
|
|
+ $scope.orderTableParams.reload();
|
|
|
+ };
|
|
|
+
|
|
|
+ /*获取时间戳代表的天数*/
|
|
|
+ $scope.getDay = function (timeStamp) {
|
|
|
+ return Math.floor(timeStamp / (1000 * 60 * 60 * 24));
|
|
|
}
|
|
|
- }
|
|
|
- $event.preventDefault();
|
|
|
- $event.stopPropagation();
|
|
|
- item[openParam] = !item[openParam];
|
|
|
- if (openParam == 'startDateOpen') {
|
|
|
- if (item['endDateOpen']) {
|
|
|
- item['endDateOpen'] = !item['endDateOpen'];
|
|
|
- }
|
|
|
- } else if (openParam == 'endDateOpen') {
|
|
|
- if (item['startDateOpen']){
|
|
|
- item['startDateOpen'] = !item['startDateOpen'];
|
|
|
- }
|
|
|
- }
|
|
|
- };
|
|
|
- $scope.changeEndDate = function () {
|
|
|
- if ($scope.condition.endDateOpen) {
|
|
|
- $scope.endDate = $scope.endDate.toString().replace(/[0-9]{2}:[0-9]{2}:[0-9]{2}/g, '23:59:59');//;'23.59';//DateUtil.yyyyMmDd($scope.endDate.getTime() + 86399000);
|
|
|
- $scope.endDate = new Date(formatDateTime(new Date($scope.endDate.toString())));
|
|
|
- }
|
|
|
- $scope.vaildDate(false);
|
|
|
- };
|
|
|
- $scope.vaildDate = function (isStart) {
|
|
|
- if ($scope.endDate !== null && $scope.startDate>$scope.endDate){
|
|
|
- if (isStart) {
|
|
|
- alert("开始日期大于结束日期,请重新输入!");
|
|
|
- $scope.startDate = null;
|
|
|
- } else {
|
|
|
- alert("开始日期大于结束日期,请重新输入!");
|
|
|
- $scope.endDate = null;
|
|
|
+ /*获取时间戳代表的小时*/
|
|
|
+ $scope.getHours = function (timeStamp) {
|
|
|
+ return Math.floor((timeStamp / (1000 * 60 * 60)) % 24);
|
|
|
}
|
|
|
- }
|
|
|
- };
|
|
|
- var formatDateTime = function (date) {
|
|
|
- var y = date.getFullYear();
|
|
|
- var m = date.getMonth() + 1;
|
|
|
- m = m < 10 ? ('0' + m) : m;
|
|
|
- var d = date.getDate();
|
|
|
- d = d < 10 ? ('0' + d) : d;
|
|
|
- var h = date.getHours();
|
|
|
- var minute = date.getMinutes();
|
|
|
- var sec = date.getSeconds();
|
|
|
- minute = minute < 10 ? ('0' + minute) : minute;
|
|
|
- return y + '-' + m + '-' + d+' '+h+':'+minute+':'+sec;
|
|
|
- };
|
|
|
- // 选择查找日期
|
|
|
- $scope.onDateCondition = function () {
|
|
|
- $scope.param.page = 1;
|
|
|
- $scope.orderTableParams.page(1);
|
|
|
- $scope.orderTableParams.reload();
|
|
|
- };
|
|
|
|
|
|
- /*获取时间戳代表的天数*/
|
|
|
- $scope.getDay = function (timeStamp) {
|
|
|
- return Math.floor(timeStamp / (1000 * 60 * 60 * 24));
|
|
|
- }
|
|
|
- /*获取时间戳代表的小时*/
|
|
|
- $scope.getHours = function (timeStamp) {
|
|
|
- return Math.floor((timeStamp / (1000 * 60 * 60)) % 24);
|
|
|
- }
|
|
|
+ /*
|
|
|
+ * input 校验
|
|
|
+ * */
|
|
|
+ $scope.fragments = [];
|
|
|
|
|
|
- /*
|
|
|
- * input 校验
|
|
|
- * */
|
|
|
- $scope.fragments = [];
|
|
|
- function initFragment (commodity) {
|
|
|
- if (!commodity) {
|
|
|
- return {};
|
|
|
- }
|
|
|
- var fragment = {};
|
|
|
- var prices = commodity.prices[0];
|
|
|
- fragment.num = commodity.minBuyQty;
|
|
|
- fragment.prices = prices;
|
|
|
+ function initFragment(commodity) {
|
|
|
+ if (!commodity) {
|
|
|
+ return {};
|
|
|
+ }
|
|
|
+ var fragment = {};
|
|
|
+ var prices = commodity.prices[0];
|
|
|
+ fragment.num = commodity.minBuyQty;
|
|
|
+ fragment.prices = prices;
|
|
|
|
|
|
- if (commodity.currencyName !== 'USD') {
|
|
|
- fragment.currency = 'RMB';
|
|
|
- } else {
|
|
|
- fragment.currency = 'USD';
|
|
|
- }
|
|
|
+ if (commodity.currencyName !== 'USD') {
|
|
|
+ fragment.currency = 'RMB';
|
|
|
+ } else {
|
|
|
+ fragment.currency = 'USD';
|
|
|
+ }
|
|
|
|
|
|
- if (fragment.currency !== 'USD') {
|
|
|
- fragment.price = prices.rMBPrice;
|
|
|
- } else {
|
|
|
- fragment.price = prices.uSDPrice;
|
|
|
- }
|
|
|
- fragment.canAdd = true;
|
|
|
- fragment.canSub = false;
|
|
|
- return fragment;
|
|
|
- }
|
|
|
- function initFragments() {
|
|
|
- angular.forEach($scope.goods, function (item) {
|
|
|
- $scope.fragments.push(initFragment(item));
|
|
|
- })
|
|
|
- }
|
|
|
- function getFragment (commodity, fragment) {
|
|
|
- // 判断是否小于第一分段的起订量
|
|
|
- if (commodity.prices[0].start > fragment.num) {
|
|
|
- fragment.num = commodity.prices[0].start;
|
|
|
- }
|
|
|
- // 获取分段的信息
|
|
|
- var prices = commodity.prices;
|
|
|
- for (var i = 0; i < prices.length; i++) {
|
|
|
- if (fragment.num <= prices[i].end) {
|
|
|
- fragment.prices = prices[i];
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $scope.onInput = function (index) {
|
|
|
- var prices = $scope.goods[index].prices;
|
|
|
- if (prices && prices.length) {
|
|
|
- for (var i = 0; i < prices.length; i++) {
|
|
|
- if ($scope.fragments[index].num >= prices[i].start && $scope.fragments[index].num <= prices[i].end) {
|
|
|
- $scope.fragments[index].price = $scope.fragments[index].currency === 'RMB' ? prices[i].rMBPrice : prices[i].uSDPrice;
|
|
|
- break;
|
|
|
+ if (fragment.currency !== 'USD') {
|
|
|
+ fragment.price = prices.rMBPrice;
|
|
|
+ } else {
|
|
|
+ fragment.price = prices.uSDPrice;
|
|
|
}
|
|
|
+ fragment.canAdd = true;
|
|
|
+ fragment.canSub = false;
|
|
|
+ return fragment;
|
|
|
}
|
|
|
- }
|
|
|
- if ($scope.goods[index].$checked) {
|
|
|
- var amount = 0;
|
|
|
- angular.forEach($scope.seekListData.content, function (item) {
|
|
|
- if (item.$status == 1) {
|
|
|
- amount = item.amount;
|
|
|
+
|
|
|
+ function initFragments() {
|
|
|
+ angular.forEach($scope.goods, function (item) {
|
|
|
+ $scope.fragments.push(initFragment(item));
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ function getFragment(commodity, fragment) {
|
|
|
+ // 判断是否小于第一分段的起订量
|
|
|
+ if (commodity.prices[0].start > fragment.num) {
|
|
|
+ fragment.num = commodity.prices[0].start;
|
|
|
+ }
|
|
|
+ // 获取分段的信息
|
|
|
+ var prices = commodity.prices;
|
|
|
+ for (var i = 0; i < prices.length; i++) {
|
|
|
+ if (fragment.num <= prices[i].end) {
|
|
|
+ fragment.prices = prices[i];
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- })
|
|
|
- if (amount > 0) {
|
|
|
- $scope.selectAmount = 0;
|
|
|
}
|
|
|
- $scope.selectPrice = 0;
|
|
|
- angular.forEach($scope.goods, function (item, index) {
|
|
|
- if (item.$checked) {
|
|
|
- if (amount > 0) {
|
|
|
- if (amount < $scope.selectAmount + $scope.fragments[index].num) {
|
|
|
- $scope.fragments[index].num = amount - $scope.selectAmount;
|
|
|
- } else {
|
|
|
- $scope.selectAmount += $scope.fragments[index].num;
|
|
|
+
|
|
|
+ $scope.onInput = function (index) {
|
|
|
+ var prices = $scope.goods[index].prices;
|
|
|
+ if (prices && prices.length) {
|
|
|
+ for (var i = 0; i < prices.length; i++) {
|
|
|
+ if ($scope.fragments[index].num >= prices[i].start
|
|
|
+ && $scope.fragments[index].num <= prices[i].end) {
|
|
|
+ $scope.fragments[index].price = $scope.fragments[index].currency
|
|
|
+ === 'RMB' ? prices[i].rMBPrice : prices[i].uSDPrice;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- $scope.selectPrice += $scope.fragments[index].num * $scope.fragments[index].price;
|
|
|
}
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- $scope.changeNum = function (newNum, index) {
|
|
|
- var pack = $scope.goods[index].perQty || $scope.goods[index].minPackQty;
|
|
|
- var buy = $scope.goods[index].minBuyQty;
|
|
|
- var reserve = $scope.goods[index].reserve;
|
|
|
- var breakUp = $scope.goods[index].breakUp;
|
|
|
- if (!newNum) {
|
|
|
- $scope.fragments[index].num = buy;
|
|
|
- } else {
|
|
|
- newNum = parseInt(newNum);
|
|
|
- if (breakUp) {
|
|
|
- if (newNum < buy) {
|
|
|
- // $scope.$message.error('最小起订量为' + buy)
|
|
|
- $scope.fragments[index].num = buy;
|
|
|
- $scope.fragments[index].canSub = false;
|
|
|
- $scope.fragments[index].canAdd = true;
|
|
|
- } else if (newNum > reserve) {
|
|
|
- // $scope.$message.error('库存不足')
|
|
|
- $scope.fragments[index].num = reserve;
|
|
|
- $scope.fragments[index].canAdd = false;
|
|
|
- $scope.fragments[index].canSub = true;
|
|
|
- } else {
|
|
|
- $scope.fragments[index].canSub = true;
|
|
|
- $scope.fragments[index].canAdd = true;
|
|
|
- $scope.fragments[index].num = newNum;
|
|
|
- newNum === buy && ($scope.fragments[index].canSub = false);
|
|
|
- newNum === reserve && ($scope.fragments[index].canAdd = false);
|
|
|
+ if ($scope.goods[index].$checked) {
|
|
|
+ var amount = 0;
|
|
|
+ angular.forEach($scope.seekListData.content, function (item) {
|
|
|
+ if (item.$status == 1) {
|
|
|
+ amount = item.amount;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (amount > 0) {
|
|
|
+ $scope.selectAmount = 0;
|
|
|
+ }
|
|
|
+ $scope.selectPrice = 0;
|
|
|
+ angular.forEach($scope.goods, function (item, index) {
|
|
|
+ if (item.$checked) {
|
|
|
+ if (amount > 0) {
|
|
|
+ if (amount < $scope.selectAmount
|
|
|
+ + $scope.fragments[index].num) {
|
|
|
+ $scope.fragments[index].num = amount
|
|
|
+ - $scope.selectAmount;
|
|
|
+ } else {
|
|
|
+ $scope.selectAmount += $scope.fragments[index].num;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $scope.selectPrice += $scope.fragments[index].num
|
|
|
+ * $scope.fragments[index].price;
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
- } else {
|
|
|
- if (newNum < buy) {
|
|
|
- // $scope.$message.error('最小起订量为' + buy)
|
|
|
+ }
|
|
|
+ $scope.changeNum = function (newNum, index) {
|
|
|
+ var pack = $scope.goods[index].perQty
|
|
|
+ || $scope.goods[index].minPackQty;
|
|
|
+ var buy = $scope.goods[index].minBuyQty;
|
|
|
+ var reserve = $scope.goods[index].reserve;
|
|
|
+ var breakUp = $scope.goods[index].breakUp;
|
|
|
+ if (!newNum) {
|
|
|
$scope.fragments[index].num = buy;
|
|
|
- $scope.fragments[index].canSub = false;
|
|
|
- if (newNum > reserve) {
|
|
|
- // $scope.$message.error('库存不足')
|
|
|
- $scope.fragments[index].num = reserve - (reserve % pack);
|
|
|
- $scope.fragments[index].canAdd = false;
|
|
|
- }
|
|
|
- } else if (newNum > reserve) {
|
|
|
- $scope.fragments[index].canSub = true;
|
|
|
- $scope.fragments[index].canAdd = false;
|
|
|
- // $scope.$message.error('库存不足')
|
|
|
- $scope.fragments[index].num = reserve - (reserve % pack);
|
|
|
} else {
|
|
|
- $scope.fragments[index].canSub = true;
|
|
|
- $scope.fragments[index].canAdd = true;
|
|
|
- var remainder = newNum % pack;
|
|
|
- if (remainder !== 0) {
|
|
|
- // $scope.$message.error('不支持拆包且包装量为' + pack)
|
|
|
- // 这个直接赋值的,应该给这个值进行判断(Math.floor(newNum / pack) + 1) * pack
|
|
|
- var res = (Math.floor(newNum / pack) + 1) * pack;
|
|
|
- $scope.fragments[index].num = res > reserve ? Math.floor(newNum / pack) * pack : res;
|
|
|
+ newNum = parseInt(newNum);
|
|
|
+ if (breakUp) {
|
|
|
+ if (newNum < buy) {
|
|
|
+ // $scope.$message.error('最小起订量为' + buy)
|
|
|
+ $scope.fragments[index].num = buy;
|
|
|
+ $scope.fragments[index].canSub = false;
|
|
|
+ $scope.fragments[index].canAdd = true;
|
|
|
+ } else if (newNum > reserve) {
|
|
|
+ // $scope.$message.error('库存不足')
|
|
|
+ $scope.fragments[index].num = reserve;
|
|
|
+ $scope.fragments[index].canAdd = false;
|
|
|
+ $scope.fragments[index].canSub = true;
|
|
|
+ } else {
|
|
|
+ $scope.fragments[index].canSub = true;
|
|
|
+ $scope.fragments[index].canAdd = true;
|
|
|
+ $scope.fragments[index].num = newNum;
|
|
|
+ newNum === buy && ($scope.fragments[index].canSub = false);
|
|
|
+ newNum === reserve
|
|
|
+ && ($scope.fragments[index].canAdd = false);
|
|
|
+ }
|
|
|
} else {
|
|
|
- $scope.fragments[index].num = newNum;
|
|
|
+ if (newNum < buy) {
|
|
|
+ // $scope.$message.error('最小起订量为' + buy)
|
|
|
+ $scope.fragments[index].num = buy;
|
|
|
+ $scope.fragments[index].canSub = false;
|
|
|
+ if (newNum > reserve) {
|
|
|
+ // $scope.$message.error('库存不足')
|
|
|
+ $scope.fragments[index].num = reserve - (reserve % pack);
|
|
|
+ $scope.fragments[index].canAdd = false;
|
|
|
+ }
|
|
|
+ } else if (newNum > reserve) {
|
|
|
+ $scope.fragments[index].canSub = true;
|
|
|
+ $scope.fragments[index].canAdd = false;
|
|
|
+ // $scope.$message.error('库存不足')
|
|
|
+ $scope.fragments[index].num = reserve - (reserve % pack);
|
|
|
+ } else {
|
|
|
+ $scope.fragments[index].canSub = true;
|
|
|
+ $scope.fragments[index].canAdd = true;
|
|
|
+ var remainder = newNum % pack;
|
|
|
+ if (remainder !== 0) {
|
|
|
+ // $scope.$message.error('不支持拆包且包装量为' + pack)
|
|
|
+ // 这个直接赋值的,应该给这个值进行判断(Math.floor(newNum / pack) + 1) * pack
|
|
|
+ var res = (Math.floor(newNum / pack) + 1) * pack;
|
|
|
+ $scope.fragments[index].num = res > reserve
|
|
|
+ ? Math.floor(newNum / pack) * pack : res;
|
|
|
+ } else {
|
|
|
+ $scope.fragments[index].num = newNum;
|
|
|
+ }
|
|
|
+ newNum === buy && ($scope.fragments[index].canSub = false);
|
|
|
+ newNum === reserve
|
|
|
+ && ($scope.fragments[index].canAdd = false);
|
|
|
+ }
|
|
|
}
|
|
|
- newNum === buy && ($scope.fragments[index].canSub = false);
|
|
|
- newNum === reserve && ($scope.fragments[index].canAdd = false);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- $scope.subNum = function (index) {
|
|
|
- if ($scope.fragments[index].canSub) {
|
|
|
- var pack = $scope.goods[index].perQty || $scope.goods[index].minPackQty;
|
|
|
- var newNum = 0;
|
|
|
- if ($scope.goods[index].breakUp) {
|
|
|
- newNum = $scope.fragments[index].num - 1;
|
|
|
- } else {
|
|
|
- newNum = $scope.fragments[index].num - pack;
|
|
|
+ $scope.subNum = function (index) {
|
|
|
+ if ($scope.fragments[index].canSub) {
|
|
|
+ var pack = $scope.goods[index].perQty
|
|
|
+ || $scope.goods[index].minPackQty;
|
|
|
+ var newNum = 0;
|
|
|
+ if ($scope.goods[index].breakUp) {
|
|
|
+ newNum = $scope.fragments[index].num - 1;
|
|
|
+ } else {
|
|
|
+ newNum = $scope.fragments[index].num - pack;
|
|
|
+ }
|
|
|
+ $scope.changeNum(newNum, index)
|
|
|
+ getFragment($scope.goods[index], $scope.fragments[index]);
|
|
|
+ $scope.onInput(index);
|
|
|
+ }
|
|
|
}
|
|
|
- $scope.changeNum(newNum, index)
|
|
|
- getFragment($scope.goods[index], $scope.fragments[index]);
|
|
|
- $scope.onInput(index);
|
|
|
- }
|
|
|
- }
|
|
|
- $scope.addNum = function (index) {
|
|
|
- if ($scope.fragments[index].canAdd) {
|
|
|
- var pack = $scope.goods[index].perQty || $scope.goods[index].minPackQty;
|
|
|
- var newNum = 0;
|
|
|
- if ($scope.goods[index].breakUp) {
|
|
|
- newNum = $scope.fragments[index].num + 1;
|
|
|
- } else {
|
|
|
- newNum = $scope.fragments[index].num + pack;
|
|
|
+ $scope.addNum = function (index) {
|
|
|
+ if ($scope.fragments[index].canAdd) {
|
|
|
+ var pack = $scope.goods[index].perQty
|
|
|
+ || $scope.goods[index].minPackQty;
|
|
|
+ var newNum = 0;
|
|
|
+ if ($scope.goods[index].breakUp) {
|
|
|
+ newNum = $scope.fragments[index].num + 1;
|
|
|
+ } else {
|
|
|
+ newNum = $scope.fragments[index].num + pack;
|
|
|
+ }
|
|
|
+ $scope.changeNum(newNum, index)
|
|
|
+ getFragment($scope.goods[index], $scope.fragments[index]);
|
|
|
+ $scope.onInput(index);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $scope.inputNum = function (index) {
|
|
|
+ if ((/^[\d]*$/).test($scope.fragments[index].num)) {
|
|
|
+ $scope.changeNum($scope.fragments[index].num, index);
|
|
|
+ getFragment($scope.goods[index], $scope.fragments[index]);
|
|
|
+ } else {
|
|
|
+ // $scope.$message.error('请输入整数')
|
|
|
+ $scope.fragments[index].num = $scope.goods[index].minBuyQty;
|
|
|
+ }
|
|
|
+ $scope.onInput(index);
|
|
|
}
|
|
|
- $scope.changeNum(newNum, index)
|
|
|
- getFragment($scope.goods[index], $scope.fragments[index]);
|
|
|
- $scope.onInput(index);
|
|
|
- }
|
|
|
- }
|
|
|
- $scope.inputNum = function (index) {
|
|
|
- if ((/^[\d]*$/).test($scope.fragments[index].num)) {
|
|
|
- $scope.changeNum($scope.fragments[index].num, index);
|
|
|
- getFragment($scope.goods[index], $scope.fragments[index]);
|
|
|
- } else {
|
|
|
- // $scope.$message.error('请输入整数')
|
|
|
- $scope.fragments[index].num = $scope.goods[index].minBuyQty;
|
|
|
- }
|
|
|
- $scope.onInput(index);
|
|
|
- }
|
|
|
-
|
|
|
- $scope.showUseFlag = false;
|
|
|
- $scope.setShowUseFlag = function (flag, offer) {
|
|
|
- if (flag) {
|
|
|
- $scope.currentOffer = offer;
|
|
|
- }
|
|
|
- $scope.showUseFlag = flag;
|
|
|
- }
|
|
|
|
|
|
- $scope.selectAmount = 0;
|
|
|
- $scope.selectPrice = 0;
|
|
|
- $scope.onSelectGoods = function (goods, seek, goodsIndex) {
|
|
|
- if (goods.$checked) {
|
|
|
- if (seek.amount) {
|
|
|
- if (seek.amount < $scope.selectAmount + $scope.fragments[goodsIndex].num) {
|
|
|
- goods.$checked = false;
|
|
|
- return;
|
|
|
+ $scope.showUseFlag = false;
|
|
|
+ $scope.setShowUseFlag = function (flag, offer) {
|
|
|
+ if (flag) {
|
|
|
+ $scope.currentOffer = offer;
|
|
|
}
|
|
|
- $scope.selectAmount += $scope.fragments[goodsIndex].num;
|
|
|
+ $scope.showUseFlag = flag;
|
|
|
}
|
|
|
- $scope.selectPrice += $scope.fragments[goodsIndex].num * $scope.fragments[goodsIndex].price;
|
|
|
- } else {
|
|
|
- if (seek.amount) {
|
|
|
- $scope.selectAmount -= $scope.fragments[goodsIndex].num;
|
|
|
+
|
|
|
+ $scope.selectAmount = 0;
|
|
|
+ $scope.selectPrice = 0;
|
|
|
+ $scope.onSelectGoods = function (goods, seek, goodsIndex) {
|
|
|
+ if (goods.$checked) {
|
|
|
+ if (seek.amount) {
|
|
|
+ if (seek.amount < $scope.selectAmount
|
|
|
+ + $scope.fragments[goodsIndex].num) {
|
|
|
+ goods.$checked = false;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $scope.selectAmount += $scope.fragments[goodsIndex].num;
|
|
|
+ }
|
|
|
+ $scope.selectPrice += $scope.fragments[goodsIndex].num
|
|
|
+ * $scope.fragments[goodsIndex].price;
|
|
|
+ } else {
|
|
|
+ if (seek.amount) {
|
|
|
+ $scope.selectAmount -= $scope.fragments[goodsIndex].num;
|
|
|
+ }
|
|
|
+ $scope.selectPrice -= $scope.fragments[goodsIndex].num
|
|
|
+ * $scope.fragments[goodsIndex].price;
|
|
|
+ }
|
|
|
}
|
|
|
- $scope.selectPrice -= $scope.fragments[goodsIndex].num * $scope.fragments[goodsIndex].price;
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- }]);
|
|
|
+ }]);
|
|
|
});
|