update
This commit is contained in:
84
commons/utils/dict.js
Normal file
84
commons/utils/dict.js
Normal file
@@ -0,0 +1,84 @@
|
||||
|
||||
export default {
|
||||
orderStatus: [
|
||||
{ label: "待支付", type: "unpaid" },
|
||||
{ label: "制作中", type: "in_production" },
|
||||
{ label: "待取餐", type: "wait_out" },
|
||||
{ label: "订单完成", type: "done" },
|
||||
{ label: "申请退单", type: "refunding" },
|
||||
{ label: "退单", type: "refund" },
|
||||
{ label: "部分退单", type: "part_refund" },
|
||||
{ label: "取消订单", type: "cancelled" },
|
||||
],
|
||||
orderType: [
|
||||
{ label: "收银", type: "cash" },
|
||||
{ label: "小程序", type: "miniapp" },
|
||||
],
|
||||
dineMode: [
|
||||
{ label: "堂食", type: "dine-in" },
|
||||
{ label: "外带", type: "take-out" },
|
||||
{ label: "外卖", type: "take-away" },
|
||||
],
|
||||
payType: [
|
||||
{ label: "主扫", type: "main_scan" },
|
||||
{ label: "被扫", type: "back_scan" },
|
||||
{ label: "微信小程序", type: "wechat_mini" },
|
||||
{ label: "支付宝小程序", type: "alipay_mini" },
|
||||
{ label: "会员支付", type: "vip_pay" },
|
||||
{ label: "现金支付", type: "cash_pay" },
|
||||
{ label: "挂账支付", type: "credit_pay" },
|
||||
],
|
||||
bizCodes: [
|
||||
{ label: "现金充值", type: "cashIn" },
|
||||
{ label: "微信小程序充值", type: "wechatIn" },
|
||||
{ label: "支付宝小程序充值", type: "alipayIn" },
|
||||
{ label: "充值奖励", type: "awardIn" },
|
||||
{ label: "充值退款", type: "rechargeRefund" },
|
||||
{ label: "订单消费", type: "orderPay" },
|
||||
{ label: "订单退款", type: "orderRefund" },
|
||||
{ label: "管理员充值", type: "adminIn" },
|
||||
{ label: "管理员消费", type: "adminOut" },
|
||||
],
|
||||
platformType: [
|
||||
{ label: '微信小程序', type: 'WX' },
|
||||
{ label: '支付宝小程序', type: 'ALI' },
|
||||
{ label: '收银机客户端', type: 'PC' },
|
||||
{ label: 'PC管理端', type: 'WEB' },
|
||||
{ label: 'APP管理端', type: 'APP' },
|
||||
{ label: '收款码', type: 'H5' },
|
||||
],
|
||||
tableStatus: {
|
||||
idle: { label: "空闲", type: "#3F9EFF" },
|
||||
using: { label: "使用中", type: "#fa5555" },
|
||||
subscribe: { label: "预定", type: "rgb(34, 191, 100)" },
|
||||
closed: { label: "关台", type: "rgb(221,221,221)" },
|
||||
opening: { label: "开台中", type: "#E6A23C" },
|
||||
cleaning: { label: "待清台", type: "#FAAD14" },
|
||||
paying: { label: "结算中", type: "#E6A23C" },
|
||||
unbind: { label: "未绑定", type: "rgb(221,221,221)" }
|
||||
},
|
||||
invoicingType: [
|
||||
{ label: '全部', type: '' },
|
||||
{ label: '手动入库', type: 'manual-in' },
|
||||
{ label: '手动出库', type: 'manual-out' },
|
||||
{ label: '盘盈入库', type: 'win-in' },
|
||||
{ label: '盘亏出库', type: 'loss-out' },
|
||||
{ label: '订单退款入库', type: 'other-out' },
|
||||
{ label: '订单消费出库', type: 'order-out' },
|
||||
{ label: '损耗出库', type: 'damage-out' },
|
||||
],
|
||||
invoicingType: [
|
||||
{ label: '全部', type: '' },
|
||||
{ label: '手动入库', type: 'manual-in' },
|
||||
{ label: '手动出库', type: 'manual-out' },
|
||||
{ label: '盘盈入库', type: 'win-in' },
|
||||
{ label: '盘亏出库', type: 'loss-out' },
|
||||
{ label: '订单退款入库', type: 'other-out' },
|
||||
{ label: '订单消费出库', type: 'order-out' },
|
||||
{ label: '损耗出库', type: 'damage-out' },
|
||||
],
|
||||
getDiceName(val,key){
|
||||
let item = this[key].find(v => v.type == val)
|
||||
return item ? item.label : ''
|
||||
}
|
||||
}
|
||||
@@ -34,4 +34,15 @@ export function numSum(arr) {
|
||||
return a + b * 100
|
||||
}, 0)
|
||||
return (sum / 100).toFixed(2)
|
||||
}
|
||||
export function mathFloorPrice(price,item) {
|
||||
if( item ){
|
||||
if( item.productType == 'weight' || item.type == 'weight'){
|
||||
return (Math.floor(price * 100)/100).toFixed(2)
|
||||
} else {
|
||||
return parseFloat(price).toFixed(2)
|
||||
}
|
||||
} else {
|
||||
return parseFloat(price).toFixed(2)
|
||||
}
|
||||
}
|
||||
@@ -140,24 +140,32 @@ function returnFormatParams(params) {
|
||||
export async function hasPermission(params) {
|
||||
//如果是商户默认拥有全部权限
|
||||
const loginType=uni.getStorageSync('loginType')
|
||||
if(loginType=='merchant'){
|
||||
if(loginType=='0'){
|
||||
return true
|
||||
}
|
||||
params = returnFormatParams(params)
|
||||
if (!params) {
|
||||
return infoBox.showToast('未找到相关权限,请检查代码或在权限配置文件commons/utils/hasPermission.js文件进行修改或增加')
|
||||
}
|
||||
const option = Object.assign({
|
||||
tips: true,
|
||||
key: '',
|
||||
text: ''
|
||||
}, params)
|
||||
const res = await $hasPermission({
|
||||
code: params.key
|
||||
})
|
||||
if (!res && option.tips) {
|
||||
infoBox.showToast('您没有' + params.text + '权限!')
|
||||
}
|
||||
return res
|
||||
// const loginType=uni.getStorageSync('loginType')
|
||||
// if(loginType=='merchant'){
|
||||
// return true
|
||||
// }
|
||||
// params = returnFormatParams(params)
|
||||
// if (!params) {
|
||||
// return infoBox.showToast('未找到相关权限,请检查代码或在权限配置文件commons/utils/hasPermission.js文件进行修改或增加')
|
||||
// }
|
||||
// const option = Object.assign({
|
||||
// tips: true,
|
||||
// key: '',
|
||||
// text: ''
|
||||
// }, params)
|
||||
// const res = await $hasPermission({
|
||||
// code: params.key
|
||||
// })
|
||||
// if (!res && option.tips) {
|
||||
// infoBox.showToast('您没有' + params.text + '权限!')
|
||||
// }
|
||||
// return res
|
||||
}
|
||||
|
||||
|
||||
194
commons/utils/index.js
Normal file
194
commons/utils/index.js
Normal file
@@ -0,0 +1,194 @@
|
||||
|
||||
export const utils = {
|
||||
ColorMain: '#318AFE',
|
||||
ColorRed: '#F02C45',
|
||||
|
||||
/**
|
||||
* 限制只让输入数字
|
||||
* @param {Object} e
|
||||
*/
|
||||
isNumber (e) {
|
||||
return e.replace(/[^\d]/g, '')
|
||||
},
|
||||
|
||||
/**
|
||||
* 限制金额输入格式
|
||||
* @param {Object} e
|
||||
*/
|
||||
isMoney (e) {
|
||||
return e.toString().replace(/[^0-9.]/g, '').replace(/^\./g, "").replace(".", "$#$").replace(/\./g, "").replace("$#$", ".").replace(/^(\-)*(\d+)\.(\d{0,2}).*$/, "$1$2.$3")
|
||||
},
|
||||
|
||||
/**
|
||||
* 判断菜品使用价格
|
||||
* @param {Object} e
|
||||
*/
|
||||
isGoodsPrice(item,user) {
|
||||
let isVip = uni.getStorageSync("shopInfo").isMemberPrice&&user.id&&user.isVip
|
||||
|
||||
let memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
let price = isVip ? memberPrice : item.price;
|
||||
price = item.discountSaleAmount ? item.discountSaleAmount : price
|
||||
return price;
|
||||
},
|
||||
|
||||
inputReg(value,key,regName){
|
||||
//判断regList对象是否存在属性 避免报错
|
||||
// utils.hasOwnProperty.call(utils,regName)&&(form[key]=utils[regName](value))
|
||||
},
|
||||
|
||||
/**
|
||||
* 金额保留两位小数
|
||||
* @param {Object} e
|
||||
*/
|
||||
toFixed (price,item) {
|
||||
if( item ){
|
||||
if( item.productType == 'weight' || item.type == 'weight'){
|
||||
return (Math.floor(price * 100)/100).toFixed(2)
|
||||
} else {
|
||||
return parseFloat(price).toFixed(2)
|
||||
}
|
||||
} else {
|
||||
return parseFloat(price).toFixed(2)
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 金额向下取整
|
||||
* @param {Object} e
|
||||
*/
|
||||
formatPrice (e) {
|
||||
return (Math.floor(n*100)/100).toFixed(2)
|
||||
},
|
||||
|
||||
/**
|
||||
* 消息提示框
|
||||
*/
|
||||
showToast(title, duration = 1.5, extObject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.showToast(Object.assign({ title: title, icon: 'none', mask: false, duration: (duration * 1000) }, extObject))
|
||||
setTimeout(resolve, (duration * 1000));
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 保留小数n位,不进行四舍五入
|
||||
* num你传递过来的数字,
|
||||
* decimal你保留的几位,默认保留小数后两位
|
||||
*/
|
||||
formatDecimal (num, decimal = 2) {
|
||||
num = num.toString()
|
||||
const index = num.indexOf('.')
|
||||
if (index !== -1) {
|
||||
num = num.substring(0, decimal + index + 1)
|
||||
} else {
|
||||
num = num.substring(0)
|
||||
}
|
||||
//截取后保留两位小数
|
||||
return parseFloat(num).toFixed(decimal)
|
||||
},
|
||||
|
||||
/**
|
||||
* 分转元
|
||||
* amount - 金额
|
||||
* parseFloat - 是否转换为数字格式,
|
||||
* 默认String
|
||||
*/
|
||||
cert2Dollar(amount, needParseFloat = false) {
|
||||
if (needParseFloat) { // parseFlot
|
||||
return formatDecimal(amount / 100)
|
||||
}
|
||||
return formatDecimal(amount / 100)
|
||||
},
|
||||
|
||||
/**
|
||||
* @desc 函数防抖
|
||||
* @param func 目标函数
|
||||
* @param wait 延迟执行毫秒数
|
||||
* @param immediate true - 立即执行, false - 延迟执行
|
||||
*/
|
||||
debounce (func, wait = 1000, immediate = true) {
|
||||
let timer;
|
||||
return function() {
|
||||
let context = this,
|
||||
args = arguments;
|
||||
if (timer) clearTimeout(timer);
|
||||
if (immediate) {
|
||||
let callNow = !timer;
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
}, wait);
|
||||
if (callNow) func.apply(context, args);
|
||||
} else {
|
||||
timer = setTimeout(() => {
|
||||
func.apply(context, args);
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @desc 函数节流
|
||||
* @param func 函数
|
||||
* @param wait 延迟执行毫秒数
|
||||
* @param type 1 使用表时间戳,在时间段开始的时候触发 2 使用表定时器,在时间段结束的时候触发
|
||||
*/
|
||||
throttle (func, wait = 1000, type = 1) {
|
||||
let previous = 0;
|
||||
let timeout;
|
||||
return function() {
|
||||
let context = this;
|
||||
let args = arguments;
|
||||
if (type === 1) {
|
||||
let now = Date.now();
|
||||
|
||||
if (now - previous > wait) {
|
||||
func.apply(context, args);
|
||||
previous = now;
|
||||
}
|
||||
} else if (type === 2) {
|
||||
if (!timeout) {
|
||||
timeout = setTimeout(() => {
|
||||
timeout = null;
|
||||
func.apply(context, args)
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 对象转数组
|
||||
* @param {Object} e
|
||||
*/
|
||||
objToArrary (obj) {
|
||||
|
||||
if (Object.values(obj) && Array.isArray(Object.values(obj)[0])){
|
||||
// 是数组
|
||||
let arr = []
|
||||
Object.values(obj).forEach(item=>{
|
||||
arr = [...arr,...item]
|
||||
})
|
||||
return arr
|
||||
} else {
|
||||
// 不是数组
|
||||
return Object.keys(obj).map(key => obj[key])
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 获取url链接参数
|
||||
* @param {Object} url
|
||||
* @param {Object} name
|
||||
*/
|
||||
getQueryString(url, name) {
|
||||
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
|
||||
var r = url.substr(1).match(reg)
|
||||
if (r != null) {
|
||||
return r[2]
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
}
|
||||
@@ -18,13 +18,13 @@ const appCache = {
|
||||
const model = {
|
||||
|
||||
setLogin(res){
|
||||
const user=res.user.user
|
||||
const user=res.shopInfo
|
||||
uni.setStorageSync('logoutHandle',false)
|
||||
uni.setStorageSync('shopId', res.shopId)
|
||||
uni.setStorageSync('shopName',res.shopName)
|
||||
uni.setStorageSync('logo',res.logo)
|
||||
uni.setStorageSync('shopId', user.id)
|
||||
uni.setStorageSync('shopName',user.shopName)
|
||||
uni.setStorageSync('logo',user.logo)
|
||||
uni.setStorageSync('loginType',res.loginType)
|
||||
uni.setStorageSync('shopUserId',user.id)
|
||||
// uni.setStorageSync('shopUserId',user.id)
|
||||
if(res.loginType=='staff'){
|
||||
uni.setStorageSync('merchantName',user.createBy||user.updateBy)
|
||||
}
|
||||
@@ -51,14 +51,14 @@ const model = {
|
||||
|
||||
if (val) {
|
||||
// 有值,为放置
|
||||
appCache.tokenVal = val
|
||||
uni.setStorageSync(appConfig.tokenKey, val)
|
||||
appCache.tokenVal = val.tokenValue
|
||||
uni.setStorageSync(appConfig.tokenKey, val.tokenValue)
|
||||
} else {
|
||||
// 否则为获取
|
||||
|
||||
if (!appCache.tokenVal) {
|
||||
//缓存取不到,获取应用本地信息
|
||||
appCache.tokenVal = uni.getStorageSync(appConfig.tokenKey)
|
||||
appCache.tokenVal = uni.getStorageSync(appConfig.tokenKey).tokenValue
|
||||
}
|
||||
return appCache.tokenVal
|
||||
}
|
||||
@@ -72,8 +72,8 @@ const model = {
|
||||
|
||||
if (val) {
|
||||
// 有值,为放置
|
||||
appCache.shopId = val
|
||||
uni.setStorageSync('shopId', val)
|
||||
appCache.shopId = val.id
|
||||
uni.setStorageSync('shopId', val.id)
|
||||
} else {
|
||||
// 否则为获取
|
||||
|
||||
@@ -223,20 +223,18 @@ const model = {
|
||||
if (currentUserInfo) {
|
||||
// 仅保存基础数据
|
||||
let saveUser = {
|
||||
|
||||
sysUserId: currentUserInfo.sysUserId, // 用户ID
|
||||
realname: currentUserInfo.realname, // 用户姓名
|
||||
avatarUrl: currentUserInfo.avatarUrl, // 头像
|
||||
telphone: currentUserInfo.telphone, // 手机号
|
||||
userType: currentUserInfo.userType, // 用户类型
|
||||
|
||||
mchNo: currentUserInfo.userNo, // 商户No
|
||||
mchShortName: currentUserInfo.shortName, // 商户简称
|
||||
mchType: currentUserInfo.mchType, // 商户类型
|
||||
mchLevel: currentUserInfo.mchLevel, // 商户级别
|
||||
isHasMemberEnt:currentUserInfo.isHasMemberEnt,// 是否购买会员模块
|
||||
entIdList: currentUserInfo.entIdList, // 权限集合List
|
||||
|
||||
// sysUserId: currentUserInfo.sysUserId, // 用户ID
|
||||
// realname: currentUserInfo.realname, // 用户姓名
|
||||
// avatarUrl: currentUserInfo.avatarUrl, // 头像
|
||||
// telphone: currentUserInfo.telphone, // 手机号
|
||||
// userType: currentUserInfo.userType, // 用户类型
|
||||
// mchNo: currentUserInfo.userNo, // 商户No
|
||||
// mchShortName: currentUserInfo.shortName, // 商户简称
|
||||
// mchType: currentUserInfo.mchType, // 商户类型
|
||||
// mchLevel: currentUserInfo.mchLevel, // 商户级别
|
||||
// isHasMemberEnt:currentUserInfo.isHasMemberEnt,// 是否购买会员模块
|
||||
// entIdList: currentUserInfo.entIdList, // 权限集合List
|
||||
...currentUserInfo
|
||||
}
|
||||
uni.setStorageSync("currentUserInfo", saveUser) // 改变存储
|
||||
appCache.currentUser = null
|
||||
|
||||
Reference in New Issue
Block a user