{% extends 'obj_form.html' %}
{% load i18n %}
{% load tj_filters %}
{% block js %}
{{ block.super }}
{% if not perms.company.sys_admin %}
$('#data-content input,#data-content .btn,#data-content select').attr("disabled",true);
{% endif %}
{% ifnotequal request.user.company.level_id 1 %}
$('#data-content input,#data-content .btn,#data-content select').attr("disabled",true);
{% endifnotequal %}
$.datetimepicker.setLocale('zh');
$('.datetimepicker').datetimepicker({
i18n:{
zh:{
months:['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月',],
dayOfWeek:["一", "二", "三", "四","五", "六", "日",]
}
},
//timepicker:true,
format:'Y-m-d H:i:s',
});
$('#product_label').autocomplete({
source: function(request, response) {
$.ajax({
url: '/obj/ajax/autocomplete/product/',
dataType: "json",
data: {
term: $("#product_label").val() ,//搜索栏里的内容
company_id: $('#id_company').val() ,//额外参数
},
success: function(data) {
response(data);
}
});
},
select: function (event, ui) {
$("#product_id").val(ui.item.value);
$("#product_label").val(ui.item.label);
return false;
}
});
$('#material_label').autocomplete({
source: function(request, response) {
$.ajax({
url: '/obj/ajax/autocomplete/material/',
dataType: "json",
data: {
term: $("#material_label").val() ,//搜索栏里的内容
company_id: $('#id_company').val() ,//额外参数
},
success: function(data) {
response(data);
}
});
},
select: function (event, ui) {
$("#material_id").val(ui.item.value);
$("#material_label").val(ui.item.label);
return false;
}
});
$('.add-product').click(function(){
var b=false;
var id=$('#product_id').val();
var name=$('#product_label').val();
var unit=$('#product_unit').val();
var qty=$('#product_qty').val();
$('#scheme-product tbody tr').each(function(idx,val){
if($(this).find('.pid').val()==$('#product_id').val()){
b=true;
return;
}
});
if($.isEmpty(id) || $.isEmpty(name) || $.isEmpty(unit) || $.isEmpty(qty)){
toastr.error("产品/单位/数量不能为空!", "操作错误:",
{timeOut: 800, positionClass: "toast-center-center"}
);
}else{
if (b){
toastr.error("此产品名称已在列表中!", "操作错误:",
{timeOut: 800, positionClass: "toast-center-center"}
);
}else{
var prefix='#id_schemeproducts_set-';
$(prefix+'__prefix__').find('.product').text(name);
var count = $('#scheme-product tbody tr').length;
var tmplMarkup = '
'+$(prefix+'__prefix__').html()+'
';
var compiledTmpl = tmplMarkup.replace(/__prefix__/g, count);
$('#scheme-product tbody').append(compiledTmpl);
$(prefix+count+'-product').val(id);
$(prefix+count+'-qty').val(qty);
$(prefix+count+'-package_id').val(unit);
$(prefix+'TOTAL_FORMS').attr('value', (count+1));
}
}
});
$('.add-material').click(function(){
var id=$('#material_id').val();
var name=$('#material_label').val();
var qty=$('#material_qty').val();
var b=false;
$('#scheme-material tbody tr').each(function(idx,val){
if($(this).find('.mid').val()==id){
b=true;
return;
}
});
if($.isEmpty(id) || $.isEmpty(name) || $.isEmpty(qty)){
toastr.error("物料名称/数量不能为空!", "操作错误:",
{timeOut: 800, positionClass: "toast-center-center"}
);
}else{
if (b){
toastr.error("此物料名称已在列表中!", "操作错误:",
{timeOut: 800, positionClass: "toast-center-center"}
);
}else{
var prefix='#id_schemematerials_set-';
$(prefix+'__prefix__').find('.material').text(name);
var count = $('#scheme-material tbody tr').length;
var tmplMarkup = ''+$(prefix+'__prefix__').html()+'
';
var compiledTmpl = tmplMarkup.replace(/__prefix__/g, count);
$('#scheme-material tbody').append(compiledTmpl);
$(prefix+count+'-material').val(id);
$(prefix+count+'-qty').val(qty);
$(prefix+'TOTAL_FORMS').attr('value', (count+1));
}
}
});
$('#id_means').change(function(){
if($(this).val()==1){
$('#id_tm_app_latest').val('').attr("disabled",true);
}else{
$('#id_tm_app_latest').attr("disabled",false);
}
});
$('.btn-save').click(function(){
a=[];
$("#sel-div option").each(function (){
a.push($(this).val());
});
if(a.length>0){
$('#id_div_ids').val(a.join(','));
};
a=[];
$("#sel-subdiv option").each(function (){
a.push($(this).val());
});
if(a.length>0){
$('#id_subdiv_ids').val(a.join(','));
};
$.SubmitForm('#obj_form form','{{request.path}}');
});
//2020-11-20
$('#div_id').change(function(){
var saldiv_id=$(this).val();
if (saldiv_id==''){
$('#subdiv_id').empty();
$('#subdiv_id').append('')
}else{
get_subdivs($(this).val());
}
});
function get_subdivs(saldiv_id){
var me=$('#subdiv_id');
$.ajax({
url: "/obj/ajax/subsaldiv/"+saldiv_id+"/",
success: function(data) {
$(me).empty();
$.each(data,function(i,d){$(me).append("")});
},
dataType: 'json'
});
};
$('.add-div').click(function(){
var id=$('#div_id').val();
{% ifequal user.id 1 %}
var label=$('#div_label').val();
{% else %}
var label=$('#div_id').find("option:selected").text();
{% endifequal %}
if(id==''){
toastr.error("请先选择战区!", "操作错误:",
{timeOut: 800, positionClass: "toast-center-center"}
);
return;
}else{
var e=false;
$("#sel-div option").each(function(){
if($(this).val() == id){
e=true;
return false;
}
});
if(e){
toastr.error(label+"已在列表中!", "操作错误:",
{timeOut: 800, positionClass: "toast-center-center"}
);
return;
}else{
$('#sel-div').append("");
}
};
});
$('.add-subdiv').click(function(){
var id=$('#subdiv_id').val();
{% ifequal user.id 1 %}
var label=$('#subdiv_label').val();
{% else %}
var label=$('#subdiv_id').find("option:selected").text();
{% endifequal %}
if(id==''){
toastr.error("请先选择分区!", "操作错误:",
{timeOut: 800, positionClass: "toast-center-center"}
);
return;
}else{
var e=false;
$("#sel-subdiv option").each(function(){
if($(this).val() == id){
e=true;
return false;
}
});
if(e){
toastr.error(label+"已在列表中!", "操作错误:",
{timeOut: 800, positionClass: "toast-center-center"}
);
return;
}else{
$('#sel-subdiv').append("");
}
};
});
$('#obj_form .select2_multiple').on('dblclick','option',function(){
$(this).remove();
});
{% endblock %}
{% block subtitle-1 %}
{% trans "领用核销" %}
{% endblock %}
{% block subtitle-2 %}
{% trans "活动方案" %}
{% endblock %}
{% block subtitle-3 %}
{% if form.instance.id %}
{% trans "修改" %}
{% else %}
{% trans "新建" %}
{% endif %}
{% endblock %}
{% block form_content %}
{{ block.super }}
{% endblock %}
{% block fmset %}
| {{pset.empty_form.DELETE}}{{pset.empty_form.id}}{{pset.empty_form.status}} |
{{pset.empty_form.product}} |
{{pset.empty_form.qty}} |
{{pset.empty_form.package_id}} |
{{pset.empty_form.remark}} |
{{ pset.management_form }}
| {{mset.empty_form.DELETE }}{{mset.empty_form.id}}{{mset.empty_form.status}} |
{{mset.empty_form.material}} |
{{mset.empty_form.qty}} |
{{mset.empty_form.remark}} |
{{ mset.management_form }}
| 删除 |
产品名称 |
数量 |
单位 |
备注 |
{% for f in pset %}
| {{f.DELETE}}{{f.id}}{{f.status}} |
{{f.product}}{{f.instance.product.name}} |
{{f.qty}} |
{{f.package_id}} |
{{f.remark}} |
{% endfor %}
| 删除 |
物料名称 |
数量 |
备注 |
{% for f in mset %}
| {{f.DELETE}}{{f.id}}{{f.status}} |
{{f.material}}{{f.instance.material.name}} |
{{f.qty}} |
{{f.remark}} |
{% endfor %}
{% endblock %}