/* 未能缩小。正在返回未缩小的内容。 (527,24-32): run-time error JS1009: Expected '}': function (527,24-32): run-time error JS1009: Expected '}': function (527,24-32): run-time error JS1006: Expected ')': function (525,23): run-time error JS1004: Expected ';' (527,38): run-time error JS1004: Expected ';' (542,31): run-time error JS1004: Expected ';' (545,33): run-time error JS1004: Expected ';' (547,14-15): run-time error JS1195: Expected expression: , (550,17-18): run-time error JS1006: Expected ')': : (550,17): run-time error JS1004: Expected ';' (551,18): run-time error JS1004: Expected ';' (551,18-19): run-time error JS1195: Expected expression: : (552,17): run-time error JS1004: Expected ';' (552,17-18): run-time error JS1195: Expected expression: : (553,20): run-time error JS1004: Expected ';' (553,20-21): run-time error JS1195: Expected expression: : (554,20): run-time error JS1004: Expected ';' (554,20-21): run-time error JS1195: Expected expression: : (556,22): run-time error JS1004: Expected ';' (556,22-23): run-time error JS1195: Expected expression: : (559,24): run-time error JS1004: Expected ';' (559,24-25): run-time error JS1195: Expected expression: : (560,21): run-time error JS1004: Expected ';' (560,21-22): run-time error JS1195: Expected expression: : (561,20): run-time error JS1004: Expected ';' (561,20-21): run-time error JS1195: Expected expression: : (562,10-11): run-time error JS1195: Expected expression: , (564,18): run-time error JS1004: Expected ';' (564,18-19): run-time error JS1195: Expected expression: : (565,19): run-time error JS1004: Expected ';' (565,19-20): run-time error JS1195: Expected expression: : (568,14-15): run-time error JS1195: Expected expression: , (570,10-11): run-time error JS1195: Expected expression: , (572,20): run-time error JS1004: Expected ';' (572,20-21): run-time error JS1195: Expected expression: : (575,5-6): run-time error JS1002: Syntax error: } (575,6-7): run-time error JS1195: Expected expression: ) (589,1-2): run-time error JS1002: Syntax error: } (589,2-3): run-time error JS1195: Expected expression: ) */ //加 function addnum(th) { var goods_count = parseInt(th.prev().val()); var sty = th.prev().attr("sty") if (sty == "qh") { th.prev().val(Number(goods_count) + 1); } else { var inventory = parseInt(th.parent().parent().parent().parent().find(".inventory").text()); if (goods_count >= inventory) { layer.msg('商品数量不能大于库存!', { icon: 2, shift: 6 }); return false; } th.prev().val(Number(goods_count) + 1); } DisCheckBox(th) statistics(); } //减 function redu(th) { var goods_count = parseInt(th.next().val()); if (goods_count >= 1) { th.next().val(Number(goods_count) - 1); } else { layer.msg('商品数量不能小于0!', { icon: 2, shift: 6 }); th.next().val(0); } DisCheckBox(th) statistics(); } //监听购买数量输入框 function monitor() { $("input[name='txtnum']").each(function () { var _this = $(this); _this.keyup(function () { var value = _this.val(); if (isNaN(value)) { layer.msg('商品数量只能输入数字!', { icon: 2, shift: 6 }); _this.val("0"); } var inventory = parseInt(_this.parent().parent().parent().parent().find("td[data-field='inventory']").find(".inventory").text()); if (value > inventory) { layer.msg('商品数量不能大于库存', { icon: 2, shift: 6 }); _this.val("0"); } }) _this.blur(function () { var value = _this.val(); if (isNaN(value) || value == "") _this.val("0"); }) _this.change(function () { DisCheckBox(_this) statistics(); }) }) $("input[name='txtnum_qh']").each(function () { var _this = $(this); _this.keyup(function () { var value = _this.val() if (isNaN(value)) { layer.msg('商品数量只能输入数字!', { icon: 2, shift: 6 }); _this.val("0"); } }) _this.blur(function () { var value = _this.val() if (isNaN(value) || value == "") _this.val("0"); }) _this.change(function () { DisCheckBox(_this) statistics(); }) }) } //选中复选框 function BoxChecked(th) { th.removeAttr("disabled").attr("checked", "checked").next().removeClass("layui-checkbox-disbaled layui-disabled") .addClass("layui-form-checked"); } //禁用复选框 function BoxDisabled(th) { th.removeAttr("checked").attr("disabled", "disabled").next().removeClass("layui-form-checked") .addClass("layui-checkbox-disbaled layui-disabled"); } //是否勾选 function DisCheckBox(th) { var li = th.parent().parent(); var box = li.parent().parent().find("input[name='layTableCheckbox']") var quantity_xh = parseInt(li.find(".changeNum").eq(0).val()); var quantity_qh = parseInt(li.find(".changeNum").eq(1).val()); quantity_xh = isNaN(quantity_xh) ? 0 : quantity_xh; quantity_qh = isNaN(quantity_qh) ? 0 : quantity_qh; if (quantity_xh <= 0 && quantity_qh <= 0) BoxDisabled(box) else BoxChecked(box) }; var max = 50; var tab_xunjia, tab_result; var sourceData = []; var resultData = []; $(function () { $(".g_header .nav ul li:nth-child(4)").addClass("act"); for (var i = 0; i < max; i++) { sourceData.push({}) } var url = new URL(this.location.href); var param_t = url.searchParams.get("t"); var param_b = url.searchParams.get("b"); var param_m = url.searchParams.get("m"); layui.use(['table', 'upload'], function () { var table = layui.table, upload = layui.upload; //渲染上传控件 upload.render({ elem: '#upload' //绑定元素 , url: '/Inquiry/Upload' //上传接口 , accept: 'file' , done: function (e) { if (e.code == 1) Upload(JSON.parse(e.data)) else layer.msg(e.msg, { icon: 2, shift: 6 }); } , error: function () { layer.msg("上传接口异常", { icon: 2, shift: 6 }); } }); //询价表 tab_xunjia = table.render({ elem: '#tab-xunjia' , data: sourceData , height: 235 //容器高度 , limit: max , cols: [[ { field: 'num', title: '', width: '4.5%', align: 'center', type: 'numbers' }, { field: 'i_title', title: '产品名称', width: '26%', align: 'center', edit: 'text' }, { field: 'i_brand', title: '品牌', width: '17.5%', align: 'center', edit: 'text' }, { field: 'i_model', title: '型号/订货号(必填)*', width: '26%', align: 'center', edit: 'text' }, { field: 'quantity', title: '数量', width: '8.5%', align: 'center', edit: 'text' }, { field: 'i_UM', title: '单位', width: '8.5%', align: 'center', edit: 'text' }, { field: 'operating', title: '操作', width: '104', align: 'center', toolbar: '#bar_table1' }, ]] }); //将链接参数的型号添加到询价表 if (param_m != null) { var result = [{ i_UM: "", i_brand: param_b, i_model: param_m, i_title: param_t, quantity: "1" }] for (var i = 0; i < 49; i++) { result.push({}) } sourceData = result; tab_xunjia.reload({ data: sourceData, limit: sourceData.length, }) } //报价表 tab_result = table.render({ elem: '#tab-result' , id: 'idTest' , data: [] , limit: 1 , cols: [[ { width: '3%', align: 'center', type: 'checkbox' }, { field: 'userQuery', title: '询价商品详情(会员)', width: '20%', templet: '#userQuery' }, { field: 'matchModify', title: '匹配修改', width: '20%', templet: '#matchModify' }, { field: 'leliResult', title: '匹配商品详情(乐利)', width: '20%', templet: '#leliResult' }, { field: 'vip_prices', title: '会员价', width: '14%', align: 'center', templet: '#vip_prices' }, { field: 'inventory', title: '货期', width: '7%', align: 'center', align: 'left', templet: '#inventory' }, { field: 'quantity', title: '数量', width: '10.5%', align: 'center', templet: '#quantity' }, { field: 'operating', title: '操作', width: '65', align: 'center', toolbar: '#bar' }, ]] }); //各控件事件监控 table.on('tool(xunjia)', function (obj) { if (obj.event === 'del') { layer.confirm('真的删除行么', function (index) { obj.del(); var n = obj.tr.data('index') sourceData.splice(n, 1) sourceData.push({}) tab_xunjia.reload({ data: sourceData }) layer.close(index); }); } }); table.on('tool(result)', function (obj) { var n = obj.tr.data('index') if (obj.event === 'del') { layer.confirm('真的删除行么', function (index) { obj.del(); resultData.splice(n, 1) //重新加载 ResultReload(); layer.close(index); }); } else if (obj.event === 'cle') { resultData[n].id = 0; resultData[n].order_no = null; resultData[n].title = null; resultData[n].model = null; resultData[n].brand = null; resultData[n].UM = null; resultData[n].special_prices = 0; resultData[n].pre_special_prices = 0; resultData[n].inventory = 0; resultData[n].pre_inventory = null; resultData[n].discount_info = null; resultData[n].is_yj = 1; resultData[n].status = 1; resultData[n].recommend = []; //重新加载 ResultReload(); } }); table.on('checkbox(result)', function (obj) { $(".layui-table-body").find("input[name='layTableCheckbox']").each(function () { if ($(this).next().hasClass("layui-checkbox-disbaled layui-disabled")) $(this).next().removeClass("layui-form-checked"); }) statistics(); }); }) }) //上传后渲染数据 function Upload(result) { if (result.length > 50) { layer.msg('一次性最大询价数量为50条,请分批询价!', { icon: 2, shift: 6 }); return; } var num = max - result.length; for (var i = 0; i < num; i++) { result.push({}) } sourceData = result; tab_xunjia.reload({ data: sourceData, limit: sourceData.length, }) } //批量查询 function batchQuery() { if ($("#inquiry_search").html() != "批量查询") return; $("#inquiry_search").html("") $(".remark").addClass("hide") var data = []; for (var i = 0; i < sourceData.length; i++) { var i_model = sourceData[i].i_model; if (i_model != "" && i_model != null) data.push(sourceData[i]) } if (data.length <= 0) { layer.msg('请填写或上传询价信息!', { icon: 2, shift: 6 }); $("#inquiry_search").html("批量查询") return; } $.ajax({ type: "post", url: '/Inquiry/Match', data: { "data": data }, success: function (e) { resultData = e.data; if (resultData != undefined) { ResultReload(); $(".cargo_result").removeClass("hide") $(".remark").removeClass("hide") $("#inquiry_search").html("批量查询") $('html,body').animate({ scrollTop: $(".cargo_result").offset().top }, 200) } } }) } //清除搜索源 function clearTable() { sourceData = []; for (var i = 0; i < max; i++) sourceData.push({}) tab_xunjia.reload({ data: sourceData, }) } //提交询价单 function submitInquiry() { if (resultData.length == 0) { layer.msg('请填写或上传询价信息!', { icon: 2, shift: 6 }); return } var data = []; for (var i = 0; i < resultData.length; i++) { data.push({ "i_title": resultData[i].i_title,"i_brand": resultData[i].i_brand,"i_model": resultData[i].i_model, "quantity": resultData[i].quantity, "i_UM": resultData[i].i_UM, "id": resultData[i].id, "goods_type": resultData[i].goods_type }) } $.ajax({ type: "post", url: '/Inquiry/Submit', data: { "data": data }, success: function (e) { if (e.code == 1) { layer.open({ icon: 1, title: '提示', btn: ["查看我的询价单", "返回首页"], content: "你的询价已经提交,我们尽快为你报价!", closeBtn: 2, shadeClose: true, success: function (layero) { var btn = layero.find('.layui-layer-btn'); btn.find('.layui-layer-btn0').attr("href", '/member/inquiries.html'); btn.find('.layui-layer-btn1').attr("href", '/index.html'); } }); } else if (e.code == 0) { layer.msg(e.msg); } } }) } //加入购物车 function add_shop_car() { var goods = []; var type = $("input[name='hid_goods_type']").val(); //获取选中数据 for (var i = 0; i < resultData.length; i++) { var box = $(".layui-form-checkbox").eq(i + 1); if ((resultData[i].status == 2 || resultData[i].is_yj == 2) && box.hasClass("layui-form-checked")) { var tr = box.parent().parent().parent(); var quantity = tr.find("input[name='txtnum']").val(); var quantity_qh = tr.find("input[name='txtnum_qh']").val(); quantity = isNaN(quantity) ? 0 : quantity; quantity_qh = isNaN(quantity_qh) ? 0 : quantity_qh; goods.push({ "goods_id": resultData[i].id, "goods_type": type, "quantity": quantity, "quantity_qh": quantity_qh }) } } if (goods.length == 0) { layer.msg('未选中要购买的商品,请选中后提交', { icon: 2, shift: 6 }); return false; } $.ajax({ type: "POST", dataType: "json", url: '/Shop/Add', data: { "carts": goods }, success: function (e) { if (e.code == 1) { layer.msg("商品成功添加到购物车", { time: 0 //不自动关闭 , btn: ['立即结算?', '再逛逛'] , yes: function (index) { layer.close(index); location.href = "/shopCart.html"; } }); } else { layer.msg(e.msg, { icon: 2, shift: 6 }); } } }) } //立即购买 function buy_now() { var goods = []; var type = $("input[name='hid_goods_type']").val(); //获取选中数据 for (var i = 0; i < resultData.length; i++) { var box = $(".layui-form-checkbox").eq(i + 1); if ((resultData[i].status == 2 || resultData[i].is_yj == 2) && box.hasClass("layui-form-checked")) { var tr = box.parent().parent().parent(); var quantity = tr.find("input[name='txtnum']").val(); var quantity_qh = tr.find("input[name='txtnum_qh']").val(); quantity = isNaN(quantity) ? 0 : quantity; quantity_qh = isNaN(quantity_qh) ? 0 : quantity_qh; goods.push({ "goods_id": resultData[i].id, "goods_type": type, "quantity": quantity, "quantity_qh": quantity_qh }) } } if (goods.length == 0) { layer.msg('未选中要购买的商品,请选中后提交', { icon: 2, shift: 6 }); return false; } //模拟表单提交并打开订单页面 var form = $("
").attr({ "action": "/shop/order" }); var input = $("").attr({ "name": "carts" }).val(JSON.stringify(goods)); form.append(input); $(document.body).append(form); form.submit(); } //阻止冒泡 兼容 function stopEvent(event) { var e = arguments.callee.caller.arguments[0] || event;//这里是因为除了IE有event其他浏览器没有所以要做兼容 if (window.event) { //这是IE浏览器 e.cancelBubble = true;//阻止冒泡事件 e.returnValue = false;//阻止默认事件 } else if (e && e.stopPropagation) { //这是其他浏览器 e.stopPropagation();//阻止冒泡事件 e.preventDefault();//阻止默认事件 } } //渲染结果数据表 function ResultReload() { tab_result.reload({ data: resultData, limit: resultData.length, height: resultData.length >= 3 ? 490 : "", done: function (res, curr, count) { for (var i = 0; i < res.data.length; i++) { if (res.data[i].status == 1 && res.data[i].is_yj == 1) BoxDisabled($(".layui-table-body").find("input[name='layTableCheckbox']").eq(i)) } $(".changeNum").each(function () { var _this = $(this); if (_this.val() > 0) BoxChecked(_this.parent().parent().parent().parent().children().find("input[name='layTableCheckbox']")); }) monitor(); statistics(); } }) } //统计总数 function statistics() { var data = []; var count = 0, total = 0; //获取选中数据 for (var i = 0; i < resultData.length; i++) { if ((resultData[i].status == 2 || resultData[i].is_yj == 2) && $(".layui-form-checkbox").eq(i + 1).hasClass("layui-form-checked")) data.push(resultData[i]) } for (var i = 0; i < data.length; i++) { var d = data[i]; var th = $(".layui-table-body .layui-form-checked").eq(i); var quantity = parseInt(th.parent().parent().parent().find("input[name='txtnum']").val()); var quantity_qh = parseInt(th.parent().parent().parent().find("input[name='txtnum_qh']").val()); quantity = isNaN(quantity) ? 0 : quantity; quantity_qh = isNaN(quantity_qh) ? 0 : quantity_qh; count += quantity + quantity_qh; total += parseFloat((d.special_prices * quantity).toFixed(2)) + parseFloat((d.pre_special_prices * quantity_qh).toFixed(2)); } $("#goods-kind").text(data.length); $("#goods-num").text(count); $("#total-price").text(total.toFixed(2)); } //渲染搜索框 $(function () { document.addEventListener("mousedown", function () { $('#search_inquiry').css("display", "none"); }); //搜索框自动提示 var controller; new autoComplete({ data: { src: async function src() { if (controller !== undefined) controller.abort(); var source; const query = document.querySelector("#txt_title").value; controller = $.ajax({ url: "/Mall/Autocomplete", method: 'post', data: JSON.stringify({ search: query }), headers: { 'Content-Type': 'application/json' }, success: function (e) { source = e; } }) source = await controller; controller = undefined; var data = await source.data; return data.map(x => x.model); }, cache: false }, selector: "#txt_title", threshold: 1, debounce: 0, placeHolder: "请输入型号进行匹配查询...", resultsList: { render: true, container: source => { source.setAttribute("class", "autoComplete_list"); }, destination: document.querySelector("#txt_title"), position: "afterend", element: "ul" }, maxResults: 10, highlight: true, resultItem: { content: function content(data, source) { source.innerHTML = data.match; }, element: "li" }, searchEngine: "loose", onSelection: function onSelection(feedback) { ReplaceModel(feedback.selection.value, $('#txt_title').attr("data-index")); } }); //搜索框注册事件 ["focus", "blur"].forEach(function (eventType) { const resultsList = document.querySelector(".autoComplete_list"); document.querySelector("#txt_title").addEventListener(eventType, function () { if (eventType === "blur") { resultsList.style.display = "none"; } else if (eventType === "focus") { resultsList.style.display = "block"; } }); }); }) //显示搜索框 function ShowSearchBox(th) { var ypos = th.offset().top; var xpos = th.offset().left; $('#search_inquiry').css({ "display": "block", 'z-index': '9999', 'position': 'absolute', 'left': xpos + "px", 'top': ypos + "px" }); $('#txt_title').attr("data-index", th.parent().parent().parent().parent().attr("data-index")).val("").focus(); } //匹配修改型号 function ReplaceModel(title, index) { if (title == "" || title == null) return; $('#search_inquiry').hide(); $(".remark").addClass("hide") tab_result.reload({ data: null, }) var temp = resultData[index]; var data = [{ "i_title": temp.i_title, "i_brand": temp.i_brand, "i_model": title, "quantity": temp.quantity, "i_UM": temp.i_UM }]; $.ajax({ type: "post", url: '/Inquiry/Match', data: { "data": data }, success: function (e) { resultData[index] = e.data[0]; resultData[index].i_model = temp.i_model; //渲染结果 ResultReload(); statistics(); $(".remark").removeClass("hide"); } }) } //选择推荐型号 function clickRecommend(th) { var title = th.text(); var index = th.parent().parent().parent().parent().parent().attr("data-index") ReplaceModel(title, index) };