Skip to content

Commit

Permalink
ms form
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuo14 committed Nov 7, 2014
1 parent 1937616 commit 31caf26
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 8 deletions.
175 changes: 175 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,179 @@ function confirm_dialog (content,ok_function) {
cancelValue: '取消',
cancel: function () {}
}).show();
}








// 通用函数

//格式化成两位小数 如果没有小数不补0,如果要补0的话用src.toFixed(2)
function formatFloat(src, pos){
return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
// return src.toFixed(4)
}
//格式化小数 等于0时不补零,否则补零
function FormatFloat(src, pos){
if(src==0){return 0;}
else{
return src.toFixed(pos);
}

}

//将字符串转换成对象,避免使用eval
function parseObj( strData ){
return (new Function( "return " + strData ))();
}

//计算字符长度区分中英文
function strlen(value){
var _tmp = value;
var _length = 0;
for (var i = 0; i < _tmp.length; i++) {
if (_tmp.charCodeAt(i) > 255) {
_length = _length + 2;
}
else {
_length++;
}
}
return _length;
}

//每列的合计
function sum_tr(i){
var sum=0;
var v = $(".product_tr").find("td:eq("+i+")").each(function(){
// $(this).css("text-align","right");
if ( !isNaN($(this).text()) && ($(this).text() != '')){
sum += parseFloat($(this).text());
}
});
return formatFloat(sum,2);
}

/**替换全部字符,使用方法:
var teststr ="asdfasdfasdfasdfasdfasdfasdfasdfasdf";
alert(teststr.replaceAll("as","df"));
**/
String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
} else {
return this.replace(reallyDo, replaceWith);
}
}

//求数组的最大值
Array.prototype.max = function() {
return Math.max.apply({},this)

}
//求数组的最小值
Array.prototype.min = function() {
return Math.min.apply({},this)

}

// 弹出提示框
function dialog_alter(ct){
art.dialog({
title: '提示',
content:ct,
height:89
})
}

