123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <script>
- $(document).ready(function () {
- //初始化数据
- $('#outTimet').datetimepicker({
- format: "Y-m-d", //格式化日期
- timepicker: false //关闭时间选项
- });
- <?php if (isset($pmData) && $pmData):?>
- //编辑页面数据初始化
- var D = "<?php echo date('Y-m-d', strtotime($pmData['outDate']));?>";
- $("#outTimet").val(D);
- var itemId = "<?php echo $itemId;?>";
- $('#itemId').val(itemId);
- var pmObj = $('.diy_select_list li[val=' + itemId + ']');
- var txt = pmObj.html();
- $('.pm_name_txt').text(txt);
- $('.item-num').text(pmObj.attr('invNo'));
- <?php else:?>
- //新增页面数据初始化
- var date = new Date;
- var year = date.getFullYear();
- var month = date.getMonth() + 1;
- var day = date.getDate(); //获取当前日(1-31)
- var maxD = year + '-' + month + '-' + day;
- $("#outTimet").attr("value", maxD);
- <?php endif;?>
- var transferType = 1;
- var itemsType = 2;
- var scrapNo = 0;
- var invNo = 0;
- $("input[name=transfer_type]").click(function(){
- transferType = $(this).val();
- if(transferType == 1){
- $('#type_num').html('不合格品数量');
- $(".item-num").text(scrapNo);
- }else{
- $('#type_num').html('合格品数量');
- $(".item-num").text(invNo);
- }
- });
- $("input[name=items_type]").click(function(){
- itemsType = $(this).val();
- $(".item-num").text(0);
- $("#itemId").val(0);
- scrapNo = 0;
- invNo = 0;
- $("input[name='transfer_num']").val(1)
- //提交数据
- $.ajax({
- type: 'POST',
- url: "<?php echo $this->createUrl('imsStore/ajaxGetItem');?>",
- data: {type:itemsType},
- async: false,
- dataType: 'json',
- success: function (result) {
- console.log(result);
- if (result.status == 1) {
- var liStr = '<li val="0" invNo="0">请选择</li>';
- var data = result.data;
- for(var i in data){
- liStr += '<li val="'+data[i].itemId+'" invNo="'+(data[i].invNo-data[i].scrapNo)+'" unit="'+data[i].unitName+'" scrapNo="'+data[i].scrapNo+'">'+data[i].itemName+'</li>'
- }
- $('.pm_name_txt').html('请选择')
- $('#item_list').html(liStr)
- $(".diy_select_list>li").click(function () {
- scrapNo = $(this).attr('scrapNo');
- invNo = $(this).attr('invNo');
- var unit = $(this).attr('unit');
- if(transferType == 1){
- $(".item-num").text(scrapNo);
- }else{
- $(".item-num").text(invNo);
- }
- $("#item-unit").text(unit);
- });
- } else {
- layer.msg(result.msg);
- }
- },
- error: function (jqXHR, textStatus, errorThrown) {
- /*错误信息处理*/
- flag = true;
- layer.msg('提交失败');
- }
- });
- });
- //显示库存
- $(".diy_select_list>li").click(function () {
- scrapNo = $(this).attr('scrapNo');
- invNo = $(this).attr('invNo');
- var unit = $(this).attr('unit');
- if(transferType == 1){
- $(".item-num").text(scrapNo);
- }else{
- $(".item-num").text(invNo);
- }
- $("#item-unit").text(unit);
- });
- //加减库存
- $(".reduce-out").click(function () {
- if($("#itemId").val() > 0){
- var obj = $("input[name='transfer_num']");
- var stock_nun = parseInt(obj.val());
- if(stock_nun > 1){
- obj.val(stock_nun - 1);
- }
- }else{
- showMsg('请选择品目名称!');
- return false;
- }
- });
- $(".add-out").click(function () {
- if($("#itemId").val() > 0){
- var obj = $("input[name='transfer_num']");
- var stock_nun = parseInt(obj.val());
- if(stock_nun < $(".item-num").text()){
- obj.val(stock_nun + 1);
- }
- }else{
- showMsg('请选择品目名称!');
- return false;
- }
- });
- //提交数据
- $(".label-primary-s").click(function () {
- var flag = true;
- if (flag){
- flag = false;
- //验证数据
- var outTitle = $.trim($("input[name='outTitle']").val());
- if (outTitle.length == 0) {
- showMsg('标题名称不能为空!');
- return false;
- } else if (outTitle.length > 49) {
- showMsg('标题名称不能超过50个字符!');
- return false;
- }
- var outDate = $.trim($("input[name='out_date']").val());
- if (!outDate) {
- showMsg('移库日期不正确!');
- return false;
- }
- if (!checkDate(outDate)) {
- showMsg('移库日期不正确!');
- return false;
- }
- var itemId = $("#itemId").val();
- if (itemId <= 0) {
- showMsg('请选择转移品目!');
- return false;
- }
- //判断出库数量
- var itemNum = parseInt($(".item-num").text());
- var outStockNum = $("input[name='transfer_num']").val();
- if(outStockNum > itemNum){
- showMsg('转移数大于库存数,不允许移库!');
- return false;
- }
- if(outStockNum <= 0){
- showMsg('转移数量数量必须大于0!');
- return false;
- }
- var noticeStr = '';
- if(transferType) noticeStr = '确认后,不合格品库存减少,合格品库存增加';
- else noticeStr = '确认后,合格品库存减少,不合格品库存增加';
- var data = {
- itemId: itemId,
- title: outTitle,
- transferType: transferType,
- outDate: outDate,
- outStockNum: outStockNum,
- itemsType: itemsType
- }
- layer.confirm('确认操作吗?</br>'+noticeStr, {
- btn: ['确定', '取消'], //按钮
- }, function () {
- $.ajax({
- type: 'POST',
- url: "<?php echo $this->createUrl('imsStore/ajaxAddTransfer');?>",
- data: data,
- async: false,
- dataType: 'json',
- success: function (result) {
- if (result.status == 1) {
- layer.alert("提交成功", {icon: 1,closeBtn:0}, function () {
- window.location.href = "<?php echo $this->createUrl('imsStore/transferlist');?>";
- })
- } else {
- flag = true;
- layer.msg(result.msg);
- }
- },
- error: function (jqXHR, textStatus, errorThrown) {
- /*错误信息处理*/
- flag = true;
- layer.msg('提交失败');
- }
- });
- });
- //提交数据
- }else{
- layer.msg("稍安勿躁,正在处理中...");
- }
- });
- //计算出库数目
- function outNum(has) {
- var getNum = $("input[name='stu_get_num']").val();
- var ever = parseInt(getNum);
- $('.rel-peapor-num').html(has);
- $('.out-num').html(ever * has);
- }
- function showMsg(msg) {
- layer.msg(msg);
- }
- function checkDate(date) {
- return (new Date(date).getDate() == date.substring(date.length - 2));
- }
- $(".label-primary-cancle").click(function () {
- history.go(-1);
- });
- });
- </script>
|