// ==UserScript== // @name saleorder // @namespace https://scriptcat.org/zh-CN/script-show-page/3813 // @version 1.7 // @description 在'销售订单'增加功能,对外版本 // @author fengxia // @match http://122.13.25.247:8888/sales/orderPage.do // @match http://47.107.106.156:8888/sales/orderPage.do // @match http://47.107.106.156:8888/sales/orderPage.do?type=edit&id=* // @match http://122.13.25.247:8888/sales/orderPage.do?type=edit&id=* // @icon data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDEiIGhlaWdodD0iNDEiIHZpZXdCb3g9IjAgMCA0MSA0MSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBzdHJva2Utd2lkdGg9IjEuNSIgY2xhc3M9ImgtNiB3LTYiIHJvbGU9ImltZyI+PHRpdGxlPkNoYXRHUFQ8L3RpdGxlPjx0ZXh0IHg9Ii05OTk5IiB5PSItOTk5OSI+Q2hhdEdQVDwvdGV4dD48cGF0aCBkPSJNMzcuNTMyNCAxNi44NzA3QzM3Ljk4MDggMTUuNTI0MSAzOC4xMzYzIDE0LjA5NzQgMzcuOTg4NiAxMi42ODU5QzM3Ljg0MDkgMTEuMjc0NCAzNy4zOTM0IDkuOTEwNzYgMzYuNjc2IDguNjg2MjJDMzUuNjEyNiA2LjgzNDA0IDMzLjk4ODIgNS4zNjc2IDMyLjAzNzMgNC40OTg1QzMwLjA4NjQgMy42Mjk0MSAyNy45MDk4IDMuNDAyNTkgMjUuODIxNSAzLjg1MDc4QzI0Ljg3OTYgMi43ODkzIDIzLjcyMTkgMS45NDEyNSAyMi40MjU3IDEuMzYzNDFDMjEuMTI5NSAwLjc4NTU3NSAxOS43MjQ5IDAuNDkxMjY5IDE4LjMwNTggMC41MDAxOTdDMTYuMTcwOCAwLjQ5NTA0NCAxNC4wODkzIDEuMTY4MDMgMTIuMzYxNCAyLjQyMjE0QzEwLjYzMzUgMy42NzYyNCA5LjM0ODUzIDUuNDQ2NjYgOC42OTE3IDcuNDc4MTVDNy4z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k5ODFDMTAuODU3NiAxOS45ODkzIDEwLjg0MjMgMTkuOTc2MyAxMC44MzA5IDE5Ljk2MDJDMTAuODE5NSAxOS45NDQxIDEwLjgxMjIgMTkuOTI1NCAxMC44MDk4IDE5LjkwNThWMTAuNjA3MUMxMC44MTA3IDkuMTgyOTUgMTEuMjE3MyA3Ljc4ODQ4IDExLjk4MTkgNi41ODY5NkMxMi43NDY2IDUuMzg1NDQgMTMuODM3NyA0LjQyNjU5IDE1LjEyNzUgMy44MjI2NEMxNi40MTczIDMuMjE4NjkgMTcuODUyNCAyLjk5NDY0IDE5LjI2NDkgMy4xNzY3QzIwLjY3NzUgMy4zNTg3NiAyMi4wMDg5IDMuOTM5NDEgMjMuMTAzNCA0Ljg1MDY3QzIzLjA0MjcgNC44ODM3OSAyMi45MzcgNC45NDIxNSAyMi44NjY4IDQuOTg0NzNMMTQuOTAyNCA5LjU4NTE3QzE0LjcwMjUgOS42OTg3OCAxNC41MzY2IDkuODYzNTYgMTQuNDIxNSAxMC4wNjI2QzE0LjMwNjUgMTAuMjYxNiAxNC4yNDY2IDEwLjQ4NzcgMTQuMjQ3OSAxMC43MTc1TDE0LjI0MjQgMjEuOTQxOVpNMTYuMDcxIDE3Ljk5OTFMMjAuNDAxOCAxNS40OTc4TDI0LjczMjUgMTcuOTk3NVYyMi45OTg1TDIwLjQwMTggMjUuNDk4M0wxNi4wNzEgMjIuOTk4NVYxNy45OTkxWiIgZmlsbD0iY3VycmVudENvbG9yIj48L3BhdGg+PC9zdmc+ // @require https://scriptcat.org/lib/513/2.1.0/ElementGetter.js // @require https://scriptcat.org/lib/637/1.4.6/ajaxHooker.js // @grant none // ==/UserScript== (function () { 'use strict'; // ==================== 配置 ==================== const SERVER_IP = (/(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/).exec(window.location.href)[0]; const BASE_URL = `http://${SERVER_IP}:8888`; // 历史价格查询缓存:key = "customer_products_year";换商品/客户时整体清空 const historyCache = new Map(); let historyCacheScope = ''; // 当前缓存对应的 "customer_products" // ==================== 工具函数 ==================== // toast 提示自动消失时间(毫秒) const TOAST_DURATION_MS = 3000; /** 页面顶部非阻塞 toast 提示,替代 alert(重复单、请求失败等) */ function notify(msg) { console.warn('[saleorder]', msg); const toast = document.createElement('div'); toast.textContent = msg; toast.style.cssText = 'position:fixed;top:20px;left:50%;transform:translateX(-50%);z-index:99999;background:#333;color:#fff;padding:8px 16px;border-radius:4px;max-width:60%;font-size:14px;box-shadow:0 2px 8px rgba(0,0,0,.3);transition:opacity .5s;'; document.body.appendChild(toast); setTimeout(() => { toast.style.opacity = '0'; setTimeout(() => toast.remove(), 500); }, TOAST_DURATION_MS); } /** 防抖 */ function debounce(fn, delay = 500) { let timer = null; return function (...args) { clearTimeout(timer); timer = setTimeout(() => fn.apply(this, args), delay); }; } /** 通用 POST 请求(返回 Promise) */ function postRequest(path, params) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); const url = new URL(BASE_URL + path); for (const key in params) { if (Array.isArray(params[key])) { params[key].forEach(v => url.searchParams.append(key, v)); } else { url.searchParams.set(key, params[key]); } } xhr.open('post', url); xhr.send(); xhr.onload = function () { if (xhr.status !== 200) { reject(new Error(`HTTP ${xhr.status}: ${xhr.statusText}`)); } else { try { resolve(JSON.parse(xhr.response)); } catch (e) { reject(new Error('JSON 解析失败')); } } }; xhr.onerror = () => reject(new Error('网络请求失败')); }); } /** 日期区间计算(修复月份 bug) */ function getIntervalDate(year) { let start_date, end_date; if (year) { start_date = `${year}-01-01`; end_date = `${year}-12-31`; } else { const date = new Date(); end_date = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; date.setDate(date.getDate() - 90); start_date = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; } return { start_date, end_date }; } // ==================== 重复订单查询 ==================== function onSourceIdChange() { const customerInput = document.querySelector('#sales-customer-showid-orderAddPage a'); const inputOrder = document.querySelector('#sales-sourceid-orderAddPage'); if (inputOrder && inputOrder.value) { QueryCustomerOrder(customerInput.innerText, inputOrder.value); } } async function QueryCustomerOrder(customer, order) { const query_date = getIntervalDate(); try { const data = await postRequest('/sales/getOrderList.do', { businessdate: query_date.start_date, businessdate1: query_date.end_date, customerid: customer, sourceid: order, isstoragelock: '0', page: '1', rows: '200', sort: 'addtime', order: 'desc', id: '', salesdept: '', status: '', goodsid: '', printsign: '', queryprinttimes: '', urgentlevel: '', lineid: '', salesuserArrs: '' }); if (data.total > 0) { const orderNo = data.rows .filter(row => row.status !== '5') .map(row => row.id) .join(','); if (orderNo) { notify(`有重复订单,订单号为${orderNo}`); } } } catch (e) { console.error('[saleorder] 重复订单查询失败:', e.message); notify(`重复订单查询失败:${e.message}`); } } // ==================== 历史价格查询 ==================== async function queryHistoryPrice(customer, products, year) { // 换商品或客户后旧缓存不再适用,整体清空重新查询 const scope = `${customer}_${products}`; if (scope !== historyCacheScope) { historyCache.clear(); historyCacheScope = scope; } const cacheKey = `${customer}_${products}_${year}`; if (historyCache.has(cacheKey)) { renderHistoryTable(historyCache.get(cacheKey), products, year); return; } const div = $(`.panel-body-noborder.layout-body.${year}`); div.html('

