diff --git a/miniprogram/app.json b/miniprogram/app.json index 4bcce25..bb4f4d0 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -7,7 +7,8 @@ "pages/produce/processManage/processManage", "pages/produce/processManageDetail/processManageDetail", "pages/orders/ordersList/ordersList", - "pages/orders/orderSort/orderSort" + "pages/orders/orderSort/orderSort", + "pages/orders/ordersList/orderPayment/orderPayment" ], "window": { "navigationBarTextStyle": "black", diff --git a/miniprogram/app.wxss b/miniprogram/app.wxss index 5c62961..26c1fe1 100644 --- a/miniprogram/app.wxss +++ b/miniprogram/app.wxss @@ -4,7 +4,8 @@ button.t-button { margin-right: 0; } -view.t-input { +view.t-input, +view.t-cell { flex: none; padding: 24rpx; } @@ -12,3 +13,7 @@ view.t-input { view.t-popup__close { padding: 12rpx; } + +.t-input__icon--prefix { + display: flex; +} diff --git a/miniprogram/pages/components/search-popup/search-popup.ts b/miniprogram/pages/components/search-popup/search-popup.ts index 68be5cb..0d57c52 100644 --- a/miniprogram/pages/components/search-popup/search-popup.ts +++ b/miniprogram/pages/components/search-popup/search-popup.ts @@ -22,7 +22,7 @@ Component({ }, customStyle: { type: String, - value: "", + value: '', }, useInputSlot: { type: Boolean, @@ -42,38 +42,43 @@ Component({ methods: { showSearch() { this.setData({ show: true }); - this.triggerEvent("showChange", true); + this.triggerEvent('showChange', true); }, close() { this.setData({ show: false }); - this.triggerEvent("showChange", false); + this.triggerEvent('showChange', false); }, ok() { this.setData({ show: false }); - this.triggerEvent("showChange", false); - this.triggerEvent("ok"); + this.triggerEvent('showChange', false); + this.triggerEvent('ok'); + }, + reset() { + this.setData({ show: false }); + this.triggerEvent('showChange', false); + this.triggerEvent('reset'); }, change(e: any) { - this.triggerEvent("change", e.detail); + this.triggerEvent('change', e.detail); }, scanCode() { const _this = this; wx.scanCode({ onlyFromCamera: true, - scanType: ["qrCode"], + scanType: ['qrCode'], success: (res) => { - const qrcode = res.result || ""; - _this.triggerEvent("change", { value: qrcode }); - _this.triggerEvent("ok"); + const qrcode = res.result || ''; + _this.triggerEvent('change', { value: qrcode }); + _this.triggerEvent('ok'); }, }); }, search() { - this.triggerEvent("ok"); + this.triggerEvent('ok'); }, clear() { - this.triggerEvent("change", { value: "" }); - this.triggerEvent("ok"); + this.triggerEvent('change', { value: '' }); + this.triggerEvent('ok'); }, }, }); diff --git a/miniprogram/pages/components/search-popup/search-popup.wxml b/miniprogram/pages/components/search-popup/search-popup.wxml index 65fa121..8fb6c85 100644 --- a/miniprogram/pages/components/search-popup/search-popup.wxml +++ b/miniprogram/pages/components/search-popup/search-popup.wxml @@ -23,7 +23,7 @@ - 搜索 - + 搜索 + 重置 \ No newline at end of file diff --git a/miniprogram/pages/orders/orderSort/orderSort.json b/miniprogram/pages/orders/orderSort/orderSort.json index 569a67a..bb3ad41 100644 --- a/miniprogram/pages/orders/orderSort/orderSort.json +++ b/miniprogram/pages/orders/orderSort/orderSort.json @@ -1,6 +1,8 @@ { "usingComponents": { - "card-plugin": "/pages/components/card-plugin/card-plugin" + "card-plugin": "/pages/components/card-plugin/card-plugin", + "card-item-plugin": "/pages/components/card-item-plugin/card-item-plugin" }, - "navigationBarTitleText": "订单排序" + "navigationBarTitleText": "订单排序", + "enablePullDownRefresh": true } \ No newline at end of file diff --git a/miniprogram/pages/orders/orderSort/orderSort.ts b/miniprogram/pages/orders/orderSort/orderSort.ts index 03cd728..3b6cabd 100644 --- a/miniprogram/pages/orders/orderSort/orderSort.ts +++ b/miniprogram/pages/orders/orderSort/orderSort.ts @@ -1,13 +1,46 @@ +import { loginStatus, post } from '@/utils/https'; +import { getAuthInfo, getDataSet, showModal, sleep, toArray, toastSuccess } from '@/utils/util'; + Page({ /** * 页面的初始数据 */ data: { - list: [1, 2], + list: [] as any[], + }, + handleLogin(e: any) { + this.setData({ isLogin: e.detail }); + if (e.detail) { + this.init(); + } + }, + init() { + this.setData({ authInfo: getAuthInfo() }); + this.getList(); }, - getList() { - // Orders/getLiteOrders + post('Orders/getLiteOrders') + .then((res: any) => { + const list = toArray(res.data); + wx.stopPullDownRefresh(); + this.setData({ list: list }); + }) + .catch(() => { + wx.stopPullDownRefresh(); + }); + }, + onOrderToTop(e: any) { + const data = getDataSet(e); + const index = data.index; + const item = this.data.list[index]; + showModal({ content: `确认把 ${item.order_no} 订单移至顶部?` }).then(() => { + post('Orders/setTop', { order_no: item.order_no }).then(() => { + toastSuccess('移动成功'); + sleep(() => { + this.getList(); + }, 1000); + }); + }); }, /** * 生命周期函数--监听页面加载 @@ -22,7 +55,18 @@ Page({ /** * 生命周期函数--监听页面显示 */ - onShow() {}, + onShow() { + this.setData({ loading: true }); + loginStatus() + .then(() => { + this.setData({ isLogin: true, loading: false }); + this.init(); + }) + .catch((err) => { + this.setData({ isLogin: false, loading: false }); + console.log('调用登录状态请求失败', err); + }); + }, /** * 生命周期函数--监听页面隐藏 @@ -37,7 +81,9 @@ Page({ /** * 页面相关事件处理函数--监听用户下拉动作 */ - onPullDownRefresh() {}, + onPullDownRefresh() { + this.init(); + }, /** * 页面上拉触底事件的处理函数 diff --git a/miniprogram/pages/orders/orderSort/orderSort.wxml b/miniprogram/pages/orders/orderSort/orderSort.wxml index bf110e3..2c68011 100644 --- a/miniprogram/pages/orders/orderSort/orderSort.wxml +++ b/miniprogram/pages/orders/orderSort/orderSort.wxml @@ -1,7 +1,30 @@ - - - {{item}} - {{item}} - {{item}} - - \ No newline at end of file + + + + + + {{ item.order_no }} + + {{index + 1}} + + + + + + + + + + + + + + 移至顶部 + + + + + \ No newline at end of file diff --git a/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.json b/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.json new file mode 100644 index 0000000..7796d3f --- /dev/null +++ b/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.json @@ -0,0 +1,9 @@ +{ + "usingComponents": { + "card-item-plugin": "/pages/components/card-item-plugin/card-item-plugin", + "account-plugin": "/pages/components/account-plugin/account-plugin", + "t-input": "tdesign-miniprogram/input/input", + "t-date-time-picker": "tdesign-miniprogram/date-time-picker/date-time-picker", + "t-cell": "tdesign-miniprogram/cell/cell" + } +} \ No newline at end of file diff --git a/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.ts b/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.ts new file mode 100644 index 0000000..4da1895 --- /dev/null +++ b/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.ts @@ -0,0 +1,151 @@ +import { loginStatus, post } from '@/utils/https'; +import { + getAuthInfo, + priceRetentionDigits, + sleep, + toastSuccess, + toNumber, + toObject, +} from '@/utils/util'; +import dayjs from 'dayjs'; + +Page({ + /** + * 页面的初始数据 + */ + data: { + params: {} as any, + record: {} as any, + datetimeVisible: false, + }, + showPicker() { + this.setData({ datetimeVisible: true }); + }, + hidePicker() { + this.setData({ datetimeVisible: false }); + }, + onConfirm(e: any) { + this.data.params.bill_date = e.detail.value; + this.setData({ + datetimeVisible: false, + params: this.data.params, + }); + }, + handleLogin(e: any) { + this.setData({ isLogin: e.detail }); + if (e.detail) { + this.init(); + } + }, + init() { + const eventChannel: any = this.getOpenerEventChannel(); + if (eventChannel) { + eventChannel?.on('saleOrderPay', (res: any) => { + const data = toObject(res.data); + const { un_payed_amount, order_no } = data; + console.log(data); + wx.setNavigationBarTitle({ title: `${order_no} 收付款` }); + this.data.params.order_no = order_no; + this.data.params.bill_date = dayjs().format('YYYY-MM-DD HH:mm:ss'); + + this.data.params.amount = priceRetentionDigits(toNumber(un_payed_amount)); + this.data.params.operator = toNumber(wx.getStorageSync('user_id')) || undefined; + this.setData({ + params: this.data.params, + record: data, + }); + }); + } + + this.setData({ authInfo: getAuthInfo() }); + }, + accountOk(e: any) { + this.data.params.last_account_id = e.detail?.account_id; + this.setData({ + params: this.data.params, + }); + // console.log(e); + }, + accountDefault(e: any) { + this.data.params.last_account_id = e.detail?.account_id; + this.setData({ + params: this.data.params, + }); + // console.log(e); + }, + onPriceInput(e: any) { + this.data.params.amount = e.detail.value; + }, + onCommentInput(e: any) { + this.data.params.comments = e.detail.value; + }, + onPay() { + const { record, params } = this.data; + const data = { + order_no: record.order_no, + bill_date: params.bill_date, + amount: params.amount, + operator: params.operator, + last_account_id: params.last_account_id, + comments: params.comments, + }; + post('Orders/orderPay', data).then(() => { + toastSuccess('保存成功'); + sleep(() => { + wx.navigateBack(); + }, 1000); + }); + }, + /** + * 生命周期函数--监听页面加载 + */ + onLoad(options) { + // console.log(options); + + this.setData({ loading: true }); + loginStatus() + .then(() => { + this.setData({ isLogin: true, loading: false }); + this.init(); + }) + .catch((err) => { + this.setData({ isLogin: false, loading: false }); + console.log('调用登录状态请求失败', err); + }); + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady() {}, + + /** + * 生命周期函数--监听页面显示 + */ + onShow() {}, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide() {}, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload() {}, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh() {}, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom() {}, + + /** + * 用户点击右上角分享 + */ + // onShareAppMessage() {}, +}); diff --git a/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.wxml b/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.wxml new file mode 100644 index 0000000..544f1e1 --- /dev/null +++ b/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.wxml @@ -0,0 +1,25 @@ + + + + + + + + + 金额 + + + + + 确定 + + + + + + \ No newline at end of file diff --git a/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.wxss b/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.wxss new file mode 100644 index 0000000..b07a591 --- /dev/null +++ b/miniprogram/pages/orders/ordersList/orderPayment/orderPayment.wxss @@ -0,0 +1,10 @@ +.custom-label { + display: inline-flex; +} + +.custom-label::after { + content: '*'; + color: red; + font-size: 32rpx; + margin-left: 4rpx; +} diff --git a/miniprogram/pages/orders/ordersList/ordersList.json b/miniprogram/pages/orders/ordersList/ordersList.json index 94b6194..e5a0937 100644 --- a/miniprogram/pages/orders/ordersList/ordersList.json +++ b/miniprogram/pages/orders/ordersList/ordersList.json @@ -1,6 +1,20 @@ { "usingComponents": { - "card-plugin": "/pages/components/card-plugin/card-plugin" + "search-popup": "/pages/components/search-popup/search-popup", + "card-plugin": "/pages/components/card-plugin/card-plugin", + "card-item-plugin": "/pages/components/card-item-plugin/card-item-plugin", + "date-picker-plugin": "/pages/components/date-picker-plugin/date-picker-plugin", + "sort-plugin": "/pages/components/sort-plugin/sort-plugin", + "count-plugin": "/pages/components/count-plugin/count-plugin", + "total-bar-plugin": "/pages/components/total-bar-plugin/total-bar-plugin", + "t-input": "tdesign-miniprogram/input/input", + "pagination-plugin": "/pages/components/pagination-plugin/pagination-plugin", + "search-input": "/pages/components/search-input/search-input", + "t-cell": "tdesign-miniprogram/cell/cell", + "t-checkbox": "tdesign-miniprogram/checkbox/checkbox", + "t-checkbox-group": "tdesign-miniprogram/checkbox-group/checkbox-group", + "t-radio": "tdesign-miniprogram/radio/radio", + "t-radio-group": "tdesign-miniprogram/radio-group/radio-group" }, "navigationBarTitleText": "销售订单" } \ No newline at end of file diff --git a/miniprogram/pages/orders/ordersList/ordersList.ts b/miniprogram/pages/orders/ordersList/ordersList.ts index c9a0cdf..19d4d29 100644 --- a/miniprogram/pages/orders/ordersList/ordersList.ts +++ b/miniprogram/pages/orders/ordersList/ordersList.ts @@ -1,18 +1,176 @@ +import { loginStatus, post } from '@/utils/https'; +import { + SaleOrderProcessStateOption, + PayedStateOption, + SaleOrderProcessStateObj, +} from '@/utils/config'; +import { + cloneLite, + getAuthInfo, + getDataSet, + showModal, + sleep, + toArray, + toastSuccess, + toNumber, + toObject, +} from '@/utils/util'; + +const defaultParams = { curr_page: 1, page_count: 20, process_state: [200] }; + Page({ /** * 页面的初始数据 */ data: { - list: [1, 2, 3], - params: { - curr_page: 1, - page_count: 20, - process_state: 200, + params: cloneLite(defaultParams) as any, + list: [] as any[], + count: 0, + amount: { + tot_tax_last_money: 0, + tot_discount_money: 0, + tot_payed_amount: 0, + tot_un_payed_amount: 0, }, + orderStep: [] as any[], + saleOrderProcessStateOption: SaleOrderProcessStateOption, + saleOrderProcessStateObj: SaleOrderProcessStateObj, + payedStateOption: PayedStateOption, + sort: [ + { label: '自定义单号', value: 'custom_order_no' }, + { label: '订单类型', value: 'category_name' }, + { label: '订单阶段', value: 'order_step_name' }, + { label: '经销商名称', value: 'custom_name' }, + { label: '经销商手机', value: 'custom_phone' }, + { label: '客户名称', value: 'end_user_name' }, + { label: '客户手机', value: 'end_user_phone' }, + { label: '客户手机', value: 'end_user_address' }, + { label: '单据日期', value: 'document_date' }, + { label: '含税合计', value: 'tot_tax_last_money' }, + { label: '优惠金额', value: 'discount_money' }, + { label: '已收金额', value: 'payed_amount' }, + { label: '未收金额', value: 'un_payed_amount' }, + { label: '创建日期', value: 'create_date' }, + ], }, + handleLogin(e: any) { + this.setData({ isLogin: e.detail }); + if (e.detail) { + this.init(); + } + }, + init() { + this.setData({ authInfo: getAuthInfo() }); + this.getList(); + this.getOrderStep(); + }, + searchChange(e: any) { + this.data.params.order_no = e.detail.value; + this.setData({ params: this.data.params }); + }, + searchChange2(e: any) { + const key = getDataSet(e).key; + const val = `${e.detail.value || ''}`.trim(); + if (val) { + this.data.params[key] = val; + } else { + delete this.data.params[key]; + } + }, + onOrderStepChange(e: any) { + this.data.params.order_step = e.detail.value; + this.setData({ params: this.data.params }); + }, + onProcessStateChange(e: any) { + this.data.params.process_state = e.detail.value; + this.setData({ params: this.data.params }); + }, + onPayedStateChange(e: any) { + this.data.params.payed_state = e.detail.value; + this.setData({ params: this.data.params }); + }, + datePickerConfirm(e: any) { + const data = getDataSet(e); + this.data.params[data.key] = e.detail.value; + this.setData({ params: this.data.params }); + }, + searchOk() { + this.getList(1); + }, + searchReset() { + this.data.params = cloneLite(defaultParams); + this.getList(1); + }, + onSort(e: any) { + this.data.params.order = e.detail.value; + this.setData({ params: this.data.params }); + this.getList(1); + }, + tabChange(e: any) { + const state = getDataSet(e).key; + this.data.params.state = state; + this.getList(); + }, + paginationChange(e: any) { + this.getList(e.detail.curr_page); + }, + getOrderStep() { + post('OrderStep/list').then((res: any) => { + this.setData({ orderStep: toArray(res.data) }); + }); + }, + getList(curr: number = 1) { + this.data.params.curr_page = curr; + this.setData({ params: this.data.params }); + const temp = JSON.parse(JSON.stringify(this.data.params)); + if (temp.order_step && temp.order_step.length) { + temp.order_step = JSON.stringify(temp.order_step); + } else { + delete temp.order_step; + } - getList() { - // /Orders/list + if (temp.process_state && temp.process_state.length) { + temp.process_state = temp.process_state.join(','); + } else { + delete temp.process_state; + } + + post('Orders/list', temp).then((res: any) => { + const list = toArray(res.data); + if (list.length == 0 && this.data.params.curr_page > 1) { + this.getList(this.data.params.curr_page - 1); + } + this.setData({ + count: toNumber(res.count), + list: list, + amount: toObject(res.amount), + }); + }); + }, + onOrderPay(e: any) { + const data = getDataSet(e); + const index = data.index; + const item = this.data.list[index]; + wx.navigateTo({ + url: '/pages/orders/ordersList/orderPayment/orderPayment', + success: function (res) { + // 通过eventChannel向被打开页面传送数据 + res.eventChannel.emit('saleOrderPay', { data: item }); + }, + }); + }, + onOrderDel(e: any) { + const data = getDataSet(e); + const index = data.index; + const item = this.data.list[index]; + showModal({ content: `确认删除 ${item.order_no} 订单?` }).then(() => { + post('Orders/delSaleOrders', { order_no: JSON.stringify([item.order_no]) }).then(() => { + toastSuccess('删除成功'); + sleep(() => { + this.getList(); + }, 1000); + }); + }); }, /** * 生命周期函数--监听页面加载 @@ -27,7 +185,18 @@ Page({ /** * 生命周期函数--监听页面显示 */ - onShow() {}, + onShow() { + this.setData({ loading: true }); + loginStatus() + .then(() => { + this.setData({ isLogin: true, loading: false }); + this.init(); + }) + .catch((err) => { + this.setData({ isLogin: false, loading: false }); + console.log('调用登录状态请求失败', err); + }); + }, /** * 生命周期函数--监听页面隐藏 diff --git a/miniprogram/pages/orders/ordersList/ordersList.wxml b/miniprogram/pages/orders/ordersList/ordersList.wxml index bf110e3..f984780 100644 --- a/miniprogram/pages/orders/ordersList/ordersList.wxml +++ b/miniprogram/pages/orders/ordersList/ordersList.wxml @@ -1,7 +1,109 @@ - - - {{item}} - {{item}} - {{item}} - - \ No newline at end of file + + + + + + + + + + + + + + + {{item.order_step_name}} + + + + + + + + + {{item.label}} + + + + + + + + + {{item.label}} + + + + + + + + + + + + + + + + + 含税金额合计: + ¥{{amount.tot_tax_last_money}} + + + 优惠金额合计: + ¥{{amount.tot_discount_money}} + + + 已收金额合计: + ¥{{amount.tot_payed_amount}} + + + 未收金额合计: + ¥{{amount.tot_un_payed_amount}} + + + + + + {{ item.order_no }} + + + + + + + + + + + + + + + + + + + 收付款 + 删除 + + + + + \ No newline at end of file diff --git a/miniprogram/pages/orders/ordersList/ordersList.wxss b/miniprogram/pages/orders/ordersList/ordersList.wxss index e69de29..8be63c1 100644 --- a/miniprogram/pages/orders/ordersList/ordersList.wxss +++ b/miniprogram/pages/orders/ordersList/ordersList.wxss @@ -0,0 +1,4 @@ +view.t-cell__title-text { + white-space: nowrap; + flex-shrink: 0; +} diff --git a/miniprogram/utils/config.ts b/miniprogram/utils/config.ts index e243664..1d026a0 100644 --- a/miniprogram/utils/config.ts +++ b/miniprogram/utils/config.ts @@ -16,17 +16,13 @@ export const colors = { export const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'; +const envVersion = wx.getAccountInfoSync().miniProgram.envVersion; + export const base = { appletName: '易宝赞普惠版', - apiHost: - wx.getAccountInfoSync().miniProgram.envVersion == 'release' - ? 'https://ebaozan.com/api/' - : 'http://192.168.1.138:93/', + apiHost: envVersion == 'release' ? 'https://f.ebaozan.com/api/' : 'http://192.168.1.138:93/', - webViewBaseUrl: - wx.getAccountInfoSync().miniProgram.envVersion == 'release' - ? 'https://ebaozan.com/' - : 'http://ebaozan.cf/', + webViewBaseUrl: envVersion == 'release' ? 'https://f.ebaozan.com/' : 'http://free.erp/', cookieKey: 'OwCookie', }; @@ -38,3 +34,26 @@ export const http = { }, unLoginCode: 110000, }; + +/** + * 生产状态 + */ +export const SaleOrderProcessStateOption = [ + { label: '生产未完成', value: 200 }, + { label: '生产已完成', value: 202 }, +]; + +export const SaleOrderProcessStateObj = { + 200: '生产未完成', + 202: '生产已完成', +}; + +/** + * 收款状态 + */ +export const PayedStateOption = [ + { label: '全部', value: '' }, + { label: '未收款', value: '1' }, + { label: '部分收款', value: '2' }, + { label: '收款完成', value: '3' }, +]; diff --git a/miniprogram/utils/https.ts b/miniprogram/utils/https.ts index 37f7356..ecb1467 100644 --- a/miniprogram/utils/https.ts +++ b/miniprogram/utils/https.ts @@ -3,7 +3,7 @@ * YangXB 2021.11.24 * */ import { base, http } from './config'; -import { getStorage, goIndexPage, isArray, setStorage, toastError } from './util'; +import { getStorage, goIndexPage, isArray, setStorage, toArray, toastError } from './util'; /** * 请求 */ @@ -129,14 +129,24 @@ export const checkSession = () => { }); }; +const getUsersConfigList = () => { + post('ErpConfig/ErpConfigList').then((res: any) => { + toArray(res?.data?.list).forEach((el) => { + wx.setStorageSync(el.config_type_en, el.config_value); + }); + }); +}; + export const loginStatus = () => { return new Promise((resolve, reject) => { post('Applet/loginStatus', {}, { showLoading: false }) .then((res: any) => { setStorage('user_info', res.user_info); + setStorage('user_id', res.user_info?.user_id); setStorage('company_info', res.company_info); setStorage('auth_info', res.auth_info); setStorage('session_id', res.session_id); + getUsersConfigList(); resolve(res); }) .catch((err: any) => { @@ -194,6 +204,7 @@ export const login = (encryptedData: any, iv: any, type?: any, company_id?: any) resolve(res); } else { setStorage('user_info', res.user_info); + setStorage('user_id', res.user_info?.user_id); setStorage('company_info', res.companys_info); setStorage('auth_info', res.auth_info); loginStatus(); diff --git a/miniprogram/utils/util.ts b/miniprogram/utils/util.ts index 44d03a5..379db61 100644 --- a/miniprogram/utils/util.ts +++ b/miniprogram/utils/util.ts @@ -1,4 +1,5 @@ import { http } from './config'; +import Big from 'big.js'; export const formatTime = (date: Date) => { const year = date.getFullYear(); @@ -19,12 +20,11 @@ export const formatNumber = (n: number | string) => { }; // 对话框 -export const showModal = (title: string, content: string, showCancel = false) => { +export const showModal = (option: { title?: string; content: string }) => { return new Promise((resolve, reject) => { wx.showModal({ - title, - content, - showCancel, + title: option.title || '系统提示', + content: option.content, success(res) { if (res.confirm) { resolve(); @@ -306,3 +306,44 @@ export const getCurrentPageRoute = () => { const currentPage = pages[pages.length - 1]; // 获取当前页面对象 return `/${currentPage.route}`; // 获取当前页面路径 }; + +/** 价格保留位数 */ +export const priceRetentionDigits = (value?: number) => { + return toNumber( + Big(toNumber(value)).toFixed(toNumber(wx.getStorageSync('PRICE_HOLD_POINT') || 2)), + ); +}; + +/** 价格保留位数字符串类型 */ +export const priceRetentionDigitsString = (value?: number) => { + return Big(toNumber(value)).toFixed(toNumber(wx.getStorageSync('PRICE_HOLD_POINT') || 2)); +}; + +/** 数量保留位数 */ +export const numRetentionDigits = (value?: number) => { + return toNumber( + Big(toNumber(value)).toFixed(toNumber(wx.getStorageSync('NUMS_HOLD_POINT') || 2)), + ); +}; + +/** 数量保留位数字符串类型 */ +export const numRetentionDigitsString = (value?: number) => { + return Big(toNumber(value)).toFixed(toNumber(wx.getStorageSync('NUMS_HOLD_POINT') || 2)); +}; + +/** + * sleep + * @param callback 回调函数 + * @param ms 毫秒, 默认300ms + * @returns + */ +export const sleep = (callback?: () => void, ms = 300): Promise => { + return new Promise((resolve) => { + setTimeout(() => { + callback?.(); + resolve(true); + }, ms); + }); +}; + +export const cloneLite = (data: any) => JSON.parse(JSON.stringify(data));