123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467 |
- <script>
- $(document).ready(function () {
- //初始化数据
- // $('#outTimet').datetimepicker({
- // format: "Y-m-d", //格式化日期
- // timepicker: false //关闭时间选项
- // });
- <?php if ($pmData):?>
- //编辑页面数据初始化
- var D = "<?php echo date('Y-m-d', strtotime($pmData['outDate']));?>";
- $("#outTimet").val(D);
- var itemId = "<?php echo $itemId;?>";
- $('#itemId').val(itemId);
- var txt = $('.select-itemId li[val=' + itemId + ']').html();
- $('.select-itemId .diy_select_txt').html(txt);
- var b = $('.rel-peapor-num').html();
- outNum(b);
- var goodsName = "<?php echo $pmData['goodsName'];?>";
- $('#goodsName').text(goodsName);
- var orderNo = "<?php echo $pmData['orderNo'];?>";
- $('.relate-goods').text(orderNo);
- <?php else:?>
- //新增页面数据初始化
- var date = new Date;
- var year = date.getFullYear();
- var month = date.getMonth() + 1;
- var day = date.getDate(); //获取当前日(1-31)
- if(month<10) month = '0'+month;
- if(day<10) day = '0'+day;
- var maxD = year + '-' + month + '-' + day;
- $("#outTimet").attr("value", maxD);
- <?php endif;?>
- // $(".grade>span").on("click", function() {
- $("body").delegate(".grade>span", "click", function () {
- $(this).parent().children(".student-list").toggle();
- return false;
- });
- // $(".student-list").on("click", "span", function() {
- $("body").delegate(".student-list>.class-li>span", "click", function () {
- $(this).parent().toggleClass("active");
- $(this).parent().children(".student-name_box").toggle();
- return false;
- });
- // 单选按钮
- $('body').on('change', "input[name='studentName']", function () {
- getsStudentSelected();
- });
- // 全选按钮
- // $(".btn-select_all").on("click", function() {
- $("body").delegate(".btn-select_all", "click", function () {
- var obj = $(this).parent().find("input");
- if($(this).hasClass('isSelected')){
- obj.each(function () {
- $(this).prop("checked", false);
- })
- $(this).removeClass("isSelected");
- }else{
- obj.each(function () {
- if(!$(this).is(":disabled")){
- $(this).prop("checked", true);
- }
- })
- $(this).addClass("isSelected");
- }
- getsStudentSelected();
- return false;
- });
- //关联正式订单
- $(".relate-goods").on("click", function () {
- var doType = $(this).attr('doType');
- relationOrderAction(1,doType);
- layer.open({
- type: 1,
- title: '选择订单',
- btn: ['确定'],
- area: ['810px', '420px'], //宽高
- btnAlign: 'c',
- content: $('.layer-relate'),
- yes: function (index, layero) {
- $('#active-submit-stu').empty();
- $('.student-list_box ul').empty();
- //提交
- var obj = $("input[name='relation_order_select']:checked");
- var orderNo = obj.next('input').val();
- var goodsName = obj.next('input').next('input').val();
- var orderId = obj.val();
- if (typeof(orderId) != undefined) {
- $(".relate-goods").text(orderNo);
- $(".relate-goods").attr('orderId', orderId);
- $("#goodsName").text(goodsName);
- $("#itemName").text($('#order_item_name').val());
- } else {
- showMsg(orderId);
- }
- layer.closeAll();
- }
- });
- return false;
- });
- //出库数目计算
- $("input[name='stu_get_num']").on("input", function () {
- var a = $('.rel-peapor-num').html();
- outNum(parseInt(a));
- });
- // 添加图片
- $("#uploadImg").on("change", function () {
- //限制图片数量
- var imgObj = $('#imgPreview img');
- if(imgObj.length>=3){
- layer.msg("最多可上传三张图片");
- return false;
- }
- 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();
- });
- })
- //-----------------------编辑名单-common---------------------------
- $(".edit-btn").on("click", function () {
- var orderId = $(".relate-goods").attr('orderId');
- var inId = "<?php echo isset($_GET['inId'])?$_GET['inId']:0; ?>"
- if (typeof(orderId) == undefined || orderId.length <= 0 || orderId == 0) {
- layer.msg("请选择关联财务订单!");
- return false;
- }
- //获取学生列表
- var isGetStu = false;
- var addNotic = '';
- if($('.student-list_box li').length<=0){
- $.ajax({
- type: 'POST',
- url: "<?php echo $this->createUrl('imsStore/ajaxAddOutputStu');?>",
- data: {orderId: orderId,inId:inId},
- async: false,
- dataType: 'json',
- success: function (result) {
- if (result.status == 1) {
- $('.student-list_box').html(result.data);
- addNotic = result.notice;
- isGetStu = true;
- } else {
- layer.msg('学生列表获取失败!');
- }
- },
- error: function (jqXHR, textStatus, errorThrown) {
- layer.msg('学生列表获取失败!');
- }
- });
- }else{
- isGetStu = true;
- }
- //初始化选择的学生
- getsStudentSelected();
- if (isGetStu == false) {
- return false;
- }
- layer.open({
- type: 1,
- title: '编辑名单 '+addNotic,
- btn: ['保存'],
- area: ['800px', '420px'], //宽高
- btnAlign: 'c',
- content: $('.layer-edit'),
- yes: function (index, layero) {
- //选择的学生
- var stuSeled = $(".student-selected>li");
- if (stuSeled.length <= 0) {
- showMsg('请选择学生!');
- } else {
- //把选择的学生信息添加到主页面
- var trStr = '';
- for (var i = 0; i < stuSeled.length; i++) {
- var stuName = $(stuSeled[i]).children('.stu_name').text();
- var stuClass = $(stuSeled[i]).children('.stu_class').text();
- var stuInfo = $(stuSeled[i]).children('i');
- var stuId = $(stuInfo).attr('value');
- // var className = $(stuInfo).attr('className');
- trStr += '<tr stuId="' + stuId + '">\n' +
- ' <th>' + (i+1) + '</th>\n' +
- ' <th>' + stuName + '</th>\n' +
- ' <th>' + stuClass + '</th>\n' +
- ' </tr>';
- }
- outNum(stuSeled.length);
- $("#active-submit-stu").html(trStr);
- layer.closeAll();
- }
- }
- });
- return false;
- });
- //删除学生
- $(".student-selected").on("click", ".btn-delete", function () {
- $(this).parent().remove();
- var studentValue = $(this).attr('value');
- $("input[value='" + studentValue + "']").prop("checked", false);
- var selectedData = $("input[name='studentName']:checked"); //获取所以选中学生
- $('#studentSelectedLength').text(selectedData.length);
- return false;
- });
- //分页
- $("body").on("click", ".pagination li", function () {
- var pageNo = $(this).attr('pageNo');
- var doType = $('.relate-goods').attr('doType');
- if(pageNo>0){
- relationOrderAction(pageNo,doType);
- }
- });
- //提交数据
- $(".sale-submit").click(function () {
- var flag = true;
- if (flag){
- flag = false;
- var orderId = $(".relate-goods").attr('orderId');
- if (orderId <= 0 || !orderId) {
- showMsg('请选择关联财务订单!');
- return false;
- }
- var outDate = $.trim($("input[name='out_date']").val());
- if (!outDate) {
- showMsg('退库日期不正确!');
- return false;
- }
- if (!checkDate(outDate)) {
- showMsg('退库日期不正确!');
- return false;
- }
- //选择的学生
- var stuSeled = $("#active-submit-stu>tr");
- var stuSeledArr = []; //已选学生id数组
- if (stuSeled.length <= 0) {
- showMsg('请添加学生!');
- return false;
- } else {
- $.each(stuSeled, function (index, value) {
- stuSeledArr.push($(value).attr('stuId'));
- });
- }
- <?php if (isset($_GET['inId']) && $_GET['inId'] != ''):?>
- //更新
- var inId = "<?php echo $_GET['inId'];?>";
- var data = {
- orderId: orderId,
- outDate: outDate,
- stuSeledArr: stuSeledArr,
- inId: inId
- }
- <?php else:?>
- var data = {
- orderId: orderId,
- outDate: outDate,
- stuSeledArr: stuSeledArr
- }
- <?php endif;?>
- //提交数据
- $.ajax({
- type: 'POST',
- url: "<?php echo $this->createUrl('imsStore/ajaxDeliveryOutAdd');?>",
- data: data,
- async: false,
- dataType: 'json',
- success: function (result) {
- console.log(result);
- if (result.status == 1) {
- layer.alert("提交成功", {icon: 1,closeBtn:0}, function () {
- window.location.href = "<?php echo $this->createUrl('imsStore/useOut/useOutType/cancle');?>";
- })
- } else {
- flag = true;
- layer.msg(result.error);
- }
- },
- error: function (jqXHR, textStatus, errorThrown) {
- /*错误信息处理*/
- flag = true;
- layer.msg('提交失败');
- }
- });
- }else{
- layer.msg("稍安勿躁,正在处理中...");
- }
- });
- //关联正式订单方法
- function relationOrderAction(page,doType) {
- if(doType=='add'){
- var orderId = 0;
- }else{
- var orderId = $('#oldOrderId').val();
- }
- $.ajax({
- type: 'POST',
- url: "<?php echo $this->createUrl('imsStore/ajaxOutputOrder');?>",
- data: {page: page,doType:doType,orderId:orderId},
- async: false,
- dataType: 'json',
- success: function (res) {
- console.log(res);
- if (res.status) {
- var html = '';
- for (var i = 0; i < res.data.list.length; i++) {
- var item = res.data.list[i];
- html += '<tr>';
- html += '<td><label class="checkbox-inline">';
- html += '<input type="radio" value="' + item['orderId'] + '" name="relation_order_select">';
- html += '<input type="hidden" value="' + item['orderNo'] + '" name="relation_orderNo_select">';
- html += '<input type="hidden" value="' + item['goodsName'] + '" name="relation_goodsName_select">';
- html += '<input type="hidden" value="' + item['itemName'] + '" id="order_item_name">';
- html += '</label></td>';
- html += '<td>' + item['orderNo'] + '</td>';
- html += '<td>' + item['goodsName'] + '</td>';
- html += '<td>' + item['goodsPackageName'] + '</td>';
- html += '<td>' + item['createTime'] + '</td>';
- html += '<td>' + item['quantity'] + '</td>';
- html += '<td>' + item['studentNo'] + '</td>';
- html += '</tr>';
- }
- console.log(page);
- setPage(res.data);
- } else {
- html += '<td>暂无数据</td>';
- }
- $('.order-table tbody').html(html);
- }
- });
- }
- //选择学生
- function getsStudentSelected() {
- var selectedData = $("input[name='studentName']:checked"); //获取所以选中学生
- var selectedDataList = [];
- var studentName, studentClass = '';
- for (var i = 0; i < selectedData.length; i++) {
- studentName = $(selectedData[i]).parent().text();
- studentClass = $(selectedData[i]).parents('li').children('span.classTitle').text();
- selectedDataList.push('<li><span class="stu_name">' + studentName + '</span>--<span class="stu_class">' + studentClass + '</span><i class="btn-delete" value="' + selectedData[i].value + '" gradeName="' + $(selectedData[i]).attr('gradeName') + '" className="' + $(selectedData[i]).attr('className') + '">X</i></li>');
- }
- $('.student-selected').html(selectedDataList);
- $('#studentSelectedLength').text(selectedData.length);
- };
- //计算出库数目
- 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 getCharLength(str) {
- return str.replace(/[\u0391-\uFFE5]/g, "a").length;
- }
- function checkDate(date) {
- return (new Date(date).getDate() == date.substring(date.length - 2));
- }
- function setPage(data) {
- var pageHtml = '';
- if(data['pages']>1){
- pageHtml+= '<li>';
- pageHtml+= '<span style="border: none;background: #ffffff;color: #666666;">';
- pageHtml+= '共'+data['total']+'条记录,共'+ data['pages']+'页';
- pageHtml+= '</span></li>';
- //上一页
- if(data['isFirstPage']){
- pageHtml+= "<li class='disabled' pageNo=0><a href='#'>上一页</a></li>";
- }else{
- pageHtml+= "<li class='' pageNo='"+data.prePage+"'><a href='#'>上一页</a></li>";
- }
- for (var i = 1; i <= data['lastPage']; i++) {
- if (i == data['pageNum']) {
- pageHtml+= "<li class='active' pageNo='"+i+"'><a href='#'>"+i+"</a></li>";
- } else {
- pageHtml+= "<li class='' pageNo='"+i+"'><a href='#' pageNo='"+i+"'>"+i+"</a></li>";
- }
- }
- //下一页
- if(data['isLastPage']){
- pageHtml+= "<li class='disabled' pageNo=0><a href='#'>下一页</a></li>";
- }else{
- pageHtml+= "<li class='' pageNo='"+data.nextPage+"'><a href='#'>下一页</a></li>";
- }
- }
- $('.pagination').html(pageHtml);
- }
- })
- </script>
|