Browse Source

报价验证

yangc 8 years ago
parent
commit
cfc5c336b7

+ 3 - 0
src/main/webapp/resources/js/usercenter/controllers/forstore/seek_purchase_ctrl.js

@@ -33,6 +33,9 @@ define(['app/app'], function (app) {
 
           $scope.nowDate = new Date();
 
+          $scope.deadDate = new Date();
+          $scope.deadDate.setMonth($scope.deadDate.getMonth() + 3);
+
           $scope.checkCode = function () {
             $scope.validObj.code = $scope.applyObj.code && $scope.applyObj.code
                 !== '';

+ 74 - 31
src/main/webapp/resources/js/vendor/controllers/forstore/seek_purchase_ctrl.js

@@ -27,6 +27,7 @@ define(['app/app'], function (app) {
               seekPurchase.getSeekPushGoodsPageInfo(param, function (data) {
                 params.total(data.totalElements);
                 $defer.resolve(data.content);
+                $scope.seekListData = data.content;
               }, function (response) {
                 toaster.pop('error', response.data);
               });
@@ -39,16 +40,28 @@ define(['app/app'], function (app) {
           }
 
 
+
+          $scope.validOffer = {
+            unitPrice: false,
+            minDay: false,
+            maxDay: false
+            // produceDate: true
+          };
+
           /*
           * 输入价格校验
           * */
           $scope.onUnitPriceBlur = function () {
             if (angular.isNumber($scope.offer.unitPrice)) {
               if ($scope.offer.unitPrice < 0) {
-                 $scope.offer.unitPrice = 0;
+                toaster.pop('warning', '提示', '单价必须是大于0的数字');
+                $scope.validOffer.unitPrice = false;
+              } else {
+                $scope.validOffer.unitPrice = true;
               }
             } else {
-              $scope.offer.unitPrice = 0;
+              toaster.pop('warning', '提示', '单价必须是大于0的数字');
+              $scope.validOffer.unitPrice = false;
             }
           }
 
@@ -69,14 +82,14 @@ define(['app/app'], function (app) {
           }
 
           $scope.onMinDayInput = function () {
-            $scope.offer.minDay = Math.floor($scope.offer.minDay)
-            if ($scope.offer.maxDay && $scope.offer.maxDay < $scope.offer.minDay) {
-              $scope.offer.minDay = $scope.offer.maxDay;
-              toaster.pop('warning', '提示', '最短交期必须小于最长交期');
-            }
-            if ($scope.offer.minDay < 1 || $scope.offer.minDay > 31) {
-              $scope.offer.minDay = $scope.offer.minDay < 1 ? 1 : 31;
-              toaster.pop('warning', '提示', '交期只能填写1-31之间的值');
+            if ($scope.offer.minDay < 1 || $scope.offer.minDay > 31 || $scope.offer.minDay.toString().indexOf('.') !== -1) {
+              $scope.validOffer.minDay = false;
+              toaster.pop('warning', '提示', '交期只能填写1-31之间的整数值');
+            } else if ($scope.offer.maxDay && $scope.offer.maxDay < $scope.offer.minDay) {
+              $scope.validOffer.minDay = false;
+              toaster.pop('warning', '提示', '最短交期应小于等于最长交期');
+            } else {
+              $scope.validOffer.minDay = true;
             }
           };
 
@@ -87,13 +100,14 @@ define(['app/app'], function (app) {
           }
 
           $scope.onMaxDayInput = function () {
-            $scope.offer.maxDay = Math.floor($scope.offer.maxDay)
-            if ($scope.offer.minDay && $scope.offer.maxDay < $scope.offer.minDay) {
-              $scope.offer.maxDay = $scope.offer.minDay;
-              toaster.pop('warning', '提示', '最短交期必须小于最长交期');
-            } else if ($scope.offer.maxDay < 1 || $scope.offer.maxDay > 31) {
-              $scope.offer.maxDay = $scope.offer.maxDay < 1 ? 1 : 31;
-              toaster.pop('warning', '提示', '交期只能填写1-31之间的值');
+            if ($scope.offer.maxDay < 1 || $scope.offer.maxDay > 31 || $scope.offer.maxDay.toString().indexOf('.') !== -1) {
+              $scope.validOffer.maxDay = false;
+              toaster.pop('warning', '提示', '交期只能填写1-31之间的整数值');
+            } else if ($scope.offer.minDay && $scope.offer.maxDay < $scope.offer.minDay) {
+              $scope.validOffer.maxDay = false;
+              toaster.pop('warning', '提示', '最短交期应小于等于最长交期');
+            } else {
+              $scope.validOffer.maxDay = true;
             }
           }
 
@@ -121,19 +135,44 @@ define(['app/app'], function (app) {
             }
           }
 
+          $scope.checkAllOffer = function () {
+            return $scope.validOffer.unitPrice && $scope.validOffer.minDay && $scope.validOffer.maxDay;
+          }
+
           // 保存报价
           $scope.saveOffer = function (seek) {
-            seekPurchase.saveOffer($scope.offer, function (data) {
-              if (data.success) {
-                $scope.setSeekActive(seek, false);
-                $scope.seekPurchaseTableParams.reload();
-                toaster.pop('success', '报价成功');
-              } else {
-                toaster.pop('error', data.message);
+            if ($scope.checkAllOffer()) {
+              seekPurchase.saveOffer($scope.offer, function (data) {
+                if (data.success) {
+                  $scope.setSeekActive(seek, false);
+                  $scope.seekPurchaseTableParams.reload();
+                  toaster.pop('success', '报价成功');
+                } else {
+                  toaster.pop('error', data.message);
+                }
+              }, function (res) {
+                toaster.pop('error', res.data);
+              });
+            } else {
+              if (!$scope.validOffer.unitPrice) {
+                if (!$scope.offer.unitPrice) {
+                  toaster.pop('warning', '提示', '单价不能为空');
+                } else {
+                  toaster.pop('warning', '提示', '单价必须是大于0的数字');
+                }
+              } else if (!$scope.validOffer.minDay || !$scope.validOffer.maxDay) {
+                if (!$scope.offer.minDay || !$scope.offer.maxDay) {
+                  toaster.pop('warning', '提示', '交期不能为空');
+                } else {
+                  if ($scope.offer.minDay > 31 || $scope.offer.minDay < 1 || $scope.offer.minDay.toString().indexOf('.') !== -1
+                      || $scope.offer.maxDay > 31 || $scope.offer.maxDay < 1 || $scope.offer.maxDay.toString().indexOf('.') !== -1) {
+                    toaster.pop('warning', '提示', '交期只能填写1-31之间的整数值');
+                  } else {
+                    toaster.pop('warning', '提示', '最短交期应小于等于最长交期');
+                  }
+                }
               }
-            }, function (res) {
-              toaster.pop('error', res.data);
-            });
+            }
           }
 
           $scope.condition = {endDateOpen: false, startDateOpen: false};
@@ -214,12 +253,16 @@ define(['app/app'], function (app) {
 
           /*设置列表状态*/
           $scope.setSeekActive = function (seek, flag) {
-            seek.$active = flag;
-            console.info(seek);
             if (flag) {
-              $scope.offer.currency = seek.currency ? seek.currency : "RMB";
-              $scope.offer.spId = seek.spId;
+              angular.forEach($scope.seekListData, function (item) {
+                item.$active = false;
+              });
+              $scope.offer = {
+                currency: seek.currency ? seek.currency : "RMB",
+                spId: seek.spId
+              }
             }
+            seek.$active = flag;
           }
         }]);
 });

+ 3 - 2
src/main/webapp/resources/view/usercenter/forstore/seekPurchase.html

@@ -427,7 +427,8 @@
                            ng-class="{'error': !validObj.deadline}"
                            datepicker-popup="yyyy-MM-dd"
                            is-open="condition.deadlineOpen"
-                           min-date="nowDate" current-text="今天" clear-text="清除" close-text="关闭"
+                           min-date="nowDate" max-date="deadDate"
+                           current-text="今天" clear-text="清除" close-text="关闭"
                            ng-click="openDatePicker($event, condition, 'deadlineOpen',3)"
                            datepicker-options="{formatDayTitle: 'yyyy年M月', formatMonth: 'M月', showWeeks: false}"
                     />
@@ -439,7 +440,7 @@
                 <div class="form-block single-price">
                     <span>单价预算</span>
                     <select ng-model="applyObj.currency">
-                        <option value="RMB"></option>
+                        <option value="RMB">¥</option>
                         <option value="USD">$</option>
                     </select>
                     <input type="number" class="form-group" ng-class="{'error': !validObj.unitPrice}" ng-model="applyObj.unitPrice" ng-blur="checkUnitPrice()" ng-change="onUnitPriceInput()" >

+ 5 - 5
src/main/webapp/resources/view/vendor/forstore/seekPurchase.html

@@ -240,7 +240,7 @@
     }
     .seek-purchase .seek-purchase-content >table tbody tr.say-price td >div >div:nth-child(2) select {
         border: none;
-        padding-left: 3px;
+        padding-left: 9px;
         background: url(static/img/seekPurchase/select-arrow-down.png) no-repeat;
         background-position: 18px 9px;
     }
@@ -269,7 +269,7 @@
         display: inline-block;
         width: 32px;
         height: 26px;
-        padding: 6px;
+        padding: 0 6px;
     }
     .seek-purchase .seek-purchase-content >table tbody tr.say-price td >div >div:nth-child(4) {
         margin-right: 69px;
@@ -387,7 +387,7 @@
                     <th width="92">操作</th>
                 </tr>
             </thead>
-            <tbody ng-repeat="seek in $data" ng-class="{'active': seek.$active}">
+            <tbody ng-repeat="seek in seekListData" ng-class="{'active': seek.$active}">
                 <tr class="default-row">
                     <td class="release-time">
                         <span ng-bind="seek.releaseDate | date:'yyyy-MM-dd'"></span>
@@ -419,10 +419,10 @@
                             <div>
                                 <i>*</i>单价
                                 <select ng-if="!seek.currency" ng-init="offer.currency = 'RMB'" ng-model="offer.currency">
-                                    <option value="RMB"></option>
+                                    <option value="RMB">¥</option>
                                     <option value="USD">$</option>
                                 </select>
-                                <div ng-if="seek.currency" ng-model="offer.currency"></div>
+                                <div ng-if="seek.currency" ng-model="offer.currency">¥</div>
                                 <input type="number" class="form-control" ng-blur="onUnitPriceBlur()" ng-change="onUnitPriceChange()" ng-model="offer.unitPrice">
                             </div>
                             <div>