123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- <script>
- var partHtml='<?php echo $part_list;?>';
- $(document).ready(function () {
- $('.some_class').datetimepicker({
- format: "Y-m-d", //格式化日期
- timepicker: false //关闭时间选项
- });
- $('.create-allocation').click(function(){
- $.ajax({
- url:'<?php echo $this->createUrl('imsStore/inventory')?>',
- type:'POST',
- dataType:'json',
- data:{'page':1},
- success:function(res){
- if(res.status==1){
- //填充数据
- var html='';
- var list=res.data.list;
- $('.prev').removeClass('hide');
- $('.next').removeClass('hide');
- for(var i=0;i<list.length;i++){
- html+='<tr>';
- html+='<td><input type="checkbox" name="select_item" value="'+list[i]['itemId']+'"><input type="hidden" class="unitName" name="unitName" value="'+list[i]['unitName']+'">';
- html+='<input type="hidden" class="invNo" name="invNo" value="'+list[i]['invNo']+'">';
- html+='</td>';
- html+='<td>'+list[i]['itemId']+'</td>';
- html+='<td class="itemName">'+list[i]['itemName']+'</td>';
- html+='<td class="itemType">'+list[i]['typeName']+'</td>';
- html+='<td>'+list[i]['invNo']+'</td>';
- html+='</tr>';
- }
- $('.item_list').html(html);
- $('.last_page').html(res.data['total_page']);
- $('.now_page').html(res.data['now_page']);
- if(res.data['now_page']==1){
- $('.prev').addClass('hide');
- }
- if(res.data['now_page']==res.data['total_page']){
- $('.next').addClass('hide');
- }
- layer.open({
- type: 1,
- title: '添加品目-低值易耗品',
- btn: ['确定','取消'],
- area: ['620px', '420px'], //宽高
- btnAlign: 'c',
- content: $('.layer-edit'),
- yes: function (index, layero) {
- $('input[name=select_item]').each(function(){
- if($(this).is(':Checked')){
- var vhtml='<tr id="'+$(this).val()+'" class="allocateDetail">';
- vhtml+='<td>'+$(this).closest('tr').find('.itemName').html()+'</td>';
- vhtml+='<td>'+$(this).closest('tr').find('.itemType').html()+'</td>';
- vhtml+='<td><input type="text" class="num" name="num" value="1"></td>';
- vhtml+='<td>'+$(this).closest('tr').find('.invNo').val()+'</td>';
- vhtml+='<td>'+$(this).closest('tr').find('.unitName').val()+'</td>';
- vhtml+='<td><a href="#" class="removePM">移除</a></td>';
- vhtml+='</tr>';
- $('#P_list').append(vhtml);
- }
- })
- layer.closeAll();
- }
- });
- }
- }
- });
- });
- //提交申请
- $('#savebutton').click(function(){
- var receiveDate=$('input[name=receiveDate]').val();
- var receiveUser=$('input[name=receiveUser]').val();
- var telephone=$('input[name=telephone]').val();
- var address=$('input[name=address]').val();
- var remark=$('#remark').val();
- var warehouse=$('.warehouse').val();
- var receiveStorage = $(".receiveStorage").val();
- var operateType = "<?php echo $operateType ?>";
- if(operateType == 'edit'){
- var atCode=$('input[name=atCode]').val();
- var atId=$('input[name=atId]').val();
- }
- var allocateDetail=[]; //品目
- $('.allocateDetail').each(function(){
- if($(this).find('.num').val()<1){
- layer.msg('申请的品目数量不正确');
- return false;
- }
- str=$(this).attr('id')+'///'+$(this).find('input[name=num]').val();
- allocateDetail.push(str);
- });
- var partDetail=[];//零件
- $('.add_part').each(function(){
- // if($(this).find('.num').val()<1){
- // layer.msg('申请的零件数量不正确');
- // return false;
- // }
- applyNo=$(this).find('input[name=num]').val();
- fpTypeId=$(this).find('.part_list').val();
- itemId=$(this).find('.device_list').val();
- str=applyNo+'///'+fpTypeId+'///'+itemId;
- partDetail.push(str);
- });
- if(warehouse <= 0){
- layer.msg('请选择申请发货仓库');
- return false;
- }
- if(receiveStorage ==''){
- layer.msg('请选择接收仓库');
- return false;
- }
- if(allocateDetail.length==0 && partDetail.length==0){
- layer.msg('请添加品目或者零件类型');
- return false;
- }
- if(receiveDate==''){
- layer.msg('请选择接收日期');
- return false;
- }
- if(receiveUser==''){
- layer.msg('请输入接收人');
- return false;
- }
- if(telephone==''){
- layer.msg('请输入接收人联系方式 ');
- return false;
- }
- if(address==''){
- layer.msg('请输入接收地址');
- return false;
- }
- var imgArr = [];
- $('#imgPreview img').each(function () {
- imgArr.push($(this).attr('src'));
- });
- if (imgArr.length <= 0) {
- layer.msg('请上传发货凭证');
- return false;
- }
-
- var data={
- 'warehouse':warehouse,
- 'allocateDetail':allocateDetail,
- 'receiveDate':receiveDate,
- 'receiveUser':receiveUser,
- 'telephone':telephone,
- 'address':address,
- 'img' : imgArr,
- 'remark' : remark,
- 'receiveStorage':receiveStorage,
- 'partDetail':partDetail
- };
- console.log(data);
- var url = '<?php echo $this->createUrl('imsStore/applysubmit')?>';
- if(operateType == 'edit'){
- data.atCode = atCode;
- data.atId = atId;
- url = '<?php echo $this->createUrl('imsStore/applyedit')?>';
- }
- $.ajax({
- url:url,
- type:'POST',
- dataType:'json',
- data:data,
- success:function(res){
- if(res.status==1){
- window.location.href='<?php echo $this->createUrl('imsStore/allocation')?>';
- }else{
- if(res.msg!=undefined){
- layer.msg(res.msg);
- }else{
- layer.msg('提交失败');
- }
- }
- }
- });
- });
- $('#P_list').on('click','.removePM',function(){
- $(this).closest('tr').remove();
- })
- $('.search_pm').click(function(){
- var pm_name=$('input[name=pm_name]').val();
- var ptype=$('.pm_type').val();
- var warehouse=$('.warehouse').val();
- loadPM(pm_name,ptype,1,warehouse);
- });
- $('.prev').click(function(){
- var now_page=parseInt($('.now_page').html());
- if(now_page<=1){
- return false;
- }
- var pm_name=$('input[name=pm_name]').val();
- var ptype=$('.pm_type').val();
- var warehouse=$('.warehouse').val();
- loadPM(pm_name,ptype,(now_page-1),warehouse);
- });
- $('.next').click(function(){
- var now_page=parseInt($('.now_page').html());
- var last_page=parseInt($('.last_page').html());
- if(now_page>=last_page){
- return false;
- }
- var pm_name=$('input[name=pm_name]').val();
- var ptype=$('.pm_type').val();
- var warehouse=$('.warehouse').val();
- loadPM(pm_name,ptype,(now_page+1),warehouse);
- });
- function loadPM(name,ptype,page,warehouse){
- $.ajax({
- url:'<?php echo $this->createUrl('imsStore/inventory')?>',
- type:'POST',
- dataType:'json',
- data:{'page':page,'name':name,'type':ptype,'warehouse':warehouse},
- success:function(res){
- if(res.status==1){
- //填充数据
- var html='';
- var list=res.data.list;
- $('.prev').removeClass('hide');
- $('.next').removeClass('hide');
- for(var i=0;i<list.length;i++){
- html+='<tr>';
- html+='<td><input type="checkbox" name="select_item" value="'+list[i]['itemId']+'"><input type="hidden" class="unitName" name="unitName" value="'+list[i]['unitName']+'">';
- html+='<input type="hidden" class="invNo" name="invNo" value="'+list[i]['invNo']+'">';
- html+='</td>';
- html+='<td>'+list[i]['itemId']+'</td>';
- html+='<td class="itemName">'+list[i]['itemName']+'</td>';
- html+='<td class="itemType">'+list[i]['typeName']+'</td>';
- html+='<td>'+list[i]['invNo']+'</td>';
- html+='</tr>';
- }
- $('.item_list').html(html);
- $('.last_page').html(res.data['total_page']);
- $('.now_page').html(res.data['now_page']);
- if(res.data['now_page']==1){
- $('.prev').addClass('hide');
- }
- if(res.data['now_page']==res.data['total_page']){
- $('.next').addClass('hide');
- }
- }
- }
- });
- }
- $(document)
- .on('change','.num',function(){
- $(this).val($(this).val().replace(/[^\d+|\.]/g,"1"));
- var num=parseInt($(this).val());
- console.log(num);
- if(num<1 ){
- $(this).val(1);
- }
- })
- // 添加图片
- $("#uploadImg").on("change", function () {
- //限制图片数量
- var imgObj = $('#imgPreview img');
- var formData = new FormData();
- formData.append('uploadFile', document.getElementById('uploadImg').files[0]);
- if(document.getElementById('uploadImg').files[0]==undefined){
- return false;
- }
- var basic = "<?php echo $basic;?>";
- $.ajax({
- url: "<?php echo $uploadUrl;?>",
- type: "post",
- data: formData,
- processData: false,
- contentType: false,
- beforeSend: function (req) {
- req.setRequestHeader("Authorization", basic);
- },
- success: function (data) {
- console.log(data);
- if (data.errCode == '00') {
- var html = "<img src='" + data.data.url + "'>";
- $('#imgPreview').append(html);
- $('#uploadImg').val('');
- } else {
- layer.msg(data.errMsg);
- }
- }
- });
- });
- $("body").on("click", "#imgPreview img", function () {
- var obj = $(this);
- var imgUrl = $(this).attr('src');
- layer.confirm('您确定删除此图片吗?', {
- btn: ['确定', '取消'] //按钮
- }, function () {
- obj.remove();
- layer.closeAll();
- });
- })
- $('.warehouse').change(function(){
- utype=$('.warehouse option:selected').attr('utype');
- console.log(utype);
- if(utype==0){
- $('.create-part').attr('disabled',false)
- }else{
- $('.create-part').attr('disabled',true)
- }
- $('.add_part').remove();
- $('.allocateDetail').remove();
- });
- $('.receiveStorage').change(function(){
- username=$('.receiveStorage option:selected').attr('username');
- mobile=$('.receiveStorage option:selected').attr('mobile');
- place=$('.receiveStorage option:selected').attr('place');
- $('input[name=receiveUser]').val(username);
- $('input[name=telephone]').val(mobile);
- $('input[name=address]').val(place);
- });
- //添加零件,设备编号
- $('.receiveStorage').change(function(){
- $('.add_part').remove();
- });
- var partTrOrder=0;
- $('.create-part').click(function(){
- // storageId=$('.receiveStorage').val();
- // if(storageId=='0'){
- // layer.msg('请选择接收仓库');
- // return false;
- // }
- html='<tr class="add_part">';
- html+='<td>'+partHtml+'</td>';
- html+='<td ><select class=" device_list part_'+partTrOrder+'"><option value="0">选择</option></select></td>';
- html+='<td></td>';
- html+='<td></td>';
- html+='<td><input type="text" class="num" name="num" value="1"></td>';
- html+='<td><a class="remove_part">移除</a></td>';
- html+='</tr>';
- //console.log(html);
- $('#part_list').append(html);
- });
- $('#part_list')
- .on('change','.part_list',function(){
- storageId=$('.receiveStorage').val();
- partType=$(this).val();
- if(partType==0){
- return false;
- }
- if(storageId=='0'){
- layer.msg('请选择接收仓库');
- return false;
- }
- obj=$(this);
- selectHtml='';
- selectHtml+='<option value="0">选择</option>';
- obj.closest('tr').find('.device_list').html(selectHtml);
- $.ajax({
- url: "<?php echo $this->createUrl('imsStore/getDeviceByPart')?>",
- type: "post",
- data: {storageId: storageId,partType:partType},
- dataType: 'json',
- success: function (res) {
- if(res.status==1){
- list=res.data;
- if(list.length>0){
- if(res.data.length>0){
- var list=res.data;
- for(var i=0;i<list.length;i++){
- selectHtml+='<option value="'+list[i]['fcId']+'" itemName="'+list[i]['itemName']+'" itemSpec="'+list[i]['itemSpec']+'" >'+list[i]['fixedCode']+'</option>';
- }
- }
- obj.closest('tr').find('.device_list').html(selectHtml);
- }else{
- layer.msg('没有对应零件类型的设备');
- }
- }
- }
- })
- })
- .on('change','.device_list',function(){
- //console.log($(this).val());
- fixedId=$(this).val();
- obj=$(this);
- if(fixedId!=0) {
- itemName=$(this).find('option:selected').attr('itemName');
- itemSpec=$(this).find('option:selected').attr('itemSpec');
- obj.closest('tr').find('td').eq(2).html(itemName);
- obj.closest('tr').find('td').eq(3).html(itemSpec);
-
- }
- })
- .on('click','.remove_part',function(){
- $(this).closest('tr').remove()
- })
- })
- </script>
|