From 55f13bb47bc8a6dcdc132a0d47d996fed142f854 Mon Sep 17 00:00:00 2001 From: xuan <1359774872@qq.com> Date: Fri, 4 Sep 2026 15:57:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E8=BF=9C=E7=A8=8B=E6=90=9C=E7=B4=A2=E5=B9=B6=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- src/App.vue | 15 + src/common/http.api.js | 2 + src/common/http.interceptor.js | 13 +- src/common/remoteSelect.js | 46 ++ src/common/remoteSelectMixin.js | 54 ++ src/common/storeFabricBusinessOut.js | 9 +- src/common/storeGoodsProcessIn.js | 8 +- src/common/storeGoodsProcessOut.js | 8 +- src/common/storeGoodsProcessReturnIn.js | 8 +- src/common/storeGoodsPurchaseIn.js | 8 +- src/common/userSession.js | 155 +++++ .../u-action-sheet/u-action-sheet.vue | 247 ++++++++ .../u-dropdown-item/u-dropdown-item.vue | 186 ++++++ src/components/u-select/u-select.vue | 538 ++++++++++++++++++ src/pages.json | 3 + .../storefabric/storeFabricBusinessOutAdd.vue | 2 +- .../storeFabricBusinessOutEdit.vue | 2 +- .../storeFabricBusinessOutList.vue | 53 +- .../storeFabricBusinessOutMixin.js | 27 +- .../storegoods/storeGoodsProcessInAdd.vue | 2 +- .../storegoods/storeGoodsProcessInEdit.vue | 2 +- .../storegoods/storeGoodsProcessInList.vue | 58 +- .../storegoods/storeGoodsProcessInMixin.js | 62 +- .../storegoods/storeGoodsProcessOutAdd.vue | 2 +- .../storegoods/storeGoodsProcessOutEdit.vue | 2 +- .../storegoods/storeGoodsProcessOutList.vue | 58 +- .../storegoods/storeGoodsProcessOutMixin.js | 56 +- .../storeGoodsProcessReturnInAdd.vue | 2 +- .../storeGoodsProcessReturnInEdit.vue | 2 +- .../storeGoodsProcessReturnInList.vue | 58 +- .../storeGoodsProcessReturnInMixin.js | 45 +- .../storegoods/storeGoodsPurchaseInAdd.vue | 2 +- .../storegoods/storeGoodsPurchaseInEdit.vue | 2 +- .../storegoods/storeGoodsPurchaseInList.vue | 58 +- .../storegoods/storeGoodsPurchaseInMixin.js | 62 +- src/pages/sys/login/index.vue | 41 +- src/pages/sys/user/index.vue | 2 +- src/pages/sys/user/setting.vue | 23 +- src/pages/sys/workbench/index.vue | 122 ++-- src/store/index.js | 14 +- vue.config.js | 5 + 41 files changed, 1734 insertions(+), 330 deletions(-) create mode 100644 src/common/remoteSelect.js create mode 100644 src/common/remoteSelectMixin.js create mode 100644 src/common/userSession.js create mode 100644 src/components/u-action-sheet/u-action-sheet.vue create mode 100644 src/components/u-dropdown-item/u-dropdown-item.vue create mode 100644 src/components/u-select/u-select.vue diff --git a/src/App.vue b/src/App.vue index 819249d..fc85d8e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -6,6 +6,7 @@ import { audioManager } from '@/utils/audioManager' import util from '@/common/util.js'; import md5 from '@/common/md5.js'; + import { restoreUserSession } from '@/common/userSession.js'; export default { globalData: { AppName: '', @@ -25,6 +26,7 @@ import { audioManager } from '@/utils/audioManager' onLaunch() { console.log('App Launch'); + restoreUserSession(); // 初始化音频管理器 audioManager.init(); @@ -374,4 +376,17 @@ import { audioManager } from '@/utils/audioManager' text-align: center; box-sizing: border-box; } + + .u-select__search, + .u-action-sheet-search, + .u-dropdown-item__search { + height: 88rpx !important; + } + + .u-select__search__input, + .u-action-sheet-search__input, + .u-dropdown-item__search__input { + font-size: 32rpx !important; + height: 88rpx !important; + } diff --git a/src/common/http.api.js b/src/common/http.api.js index 481dcc5..6a55643 100644 --- a/src/common/http.api.js +++ b/src/common/http.api.js @@ -142,6 +142,8 @@ const install = (Vue, vm) => { // PDA登录接口 pdaLogin: (params = {}) => vm.$u.postJson('/login', params), pdaLogout: (params = {}) => vm.$u.postJson('/logout', params), + // 登录后获取当前用户信息、菜单与按钮权限 + pdaGetInformation: (params = {}) => vm.$u.get('/information', params), // 获取配布单列表 getFpmArrangeOrderList: (params = {}) => vm.$u.get('/product/fpmArrangeOrder/getFpmArrangeOrderList', params), // 获取成品配布单详情 diff --git a/src/common/http.interceptor.js b/src/common/http.interceptor.js index 9ba2bba..3cef942 100644 --- a/src/common/http.interceptor.js +++ b/src/common/http.interceptor.js @@ -2,6 +2,8 @@ * Copyright (c) 2013-Now http://aidex.vip All rights reserved. */ // 此处第二个参数vm,就是我们在页面使用的this,你可以通过vm获取vuex等操作 +import { clearUserSession } from '@/common/userSession.js'; + const install = (Vue, vm) => { // 通用请求头设定 const ajaxHeader = 'x-ajax'; @@ -43,8 +45,9 @@ const install = (Vue, vm) => { } // 设定传递 Token 认证参数 aidex - if (!req.header[sessionIdHeader] && vm.vuex_token){ - req.header[sessionIdHeader] = vm.vuex_token; + if (!req.header[sessionIdHeader]){ + const loginData = uni.getStorageSync('RemoteTokenData'); + req.header[sessionIdHeader] = vm.vuex_token || (loginData && loginData.token) || ''; } // 为节省流量,记住我数据不是每次都发送的,当会话失效后,尝试重试登录 aidex @@ -65,11 +68,7 @@ const install = (Vue, vm) => { // 处理401未授权状态码 if (res.statusCode === 401) { vm.$u.toast('登录已过期,请重新登录'); - // 清除token和用户信息 - uni.removeStorageSync('token'); - vm.$u.vuex('vuex_token', ''); - vm.$u.vuex('vuex_user', {}); - // 跳转到登录页面 + clearUserSession(); uni.reLaunch({ url: '/pages/sys/login/index' }); diff --git a/src/common/remoteSelect.js b/src/common/remoteSelect.js new file mode 100644 index 0000000..4c60506 --- /dev/null +++ b/src/common/remoteSelect.js @@ -0,0 +1,46 @@ +/** + * 从往来单位等列表接口中取出数组。 + * 兼容拦截器解包后的 { list, total },以及完整响应 + * { data: { code, data: { list, total } } }。 + */ +export function extractList(data, depth = 0) { + if (!data || depth > 6) return []; + if (Array.isArray(data)) return data; + if (Array.isArray(data.list)) return data.list; + if (Array.isArray(data.items)) return data.items; + if (Array.isArray(data.records)) return data.records; + if (data.data && typeof data.data === 'object') return extractList(data.data, depth + 1); + return []; +} + +/** 将下拉/列表接口响应转为 u-select 所需的 { value, label } */ +export function mapToSelectOptions(data) { + return extractList(data).filter((item) => item && typeof item === 'object').map((item) => ({ + value: item.id != null ? item.id : item.value, + label: item.name || item.label || item.code || (item.id != null ? String(item.id) : ''), + })); +} + +/** + * 下拉远程搜索:把关键字写入接口常用的 name 参数。 + * 空关键字时不带 name,让后端返回默认列表。 + */ +export function withNameParam(params, keyword) { + const next = Object.assign({}, params || {}); + const name = String(keyword || '').trim(); + if (name) next.name = name; + else delete next.name; + return next; +} + +export const REMOTE_SELECT_TYPES = [ + '染厂', + '加工单位', + '供应商', + '仓库名称', + '营销体系', +]; + +export function isRemoteSelectType(type) { + return REMOTE_SELECT_TYPES.indexOf(type) !== -1; +} diff --git a/src/common/remoteSelectMixin.js b/src/common/remoteSelectMixin.js new file mode 100644 index 0000000..e8b9a58 --- /dev/null +++ b/src/common/remoteSelectMixin.js @@ -0,0 +1,54 @@ +import { isRemoteSelectType } from '@/common/remoteSelect'; + +/** + * 表单页远程下拉搜索。 + * 使用方需实现 fetchRemoteSelectOptions(type, keyword),返回 { value, label }[]。 + * + * 注意:不要用 `_` / `$` 前缀的 data 字段名——Vue2 不会代理到 this, + * `++this._xxx` 会得到 NaN,导致列表不更新、loading 不关。 + */ +export default { + data() { + return { + selectSearching: false, + selectSearchSeq: 0, + }; + }, + computed: { + isRemoteSelect() { + return isRemoteSelectType(this.selectType); + }, + }, + methods: { + isRemoteSelectType, + openSelectPicker(type, cachedList) { + this.selectType = type; + this.selectList = Array.isArray(cachedList) ? cachedList.slice() : []; + this.selectShow = true; + }, + onSelectSearch(keyword) { + if (!isRemoteSelectType(this.selectType)) return; + if (typeof this.fetchRemoteSelectOptions !== 'function') return; + const seq = ++this.selectSearchSeq; + this.selectSearching = true; + const finish = () => { + if (seq === this.selectSearchSeq) this.selectSearching = false; + }; + Promise.resolve() + .then(() => this.fetchRemoteSelectOptions(this.selectType, keyword)) + .then((list) => { + if (seq !== this.selectSearchSeq) return; + this.selectList = Array.isArray(list) ? list.slice() : []; + }) + .catch((e) => { + if (seq !== this.selectSearchSeq) return; + if (typeof this.showError === 'function') { + this.showError((e && e.message) || '搜索失败'); + } else { + uni.showToast({ title: (e && e.message) || '搜索失败', icon: 'none' }); + } + }) + .then(finish, finish); + }, + }, +}; diff --git a/src/common/storeFabricBusinessOut.js b/src/common/storeFabricBusinessOut.js index 83932c9..23eb783 100644 --- a/src/common/storeFabricBusinessOut.js +++ b/src/common/storeFabricBusinessOut.js @@ -80,14 +80,7 @@ export function getStatusOptions() { })); } -/** 将下拉/列表接口响应转为 u-select 所需的 { value, label } */ -export function mapToSelectOptions(data) { - const list = Array.isArray(data) ? data : (data && (data.list || data.items || data.records)) || []; - return list.map((item) => ({ - value: item.id, - label: item.name || item.label || item.code || String(item.id), - })); -} +export { mapToSelectOptions } from '@/common/remoteSelect'; // 匹数:后端以 0.01 匹存储(乘以100的整数),展示需除以100 export function formatRoll(value) { diff --git a/src/common/storeGoodsProcessIn.js b/src/common/storeGoodsProcessIn.js index a8d2551..7693a3f 100644 --- a/src/common/storeGoodsProcessIn.js +++ b/src/common/storeGoodsProcessIn.js @@ -74,13 +74,7 @@ export function getStatusOptions() { })); } -export function mapToSelectOptions(data) { - const list = Array.isArray(data) ? data : (data && (data.list || data.items || data.records)) || []; - return list.map((item) => ({ - value: item.id, - label: item.name || item.label || item.code || String(item.id), - })); -} +export { mapToSelectOptions } from '@/common/remoteSelect'; /** 匹数:后端 ×100 存储 */ export function formatRoll(value) { diff --git a/src/common/storeGoodsProcessOut.js b/src/common/storeGoodsProcessOut.js index 844c734..334955d 100644 --- a/src/common/storeGoodsProcessOut.js +++ b/src/common/storeGoodsProcessOut.js @@ -59,13 +59,7 @@ export function getStatusOptions() { })); } -export function mapToSelectOptions(data) { - const list = Array.isArray(data) ? data : (data && (data.list || data.items || data.records)) || []; - return list.map((item) => ({ - value: item.id, - label: item.name || item.label || item.code || String(item.id), - })); -} +export { mapToSelectOptions } from '@/common/remoteSelect'; /** 匹数:后端 ×100 存储 */ export function formatRoll(value) { diff --git a/src/common/storeGoodsProcessReturnIn.js b/src/common/storeGoodsProcessReturnIn.js index c8765e8..6ff8ff5 100644 --- a/src/common/storeGoodsProcessReturnIn.js +++ b/src/common/storeGoodsProcessReturnIn.js @@ -55,13 +55,7 @@ export function getStatusOptions() { })); } -export function mapToSelectOptions(data) { - const list = Array.isArray(data) ? data : (data && (data.list || data.items || data.records)) || []; - return list.map((item) => ({ - value: item.id, - label: item.name || item.label || item.code || String(item.id), - })); -} +export { mapToSelectOptions } from '@/common/remoteSelect'; /** 匹数:后端 ×100 存储 */ export function formatRoll(value) { diff --git a/src/common/storeGoodsPurchaseIn.js b/src/common/storeGoodsPurchaseIn.js index 40a3232..7ce15e4 100644 --- a/src/common/storeGoodsPurchaseIn.js +++ b/src/common/storeGoodsPurchaseIn.js @@ -87,13 +87,7 @@ export function getStatusOptions() { })); } -export function mapToSelectOptions(data) { - const list = Array.isArray(data) ? data : (data && (data.list || data.items || data.records)) || []; - return list.map((item) => ({ - value: item.id, - label: item.name || item.label || item.code || String(item.id), - })); -} +export { mapToSelectOptions } from '@/common/remoteSelect'; /** 匹数:后端 ×100 存储 */ export function formatRoll(value) { diff --git a/src/common/userSession.js b/src/common/userSession.js new file mode 100644 index 0000000..17f0498 --- /dev/null +++ b/src/common/userSession.js @@ -0,0 +1,155 @@ +/** + * 登录会话:token、用户信息、菜单/按钮权限 + */ +import store from '@/store/index.js'; + +const TOKEN_KEY = 'RemoteTokenData'; +const USER_TOKEN_KEY = 'userToken'; +const INFORMATION_KEY = 'PdaUserInformation'; + +function commitVuex(name, value) { + store.commit('$uStore', { name, value }); +} + +function applyGlobalData(patch) { + try { + const app = getApp(); + if (!app || !app.globalData) { + return; + } + Object.keys(patch).forEach((key) => { + app.globalData[key] = patch[key]; + }); + } catch (e) { + console.log('applyGlobalData error', e); + } +} + +export function getLoginData() { + return uni.getStorageSync(TOKEN_KEY) || null; +} + +export function getUserInformation() { + return uni.getStorageSync(INFORMATION_KEY) || null; +} + +export function applyLoginData(loginData) { + if (!loginData) { + return; + } + uni.setStorageSync(TOKEN_KEY, loginData); + uni.setStorageSync(USER_TOKEN_KEY, { Token: loginData.token }); + if (loginData.token) { + commitVuex('vuex_token', loginData.token); + } + applyGlobalData({ + Token: loginData.token || '', + EmployeeID: loginData.employee_id != null ? loginData.employee_id : (loginData.user_id || 0), + LoginID: loginData.user_id || 0, + LoginName: loginData.user_name || '', + UserName: loginData.user_name || '', + PlanDepartmentID: loginData.default_sale_system_id || 0, + PlanDepartmentName: loginData.default_sale_system_name || '', + StoreNameID: loginData.default_physical_warehouse_id || 0, + StoreName: loginData.default_physical_warehouse_name || '', + IsSaleUserStatus: 0, + UserGroup: '', + StoreTypeNo: '' + }); +} + +export function applyUserInformation(info) { + if (!info) { + return; + } + uni.setStorageSync(INFORMATION_KEY, info); + const profile = { + userName: info.user_name || '', + user_id: info.user_id, + user_name: info.user_name || '', + avatar: info.avatar_url || '', + avatar_url: info.avatar_url || '', + employee_id: info.employee_id, + department_id: info.department_id, + department_name: info.department_name || '', + phone: info.phone || '', + default_sale_system_id: info.default_sale_system_id, + default_sale_system_name: info.default_sale_system_name || '', + default_customer_id: info.default_customer_id, + default_customer_name: info.default_customer_name || '', + role_id: info.role_id || [] + }; + commitVuex('vuex_user', profile); + applyGlobalData({ + EmployeeID: info.employee_id != null ? info.employee_id : (info.user_id || 0), + LoginID: info.user_id || 0, + LoginName: info.user_name || '', + UserName: info.user_name || '', + PlanDepartmentID: info.default_sale_system_id || 0, + PlanDepartmentName: info.default_sale_system_name || '' + }); +} + +export function restoreUserSession() { + const loginData = getLoginData(); + if (loginData && loginData.token) { + applyLoginData(loginData); + } + const info = getUserInformation(); + if (info) { + applyUserInformation(info); + } +} + +export function clearUserSession() { + uni.removeStorageSync(TOKEN_KEY); + uni.removeStorageSync(USER_TOKEN_KEY); + uni.removeStorageSync(INFORMATION_KEY); + uni.removeStorageSync('token'); + commitVuex('vuex_token', ''); + commitVuex('vuex_user', {}); + applyGlobalData({ + Token: '', + EmployeeID: 0, + LoginID: 0, + LoginName: '', + UserName: '', + PlanDepartmentID: 0, + PlanDepartmentName: '', + StoreNameID: 0, + StoreName: '', + IsSaleUserStatus: 0, + UserGroup: '', + StoreTypeNo: '' + }); +} + +export function hasResourceRouter(name) { + if (!name) { + return true; + } + const info = getUserInformation(); + if (!info) { + return true; + } + const names = info.resource_router_names; + if (!Array.isArray(names)) { + return true; + } + return names.indexOf(name) !== -1; +} + +export function hasButtonCode(code) { + if (!code) { + return true; + } + const info = getUserInformation(); + if (!info) { + return true; + } + const codes = info.button_codes; + if (!Array.isArray(codes)) { + return true; + } + return codes.indexOf(code) !== -1; +} diff --git a/src/components/u-action-sheet/u-action-sheet.vue b/src/components/u-action-sheet/u-action-sheet.vue new file mode 100644 index 0000000..21b2d25 --- /dev/null +++ b/src/components/u-action-sheet/u-action-sheet.vue @@ -0,0 +1,247 @@ + + + + + diff --git a/src/components/u-dropdown-item/u-dropdown-item.vue b/src/components/u-dropdown-item/u-dropdown-item.vue new file mode 100644 index 0000000..7f79c2f --- /dev/null +++ b/src/components/u-dropdown-item/u-dropdown-item.vue @@ -0,0 +1,186 @@ + + + + + diff --git a/src/components/u-select/u-select.vue b/src/components/u-select/u-select.vue new file mode 100644 index 0000000..cfc1f63 --- /dev/null +++ b/src/components/u-select/u-select.vue @@ -0,0 +1,538 @@ + + + + + diff --git a/src/pages.json b/src/pages.json index 736b166..01c044f 100644 --- a/src/pages.json +++ b/src/pages.json @@ -1,5 +1,8 @@ { "easycom": { + "^u-select$": "@/components/u-select/u-select.vue", + "^u-action-sheet$": "@/components/u-action-sheet/u-action-sheet.vue", + "^u-dropdown-item$": "@/components/u-dropdown-item/u-dropdown-item.vue", "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue" }, "pages": [ diff --git a/src/pages/storefabric/storeFabricBusinessOutAdd.vue b/src/pages/storefabric/storeFabricBusinessOutAdd.vue index 16242cd..bdad569 100644 --- a/src/pages/storefabric/storeFabricBusinessOutAdd.vue +++ b/src/pages/storefabric/storeFabricBusinessOutAdd.vue @@ -122,7 +122,7 @@ - + diff --git a/src/pages/storefabric/storeFabricBusinessOutEdit.vue b/src/pages/storefabric/storeFabricBusinessOutEdit.vue index 906a14a..04412f0 100644 --- a/src/pages/storefabric/storeFabricBusinessOutEdit.vue +++ b/src/pages/storefabric/storeFabricBusinessOutEdit.vue @@ -51,7 +51,7 @@ - + diff --git a/src/pages/storefabric/storeFabricBusinessOutList.vue b/src/pages/storefabric/storeFabricBusinessOutList.vue index 8d2dc36..b389be0 100644 --- a/src/pages/storefabric/storeFabricBusinessOutList.vue +++ b/src/pages/storefabric/storeFabricBusinessOutList.vue @@ -59,7 +59,7 @@ - + @@ -75,6 +75,7 @@ import { mapToSelectOptions, fetchAllOrderList, } from '@/common/storeFabricBusinessOut'; +import { withNameParam } from '@/common/remoteSelect'; export default { components: { addBtn, FabricOutItem }, @@ -90,6 +91,9 @@ export default { deliveryUnitOptions: [], businessUnitOptions: [], unitOptionsLoading: false, + selectSearching: false, + unitSearchSeq: 0, + unitSelectList: [{ value: '', label: '全部' }], billTypeName: (BILL_TYPES[0] || {}).label || '坯布其他出货单', filters: { order_no: '', @@ -118,10 +122,6 @@ export default { businessUnitLabel() { return this.filters.business_unit_name || ''; }, - unitSelectList() { - const options = this.unitSelectType === 'delivery' ? this.deliveryUnitOptions : this.businessUnitOptions; - return [{ value: '', label: '全部' }, ...options]; - }, }, onLoad() { uni.setNavigationBarTitle({ title: '坯布出库列表' }); @@ -160,21 +160,40 @@ export default { return this.businessUnitOptions; }); }, + applyUnitSelectList(list) { + const rows = Array.isArray(list) ? list.slice() : []; + this.unitSelectList = [{ value: '', label: '全部' }].concat(rows); + }, openUnitSelect(type) { - if (this.unitOptionsLoading) return; - this.unitOptionsLoading = true; - const loadFn = type === 'delivery' ? this.loadDeliveryUnitOptions : this.loadBusinessUnitOptions; - loadFn.call(this) - .then((list) => { - if (!list.length) { - uni.showToast({ title: '暂无可选单位', icon: 'none' }); - return; + this.unitSelectType = type; + const cache = type === 'delivery' ? this.deliveryUnitOptions : this.businessUnitOptions; + this.applyUnitSelectList(cache); + this.unitSelectShow = true; + }, + onUnitSearch(keyword) { + const seq = ++this.unitSearchSeq; + const isDelivery = this.unitSelectType === 'delivery'; + const empty = !String(keyword || '').trim(); + this.selectSearching = true; + const params = isDelivery ? {} : { unit_type_id: BUSINESS_UNIT_TYPE_DYE_FACTORY }; + this.$u.api.businessUnit.list(withNameParam(params, keyword)) + .then((res) => { + if (seq !== this.unitSearchSeq) return; + const list = mapToSelectOptions(res); + if (empty) { + if (isDelivery) this.deliveryUnitOptions = list; + else this.businessUnitOptions = list; } - this.unitSelectType = type; - this.unitSelectShow = true; + this.applyUnitSelectList(list); }) - .finally(() => { - this.unitOptionsLoading = false; + .catch((e) => { + if (seq !== this.unitSearchSeq) return; + uni.showToast({ title: (e && e.message) || '搜索失败', icon: 'none' }); + }) + .then(() => { + if (seq === this.unitSearchSeq) this.selectSearching = false; + }, () => { + if (seq === this.unitSearchSeq) this.selectSearching = false; }); }, openDeliveryUnitSelect() { diff --git a/src/pages/storefabric/storeFabricBusinessOutMixin.js b/src/pages/storefabric/storeFabricBusinessOutMixin.js index 8e14b02..a53da25 100644 --- a/src/pages/storefabric/storeFabricBusinessOutMixin.js +++ b/src/pages/storefabric/storeFabricBusinessOutMixin.js @@ -10,6 +10,8 @@ */ import util from '@/common/util'; import scanMixin from '@/common/scanMixin.js'; +import remoteSelectMixin from '@/common/remoteSelectMixin.js'; +import { withNameParam } from '@/common/remoteSelect'; import { initTts, speak } from '@/common/tts.js'; import { AUDIT_STATUS_MAP, @@ -36,7 +38,7 @@ import { } from '@/common/storeFabricBusinessOut'; export default { - mixins: [scanMixin], + mixins: [scanMixin, remoteSelectMixin], data() { return { pageMode: 'add', @@ -145,6 +147,15 @@ export default { return this.businessUnitOptions; }); }, + fetchRemoteSelectOptions(type, keyword) { + if (type !== '染厂') return Promise.resolve([]); + return this.$u.api.businessUnit.list(withNameParam({ unit_type_id: BUSINESS_UNIT_TYPE_DYE_FACTORY }, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (!String(keyword || '').trim()) this.businessUnitOptions = list; + return list; + }); + }, getEmptyForm() { return { order_no: '', @@ -185,19 +196,9 @@ export default { }, pickerSelectFun(type) { if (!this.headerEditable) return; - this.selectType = type; - const openPicker = (list) => { - if (!list.length) { - this.showError('暂无可选数据'); - return; - } - this.selectList = list; - this.selectShow = true; - }; if (type === '染厂') { - this.ensureBusinessUnitOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载单位列表失败')); + this.openSelectPicker(type, this.businessUnitOptions); + return; } }, selectConfirmFun(e) { diff --git a/src/pages/storegoods/storeGoodsProcessInAdd.vue b/src/pages/storegoods/storeGoodsProcessInAdd.vue index ab36052..807bd6a 100644 --- a/src/pages/storegoods/storeGoodsProcessInAdd.vue +++ b/src/pages/storegoods/storeGoodsProcessInAdd.vue @@ -107,7 +107,7 @@ @action="handleStatusAction" /> - + diff --git a/src/pages/storegoods/storeGoodsProcessInEdit.vue b/src/pages/storegoods/storeGoodsProcessInEdit.vue index 9614908..6c11a4b 100644 --- a/src/pages/storegoods/storeGoodsProcessInEdit.vue +++ b/src/pages/storegoods/storeGoodsProcessInEdit.vue @@ -85,7 +85,7 @@ - + diff --git a/src/pages/storegoods/storeGoodsProcessInList.vue b/src/pages/storegoods/storeGoodsProcessInList.vue index 128b3ce..4ec64a6 100644 --- a/src/pages/storegoods/storeGoodsProcessInList.vue +++ b/src/pages/storegoods/storeGoodsProcessInList.vue @@ -47,7 +47,7 @@ - + @@ -63,6 +63,7 @@ import { mapToSelectOptions, fetchAllOrderList, } from '@/common/storeGoodsProcessIn'; +import { withNameParam } from '@/common/remoteSelect'; export default { components: { addBtn, ProcessInItem }, @@ -79,6 +80,9 @@ export default { processUnitOptions: [], warehouseOptions: [], unitOptionsLoading: false, + selectSearching: false, + unitSearchSeq: 0, + unitSelectList: [{ value: '', label: '全部' }], filters: { order_no: '', process_unit_id: '', @@ -104,10 +108,6 @@ export default { warehouseLabel() { return this.filters.warehouse_name || ''; }, - unitSelectList() { - const options = this.unitSelectType === 'warehouse' ? this.warehouseOptions : this.processUnitOptions; - return [{ value: '', label: '全部' }, ...options]; - }, }, onLoad() { uni.setNavigationBarTitle({ title: '加工进仓列表' }); @@ -145,22 +145,40 @@ export default { return this.warehouseOptions; }); }, + applyUnitSelectList(list) { + const rows = Array.isArray(list) ? list.slice() : []; + this.unitSelectList = [{ value: '', label: '全部' }].concat(rows); + }, openUnitSelect(type) { - if (this.unitOptionsLoading) return; - this.unitOptionsLoading = true; - const loadFn = type === 'warehouse' ? this.loadWarehouseOptions : this.loadProcessUnitOptions; - loadFn.call(this) - .then((list) => { - if (!list.length) { - uni.showToast({ title: '暂无可选数据', icon: 'none' }); - return; - } - this.unitSelectType = type; - this.unitSelectShow = true; - }) - .finally(() => { - this.unitOptionsLoading = false; - }); + this.unitSelectType = type; + const cache = type === 'warehouse' ? this.warehouseOptions : this.processUnitOptions; + this.applyUnitSelectList(cache); + this.unitSelectShow = true; + }, + onUnitSearch(keyword) { + const seq = ++this.unitSearchSeq; + const type = this.unitSelectType; + const empty = !String(keyword || '').trim(); + this.selectSearching = true; + const req = type === 'warehouse' + ? this.$u.api.physicalWarehouse.getDropdownList(withNameParam({ warehouse_type_id: WAREHOUSE_TYPE_FINISHED }, keyword)) + : this.$u.api.businessUnit.list(withNameParam({ unit_type_id: BUSINESS_UNIT_TYPE_PROCESS }, keyword)); + req.then((res) => { + if (seq !== this.unitSearchSeq) return; + const list = mapToSelectOptions(res); + if (empty) { + if (type === 'warehouse') this.warehouseOptions = list; + else this.processUnitOptions = list; + } + this.applyUnitSelectList(list); + }).catch((e) => { + if (seq !== this.unitSearchSeq) return; + uni.showToast({ title: (e && e.message) || '搜索失败', icon: 'none' }); + }).then(() => { + if (seq === this.unitSearchSeq) this.selectSearching = false; + }, () => { + if (seq === this.unitSearchSeq) this.selectSearching = false; + }); }, openProcessUnitSelect() { this.openUnitSelect('process'); diff --git a/src/pages/storegoods/storeGoodsProcessInMixin.js b/src/pages/storegoods/storeGoodsProcessInMixin.js index ecaafb5..a9e042d 100644 --- a/src/pages/storegoods/storeGoodsProcessInMixin.js +++ b/src/pages/storegoods/storeGoodsProcessInMixin.js @@ -8,6 +8,8 @@ */ import util from '@/common/util'; import scanMixin from '@/common/scanMixin.js'; +import remoteSelectMixin from '@/common/remoteSelectMixin.js'; +import { withNameParam } from '@/common/remoteSelect'; import { initTts, speak } from '@/common/tts.js'; import { AUDIT_STATUS_MAP, @@ -36,7 +38,7 @@ import { } from '@/common/storeGoodsProcessIn'; export default { - mixins: [scanMixin], + mixins: [scanMixin, remoteSelectMixin], data() { return { pageMode: 'add', @@ -309,6 +311,34 @@ export default { return this.saleSystemOptions; }); }, + fetchRemoteSelectOptions(type, keyword) { + const empty = !String(keyword || '').trim(); + if (type === '加工单位') { + return this.$u.api.businessUnit.list(withNameParam({ unit_type_id: BUSINESS_UNIT_TYPE_PROCESS }, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (empty) this.processUnitOptions = list; + return list; + }); + } + if (type === '仓库名称') { + return this.$u.api.physicalWarehouse.getDropdownList(withNameParam({ warehouse_type_id: WAREHOUSE_TYPE_FINISHED }, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (empty) this.warehouseOptions = list; + return list; + }); + } + if (type === '营销体系') { + return this.$u.api.saleSystem.getDropdownList(withNameParam({}, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (empty) this.saleSystemOptions = list; + return list; + }); + } + return Promise.resolve([]); + }, applyDefaultWarehouse() { const app = getApp(); const picked = pickDefaultWarehouse( @@ -390,30 +420,22 @@ export default { }, pickerSelectFun(type) { if (!this.headerEditable) return; - this.selectType = type; - const openPicker = (list) => { - if (!list.length) { + if (type === '进仓类型') { + this.selectType = type; + if (!this.inOrderTypeOptions.length) { this.showError('暂无可选数据'); return; } - this.selectList = list; + this.selectList = this.inOrderTypeOptions; this.selectShow = true; - }; - if (type === '进仓类型') { - openPicker(this.inOrderTypeOptions); - } else if (type === '加工单位') { - this.ensureProcessUnitOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载加工单位失败')); - } else if (type === '仓库名称') { - this.ensureWarehouseOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载仓库失败')); - } else if (type === '营销体系') { - this.ensureSaleSystemOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载营销体系失败')); + return; } + const cache = { + '加工单位': this.processUnitOptions, + '仓库名称': this.warehouseOptions, + '营销体系': this.saleSystemOptions, + }; + if (cache[type]) this.openSelectPicker(type, cache[type]); }, selectConfirmFun(e) { const item = e[0]; diff --git a/src/pages/storegoods/storeGoodsProcessOutAdd.vue b/src/pages/storegoods/storeGoodsProcessOutAdd.vue index bdbf79d..683fcaa 100644 --- a/src/pages/storegoods/storeGoodsProcessOutAdd.vue +++ b/src/pages/storegoods/storeGoodsProcessOutAdd.vue @@ -64,7 +64,7 @@ @action="handleStatusAction" /> - + diff --git a/src/pages/storegoods/storeGoodsProcessOutEdit.vue b/src/pages/storegoods/storeGoodsProcessOutEdit.vue index 68a0451..f2bc1ee 100644 --- a/src/pages/storegoods/storeGoodsProcessOutEdit.vue +++ b/src/pages/storegoods/storeGoodsProcessOutEdit.vue @@ -45,7 +45,7 @@ - + diff --git a/src/pages/storegoods/storeGoodsProcessOutList.vue b/src/pages/storegoods/storeGoodsProcessOutList.vue index bfe1d58..d9f573a 100644 --- a/src/pages/storegoods/storeGoodsProcessOutList.vue +++ b/src/pages/storegoods/storeGoodsProcessOutList.vue @@ -47,7 +47,7 @@ - + @@ -63,6 +63,7 @@ import { mapToSelectOptions, fetchAllOrderList, } from '@/common/storeGoodsProcessOut'; +import { withNameParam } from '@/common/remoteSelect'; export default { components: { addBtn, ProcessOutItem }, @@ -79,6 +80,9 @@ export default { processUnitOptions: [], warehouseOptions: [], unitOptionsLoading: false, + selectSearching: false, + unitSearchSeq: 0, + unitSelectList: [{ value: '', label: '全部' }], filters: { order_no: '', process_unit_id: '', @@ -104,10 +108,6 @@ export default { warehouseLabel() { return this.filters.warehouse_name || ''; }, - unitSelectList() { - const options = this.unitSelectType === 'warehouse' ? this.warehouseOptions : this.processUnitOptions; - return [{ value: '', label: '全部' }, ...options]; - }, }, onLoad() { uni.setNavigationBarTitle({ title: '加工出仓列表' }); @@ -145,22 +145,40 @@ export default { return this.warehouseOptions; }); }, + applyUnitSelectList(list) { + const rows = Array.isArray(list) ? list.slice() : []; + this.unitSelectList = [{ value: '', label: '全部' }].concat(rows); + }, openUnitSelect(type) { - if (this.unitOptionsLoading) return; - this.unitOptionsLoading = true; - const loadFn = type === 'warehouse' ? this.loadWarehouseOptions : this.loadProcessUnitOptions; - loadFn.call(this) - .then((list) => { - if (!list.length) { - uni.showToast({ title: '暂无可选数据', icon: 'none' }); - return; - } - this.unitSelectType = type; - this.unitSelectShow = true; - }) - .finally(() => { - this.unitOptionsLoading = false; - }); + this.unitSelectType = type; + const cache = type === 'warehouse' ? this.warehouseOptions : this.processUnitOptions; + this.applyUnitSelectList(cache); + this.unitSelectShow = true; + }, + onUnitSearch(keyword) { + const seq = ++this.unitSearchSeq; + const type = this.unitSelectType; + const empty = !String(keyword || '').trim(); + this.selectSearching = true; + const req = type === 'warehouse' + ? this.$u.api.physicalWarehouse.getDropdownList(withNameParam({ warehouse_type_id: WAREHOUSE_TYPE_FINISHED }, keyword)) + : this.$u.api.businessUnit.list(withNameParam({ unit_type_id: BUSINESS_UNIT_TYPE_PROCESS }, keyword)); + req.then((res) => { + if (seq !== this.unitSearchSeq) return; + const list = mapToSelectOptions(res); + if (empty) { + if (type === 'warehouse') this.warehouseOptions = list; + else this.processUnitOptions = list; + } + this.applyUnitSelectList(list); + }).catch((e) => { + if (seq !== this.unitSearchSeq) return; + uni.showToast({ title: (e && e.message) || '搜索失败', icon: 'none' }); + }).then(() => { + if (seq === this.unitSearchSeq) this.selectSearching = false; + }, () => { + if (seq === this.unitSearchSeq) this.selectSearching = false; + }); }, openProcessUnitSelect() { this.openUnitSelect('process'); diff --git a/src/pages/storegoods/storeGoodsProcessOutMixin.js b/src/pages/storegoods/storeGoodsProcessOutMixin.js index 77aa0f5..484757a 100644 --- a/src/pages/storegoods/storeGoodsProcessOutMixin.js +++ b/src/pages/storegoods/storeGoodsProcessOutMixin.js @@ -7,6 +7,8 @@ */ import util from '@/common/util'; import scanMixin from '@/common/scanMixin.js'; +import remoteSelectMixin from '@/common/remoteSelectMixin.js'; +import { withNameParam } from '@/common/remoteSelect'; import { initTts, speak } from '@/common/tts.js'; import { AUDIT_STATUS_MAP, @@ -32,7 +34,7 @@ import { } from '@/common/storeGoodsProcessOut'; export default { - mixins: [scanMixin], + mixins: [scanMixin, remoteSelectMixin], data() { return { pageMode: 'add', @@ -211,6 +213,26 @@ export default { return this.warehouseOptions; }); }, + fetchRemoteSelectOptions(type, keyword) { + const empty = !String(keyword || '').trim(); + if (type === '加工单位') { + return this.$u.api.businessUnit.list(withNameParam({ unit_type_id: BUSINESS_UNIT_TYPE_PROCESS }, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (empty) this.processUnitOptions = list; + return list; + }); + } + if (type === '仓库名称') { + return this.$u.api.physicalWarehouse.getDropdownList(withNameParam({ warehouse_type_id: WAREHOUSE_TYPE_FINISHED }, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (empty) this.warehouseOptions = list; + return list; + }); + } + return Promise.resolve([]); + }, applyDefaultWarehouse() { const app = getApp(); const picked = pickDefaultWarehouse( @@ -264,28 +286,26 @@ export default { }, pickerSelectFun(type) { if (!this.headerEditable) return; - this.selectType = type; - const openPicker = (list) => { - if (!list.length) { - this.showError('暂无可选数据'); - return; - } - this.selectList = list; - this.selectShow = true; - }; if (type === '出仓类型') { + this.selectType = type; + const openPicker = (list) => { + if (!list.length) { + this.showError('暂无可选数据'); + return; + } + this.selectList = list; + this.selectShow = true; + }; this.ensureOutOrderTypeOptions() .then(openPicker) .catch((e) => this.showError(e.message || '加载出仓类型失败')); - } else if (type === '加工单位') { - this.ensureProcessUnitOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载加工单位失败')); - } else if (type === '仓库名称') { - this.ensureWarehouseOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载仓库失败')); + return; } + const cache = { + '加工单位': this.processUnitOptions, + '仓库名称': this.warehouseOptions, + }; + if (cache[type]) this.openSelectPicker(type, cache[type]); }, selectConfirmFun(e) { const item = e[0]; diff --git a/src/pages/storegoods/storeGoodsProcessReturnInAdd.vue b/src/pages/storegoods/storeGoodsProcessReturnInAdd.vue index 2ea976a..6b21872 100644 --- a/src/pages/storegoods/storeGoodsProcessReturnInAdd.vue +++ b/src/pages/storegoods/storeGoodsProcessReturnInAdd.vue @@ -72,7 +72,7 @@ @action="handleStatusAction" /> - + diff --git a/src/pages/storegoods/storeGoodsProcessReturnInEdit.vue b/src/pages/storegoods/storeGoodsProcessReturnInEdit.vue index 9b792dd..604d59e 100644 --- a/src/pages/storegoods/storeGoodsProcessReturnInEdit.vue +++ b/src/pages/storegoods/storeGoodsProcessReturnInEdit.vue @@ -56,7 +56,7 @@ - + diff --git a/src/pages/storegoods/storeGoodsProcessReturnInList.vue b/src/pages/storegoods/storeGoodsProcessReturnInList.vue index 0f24254..12a1be1 100644 --- a/src/pages/storegoods/storeGoodsProcessReturnInList.vue +++ b/src/pages/storegoods/storeGoodsProcessReturnInList.vue @@ -47,7 +47,7 @@ - + @@ -63,6 +63,7 @@ import { mapToSelectOptions, fetchAllOrderList, } from '@/common/storeGoodsProcessReturnIn'; +import { withNameParam } from '@/common/remoteSelect'; export default { components: { addBtn, ProcessReturnInItem }, @@ -79,6 +80,9 @@ export default { processUnitOptions: [], warehouseOptions: [], unitOptionsLoading: false, + selectSearching: false, + unitSearchSeq: 0, + unitSelectList: [{ value: '', label: '全部' }], filters: { order_no: '', process_unit_id: '', @@ -104,10 +108,6 @@ export default { warehouseLabel() { return this.filters.warehouse_name || ''; }, - unitSelectList() { - const options = this.unitSelectType === 'warehouse' ? this.warehouseOptions : this.processUnitOptions; - return [{ value: '', label: '全部' }, ...options]; - }, }, onLoad() { uni.setNavigationBarTitle({ title: '加工退货进仓列表' }); @@ -145,22 +145,40 @@ export default { return this.warehouseOptions; }); }, + applyUnitSelectList(list) { + const rows = Array.isArray(list) ? list.slice() : []; + this.unitSelectList = [{ value: '', label: '全部' }].concat(rows); + }, openUnitSelect(type) { - if (this.unitOptionsLoading) return; - this.unitOptionsLoading = true; - const loadFn = type === 'warehouse' ? this.loadWarehouseOptions : this.loadProcessUnitOptions; - loadFn.call(this) - .then((list) => { - if (!list.length) { - uni.showToast({ title: '暂无可选数据', icon: 'none' }); - return; - } - this.unitSelectType = type; - this.unitSelectShow = true; - }) - .finally(() => { - this.unitOptionsLoading = false; - }); + this.unitSelectType = type; + const cache = type === 'warehouse' ? this.warehouseOptions : this.processUnitOptions; + this.applyUnitSelectList(cache); + this.unitSelectShow = true; + }, + onUnitSearch(keyword) { + const seq = ++this.unitSearchSeq; + const type = this.unitSelectType; + const empty = !String(keyword || '').trim(); + this.selectSearching = true; + const req = type === 'warehouse' + ? this.$u.api.physicalWarehouse.getDropdownList(withNameParam({ warehouse_type_id: WAREHOUSE_TYPE_FINISHED }, keyword)) + : this.$u.api.businessUnit.list(withNameParam({ unit_type_id: BUSINESS_UNIT_TYPE_PROCESS }, keyword)); + req.then((res) => { + if (seq !== this.unitSearchSeq) return; + const list = mapToSelectOptions(res); + if (empty) { + if (type === 'warehouse') this.warehouseOptions = list; + else this.processUnitOptions = list; + } + this.applyUnitSelectList(list); + }).catch((e) => { + if (seq !== this.unitSearchSeq) return; + uni.showToast({ title: (e && e.message) || '搜索失败', icon: 'none' }); + }).then(() => { + if (seq === this.unitSearchSeq) this.selectSearching = false; + }, () => { + if (seq === this.unitSearchSeq) this.selectSearching = false; + }); }, openProcessUnitSelect() { this.openUnitSelect('process'); diff --git a/src/pages/storegoods/storeGoodsProcessReturnInMixin.js b/src/pages/storegoods/storeGoodsProcessReturnInMixin.js index 8095354..368504f 100644 --- a/src/pages/storegoods/storeGoodsProcessReturnInMixin.js +++ b/src/pages/storegoods/storeGoodsProcessReturnInMixin.js @@ -8,6 +8,8 @@ */ import util from '@/common/util'; import scanMixin from '@/common/scanMixin.js'; +import remoteSelectMixin from '@/common/remoteSelectMixin.js'; +import { withNameParam } from '@/common/remoteSelect'; import { initTts, speak } from '@/common/tts.js'; import { AUDIT_STATUS_MAP, @@ -31,7 +33,7 @@ import { } from '@/common/storeGoodsProcessReturnIn'; export default { - mixins: [scanMixin], + mixins: [scanMixin, remoteSelectMixin], data() { return { pageMode: 'add', @@ -284,6 +286,26 @@ export default { return this.warehouseOptions; }); }, + fetchRemoteSelectOptions(type, keyword) { + const empty = !String(keyword || '').trim(); + if (type === '加工单位') { + return this.$u.api.businessUnit.list(withNameParam({ unit_type_id: BUSINESS_UNIT_TYPE_PROCESS }, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (empty) this.processUnitOptions = list; + return list; + }); + } + if (type === '仓库名称') { + return this.$u.api.physicalWarehouse.getDropdownList(withNameParam({ warehouse_type_id: WAREHOUSE_TYPE_FINISHED }, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (empty) this.warehouseOptions = list; + return list; + }); + } + return Promise.resolve([]); + }, applyDefaultWarehouse() { const app = getApp(); const picked = pickDefaultWarehouse( @@ -336,24 +358,11 @@ export default { }, pickerSelectFun(type) { if (!this.headerEditable) return; - this.selectType = type; - const openPicker = (list) => { - if (!list.length) { - this.showError('暂无可选数据'); - return; - } - this.selectList = list; - this.selectShow = true; + const cache = { + '加工单位': this.processUnitOptions, + '仓库名称': this.warehouseOptions, }; - if (type === '加工单位') { - this.ensureProcessUnitOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载加工单位失败')); - } else if (type === '仓库名称') { - this.ensureWarehouseOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载仓库失败')); - } + if (cache[type]) this.openSelectPicker(type, cache[type]); }, selectConfirmFun(e) { const item = e[0]; diff --git a/src/pages/storegoods/storeGoodsPurchaseInAdd.vue b/src/pages/storegoods/storeGoodsPurchaseInAdd.vue index aec8ccd..141d5b9 100644 --- a/src/pages/storegoods/storeGoodsPurchaseInAdd.vue +++ b/src/pages/storegoods/storeGoodsPurchaseInAdd.vue @@ -107,7 +107,7 @@ @action="handleStatusAction" /> - + diff --git a/src/pages/storegoods/storeGoodsPurchaseInEdit.vue b/src/pages/storegoods/storeGoodsPurchaseInEdit.vue index 5ce0f70..71899c4 100644 --- a/src/pages/storegoods/storeGoodsPurchaseInEdit.vue +++ b/src/pages/storegoods/storeGoodsPurchaseInEdit.vue @@ -85,7 +85,7 @@ - + diff --git a/src/pages/storegoods/storeGoodsPurchaseInList.vue b/src/pages/storegoods/storeGoodsPurchaseInList.vue index 944eb39..574d0ab 100644 --- a/src/pages/storegoods/storeGoodsPurchaseInList.vue +++ b/src/pages/storegoods/storeGoodsPurchaseInList.vue @@ -47,7 +47,7 @@ - + @@ -63,6 +63,7 @@ import { mapToSelectOptions, fetchAllOrderList, } from '@/common/storeGoodsPurchaseIn'; +import { withNameParam } from '@/common/remoteSelect'; export default { components: { addBtn, PurchaseInItem }, @@ -79,6 +80,9 @@ export default { supplierOptions: [], warehouseOptions: [], unitOptionsLoading: false, + selectSearching: false, + unitSearchSeq: 0, + unitSelectList: [{ value: '', label: '全部' }], filters: { order_no: '', supplier_id: '', @@ -104,10 +108,6 @@ export default { warehouseLabel() { return this.filters.warehouse_name || ''; }, - unitSelectList() { - const options = this.unitSelectType === 'warehouse' ? this.warehouseOptions : this.supplierOptions; - return [{ value: '', label: '全部' }, ...options]; - }, }, onLoad() { uni.setNavigationBarTitle({ title: '成品采购进仓' }); @@ -145,22 +145,40 @@ export default { return this.warehouseOptions; }); }, + applyUnitSelectList(list) { + const rows = Array.isArray(list) ? list.slice() : []; + this.unitSelectList = [{ value: '', label: '全部' }].concat(rows); + }, openUnitSelect(type) { - if (this.unitOptionsLoading) return; - this.unitOptionsLoading = true; - const loadFn = type === 'warehouse' ? this.loadWarehouseOptions : this.loadSupplierOptions; - loadFn.call(this) - .then((list) => { - if (!list.length) { - uni.showToast({ title: '暂无可选数据', icon: 'none' }); - return; - } - this.unitSelectType = type; - this.unitSelectShow = true; - }) - .finally(() => { - this.unitOptionsLoading = false; - }); + this.unitSelectType = type; + const cache = type === 'warehouse' ? this.warehouseOptions : this.supplierOptions; + this.applyUnitSelectList(cache); + this.unitSelectShow = true; + }, + onUnitSearch(keyword) { + const seq = ++this.unitSearchSeq; + const type = this.unitSelectType; + const empty = !String(keyword || '').trim(); + this.selectSearching = true; + const req = type === 'warehouse' + ? this.$u.api.physicalWarehouse.getDropdownList(withNameParam({ warehouse_type_id: WAREHOUSE_TYPE_FINISHED }, keyword)) + : this.$u.api.businessUnit.list(withNameParam({ unit_type_id: BUSINESS_UNIT_TYPE_PRODUCT_SUPPLIER }, keyword)); + req.then((res) => { + if (seq !== this.unitSearchSeq) return; + const list = mapToSelectOptions(res); + if (empty) { + if (type === 'warehouse') this.warehouseOptions = list; + else this.supplierOptions = list; + } + this.applyUnitSelectList(list); + }).catch((e) => { + if (seq !== this.unitSearchSeq) return; + uni.showToast({ title: (e && e.message) || '搜索失败', icon: 'none' }); + }).then(() => { + if (seq === this.unitSearchSeq) this.selectSearching = false; + }, () => { + if (seq === this.unitSearchSeq) this.selectSearching = false; + }); }, openSupplierSelect() { this.openUnitSelect('supplier'); diff --git a/src/pages/storegoods/storeGoodsPurchaseInMixin.js b/src/pages/storegoods/storeGoodsPurchaseInMixin.js index 1814a8e..8a712ee 100644 --- a/src/pages/storegoods/storeGoodsPurchaseInMixin.js +++ b/src/pages/storegoods/storeGoodsPurchaseInMixin.js @@ -8,6 +8,8 @@ */ import util from '@/common/util'; import scanMixin from '@/common/scanMixin.js'; +import remoteSelectMixin from '@/common/remoteSelectMixin.js'; +import { withNameParam } from '@/common/remoteSelect'; import { initTts, speak } from '@/common/tts.js'; import { AUDIT_STATUS_MAP, @@ -38,7 +40,7 @@ import { } from '@/common/storeGoodsPurchaseIn'; export default { - mixins: [scanMixin], + mixins: [scanMixin, remoteSelectMixin], data() { return { pageMode: 'add', @@ -311,6 +313,34 @@ export default { return this.saleSystemOptions; }); }, + fetchRemoteSelectOptions(type, keyword) { + const empty = !String(keyword || '').trim(); + if (type === '供应商') { + return this.$u.api.businessUnit.list(withNameParam({ unit_type_id: BUSINESS_UNIT_TYPE_PRODUCT_SUPPLIER }, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (empty) this.supplierOptions = list; + return list; + }); + } + if (type === '仓库名称') { + return this.$u.api.physicalWarehouse.getDropdownList(withNameParam({ warehouse_type_id: WAREHOUSE_TYPE_FINISHED }, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (empty) this.warehouseOptions = list; + return list; + }); + } + if (type === '营销体系') { + return this.$u.api.saleSystem.getDropdownList(withNameParam({}, keyword)) + .then((res) => { + const list = mapToSelectOptions(res); + if (empty) this.saleSystemOptions = list; + return list; + }); + } + return Promise.resolve([]); + }, applyDefaultWarehouse() { const app = getApp(); const picked = pickDefaultWarehouse( @@ -394,30 +424,22 @@ export default { }, pickerSelectFun(type) { if (!this.headerEditable) return; - this.selectType = type; - const openPicker = (list) => { - if (!list.length) { + if (type === '订单类型') { + this.selectType = type; + if (!this.saleModeOptions.length) { this.showError('暂无可选数据'); return; } - this.selectList = list; + this.selectList = this.saleModeOptions; this.selectShow = true; - }; - if (type === '供应商') { - this.ensureSupplierOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载供应商失败')); - } else if (type === '仓库名称') { - this.ensureWarehouseOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载仓库失败')); - } else if (type === '营销体系') { - this.ensureSaleSystemOptions() - .then(openPicker) - .catch((e) => this.showError(e.message || '加载营销体系失败')); - } else if (type === '订单类型') { - openPicker(this.saleModeOptions); + return; } + const cache = { + '供应商': this.supplierOptions, + '仓库名称': this.warehouseOptions, + '营销体系': this.saleSystemOptions, + }; + if (cache[type]) this.openSelectPicker(type, cache[type]); }, selectConfirmFun(e) { const item = e[0]; diff --git a/src/pages/sys/login/index.vue b/src/pages/sys/login/index.vue index 3f7eb07..5370bf7 100644 --- a/src/pages/sys/login/index.vue +++ b/src/pages/sys/login/index.vue @@ -105,8 +105,8 @@ - + 版本: {{ appVersion }} @@ -125,6 +125,7 @@ import md5 from '@/common/md5.js'; import manifest from '@/manifest.json'; import { mapState } from 'vuex' import app_upgrade from '@/uni_modules/app-upgrade/js_sdk/index.js' +import { applyLoginData, applyUserInformation } from '@/common/userSession.js' export default { data() { return { @@ -218,9 +219,8 @@ export default { }, onApiUrlConfirm(e) { - console.log('e', JSON.stringify(e)); - const selectedValue = this.apiUrlList[e[0]].value; - console.log('selectedValue', selectedValue) + const selectedValue = e && e[0] && e[0].value; + if (selectedValue == null) return; this.selectedApiUrl = selectedValue; this.showApiUrlPicker = false; @@ -334,11 +334,10 @@ export default { this.$u.api.pdaLogin({ 'phone': this.login.username, 'password': this.login.password, - }).then((res) => { + }).then(async (res) => { console.log('login res', res) var aLoginUserData = res; - //console.log('--aLoginUserData->>' + JSON.stringify(aLoginUserData)); // 只在开发环境保存 apiurl 到本地存储 if (config.isDevelopment) { uni.setStorage({ @@ -347,27 +346,17 @@ export default { }); util.updateApiUrl(currentApiUrl); } - // 保存 token 到本地存储 - uni.setStorageSync('RemoteTokenData', aLoginUserData); - uni.setStorage({ - key: 'userToken', - data: { - Token: aLoginUserData.token, - } - }); + applyLoginData(aLoginUserData); + + try { + const userInfo = await this.$u.api.pdaGetInformation(); + console.log('information res', userInfo); + applyUserInformation(userInfo); + } catch (infoError) { + console.log('information error', infoError); + } - getApp().globalData.Token = aLoginUserData.token; - getApp().globalData.EmployeeID = aLoginUserData.user_id; - getApp().globalData.IsSaleUserStatus = 0; - getApp().globalData.LoginID = aLoginUserData.user_id; - getApp().globalData.LoginName = aLoginUserData.user_name; - getApp().globalData.PlanDepartmentID = aLoginUserData.default_sale_system_id; - getApp().globalData.PlanDepartmentName = aLoginUserData.default_sale_system_name; - getApp().globalData.UserGroup = ''; - getApp().globalData.StoreNameID = aLoginUserData.default_physical_warehouse_id; - getApp().globalData.StoreName = aLoginUserData.default_physical_warehouse_name; - getApp().globalData.StoreTypeNo = ''; setTimeout(() => { uni.reLaunch({ url: '/pages/sys/workbench/index' diff --git a/src/pages/sys/user/index.vue b/src/pages/sys/user/index.vue index 9f14f5b..df575da 100644 --- a/src/pages/sys/user/index.vue +++ b/src/pages/sys/user/index.vue @@ -69,7 +69,7 @@ export default { }; }, onLoad(e) { - this.loginUserName = getApp().globalData.UserName; + this.loginUserName = getApp().globalData.UserName || (this.vuex_user && this.vuex_user.user_name) || ''; }, computed: { diff --git a/src/pages/sys/user/setting.vue b/src/pages/sys/user/setting.vue index 4882738..3362e4e 100644 --- a/src/pages/sys/user/setting.vue +++ b/src/pages/sys/user/setting.vue @@ -21,6 +21,7 @@ import app_upgrade from '@/uni_modules/app-upgrade/js_sdk/index.js' import util from '@/common/util.js'; import config from '../../../common/config'; +import { clearUserSession } from '@/common/userSession.js'; export default { data() { @@ -84,27 +85,17 @@ export default { // #endif }, logout() { - this.$u.api.pdaLogout().then(res => { - console.log('res',res) - if (res.code != 0) { - // this.$u.toast('退出登录失败'); - uni.reLaunch({ - url: '/pages/sys/login/index' - }); - return - } - // 清除token和用户信息 - uni.removeStorageSync('token'); - this.$store.dispatch('updateUserInfo', null); + const goLogin = () => { + clearUserSession(); uni.reLaunch({ url: '/pages/sys/login/index' }); + }; + this.$u.api.pdaLogout().then(() => { + goLogin(); }).catch(error => { console.log('error',error) - // 即使退出登录失败,也要清除本地token和用户信息 - uni.removeStorageSync('token'); - this.$store.dispatch('updateUserInfo', null); - // this.$u.toast('退出登录失败'); + goLogin(); }); } } diff --git a/src/pages/sys/workbench/index.vue b/src/pages/sys/workbench/index.vue index 9cd7a3c..ec15173 100644 --- a/src/pages/sys/workbench/index.vue +++ b/src/pages/sys/workbench/index.vue @@ -7,57 +7,31 @@ - 销售管理 - - - - - - - 成品配布 - - - - - - - - - - 成品管理 - - - - - - - 加工进仓 - - - - - - 加工出仓 - - - - - - 加工退货进仓 - - - - - - 采购进仓 - - - + + {{ group.title }} + + + + + + + {{ item.name }} + + + + + 暂无可用功能