{% extends 'obj_form.html' %} {% load i18n %} {% load tj_filters %} {% block js %} {{ block.super }} /* $('#div_label,#subdiv_label,.add-div,.add-subdiv').attr("disabled",true); */ $('.select2_multiple').on('dblclick','option',function(){ $(this).remove(); }); //2022-11-30 //2;"";"2022-11-29 11:24:41.014811+08";320;"宴会申请审批通过" //3;"";"2022-11-30 11:39:34.227765+08";293;"下级经销商收货确认" $('#sel-triggers').select2({ data:{{triggers|safe}}, multiple:true }); //select2 数据回显 var arr_triggers=[]; {% for t in form.instance.triggers %} arr_triggers.push('{{t.id}}'); {% ifequal t.id '2' %} $('#pkg_banquet').val({{t.details.package}}); $('#val_banquet').val({{t.details.value}}); {% endifequal%} {% ifequal t.id '3' %} $('#pkg_receipt').val({{t.details.package}}); $('#val_receipt_lv1').val({{t.details.value_level1}}); $('#val_receipt_lv2').val({{t.details.value_level2}}); {% endifequal%} {% endfor %} //显示隐藏相关DIV $("#sel-triggers").change(function() { var bReceipt=false,bBanquet=false; if($("#sel-triggers").is(':visible')){ var ts=$('#sel-triggers').select2('data'); for(var k in ts){ if(ts[k].id==2){bBanquet=true}; if(ts[k].id==3){bReceipt=true}; }; }; if(bReceipt){ $('#div_receipt').show(); }else{ $('#div_receipt').hide(); }; if(bBanquet){ $('#div_banquet').show(); }else{ $('#div_banquet').hide(); }; }); $('#sel-triggers').val(arr_triggers); $('#sel-triggers').trigger("change"); {% ifnotequal user.company.level_id 1%} {% if not user.perms.company.sys_admin%} $('#data-content input,#data-content .btn,#data-content select').attr("disabled",true); {% endif %} {% endifnotequal %} {% if form.instance.company %} $('#co').val('{{form.instance.company.id}}'); $('#id_channelrebate_promotion-__prefix__-company').val('{{form.instance.company}}'); {% else %} $('#co').val(''); $('#product_label,#agent_label,#div_label,#subdiv_label').attr("disabled","disabled"); {% endif %} $('#co').change(function(){ $('#id_company').val($(this).val()); var b,bLblShow; if($('#co').val()==''){ b=true; }else{ b=false; }; $('#product_label,#agent_label,#div_label,#subdiv_label').attr("disabled",b); }); $('.datepicker').datepicker({dateFormat: 'yy-mm-dd'}); //$('.datepicker').datepicker('setDate',new Date()); setDatePickerZh(); $.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: $('#co').val() ,//额外参数 }, success: function(data) { response(data); } }); }, select: function (event, ui) { $("#product_id").val(ui.item.value); $("#product_label").val(ui.item.label); return false; } }); $('#agent_label').autocomplete({ source: function(request, response) { $.ajax({ url: '/obj/ajax/autocomplete/agent/', dataType: "json", data: { term: $("#agent_label").val() ,//搜索栏里的内容 company_id: $('#co').val() ,//额外参数 }, success: function(data) { response(data); } }); }, select: function (event, ui) { $("#agent_id").val(ui.item.value); $("#agent_label").val(ui.item.label); return false; } }); $('#div_label').autocomplete({ source: function(request, response) { $.ajax({ url: '/obj/ajax/autocomplete/saldiv/', dataType: "json", data: { term: $("#div_label").val() ,//搜索栏里的内容 company_id: $('#co').val() ,//额外参数 }, success: function(data) { response(data); } }); }, select: function (event, ui) { $("#div_id").val(ui.item.value); $("#div_label").val(ui.item.label); //2020-10-19 get_subdivs(ui.item.value); return false; } }); //$('#subdiv_label').autocomplete({ // source: function(request, response) { // $.ajax({ // url: '/obj/ajax/autocomplete/subdiv/', // dataType: "json", // data: { // term: $("#subdiv_label").val() ,//搜索栏里的内容 // company_id: $('#co').val() ,//额外参数 // }, // success: function(data) { // response(data); // } // }); // }, // select: function (event, ui) { // $("#subdiv_id").val(ui.item.value); // $("#subdiv_label").val(ui.item.label); // return false; // } //}); $('#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(""+d[1]+"")}); }, dataType: 'json' }); }; $('.add-product').click(function(){ var id=$('#product_id').val(); var label=$('#product_label').val(); if(id==''){ toastr.error("请先选择产品!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ var e=false; $("#sel-product 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-product').append(""+label+""); } }; }); $('.add-agent').click(function(){ var id=$('#agent_id').val(); var label=$('#agent_label').val(); if(id==''){ toastr.error("请先选择经销商!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ var e=false; $("#sel-agent 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-agent').append(""+label+""); } }; }); $('.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(""+label+""); } }; }); $('.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(""+label+""); } }; }); $('.add-rebate').click(function(){ var prefix='#id_channelrebate_promotion-'; var count = $('#formset').find('.rebate').length; var tmplMarkup = $('#empty-form').html(); var compiledTmpl = tmplMarkup.replace(/__prefix__/g, count); $('#formset').append(compiledTmpl); $(prefix+'TOTAL_FORMS').attr('value', (count+1)); }); $('#obj_form').on('click','.add-pval',function(){ var div=$(this).closest('.rebate'); var sel=$(div).find('.sel-plv'); var id=sel.val(); var label=sel.find("option:selected").text(); var e=false; var val=$(div).find('.pval').val(); if($.isEmpty(id)){ toastr.error("营销层级不能为空", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }; if(val==''){ toastr.error("未输入层级返利金额", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }; $(div).find(".sel-plvs option").each(function(){ if($(this).val() == id){ e=true; return false; } }); if(e){ toastr.error(label+"已在列表中!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return; }else{ $(div).find('.sel-plvs').append(""+label+":"+val+""); }; //2020-11-03 $('#formset .select2_multiple').on('dblclick','option',function(){ $(this).remove(); }); }); $('#obj_form').on('change','.sel-lv',function(){ var me=$(this); $.ajax({ url: '/company/ajax/parent/level/'+$(this).val()+'/', dataType: "json", success: function(data) { var div=$(me).closest('.rebate'); var html=''; var lv,b; for(i in data.parents){ lv=data.parents[i]; html=html+""+lv.name+""; }; $(div).find('.sel-plv').html(html); if(html==''){ b=true; }else{ b=false } $(div).find('.add-pval').attr('disabled',b); } }); }); $('.btn-save').click(function(){ if($.isEmpty($('#id_company').val()) || $.isEmpty($('#id_tm_start').val()) || $.isEmpty($('#id_tm_end').val()) || $.isEmpty($('#id_name').val())){ toastr.error("公司名称,活动名称,开始时间,结束时间 不能为空", "操作错误:", {timeOut: 1800, positionClass: "toast-center-center"} ); return; }; //2022-11-30 var ts=$('#sel-triggers').select2('data'); var a=[],d,details={}; for(var k in ts ){ switch (ts[k].id) { case "2": //宴会申请 details={ "package":$('#pkg_banquet').val(), "value":($.isEmpty($('#val_banquet').val())?0:$('#val_banquet').val()) }; break; case "3": //商收货确认 details={ "package":$('#pkg_receipt').val(), "value_level1":($.isEmpty($('#val_receipt_lv1').val())?0:$('#val_receipt_lv1').val()), "value_level2":($.isEmpty($('#val_receipt_lv2').val())?0:$('#val_receipt_lv2').val()), }; break; }; a.push({'id':ts[k].id, 'text':ts[k].text, 'details':details}); }; $('#id_triggers').val(JSON.stringify(a)); //2021-06-23 if($('#id_scan_type').val()==2){ var a=[]; var sa=[]; var customer_rebates=''; var lv_id; $('#customer-rebates table tbody tr').each(function(){ if($.isEmpty($(this).find('.lv_val').val())){ $(this).find(".lv_del").attr("checked",true); }else{ if($(this).find('.lv_del').attr('checked')!=true){ lv_id=$(this).find('.lv_lv').val(); if(a.indexOf(lv_id)==-1){ sa.push('{'+ '"id":'+lv_id+','+ '"name":"'+$(this).find('.lv_lv').find("option:selected").text()+'",'+ '"value":'+$(this).find('.lv_val').val()+ '}') }; } } }); $('#id_rebates').val('['+sa.join(',')+']'); }else{ var a=[]; var s=''; $("#formset .rebate").each(function (){ a=[]; var me=$(this); $(me).find('.sel-plvs option').each(function(){ s=$(this).val()+'|'+$(this).attr('o-rc')+'|'+$(this).attr('o-vl')+'|'+$(this).attr('o-nm'); a.push(s); }); if(a.length>0){ $(me).find('.pvals').val(a.join('&')); }; }); a=[]; $("#sel-product option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_products').val(a.join(',')); }else{ $('#id_products').val(''); }; a=[]; $("#sel-agent option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_agents').val(a.join(',')); }else{ $('#id_agents').val(''); }; a=[]; $("#sel-div option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_div_ids').val(a.join(',')); }else{ $('#id_div_ids').val(''); }; a=[]; $("#sel-subdiv option").each(function (){ a.push($(this).val()); }); if(a.length>0){ $('#id_subdiv_ids').val(a.join(',')); }else{ $('#id_subdiv_ids').val(''); }; }; $.SubmitForm('#obj_form form','{{request.path}}'); }); {% for f in formset %} var prefix='#id_channelrebate_promotion-'; var count = $('#formset').find('.rebate').length; var tmplMarkup = $('#empty-form').html(); var compiledTmpl = tmplMarkup.replace(/__prefix__/g, count); $('#formset').append(compiledTmpl); $(prefix+count+'-id').val('{{f.instance.id}}'); $(prefix+count+'-level').val('{{f.instance.level.id}}'); $(prefix+count+'-vtype_id').val('{{f.instance.vtype_id}}'); $(prefix+count+'-val').val('{{f.instance.val}}'); $(prefix+count+'-distance').val('{{f.instance.distance}}'); if("{{f.instance.pvals|default_if_none:''}}".length>0){ var html=''; var aa='{{f.instance.pvals}}'.split('&'); for(i=0;i"+a[3]+':'+a[2]+""; }; $(prefix+count).find('.sel-plvs').html(html); }; $(prefix+'TOTAL_FORMS').attr('value', (count+1)); {% endfor %} //2020-11-06 $('#data-content [data-toggle="tooltip"]').tooltip(); $('#id_scan_type').change(function(){ // 2022-12-01 var bLblShow; if($(this).val()==1){ $('#formset').show(); $('#formset-add').show(); $('#div-package').show(); $('#customer-rebates').hide(); $('#customer-rebate-add').hide(); $('#div-terminal-qualified').hide(); $('#div-end-level').hide(); // 2022-12-01 bLblShow=true; }else{ $('#formset').hide(); $('#div-package').hide(); $('#formset-add').hide(); $('#customer-rebates').show(); $('#customer-rebate-add').show(); $('#div-terminal-qualified').show(); $('#div-end-level').show(); // 2022-12-011 if($(this).val()==3){ bLblShow=false; }else{ bLblShow=true; }; }; //2022-12-01 if(bLblShow){ $('#div_lblscan,#customer-rebates').show(); $('#div_triggers,#div_banquet,#div_receipt').hide(); }else{ $('#div_lblscan,#customer-rebates').hide(); $('#div_triggers').show(); }; $('#sel-triggers').trigger("change"); }); //2022-12-01 $('#id_scan_type').change(); $('.customer-rebate-add').click(function(){ var html=""+ ""+ "一级经销商"+ "二级经销商"+ "三级经销商"+ "四级经销商"+ "五级经销商"+ ""+ ""+ ""; $("#tb-customer-rebates").append(html); }); //2023-05-04 var cnt_acc=0; $('.aformset-show').click(function(){ $('#adlg').modal('show'); }); {% for f in aformset %} var prefix='#id_channelpromotionaccumulatins_promotion-'; var count = {{forloop.counter0}}; $(prefix+count+'-id').val('{{f.instance.id|default_if_none:""}}'); $(prefix+count+'-company').val('{{request.user.company_id}}'); $(prefix+count+'-cycler').val('{{f.instance.cycler}}'); $(prefix+count+'-label_pkg').val('{{f.instance.label_pkg}}'); $(prefix+count+'-amount').val('{{f.instance.amount}}'); $(prefix+count+'-priority').val('{{f.instance.priority}}'); $(prefix+'TOTAL_FORMS').attr('value', (count+1)); cnt_acc=cnt_acc+1; {% endfor %} //不足3行添加空行 while(cnt_acc<3){ var prefix='#id_channelpromotionaccumulatins_promotion-'; var count=cnt_acc; var tmplMarkup = $('#atb_empty').html(); var compiledTmpl = tmplMarkup.replace(/__prefix__/g, count); $('#atb').append(compiledTmpl); $(prefix+count+'-id').val(''); $(prefix+count+'-company').val('{{request.user.company_id}}'); $(prefix+count+'-label_pkg').val('1'); $(prefix+count+'-amount').val(''); $(prefix+count+'-priority').val(''); $(prefix+'TOTAL_FORMS').attr('value', (count+1)); cnt_acc++; }; {% 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 }} {% trans '触发类型' %} {{form.scan_type}} {% get_verbose_field_name form.instance 'name' %} {{ form.name }} {% get_verbose_field_name form.instance 'awardcategory' %} {{ form.awardcategory }} {% get_verbose_field_name form.instance 'priority' %} {{ form.priority }} {% get_verbose_field_name form.instance 'products' %} {% get_verbose_field_name form.instance 'agents' %} {% get_verbose_field_name form.instance 'div_ids' %} {% ifequal user.id 1 %} {% else %} 所有战区 {% for o in saldivision %} {{o.1}} {% endfor %} {% endifequal %} {% get_verbose_field_name form.instance 'subdiv_ids' %} 所有分区 {% for o in products %} {{o.1}} {% endfor %} {% for o in agents %} {{o.1}} {% endfor %} {% for o in div_ids %} {{o.1}} {% endfor %} {% for o in subdiv_ids %} {{o.1}} {% endfor %} 活动开始时间 {{ form.tm_start }} 活动结束时间 {{ form.tm_end }} 最早发货日期 {{ form.dt_delivery }} {% get_verbose_field_name form.instance 'status' %} {{ form.status }} 积分兑换比率 {{ form.point_ratio }} {% get_verbose_field_name form.instance 'digest' %} {{ form.digest }} {% endblock %} {% block extra %} {% trans '核算基本单位' %} {{ form.package_unit }} 渠道终端层级 {{form.end_level}} 必经终端店扫码 {{form.terminal_qualified}} {% trans '添加扫码场景' %} {% trans '添加层级奖励' %} {% if form.instance.channelpromotionaccumulatins_promotion.all %} {{ '修改累计扫码' }} {% else %} {{ '设置累计扫码返利' }} {% endif %} 系统触发事件 {% trans '保存活动设置' %} {% trans '收货确认单位' %} 箱 瓶 {% trans '一级商奖励' %} {% trans '二级商奖励' %} {% trans '宴会申请单位' %} 箱 瓶 {% trans '经销商奖励' %} {% trans '触发动作' %} {% trans '审批通过' %} {% endblock %} {% block fmset %} {% trans '扫码层级' %} {{ formset.empty_form.level }} {{formset.empty_form.id}}{{formset.empty_form.promotion}}{{formset.empty_form.pvals}} {% trans '扫码类型' %} {{ formset.empty_form.vtype_id }} {% trans '返利金额' %} {{ formset.empty_form.val }} {% trans '距离限定' %} {{ formset.empty_form.distance }} {% trans '勾选删除当前扫码场景' %} {{ formset.empty_form.DELETE }} {% trans '经销商层级返利' %} {{ formset.management_form }} 删除经销商层级返利金额(点值) {% for r in form.instance.rebates %} 一级经销商 二级经销商 三级经销商 四级经销商 五级经销商 {% endfor %} × 累计返利设置 {{aformset.empty_form.id}} {{aformset.empty_form.company}} {{ aformset.empty_form.DELETE }} {{aformset.empty_form.awardcategory}} {{aformset.empty_form.cycler}} {{aformset.empty_form.label_pkg}} {{aformset.empty_form.amount}} {{aformset.empty_form.priority}} {{aformset.empty_form.target}} {% trans '删除' %} {% trans '奖励方式' %} {% trans '扫码基数' %} {% trans '计数单位' %} {% trans '返利' %} {% trans '优先级' %} {% trans '反利对象' %} {% for f in aformset %} {{f.id}}{{f.company}} {{f.DELETE}} {{ f.awardcategory }} {{ f.cycler }} {{ f.label_pkg }} {{ f.amount}} {{ f.priority}} {{ f.target }} {% endfor %} {{ aformset.management_form }} {% endblock %}