加载中...

'); try { const [returns_order, sale_order] = await Promise.all([ fetchCustomerSalesFlow(customer, products, year), fetchSalesOrderTrack(customer, products, year) ]); const list_order = []; for (const row of returns_order) { list_order.push({ goodsid: row.goodsid, date: row.businessdate, unitnum: row.unitnum, price: row.price, sendnum: row.unitnum, checkprice: row.price, order: row.customerbillid, }); } for (const row of sale_order) { if (row.ordernum > 0) { list_order.push({ goodsid: row.goodsid, date: row.businessdate, unitnum: row.initsendnum, price: row.dispatchprice, sendnum: row.sendnum === undefined ? '未出库' : row.sendnum, checkprice: row.checkprice === undefined ? '未验收' : row.checkprice, order: row.sourceid, }); } } // 排序:日期 → 单号 → 数量绝对值 list_order.sort((a, b) => { const dateDiff = new Date(a.date) - new Date(b.date); if (dateDiff !== 0) return dateDiff; const orderDiff = a.order.localeCompare(b.order); if (orderDiff !== 0) return orderDiff; return Math.abs(a.unitnum) - Math.abs(b.unitnum); }); historyCache.set(cacheKey, list_order); renderHistoryTable(list_order, products, year); } catch (e) { console.error('[saleorder] 历史价格查询失败:', e.message); notify(`历史价格查询失败:${e.message}`); $(`.panel-body-noborder.layout-body.${year}`).html( `

