Authored by Aiden Xu

分期订单

@@ -22,6 +22,9 @@ var repayment = new Repayment({ @@ -22,6 +22,9 @@ var repayment = new Repayment({
22 22
23 return ret; 23 return ret;
24 }, 24 },
  25 + onGetSelectableCount: function() {
  26 + return $(CHECKBOX_SELECTOR).length;
  27 + },
25 onDeselectAll: function() { 28 onDeselectAll: function() {
26 $(CHECKBOX_SELECTOR + ':checked').prop('checked', false); 29 $(CHECKBOX_SELECTOR + ':checked').prop('checked', false);
27 return []; 30 return [];
@@ -76,3 +79,7 @@ $(CHECKBOX_SELECTOR + ':checkbox').click(function() { @@ -76,3 +79,7 @@ $(CHECKBOX_SELECTOR + ':checkbox').click(function() {
76 79
77 repayment.update(); 80 repayment.update();
78 }); 81 });
  82 +
  83 +
  84 +// 默认选择第一个
  85 +$(CHECKBOX_SELECTOR + ':checkbox:first').click();
@@ -8,6 +8,15 @@ var Repayment = function(options) { @@ -8,6 +8,15 @@ var Repayment = function(options) {
8 onDeselectAll: $.noop, 8 onDeselectAll: $.noop,
9 9
10 /** 10 /**
  11 + * 返回可选择数目
  12 + *
  13 + * @returns {number}
  14 + */
  15 + onGetSelectableCount: function() {
  16 + return 0;
  17 + },
  18 +
  19 + /**
11 * 获取选择 20 * 获取选择
12 * 21 *
13 * @returns {Array} 22 * @returns {Array}
@@ -116,11 +125,17 @@ Repayment.prototype.getSelection = function() { @@ -116,11 +125,17 @@ Repayment.prototype.getSelection = function() {
116 return this.settings.onGetSelection(); 125 return this.settings.onGetSelection();
117 }; 126 };
118 127
  128 +/**
  129 + * 更新组件并计算金额
  130 + */
119 Repayment.prototype.update = function() { 131 Repayment.prototype.update = function() {
120 var values = this.getSelection(); 132 var values = this.getSelection();
121 var $repaymentBottom = $('.repayment-bottom'); 133 var $repaymentBottom = $('.repayment-bottom');
122 var self = this; 134 var self = this;
123 135
  136 + // 是否选择全部
  137 + var totalCheck = this.settings.onGetSelectableCount() === values.length;
  138 +
124 this.total = 0; 139 this.total = 0;
125 this.fee = 0; 140 this.fee = 0;
126 141
@@ -138,6 +153,8 @@ Repayment.prototype.update = function() { @@ -138,6 +153,8 @@ Repayment.prototype.update = function() {
138 $repaymentBottom.slideDown(); 153 $repaymentBottom.slideDown();
139 } 154 }
140 155
  156 + $('#repayment-total').prop('checked', totalCheck).data('checked', totalCheck);
  157 +
141 this.setTotal(this.total); 158 this.setTotal(this.total);
142 this.setFee(this.fee); 159 this.setFee(this.fee);
143 160