{% extends 'obj_form.html' %} {% load i18n %} {% load tj_filters %} {% block js %} {{ block.super }} var editor = null; {% if cfg.product_photo %} var content = $("#id_product_content").val(); if (content!="None"){ $("#htmlEdit").html(content); } var E = window.wangEditor editor = new E('#htmlEdit') editor.config.uploadImgServer = '/mall/points_product/upload/' editor.config.uploadImgMaxLength = 20 editor.config.uploadImgMaxSize = 3 * 1024 * 1024 // 512kb editor.config.uploadFileName = 'file' editor.create() {% endif %} $('#data-content div.product_photo br').remove(); $('#photo-clear_id,#id_photo').removeClass('form-control'); var html='{% trans "属性名" %}'+ '{% trans "属性值" %}'+ '{% trans "单位" %}'+ '{% trans "备注" %}'; var s='',sel='', sSel=''; {% for p in props %} s=''; sel=''; html = html + ''+ '{{ p.label }}'+ ''+sel+''+ '{{ p.unit }}'+ ' '+ ''; {% endfor %} {% if props %} $('#tb_props tbody').html(html); {% endif %} $('#tb_props').append(''); $('.btn-save').click(function(){ if(editor){ var editorData = editor.txt.html(); $("#id_product_content").val(editorData); } $(this).hide(); //2022-06-12 if( !$.isEmpty($('#shelf_life_value').val()) ){ var period=$('#shelf_life_period').val(); var value=$('#shelf_life_value').val(); $('#id_shelf_life').val('{"period":"'+period+'","value":'+value+'}'); } $.SubmitForm('#obj_form form','{{request.path}}'); }); //2022-06-12 {% if form.instance.shelf_life %} $('#shelf_life_period').val('{{form.instance.shelf_life.period}}'); $('#shelf_life_value').val({{form.instance.shelf_life.value}}); {% endif %} //2020-11-24 $('#data-content .btn-delete').click(function(){ $.ajax({ url:'/obj/delete/product/{{form.instance.id}}/', success: function(data) { if(data.cnt>0){ toastr.success('当前产品已删除!', '操作成功:', {timeOut: 800, positionClass: "toast-center-center"} ); $.RefreshContent("/obj/list/product/"); }; }, }); }); $('#obj_form .product_photo a').click(function(event){ event.preventDefault(); var src=$(this).attr('href'); var i="
"; $.OpenCfmDlg($('#id_name').val(),i); }); //2022-12-09 $('.btn-show-components').click(function(){ $('#components-modal').modal('show'); }); $('#cp_label').autocomplete({ source: function(request, response) { $.ajax({ url: '/obj/ajax/autocomplete/product/', dataType: "json", data: { term: $("#cp_label").val() ,//搜索栏里的内容 company_id:{{request.user.company_id}} //额外参数 }, success: function(data) { response(data); } }); }, select: function (event, ui) { $("#cp_id").val(ui.item.value); $("#cp_label").val(ui.item.label); return false; } }); $('#components-modal .add-cp').click(function(){ var cp_name=$('#cp_label').val(); var cp_id=$('#cp_id').val(); var cp_qty=$('#cp_qty').val(); //console.log(cp_id,cp_name,cp_qty); if($.isEmpty(cp_id) || $.isEmpty(cp_name) || $.isEmpty(cp_qty)){ toastr.error( "产品和数量不能为空!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); return false; }else{ var bExists=false; $("#tb-components tbody tr").each(function(rowIndex) { if($(this).attr('cp_id')==cp_id){ bExists=true; return; }; }); if (bExists){ toastr.error( "产品'"+cp_name+"'在表中已存在!", "操作错误:", {timeOut: 800, positionClass: "toast-center-center"} ); }else{ var tr=""+ ""+cp_name+""+ ""+cp_qty+""+ "删除"; $('#tb-components tbody').append(tr); }; }; }); $('#tb-components').on('click', 'a.cp_delete', function(){ $(this).closest('tr').remove(); }); $('#components-modal .btn-confirm').click(function(){ var ps=[],aPs=[],sId='',sName='',sQty=''; $("#tb-components tbody tr").each(function(rowIndex) { sId=$(this).attr('cp_id'); sName=$(this).find('.cp_name').text(); sQty=$(this).find('.cp_qty').text(); ps.push({ 'id':sId, 'name':sName,'qty':sQty }); aPs.push(sName+":"+sQty+"份"); }); $('#id_components').val(JSON.stringify(ps)); $('#components').text(aPs.join(' ; ')); $('#components-modal').modal('hide'); }); var aCp=[],sTr=''; {% if form.instance.components %} {% for p in form.instance.components %} aCp.push('{{p.name}}:{{p.qty}}份'); sTr=sTr+""+ "{{p.name}}"+ "{{p.qty}}"+ "删除"; {% endfor %} $('#components').text(aCp.join(' ; ')); $('#tb-components tbody').append(sTr); {% endif %} {% endblock %} {% block subtitle-1 %} {% trans "产品管理" %} {% endblock %} {% block subtitle-2 %} {% trans "产品名称" %} {% endblock %} {% block form_content %} {{ block.super }} {% if has_series %}
{{ form.series }}
{% endif %} {% if form.instance.company.has_external_code %}
{{ form.external_code }}
{% endif %}
{{ form.name }}
{{ form.barcode }}
{{ form.pl }}
{{ form.standard }}
{{ form.processflow }}
{{ form.desc }}
{% ifequal user.company.id 26560 %}
{{ form.specs }}
{% endifequal %} {% if cfg.product_price %}
{{ form.price }}
{% endif %}
{% if cfg.shelf_life %}
{{ form.remark|default_if_none:'' }}
{% else %}
{{ form.remark|default_if_none:'' }}
{% endif %} {% if cfg.product_photo %}
{{ form.photo }}
{% endif %}
{% if cfg.product_photo %}
产品介绍:
{% endif %}
{% if form.instance.id %} {% if is_show %} {% trans '删除' %} {% endif %} {% endif %} {% trans '保存' %}
{% endblock %}