//大写金额
function cmycurd(num){ //转成人民币大写金额形式
var str1 = '零壹贰叁肆伍陆柒捌玖'; //0-9所对应的汉字
var str2 = '万仟佰拾亿仟佰拾万仟佰拾元角分'; //数字位所对应的汉字
var str3; //从原num值中取出的值
var str4; //数字的字符串形式
var str5 = ''; //人民币大写金额形式
var i; //循环变量
var j; //num的值乘以100的字符串长度
var ch1; //数字的汉语读法
var ch2; //数字位的汉字读法
var nzero = 0; //用来计算连续的零值是几个

num = Math.abs(num).toFixed(2); //将num取绝对值并四舍五入取2位小数
str4 = (num * 100).toFixed(0).toString(); //将num乘100并转换成字符串形式
j = str4.length; //找出最高位
if (j > 15){return '溢出';}
str2 = str2.substr(15-j); //取出对应位数的str2的值。如:200.55,j为5所以str2=佰拾元角分

//循环取出每一位需要转换的值
for(i=0;i<j;i++){
str3 = str4.substr(i,1); //取出需转换的某一位的值
if (i != (j-3) && i != (j-7) && i != (j-11) && i != (j-15)){ //当所取位数不为元、万、亿、万亿上的数字时
if (str3 == '0'){
ch1 = '';
ch2 = '';
nzero = nzero + 1;
}
else{
if(str3 != '0' && nzero != 0){
ch1 = '零' + str1.substr(str3*1,1);
ch2 = str2.substr(i,1);
nzero = 0;
}
else{
ch1 = str1.substr(str3*1,1);
ch2 = str2.substr(i,1);
nzero = 0;
}
}
}
else{ //该位是万亿,亿,万,元位等关键位
if (str3 != '0' && nzero != 0){
ch1 = "零" + str1.substr(str3*1,1);
ch2 = str2.substr(i,1);
nzero = 0;
}
else{
if (str3 != '0' && nzero == 0){
ch1 = str1.substr(str3*1,1);
ch2 = str2.substr(i,1);
nzero = 0;
}
else{
if (str3 == '0' && nzero >= 3){
ch1 = '';
ch2 = '';
nzero = nzero + 1;
}
else{
if (j >= 11){
ch1 = '';
nzero = nzero + 1;
}
else{
ch1 = '';
ch2 = str2.substr(i,1);
nzero = nzero + 1;
}
}
}
}
}
if (i == (j-11) || i == (j-3)){ //如果该位是亿位或元位,则必须写上
ch2 = str2.substr(i,1);
}
str5 = str5 + ch1 + ch2;

if (i == j-1 && str3 == '0' ){ //最后一位(分)为0时,加上“整”
str5 = str5 + '整';
}
}
if (num == 0){
str5 = '零元整';
}
return str5;
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ table th.date {width:88px;}
table th.time {width:140px;}
table th.cando {width:114px;}
.no-border {border: none;}
#add_content {display: none;}
/*
.step {border-bottom: 2px solid #eee; position: relative; z-index: 99; margin-bottom: 20px; background: none repeat scroll 0 0 rgba(0, 0, 0, 0);}
.step .nav-justified {position: relative; top: 2px;}
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/kobe/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def new
def show
end

def create
render :text => params
end

def edit
end
end
1 change: 1 addition & 0 deletions app/models/orders_product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def self.xml(who='',options={})
%Q{
<?xml version='1.0' encoding='UTF-8'?>
<root>
<node column='id' data_type='hidden'/>
<node column='category_code' data_type='hidden'/>
<node name='品目' class='tree_radio required' json_url='/json/areas' partner='category_code'/>
<node name='品牌' column='brand' class='required'/>
Expand Down
23 changes: 22 additions & 1 deletion app/views/kobe/orders/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,25 @@
<p>master slave form</p>
<div class='col-md-12'>
<%= draw_myform(@ms_form) %>
</div>
</div>

<script type="text/javascript">
$(function() {
// 增加明细
var add_div = $("#add_content");
var add_max = add_div.siblings(".details_part").length;
var add_content = add_div.html();
add_div.empty();
$("#add_button").click(function(){
add_max += 1;
add_div.before(add_content.replaceAll("_orz_",add_max));
})

// 折叠/展开明细
$('body').on("click","div.details_part span i.fa",function(){
$(this).toggleClass("fa-chevron-circle-down");
$(this).toggleClass("fa-chevron-circle-right");
$(this).parent().next("div.input_part").slideToggle("fast");
});
});
</script>
8 changes: 3 additions & 5 deletions lib/master_slave_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ def get_input_part
end

def get_slave_input_part
self.add_content = get_add_content
tmp = ""
slave_objs.each_with_index{|o,i|
tmp << get_input_content(o,i+1)
self.add_content = tmp if i == 0
}
slave_objs.each_with_index{|o,i|tmp << get_input_content(o,i+1)}
return tmp
end

def get_add_content
"<div id='add_content'>#{get_input_content(slave_objs[0].class.new,'$_$')}</div>"
"<div id='add_content'>#{get_input_content(slave_objs[0].class.new,'_orz_')}</div>"
end


Expand Down
4 changes: 2 additions & 2 deletions lib/my_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def self_form_button(is_ms_form=false)
tmp << "<button id='#{options[:form_id]}_submit' class='btn-u' type='submit'><i class='fa fa-floppy-o'></i> 保 存 </button>"
tmp << "<button id='#{options[:form_id]}_reset' class='btn-u btn-u-default' type='reset'><i class='fa fa-repeat'></i> 重 置 </button>"
if is_ms_form
tmp.unshift("<button id='add_content' class='btn-u btn-u-blue' type='button'><i class='fa fa-plus-square'></i> 增 加 </button>")
tmp.unshift("<button id='add_button' class='btn-u btn-u-blue' type='button'><i class='fa fa-plus-square'></i> 增 加 </button>")
end
return tmp.join(" ")
end
Expand All @@ -55,7 +55,7 @@ def upload_form_button(is_ms_form=false)
tmp << "<span class='btn-u' id='#{options[:form_id]}_submit'><i class='fa fa-floppy-o'></i> 保 存 </span>"
tmp << "<span class='btn-u btn-u-default' id='#{options[:form_id]}_reset'><i class='fa fa-repeat'></i> 重 置 </span>"
if is_ms_form
tmp.unshift("<span id='add_content' class='btn-u btn-u-blue'><i class='fa fa-plus-square'></i> 增 加 </span>")
tmp.unshift("<span id='add_button' class='btn-u btn-u-blue'><i class='fa fa-plus-square'></i> 增 加 </span>")
end
return tmp.join(" ")
end
Expand Down

0 comments on commit 31caf26

Please sign in to comment.