查询失败: ${e.message}

` ); } } function renderHistoryTable(list_order, products, year) { let tr_html = ''; let x = 1; if (list_order.length === 0) { tr_html = `${products}无销售`; } else { for (const row of list_order) { const rowClass = (x % 2 === 0) ? 'datagrid-row-alt datagrid-row' : 'datagrid-row'; const style = (row.price !== row.checkprice) ? 'font-weight: bold;color: red;' : ''; tr_html = ` ${row.goodsid} ${row.date} ${row.unitnum} ${row.price} ${row.sendnum} ${row.checkprice} ` + tr_html; x++; } } const table_html = `
编码 日期 数量 单价 出库数量 验收单价
${tr_html}
`; $(`.panel-body-noborder.layout-body.${year}`).html(table_html); } function fetchCustomerSalesFlow(customer, products, year) { const query_date = getIntervalDate(year); return postRequest('/report/finance/showCustomerSalesFlowList.do', { businessdate1: query_date.start_date, businessdate2: query_date.end_date, goodsid: products, customerid: customer, 'billtype[]': ['2', '3'], invoice1: '1', writeoff1: '1', invoice2: '1', writeoff2: '1', page: '1', rows: '1000', salesuser: '', batchno: '', goodssort: '', pcustomerid: '', salesarea: '', customersort: '', salesdept: '', writeoffdate1: '', writeoffdate2: '', orderid: '', type: '', brandid: '', id: '', storageid: '', supplierid: '' }).then(data => data.rows); } function fetchSalesOrderTrack(customer, products, year) { const query_date = getIntervalDate(year); return postRequest('/report/sales/showSalesOrderTrackReportData.do', { businessdate1: query_date.start_date, businessdate2: query_date.end_date, goodsid: products, customerid: customer, page: '1', rows: '1000', sort: 'businessdate', order: 'asc', id: '', brandid: '', checkstatus: '', salesuser: '', pcustomerid: '', indooruserid: '', sourceid: '', goodssort: '' }).then(data => data.rows); } // ==================== 历史价格面板 UI ==================== function buildHistoryPanel() { const targetDiv = $('div.panel.window').filter("[style*='display: block;']"); const targetShadow = $('div.window-shadow').filter("[style*='display: block;']"); const div_top = targetDiv.css('top'); const div_width = $('div.window-mask').width(); const div_num = div_width - 1110; targetDiv.css('left', div_num * 0.85 + 'px'); targetShadow.css('left', div_num * 0.85 + 'px'); const currentYear = new Date().getFullYear(); const startYear = Math.max(currentYear - 5, 2022); let tab_div = ''; let table_div = ''; for (let year = startYear; year <= currentYear; year++) { let liClass = ''; let divStyle = 'display: none'; if (year === startYear) liClass += 'tabs-last'; if (year === currentYear) { liClass += ' tabs-first tabs-selected'; divStyle = 'display: block'; } tab_div += `
  • ${year}
  • `; table_div += `
    `; } const newDiv = `
    ${table_div}
    `; targetDiv.before(newDiv); const remove_div = $('.new_div'); // ESC 键关闭面板(绑定/解绑管理) const escHandler = function (event) { if (event.keyCode === 27) { remove_div.remove(); $(document).off('keydown', escHandler); return false; } }; $(document).on('keydown', escHandler); // 关闭按钮 targetDiv.find('.panel-tool-close').on('click', function () { remove_div.remove(); $(document).off('keydown', escHandler); }); // Tab 切换 $('.new_div .tabs li').on('click', function () { if (!$(this).hasClass('tabs-selected')) { const index = $(this).index(); const div_table = $('.new_div .panel-body-noborder.layout-body'); div_table.css('display', 'none'); div_table.eq(index).css('display', 'block'); $('.new_div .tabs li').removeClass('tabs-selected'); $(this).addClass('tabs-selected'); const products_id = $('#sales-goodsId-orderDetailAddPage-hidden').val(); if (products_id) { const customer_id = $('#sales-customer-orderAddPage-hidden').val(); const select_year = $('.new_div .tabs-selected span').html(); queryHistoryPrice(customer_id, products_id, select_year); } } }); } // ==================== 商品信息回填 ==================== function createTableTd() { elmGetter.each('#remark', document, add_model => { const table_tr = add_model.closest('tr'); const table_tbody = add_model.closest('tbody'); const model_string = ` 规格: `; table_tr.insertAdjacentHTML('beforeend', model_string); const price_string = ` 最新采购价: `; table_tbody.insertAdjacentHTML('beforeend', price_string); }); } // ==================== 事件绑定与初始化 ==================== function findAndBindEvents() { // 单号输入框:使用 change 事件避免 alert 抢焦点导致死循环 elmGetter.each('#sales-sourceid-orderAddPage', document, order => { order.addEventListener('change', debounce(onSourceIdChange, 600)); }); // 监听弹窗打开 → 创建历史价格面板 elmGetter.each('#sales-dialog-orderAddPage-content', document, () => { buildHistoryPanel(); }); } // Ajax Hook:商品详情返回时回填规格和最新采购价 ajaxHooker.hook(request => { if (request.url === 'sales/getGoodsDetail.do') { request.response = res => { let products_id, products_model, products_newbuyprice; try { const json_array = (JSON.parse(res.responseText)).detail.goodsInfo; products_id = json_array.id; products_model = json_array.model; products_newbuyprice = json_array.newbuyprice; } catch (err) { console.error('[saleorder] getGoodsDetail 解析失败:', err); return; } const customer_id = $('#sales-customer-orderAddPage-hidden').val(); const select_year = $('.new_div .tabs-selected span').html(); $('#products_price').val(products_newbuyprice); $('#products_model').val(products_model); if (customer_id && products_id && select_year) { queryHistoryPrice(customer_id, products_id, select_year); } }; } }); // 启动 findAndBindEvents(); createTableTd(); })();