// 提示框 function modelShow( title = '提示', content = '确认执行此操作吗?', callback = () => {}, showCancel = true, editable = false, cancelText = '取消', confirmText = '确定', placeholderText = '请输入取消原因' ) { uni.showModal({ title: title, content: content, showCancel: showCancel, cancelText: cancelText, confirmText: confirmText, cancelText: cancelText, editable: editable, placeholderText: placeholderText, success: function(res) { if (res.confirm) { // 用户点击确定操作 setTimeout(() => { callback(res.content) }, 500) } else if (res.cancel) { // 用户取消操作 } } }) } //货币格式化 function formatMoney(number, places, symbol, thousand, decimal) { number = number || 0 places = !isNaN((places = Math.abs(places))) ? places : 2 symbol = symbol !== undefined ? symbol : '¥' thousand = thousand || ',' decimal = decimal || '.' var negative = number < 0 ? '-' : '', i = parseInt((number = Math.abs(+number || 0).toFixed(places)), 10) + '', j = (j = i.length) > 3 ? j % 3 : 0 return ( symbol + negative + (j ? i.substr(0, j) + thousand : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (places ? decimal + Math.abs(number - i) .toFixed(places) .slice(2) : '') ) } /** * 金额相加 * @param {Object} value1 * @param {Object} value2 */ function moneySum(value1, value2) { return (parseFloat(value1) + parseFloat(value2)).toFixed(2); } /** * 金额相减 * @param {Object} value1 * @param {Object} value2 */ function moneySub(value1, value2) { value1 = value1 ? value1 : 0 value2 = value2 ? value2 : 0 let res = (parseFloat(value1) - parseFloat(value2)).toFixed(2); return res > 0 ? res : '0.00'; } /** * 显示消息提示框 * @param {Object} params 参数 */ function showToast(params = {}) { params.title = params.title || "" params.icon = params.icon || "none" params.position = params.position || 'bottom' params.duration = 1500 uni.showToast(params) } export { formatMoney, modelShow, moneySum, moneySub, showToast, }