Home > front end >  Selected to form a line (checkbox), and then selected another form one row, click on the button, com
Selected to form a line (checkbox), and then selected another form one row, click on the button, com

Time:12-22

Selected task list box area (checkbox), a row of data to a row, select field for a crane, crane operation plan, click the generate field to generate a new record
How to write this to validate js and views section
HTML:
Box area task list



{# & lt; Th name="index" & gt; The serial number & lt;/th> #}


{# & lt; Th name="plan_num & gt;" Box & lt;/th> #}


{# & lt; Th name="unplan_num & gt;" A crane number & lt;/th> #}

{# & lt; Th name="unplan_num & gt;" Equipment & lt;/th> #}
Operation & lt;/th>






Id="crane_plan" & gt; Generate a crane operation plan



A crane operation plan



A crane no. & lt;/th>
Box area & lt;/th>
Carton no. & lt;/th>
Size & lt;/th>


{# & lt; Th> Operation sequence number & lt;/th> #}
Tight before operation case number & lt;/th>
{# & lt; Th> After the tight case number & lt;/th> #}













Js:
//box area task information and field information, generate field crane operation plan
Layui. Use ([' form ', 'element', 'laydate], function () {
Var jQuery=layui. JQuery
, layer=layui layer
, form=layui. Form
Element, element=layui.;
$(" # crane_plan ") on (' click ', function () {

Let block_no=$(` input [name="blocksel"] : checked `). Val ();
Let selectedSlot=[];
Let selectedCrane2=[];

$(" input [name='select_solt] : the checkbox: checked "). Each (function () {
Let $trEle=$(this). The parent (). The parent ();
Let CtnNo=$trEle. The children (). Eq (0). The text ();
//let CtnSize=$trEle. The children (). Eq. (1) the text ();
//let OpBayNo=$trEle. The children (). Eq. (2) the text ();
//let OpClass=$trEle. The children (). Eq. (3) the text ();
//let PreOpCtnNo=$trEle. The children (). Eq. (4) the text ();
SelectedSlot. Push (CtnNo);
This. Checked=false;
This. Disabled=true;
});
$(" input [name='select_crane2] : the checkbox: checked "). Each (function () {
Let $trEle=$(this). The parent (). The parent ();
Let YcNo=$trEle. The children (). Eq (0). The text ();
SelectedCrane2. Push (YcNo);
This. Checked=false;
This. Disabled=true;
});
Info={
Block_no: block_no,
SelectedSlot: selectedSlot,
SelectedCrane2: selectedCrane2
};
The console. The log (info);

$. Ajax ({
Url: "/yard/create_plan/,"
Type: "POST",
Data: JSON. Stringify (info),
Success: the function (res) {
Alert (" submit success ");
$(" # crane_work_tbody "). The empty ();
//$(" # bay_show "). The empty ();
Let tbodyObj=$(" # crane_work_tbody ");

For (let j=0; J & lt; Res. Length; J++) {
Let the index=res [j];
For (the let I=0; I & lt; Index. Length; I++) {
Let newTr=document. The createElement method (' tr);
Let newTd=` & lt; Td & gt; The ${index [I] YcNo} & lt;/td>
The ${index [I] OpZone} & lt;/td> The ${index [I] CtnNo} & lt;/td>
The ${index [I] CtnSize} & lt;/td> The ${index [I] OpBayNo} & lt;/td>
The ${index [I] OpClass} & lt;/td> The ${index [I] PreOpCtnNo} & lt;/td>
`;
NewTr. InnerHTML=newTd;
TbodyObj [0]. The appendChild (newTr);
}

}
}
})
})
})



Views:
Def create_plan (request) :
. If the request method=="POST" :
Data=https://bbs.csdn.net/topics/json.loads (the request body. Decode (' utf-8))
Block_no=data [' Block_no]
SelectedCrane2=data [' selectedCrane2]
SelectedSlot=data [' selectedSlot]

For I in range (0, len (selectedSlot) :
CtnNo=data [' CtnNo]
CtnSize=data [' CtnSize]
OpBayNo=data [' OpBayNo]
OpClass=data [' OpClass]
PreOpCtnNo=data [' PreOpCtnNo]

For I in range (0, len (selectedCrane2) :
YcNo=data [' YcNo]

For I in range (0, len (Block_no) :
Try:
Obj=YardCraneOperaOrder. Objects. The get (OpZone=Block_no, YcNo=YcNo)
Except YardCraneOperaOrder. DoesNotExist:
Obj=None
If obj is None:
YardCraneOperaOrder. Objects. Update_or_create (YcNo=YcNo,
OpZone=Block_no,
CtnNo=CtnNo,
CtnSize=CtnSize,
OpBayNo=OpBayNo,
OpClass=OpClass,
PreOpCtnNo=PreOpCtnNo,

)
MSG="success"
nullnullnullnull
  • Related