123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- <script>
- $(document).ready(function () {
- $('#stocktakingDate').datetimepicker({
- format: "Y-m-d", //格式化日期
- timepicker: false //关闭时间选项
- });
- <?php if (isset($_GET['stockId'])):?>
- var itemId = "<?php echo $detail['itemId'];?>";
- $('#itemId').val(itemId);
- var obj = $('.select-itemId li[val=' + itemId + ']');
- var txt = obj.html();
- $('.select-itemId .diy_select_txt').html(txt);
- setItem(obj);
- getKuisun();
- <?php endif;?>
- //品目类别
- $('input[name="itemType"]').change(function () {
- var itemType = $(this).val();
- if(itemType!=0){
- $('#fixCode td').html('');
- $('#fixCode').fadeOut();
- }
- //初始化
- $('#itemId').val(0);
- $('.diy_select_txt').html('请选择品目名称');
- $('.item_desc').empty();
- $('#stockNo').val('');
- $('.get-status').empty();
- $('#imgPreview').empty();
- $.ajax({
- url: "<?php echo Yii::app()->createUrl('imsStore/getItem')?>",
- type: "post",
- data: {'itemType':itemType},
- dataType: 'json',
- success: function (res) {
- if(res.status){
- var html='';
- html+='<li val="0">请选择品目名称</li>';
- for (var i=0;i<res.data.length;i++){
- var ii = res.data[i];
- html+= '<li val="'+ii.itemId+'" ' +
- 'itemSpec="'+ii.itemSpec+'" ' +
- 'unitName="'+ii.unitName+'" ' +
- 'unitId="'+ii.unitId+'" ' +
- 'invNo="'+ii.invNo+'" ' +
- 'itemCode="'+ii.itemCode+'" ' +
- 'itemName="'+ii.itemName+'">' +
- ii.itemName
- '</li>';
- }
- $('.select-itemId ul').html(html);
- }else{
- layer.msg("暂无品目");
- var html='<li val="0">请选择品目名称</li>';
- $('.select-itemId ul').html(html);
- return false;
- }
- }
- })
- });
- //筛选品目
- $('body').on('click','.select-itemId li',function () {
- var currVal = $(this).attr('val');
- if (currVal> 0) {
- setItem($(this));
- }else{
- $('#fixCode td').empty();
- $('.item_desc').empty();
- }
- });
- //盈亏计算
- $('body').on('input','#stockNo' ,function () {
- getKuisun();
- });
- // 添加图片
- $("#fileImg").on("change", function () {
- //限制图片数量
- var imgObj = $('#imgPreview img');
- if(imgObj.length>=3){
- layer.msg("最多可上传三张图片");
- return false;
- }
- var formData = new FormData();
- formData.append('uploadFile', document.getElementById('fileImg').files[0]);
- if(document.getElementById('fileImg').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();
- });
- })
- //提交
- $("#savebutton").click(function () {
- var flag = true;
- if (flag){
- flag = false;
- var stockTitle = $.trim($("input[name='stockTitle']").val());
- var stocktakingDate = $("input[name='stocktakingDate']").val();
- var itemId = $("input[name='itemId']").val();
- var stockNo = $.trim($("input[name='stockNo']").val());
- var itemType = $('input[name="itemType"]:checked');
- var remark = $('#remark').val();
- if (stockTitle == '') {
- layer.msg('标题名称不能为空!');
- return false;
- } else if (stockTitle.length > 49) {
- showMsg('标题名称不能超过50个字符!');
- return false;
- }
- if (!stocktakingDate) {
- layer.msg('时间不能为空!');
- return false;
- }
- if(itemType.length<=0){
- layer.msg('请选择品目类型!');
- return false;
- }
- if (itemId<=0) {
- layer.msg('请选择盘点品目!');
- return false;
- }
- if ($.trim(stockNo)=='') {
- layer.msg('盘点数量不能为空!');
- return false;
- }
- var imgArr = [];
- $('#imgPreview img').each(function () {
- imgArr.push($(this).attr('src'));
- });
- if (imgArr.length < 1) {
- layer.msg('请上传图片!');
- return false;
- }
- //固定资产
- var fixedCodesArr = [];
- var inFixedCodesArr = [];
- if (itemType.val()==0){
- var fixedObj = $('input[name="fixedCodes"]:checked');
- fixedObj.each(function () {
- fixedCodesArr.push($(this).val());
- });
- var infixedObj = $('input[name="fixedCodes"]');
- infixedObj.each(function () {
- inFixedCodesArr.push($(this).val());
- });
- }
- <?php if (isset($_GET['stockId']) && $_GET['stockId'] != ''):?>
- var data = {
- stockTitle: stockTitle,
- stocktakingDate: stocktakingDate,
- itemId: itemId,
- itemCode: $('input[name="itemCode"]').val(),
- itemName: $('input[name="itemName"]').val(),
- itemSpec: $('input[name="itemSpec"]').val(),
- unitId: $('input[name="unitId"]').val(),
- stockNo: parseInt($('#stockNo').val()),
- imgArr: imgArr,
- theoreticalNo: parseInt($("#invNo").val()),
- stockId: "<?php echo $_GET['stockId'];?>",
- itemType: itemType.val(),
- fixedCodes:fixedCodesArr,
- invFixedCodes:inFixedCodesArr,
- remark:remark
- };
- <?php else:?>
- var data = {
- stockTitle: stockTitle,
- stocktakingDate: stocktakingDate,
- itemId: itemId,
- itemCode: $('input[name="itemCode"]').val(),
- itemName: $('input[name="itemName"]').val(),
- itemSpec: $('input[name="itemSpec"]').val(),
- unitId: $('input[name="unitId"]').val(),
- stockNo: parseInt($('#stockNo').val()),
- imgArr: imgArr,
- theoreticalNo: parseInt($("#invNo").val()),
- itemType: itemType.val(),
- fixedCodes:fixedCodesArr,
- invFixedCodes:inFixedCodesArr,
- remark:remark
- };
- <?php endif;?>
- $.ajax({
- type: 'POST',
- url: "<?php echo $this->createUrl('imsStore/ajaxStockAdd');?>",
- data: data,
- async: false,
- dataType: 'json',
- success: function (result) {
- console.log(result);
- if (result.status == 1) {
- layer.alert(result.msg, {icon: 1,closeBtn:0}, function () {
- window.location.href = "<?php echo $this->createUrl('imsStore/stock');?>";
- })
- } else {
- flag = true;
- layer.alert(result.msg,{icon:2});
- }
- },
- error: function (jqXHR, textStatus, errorThrown) {
- /*错误信息处理*/
- flag = true;
- layer.msg('提交失败');
- }
- });
- } else {
- layer.msg("稍安勿躁,正在处理中...");
- }
- });
- function setItem(obj){
- var html = '规格:' + obj.attr('itemSpec') + '; 单位:' + obj.attr('unitName') + '; 理论数量:' + obj.attr('invNo');
- $(".item_desc").html(html);
- $("#invNo").val(obj.attr('invNo'));
- $('input[name="itemSpec"]').val(obj.attr('itemSpec'));
- $('input[name="itemName"]').val(obj.attr('itemName'));
- $('input[name="itemCode"]').val(obj.attr('itemCode'));
- $('input[name="unitId"]').val(obj.attr('unitId'));
- //固定资产编号
- var hasFixed = [];
- <?php if (isset($_GET['stockId']) && $_GET['stockId'] != '' && isset($detail['fixedCodes'])):?>
- var hasFixeds = "<?php echo implode(',',$detail['fixedCodes'])?>";
- var hasFixed = hasFixeds.split(',');
- <?php endif;?>
- console.log(hasFixed);
- var itemId = $("#itemId").val();
- var itemType = $('input[name="itemType"]:checked').val();
- if (itemType==0){
- $.ajax({
- type: 'post',
- url: "<?php echo Yii::app()->createUrl('imsStore/getFixCode');?>",
- data: {'itemId':obj.attr("val")},
- dataType: 'json',
- success: function (res) {
- console.log(res);
- var html = '';
- for (var i=0;i<res.data.length;i++){
- var fixedCodes = res.data[i];
- if($.inArray(fixedCodes,hasFixed)<0){
- html+='<lable style="margin-right: 10px;display:inline-block;"><input name="fixedCodes" type="checkbox" value="'+fixedCodes+'"> '+fixedCodes+'</lable>';
- }else{
- html+='<lable style="margin-right: 10px;display:inline-block;"><input name="fixedCodes" checked type="checkbox" value="'+fixedCodes+'"> '+fixedCodes+'</lable>';
- }
- }
- $('#fixCode').fadeIn();
- $('#fixCode td').html(html);
- }
- });
- }
- }
- function getKuisun() {
- var num = parseInt($('#stockNo').val());
- var procurementUnit = parseInt($("#invNo").val());
- if (num == procurementUnit) {
- var html = ' <em class="same">平</em>';
- $(".sale-num").html(html);
- }
- if (num < procurementUnit) {
- var html = '<em class="less">亏</em>盈亏数:<span class="red">' + (num - procurementUnit) + '</span>';
- $(".sale-num").html(html);
- }
- if (num > procurementUnit) {
- var html = ' <em class="more">盈</em>盈亏数:<span class="red">' + (num - procurementUnit) + '</span>';
- $(".sale-num").html(html);
- }
- }
- });
- </script>
|