Commit 0b6927e3 by 杨北旺

合并代码

2 parents f42ab85f 6ad1666f
Showing 148 changed files with 4292 additions and 189 deletions
......@@ -111,10 +111,17 @@ const defaultMerchantId = {
uat: '44210895',
prod: '44189923'
}[target[index]]
const CONFIG_ENV_MAP={
'1':'develope',
'2':'test',
'3':'production'
}
module.exports = {
index,
domain,
pathEnum,
secretKey,
defaultMerchantId
defaultMerchantId,
env:CONFIG_ENV_MAP[index]
}
import api from "../request/http";
const path = 'scrm.api.coupon.'
const ghPath = 'scrm.api.carlife.cgacar.'
import api from '../request/http'
module.exports = {
/**获取卡券列表 */
getCardData(data) {
return api.post({
method: `${path}app.list`,
method: `scrm.api.coupon.app.list`,
...data
// discountTypes: [3, 7]
})
},
//获取领券中心优惠券列表
getCarCenterdData(data){
return api.post({
method: `${path}list.couponCenterList`,
...data
})
},
/**获取卡券数量 */
getCouponNum() {
return api.post({
......@@ -26,77 +17,43 @@ module.exports = {
},
/**获取首页可以领取的券 */
getHomeCardData(data) {
let merchantId = wx.$storage.get('srcm_shopmall_merchant_id')
let {merchantId} = wx.p.storage.get('merchant_info')
if (merchantId) {
merchantId = Number(JSON.parse(merchantId))
data.merchantId = merchantId
}
if (merchantId) {
data.merchantId = merchantId
}
return api.post({
method: `${path}list.merchant.account`,
method: `scrm.api.coupon.list.merchant.account`,
...data
})
},
/**领取优惠券 */
toReciveCard(data) {
let {
merchantId
} = wx.p.storage.get('merchant_info')
if (merchantId) {
merchantId = Number(JSON.parse(merchantId))
data.merchantId = merchantId
}
return api.post({
method: `${path}customer.receive`,
method: `scrm.api.coupon.customer.receive`,
...data,
receiveWay: 1,
receiveSource: 3
})
},
/**卡券详情 */
couponsDetail(data) {
return api.post({
method: `${path}verification.code.detail`,
...data
})
},
/**广汇卡券 卡券全部列表 */
ghCouponsData() {
return api.post({
method: `${ghPath}coupon.list.benefits`
})
},
/**广汇卡券 抵用记录列表 */
ghDealNote() {
return api.post({
method: `${ghPath}coupon.list.credit.cards`
})
},
/**广汇卡券 发布确认列表 */
ghDealPublish() {
return api.post({
method: `${ghPath}coupon.list.card.deal`
})
},
/**广汇卡券 抵用确认列表 */
ghDealResist() {
return api.post({
method: `${ghPath}coupon.list.resist.deal`
})
},
/**抵用确认提交 */
ghSumbitResist(data) {
return api.post({
method: `${ghPath}coupon.resist.deal`,
...data
})
},
/**发布确认提交 */
ghSumbitPublish(data) {
return api.post({
method: `${ghPath}coupon.card.deal`,
method: `scrm.api.coupon.verification.code.detail`,
...data
})
},
/**免费领取体验卡 */
tolqFreecard(data) {
return api.post(
{
return api.post({
method: `scrm.api.equity.h5.free.card.receive`,
...data
},
......@@ -113,15 +70,14 @@ module.exports = {
/** 获取企微分享优惠卷信息 */
getCouponInfo(data) {
return api.post({
method: `${path}share.info`,
method: `scrm.api.coupon.share.info`,
...data
})
},
/**领取优惠券 */
receiveCoupon(data) {
return api.post(
{
method: `${path}share.receive`,
return api.post({
method: `scrm.api.coupon.share.receive`,
...data,
receiveSource: 4
},
......@@ -183,5 +139,21 @@ module.exports = {
method: `scrm.api.coupon.detail`,
...data
})
}
},
// 领取发现模块的优惠券
toReciveDiscoverCard(data) {
let {
merchantId
} = wx.p.storage.get('merchant_info')
if (merchantId) {
merchantId = Number(JSON.parse(merchantId))
data.merchantId = merchantId
}
return api.post({
method: `scrm.api.coupon.customer.receive`,
...data,
receiveWay: 9,
receiveSource: 3
})
},
}
......@@ -5,8 +5,10 @@ import homeApi from './home'
import discoveryApi from './discovery'
import shopmallApi from './shopmall'
import mineApi from './mine'
import equityApi from './equity'
import systemApi from './system'
import couponsApi from './coupons'
import equityApi from './equity'
module.exports = {
wechatApi,
entmicroApi,
......@@ -15,6 +17,7 @@ module.exports = {
discoveryApi,
shopmallApi,
mineApi,
equityApi,
couponsApi
systemApi,
couponsApi,
equityApi
}
\ No newline at end of file
......@@ -54,4 +54,20 @@ module.exports = {
getUserAddressDefault() {
return api.fetch('scrm.api.carlife.weapp.userAddress.getDefault')
},
/**. 分页查询订单 */
getOrderList(data) {
return api.post({
method: `scrm.api.shopmall.weapp.order.page`,
pageSize: 99999,
...data
})
},
/**获取订单状态数量 */
getOrderNumberList(data) {
return api.post({
method: 'scrm.api.shopmall.weapp.order.statis',
...data
})
}
}
\ No newline at end of file
......@@ -45,8 +45,8 @@ module.exports = {
})
},
/**购物车结算 */
settlementShoppingcart(data) {
/**购物车结算 */
settlementShoppingcart(data) {
return api.post({
method: `scrm.api.shopmall.weapp.shoppingcart.settlement`,
...data
......@@ -67,4 +67,51 @@ module.exports = {
...data
})
},
/**订单详情 */
getOrderDetail(orderCode) {
return api.post({
method: `scrm.api.shopmall.weapp.order.detail`,
orderCode
})
},
/**获取订单的售后详情 */
getOrderRefundDetail(orderCode) {
return api.post({
method: `scrm.api.shopmall.weapp.orderRefund.detail`,
orderCode
})
},
/**活动详情 */
getActivityDetail(id) {
return api.fetch('scrm.api.shopmall.weapp.activity.detail', {
id
})
},
/** 根据商品ID获取商品 */
getGoodsDetail(id) {
return api.fetch('scrm.api.shopmall.weapp.goods.getById', {
id,
viewAmount: true
})
},
/** 获取商品关联优惠券列表 */
getGoodscouponList(data) {
return api.fetch('scrm.api.shopmall.weapp.goods.user.coupons.get', data)
},
/** 领取商品详情优惠券 */
getCoupon(data) {
return api.fetch('scrm.api.coupon.customer.receive', data)
},
/**根据规格值组合获取规格组合库存及零售价 */
getGoodsSpecificationExtra(data) {
return api.post({
method: `scrm.api.shopmall.weapp.goods.getGoodsSpecificationExtra`,
...data
})
},
}
\ No newline at end of file
import http from "../request/http";
import { env } from "../env/index";
const serverConfig = {
mockRequestCount: null,
mockTimer: {},
mockCache: null,
};
const configModule = 'mini-hmd'
const configUrl = `https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=${configModule}&env=${env}`;
/**获取mock数据 */
const getMockData = async () => {
const MOCKDATA = wx.p.storage.get("mock_data");
try {
if (MOCKDATA && Date.now() - MOCKDATA.createTime < 5 * 60e3) {
return Promise.resolve(MOCKDATA);
} else {
if (!serverConfig.mockRequestCount) {
serverConfig.mockCache = null;
serverConfig.mockRequestCount = Date.now();
const data = await http.wx_request({ url:configUrl });;
data.createTime = Date.now();
serverConfig.mockCache = data;
wx.p.storage.set("mock_data", data);
return Promise.resolve(data);
} else {
const key = Date.now();
return new Promise((resolve) => {
serverConfig.mockTimer[key] = setInterval(() => {
if (serverConfig.mockCache) {
clearInterval(serverConfig.mockTimer[key]);
serverConfig.mockRequestCount = null;
resolve(serverConfig.mockCache);
}
}, 1e3);
});
}
}
} catch (error) {
if (serverConfig.mockTimer[key]) clearInterval(serverConfig.mockTimer[key]);
serverConfig.mockRequestCount = null;
return Promise.reject(error);
}
};
// 图片版本号
const getImageVersion = async () => {
const accountInfo = await getMockData()
return accountInfo?.version || Date.now()
}
module.exports={
getImageVersion
}
\ No newline at end of file
import http from '../request/http'
// const { appId } = wx.getAccountInfoSync().miniProgram
import {
appId
} from '~/utils/constants'
const { appId } = wx.getAccountInfoSync().miniProgram
let loginCount = null,
loginCache = null,
loginTimer = null
......
import sign from './sign.js'
import {
defaultMerchantId,
secretKey,
pathEnum,
domain,
index,
sign
} from './sign.js'
let INTERRUPT = false
} from '../env/index'
/**接口 */
class Request {
get(params, returnAll = false) {
......@@ -15,15 +13,36 @@ class Request {
post(params, returnAll = false) {
return this.request('POST', params, returnAll)
}
fetch(method,data, returnAll = true){
return this.post(
{
fetch(method, data, returnAll = true) {
return this.post({
method,
...data,
},
returnAll
);
}
wx_request({
url,
method = 'GET',
data = {},
header = {},
dataType = 'json',
responseType = "text"
}) {
return new Promise((resolve) => {
wx.request({
url,
data,
method,
header,
dataType,
responseType,
success(response) {
resolve(response.data)
}
})
})
}
reportTrack(params) {
return this.request('POST', params, true)
}
......@@ -32,7 +51,9 @@ class Request {
wx.showNavigationBarLoading()
let header = RequestMethods === 'POST' ? {
'content-type': 'application/x-www-form-urlencoded'
} : {'Cache-Control': 'no-cache'}
} : {
'Cache-Control': 'no-cache'
}
header.merchantId = defaultMerchantId
let projectName = this.getRopProject(params.method)
if (!projectName) projectName = this.getRopProject(params.method)
......@@ -60,21 +81,9 @@ class Request {
}
if (code == 20 || code == 21) {
wx.hideLoading()
const thisPage = wx.p.router.getPageInstance()
if (thisPage && thisPage.pageRefresh) thisPage.pageRefresh()
if (!wx.p.authStatus) {
if (INTERRUPT) return
INTERRUPT = true
wx.showLoading()
getApp().login().then(() => {
if (thisPage.init && thisPage.data.userInfo) thisPage.init()
if (thisPage.loginCallBack && thisPage.data.userInfo) thisPage.loginCallBack(thisPage.data.userInfo)
if (thisPage.onRoute) thisPage.onRoute()
thisPage.onLoad()
thisPage.onShow()
INTERRUPT = false
})
}
return wx.reLaunch({
url: '/pages/loading/loading'
})
} else {
if (code == '0') {
resolve(data.data)
......@@ -136,22 +145,5 @@ class Request {
const projectName = method.split('.')[2]
return projectName
}
getMock() {
let url = 'https://oss-config.dev.glsx.com.cn/mock/6264ff4760f415276f6dfe62/aicard-config'
if (index == 3 || index == 4) url = 'https://oss-config.test.glsx.com.cn/mock/6274e3050da5034a58680aa6/aicard-config'
return new Promise((resolve) => {
wx.request({
url,
data: {},
method: 'GET',
header: {},
dataType: 'json',
responseType: 'text',
success(response) {
resolve(response.data)
}
})
})
}
}
export default new Request()
\ No newline at end of file
import sha1 from '../../lib/sha1'
import qs from '../../lib/qs'
import environment from '../env/index.js'
import {sha1,qs} from '../../lib/index'
const sign = (params, secret, noSignAttr = []) => {
delete params.sign
var objStr = qs.stringify(params, {
......@@ -33,8 +31,4 @@ const sign = (params, secret, noSignAttr = []) => {
realObj.sign = sha1(secret + str.join('') + secret).toUpperCase()
return realObj
}
module.exports = {
...environment,
sign
}
\ No newline at end of file
export default sign
\ No newline at end of file
// app.js
// 初始化sentry
// import sentryInit from '~/utils/sentryConfig/sentryInit'
// sentryInit()
import api from './api/index'
import {router} from './router/index'
import sentryInit from "~/utils/sentryConfig/sentryInit";
sentryInit();
import api from "./api/index";
import { router } from "./router/index";
// 判断小程序是否需要更新
import getUpdateManager from './lib/wxUpdateManager'
import utils from './utils/index'
import { getUpdateManager } from "./lib/index";
import utils from "./utils/index";
// 埋点 有需要再引入
// import './utils/track/Track'
App({
onLaunch(options) {
getUpdateManager()
getUpdateManager();
/**挂载到wx对象 */
wx.p={
authStatus:false,
wx.p = {
authStatus: false,
...utils,
api,
router,
storage:new utils.cache.Storage(),
}
storage: new utils.cache.Storage(),
};
// 存储设备信息
utils.cache.storageApi.setSystem_info()
utils.cache.storageApi.setSystem_info();
},
/**页面不存在时触发 */
onPageNotFound(e) {
wx.p.router.goHome()
wx.p.router.goHome();
},
onHide() {},
globalData: {
ROUTE_QUERY:{}
}
})
ROUTE_QUERY: {},
},
});
......@@ -32,8 +32,8 @@
{
"pagePath": "pages/tab/equity/index",
"text": "权益",
"iconPath": "assets/images/mall.png",
"selectedIconPath": "assets/images/mall_active.png"
"iconPath": "assets/images/equity.png",
"selectedIconPath": "assets/images/equity_active.png"
},
{
"pagePath": "pages/tab/mall/index",
......@@ -82,7 +82,9 @@
"pages": [
"pages/index/index",
"pages/shoppingCart/shoppingCart",
"pages/pay/pay"
"pages/pay/pay",
"pages/detail/detail",
"pages/search/search"
]
},
{
......@@ -91,15 +93,29 @@
"pages/index/index",
"pages/setting/index",
"pages/address/index/index",
"pages/address/detail/detail"
"pages/address/detail/detail",
"pages/order/index/index",
"pages/order/detail/detail",
"pages/order/complete/complete",
"pages/order/afterSale_step_one/afterSale_step_one",
"pages/order/afterSale_step_two/afterSale_step_two",
"pages/order/afterSale_step_three/afterSale_step_three",
"pages/order/afterSaleDetail/afterSaleDetail",
"pages/coupon/index/index",
"pages/coupon/success/success",
"pages/coupon/center/center",
"pages/coupon/detail/detail",
"pages/coupon/recommend/recommend",
"pages/coupon/usedDetail/usedDetail"
]
}
],
"usingComponents": {
"calendar": "/components/Calendar/Calendar",
"navigation-bar": "/components/NavigationBar/NavigationBar",
"glsx-image": "/components/image/index",
"authorize": "/components/Authorize/Authorize"
"authorize": "/components/Authorize/Authorize",
"popup": "/components/Popup/Popup",
"goods-action": "/components/GoodsAction/GoodsAction"
},
"style": "v2",
"resolveAlias": {
......
// components/GoodsAction/GoodsAction.js
Component({
/**
* 组件的属性列表
*/
properties: {
hideShop: Boolean,
payDisabled: Boolean,
custom: Boolean,
stock: Boolean,
buyFlag: Boolean,
platformShop:Boolean
},
/**
* 组件的初始数据
*/
data: {},
/**
* 组件的方法列表
*/
methods: {
getViewInfo() {
wx.p.wxApi.getViewInfo(
'.goods-action-box',
res => {
this.triggerEvent('ready', res.height)
},
this
)
},
jump(e) {
let { url } = e.currentTarget.dataset
if (url == 'home') wx.p.router.goHome()
else wx.p.router.go('/packageMall/pages/shoppingCart/shoppingCart')
},
click(e) {
let { event } = e.currentTarget.dataset
this.triggerEvent('click', event)
}
},
lifetimes: {
attached() {
this.getViewInfo()
}
}
})
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
<view class="goods-action-box isFullSucreen">
<block wx:if="{{custom}}">
<slot></slot>
</block>
<block wx:else>
<view class="goods-action">
<view class="navigation-box">
<view class="item" bindtap="jump" data-url="home">
<view class="sprite-icon">
<glsx-image src="mall/goods-home.png"></glsx-image>
</view>
首页
</view>
<view class="item" wx:if="{{!hideShop}}" bindtap="jump">
<view class="sprite-icon" >
<glsx-image src="mall/goods-shopping.png"></glsx-image>
</view>
购物车
</view>
</view>
<view class="btn-box {{hideShop}}">
<view class="btn join text-center {{stock?'disabled':''}}" bindtap="click" data-event="join">
加入购物车
</view>
<view class="btn pay text-center {{payDisabled && hideShop?'disabled':''}} {{stock?'disabled':''}} {{buyFlag?'disabled':''}}" bindtap="click" data-event="pay">
立即购买
</view>
</view>
</view>
</block>
</view>
\ No newline at end of file
/* components/GoodsAction/GoodsAction.wxss */
.text-center {
display: flex;
align-items: center;
justify-content: center;
}
.goods-action-box {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: #fff;
z-index: 9;
animation: show-goods-action .55s forwards;
}
@keyframes show-goods-action{
0%{
bottom: -100%;
}
100%{
bottom: 0;
}
}
.goods-action {
padding: 10rpx var(--margin);
display: flex;
align-items: center;
box-sizing: border-box;
height: 100rpx;
}
.isFullSucreen {
padding-bottom: constant(safe-area-inset-bottom) !important;
padding-bottom: env(safe-area-inset-bottom) !important;
}
.navigation-box {
display: flex;
align-items: center;
font-size: 20rpx;
justify-content: space-between;
}
.navigation-box .item{
display: flex;
flex-direction: column;
align-items: center;
margin:0 14rpx;
}
.navigation-box .sprite-icon{
width: 40rpx;
height: 40rpx;
}
.btn-box {
display: flex;
align-items: center;
margin-left: auto;
border-radius: var(--borderRadius);
overflow: hidden;
}
.btn-box .btn {
width: 258rpx;
height: 80rpx;
color: #fff;
font-size: 28rpx;
}
.btn-box .pay {
background-color: var(--btnColor);
}
.btn-box .join {
background-color: #FDC23E;
}
.btn-box.true .join{
display: none;
}
.btn-box.true .btn{
width: 588rpx;
background-color: var(--themeColor);
}
.btn-box .pay.disabled{
background-color: #B1B1B3 !important;
}
.btn-box .disabled{
background-color: #B1B1B3 !important;
}
\ No newline at end of file
// tabWorkOrder/pages/createOrder/createOrderComponents/Popup/Popup.js
import {
componentsMixin
} from '../../mixins/index'
Component({
behaviors: [componentsMixin],
/**
* 组件的属性列表
*/
......@@ -64,13 +60,5 @@ Component({
confirm() {
this.triggerEvent('confirm')
}
},
attached() {
const {
isTab
} = wx.p.router.getRouterList().find(item => item.url === `/${wx.p.router.getPageInstance().route}`)
this.setData({
isTab
})
},
}
})
\ No newline at end of file
......@@ -4,14 +4,14 @@
<block wx:if="{{title}}">
<view class="popup-title text-center">{{title}}</view>
</block>
<view class="popup-slot {{isTab && !hideTab? '': title?'isFullSucreen':'isFullSucreen-notitle'}}">
<view class="popup-slot {{title?'':'notitle' }}">
<slot></slot>
</view>
<view class="popup-footer {{isTab && !hideTab?'':'isFullSucreen'}}" wx:if="{{only}}">
<view class="popup-footer isFullSucreen" wx:if="{{only}}">
<view class="cancel btn text-center" bindtap="hidePopup">取消</view>
<view class="confirm btn text-center" bindtap="confirm">确认</view>
</view>
<view class="popup-footer {{isTab && !hideTabb?'':'isFullSucreen'}}" wx:else>
<view class="popup-footer isFullSucreen" wx:else>
<view class="confirm doubtn text-center" bindtap="confirm">确认</view>
</view>
</view>
......
/* tabWorkOrder/pages/createOrder/createOrderComponents/Popup/Popup.wxss */
@import "/assets/style/common.wxss";
.popup {
position: fixed;
top: 0;
......@@ -45,15 +46,14 @@
}
.popup-slot {
height: calc(100% - 200rpx);
height: calc(100% - 200rpx - var(--constantSafeAreaInsetBottom));
height: calc(100% - 200rpx - var(--envSafeAreaInsetBottom));
}
.popup-slot.isFullSucreen {
height: calc(100% - 258rpx);
}
.popup-slot.isFullSucreen-notitle {
height: calc(100% - 158rpx);
.popup-slot.notitle {
height: calc(100% - 158rpx - var(--constantSafeAreaInsetBottom));
height: calc(100% - 158rpx - var(--envSafeAreaInsetBottom));
}
.popup-footer {
......@@ -66,10 +66,6 @@
z-index: 2;
}
.popup-footer.isFullSucreen {
padding-bottom: constant(safe-area-inset-bottom) !important;
padding-bottom: env(safe-area-inset-bottom) !important;
}
.popup-footer .btn {
width: 330rpx;
......
// components/Tab/Tab.js
import {componentsMixin } from '../../mixins/index'
Component({
behaviors:[componentsMixin],
/**
* 组件的属性列表
*/
......
/* components/Tab/Tab.wxss */
@import "../../common.wxss";
@import "../../assets/style/common.wxss";
.tab-box {
display: flex;
......
// components/image/index.js
import {
IMG_URL,
IMG_VERSION
} from '~/utils/constants'
} from '~/config'
import {
systemApi
} from '~/api/index'
Component({
externalClasses: ['custom-class', 'class'],
/**
......@@ -19,7 +21,7 @@ Component({
let isFullAdd = checkList.map(item => url.includes(item)).some(item => item)
this.setData({
isWebp,
imagePath: `${isFullAdd ? '' : IMG_URL}${url}?v=` + await IMG_VERSION()
imagePath: `${isFullAdd ? '' : IMG_URL}${url}?v=` + await systemApi.getImageVersion()
})
}
}
......
......@@ -10,4 +10,4 @@ export const preReleaseAppId = 'wx6e40cfb83ce4ffb1'
export const dsnUrl = 'https://44b18e4acc2e4ab18f12a69a561b55bc@sentry.glsx.com.cn/39'
// cdn图片地址
export const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/hmd'
export const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/hmd/'
import sha1 from './sha1.js'
import qs from './qs'
import wxqrcode from './wxqrcode.js'
import getUpdateManager from "./wxUpdateManager";
import * as Sentry from './sentry-miniapp'
module.exports ={ sha1,qs,wxqrcode,getUpdateManager,Sentry }
\ No newline at end of file
......@@ -4,7 +4,7 @@ var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexport
var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
__DEFINE__(1689247481138, function(require, module, exports) {
__DEFINE__(1689250267950, function(require, module, exports) {
/*
* @Descripttion: api封装类
* @version: 1.0.0
......@@ -225,8 +225,8 @@ class GlMapApi {
}
if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });exports.default = GlMapApi;
}, function(modId) {var map = {"./request":1689247481139}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689247481139, function(require, module, exports) {
}, function(modId) {var map = {"./request":1689250267951}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689250267951, function(require, module, exports) {
/*
* @Descripttion: 定义一个Request类,用于封装请求高德地图API的方法
* @version: 1.0.0
......@@ -340,8 +340,8 @@ class Request {
}
if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });exports.default = Request;
}, function(modId) { var map = {"./lib/md5":1689247481140,"./lib/qs":1689247481141,"./constants":1689247481142,"./helper":1689247481143}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689247481140, function(require, module, exports) {
}, function(modId) { var map = {"./lib/md5":1689250267952,"./lib/qs":1689250267953,"./constants":1689250267954,"./helper":1689250267955}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689250267952, function(require, module, exports) {
(function () {
......@@ -1017,7 +1017,7 @@ __DEFINE__(1689247481140, function(require, module, exports) {
}
})();
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689247481141, function(require, module, exports) {
__DEFINE__(1689250267953, function(require, module, exports) {
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
......@@ -1658,7 +1658,7 @@ module.exports = {
});
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689247481142, function(require, module, exports) {
__DEFINE__(1689250267954, function(require, module, exports) {
/*
* @Descripttion: 常量类
* @version: 1.0.0
......@@ -1671,7 +1671,7 @@ __DEFINE__(1689247481142, function(require, module, exports) {
if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });var MAP_OPTIONS = exports.MAP_OPTIONS = { domain: 'https://restapi.amap.com', KEY: '373bd88fa36ebc0247d60281386b6cec', SECRET: 'a2a93fa04721a36819d86b71cb31fe41' };
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689247481143, function(require, module, exports) {
__DEFINE__(1689250267955, function(require, module, exports) {
/*
* @Descripttion:帮助类
* @version: 1.0.0
......@@ -1684,7 +1684,7 @@ __DEFINE__(1689247481143, function(require, module, exports) {
if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });var isMiniprogram = exports.isMiniprogram = !window;
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
return __REQUIRE__(1689247481138);
return __REQUIRE__(1689250267950);
})()
//miniprogram-npm-outsideDeps=["./stringify","./parse","./formats","./utils"]
//# sourceMappingURL=index.js.map
\ No newline at end of file
module.exports = (function() {
var __MODS__ = {};
var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
__DEFINE__(1689250267956, function(require, module, exports) {
Object.defineProperty(exports, '__esModule', { value: true });
/**
* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
*
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
*/
/**
* Correct the given number to specifying significant digits.
*
* @param num The input number
* @param precision An integer specifying the number of significant digits
*
* @example strip(0.09999999999999998) === 0.1 // true
*/
function strip(num, precision) {
if (precision === void 0) { precision = 15; }
return +parseFloat(Number(num).toPrecision(precision));
}
/**
* Return digits length of a number.
*
* @param num The input number
*/
function digitLength(num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
return len > 0 ? len : 0;
}
/**
* Convert the given number to integer, support scientific notation.
* The number will be scale up if it is decimal.
*
* @param num The input number
*/
function float2Fixed(num) {
if (num.toString().indexOf('e') === -1) {
return Number(num.toString().replace('.', ''));
}
var dLen = digitLength(num);
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
}
/**
* Log a warning if the given number is out of bounds.
*
* @param num The input number
*/
function checkBoundary(num) {
if (_boundaryCheckingState) {
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
console.warn(num + " is beyond boundary when transfer to integer, the results may not be accurate");
}
}
}
/**
* Create an operation to support rest params.
*
* @param operation The original operation
*/
function createOperation(operation) {
return function () {
var nums = [];
for (var _i = 0; _i < arguments.length; _i++) {
nums[_i] = arguments[_i];
}
var first = nums[0], others = nums.slice(1);
return others.reduce(function (prev, next) { return operation(prev, next); }, first);
};
}
/**
* Accurate multiplication.
*
* @param nums The numbers to multiply
*/
var times = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
checkBoundary(leftValue);
return leftValue / Math.pow(10, baseNum);
});
/**
* Accurate addition.
*
* @param nums The numbers to add
*/
var plus = createOperation(function (num1, num2) {
// 取最大的小数位
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
// 把小数都转为整数然后再计算
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
});
/**
* Accurate subtraction.
*
* @param nums The numbers to subtract
*/
var minus = createOperation(function (num1, num2) {
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
});
/**
* Accurate division.
*
* @param nums The numbers to divide
*/
var divide = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
checkBoundary(num1Changed);
checkBoundary(num2Changed);
// fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
});
/**
* Accurate rounding method.
*
* @param num The number to round
* @param decimal An integer specifying the decimal digits
*/
function round(num, decimal) {
var base = Math.pow(10, decimal);
var result = divide(Math.round(Math.abs(times(num, base))), base);
if (num < 0 && result !== 0) {
result = times(result, -1);
}
return result;
}
var _boundaryCheckingState = true;
/**
* Whether to check the bounds of number, default is enabled.
*
* @param flag The value to indicate whether is enabled
*/
function enableBoundaryChecking(flag) {
if (flag === void 0) { flag = true; }
_boundaryCheckingState = flag;
}
var index = {
strip: strip,
plus: plus,
minus: minus,
times: times,
divide: divide,
round: round,
digitLength: digitLength,
float2Fixed: float2Fixed,
enableBoundaryChecking: enableBoundaryChecking,
};
exports.strip = strip;
exports.plus = plus;
exports.minus = minus;
exports.times = times;
exports.divide = divide;
exports.round = round;
exports.digitLength = digitLength;
exports.float2Fixed = float2Fixed;
exports.enableBoundaryChecking = enableBoundaryChecking;
exports['default'] = index;
}, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
return __REQUIRE__(1689250267956);
})()
//miniprogram-npm-outsideDeps=[]
//# sourceMappingURL=index.js.map
\ No newline at end of file
{"version":3,"sources":["index.js"],"names":[],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"index.js","sourcesContent":["\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n/**\r\n * @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。\r\n *\r\n * 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998\r\n */\r\n/**\r\n * Correct the given number to specifying significant digits.\r\n *\r\n * @param num The input number\r\n * @param precision An integer specifying the number of significant digits\r\n *\r\n * @example strip(0.09999999999999998) === 0.1 // true\r\n */\r\nfunction strip(num, precision) {\r\n if (precision === void 0) { precision = 15; }\r\n return +parseFloat(Number(num).toPrecision(precision));\r\n}\r\n/**\r\n * Return digits length of a number.\r\n *\r\n * @param num The input number\r\n */\r\nfunction digitLength(num) {\r\n // Get digit length of e\r\n var eSplit = num.toString().split(/[eE]/);\r\n var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);\r\n return len > 0 ? len : 0;\r\n}\r\n/**\r\n * Convert the given number to integer, support scientific notation.\r\n * The number will be scale up if it is decimal.\r\n *\r\n * @param num The input number\r\n */\r\nfunction float2Fixed(num) {\r\n if (num.toString().indexOf('e') === -1) {\r\n return Number(num.toString().replace('.', ''));\r\n }\r\n var dLen = digitLength(num);\r\n return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);\r\n}\r\n/**\r\n * Log a warning if the given number is out of bounds.\r\n *\r\n * @param num The input number\r\n */\r\nfunction checkBoundary(num) {\r\n if (_boundaryCheckingState) {\r\n if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {\r\n console.warn(num + \" is beyond boundary when transfer to integer, the results may not be accurate\");\r\n }\r\n }\r\n}\r\n/**\r\n * Create an operation to support rest params.\r\n *\r\n * @param operation The original operation\r\n */\r\nfunction createOperation(operation) {\r\n return function () {\r\n var nums = [];\r\n for (var _i = 0; _i < arguments.length; _i++) {\r\n nums[_i] = arguments[_i];\r\n }\r\n var first = nums[0], others = nums.slice(1);\r\n return others.reduce(function (prev, next) { return operation(prev, next); }, first);\r\n };\r\n}\r\n/**\r\n * Accurate multiplication.\r\n *\r\n * @param nums The numbers to multiply\r\n */\r\nvar times = createOperation(function (num1, num2) {\r\n var num1Changed = float2Fixed(num1);\r\n var num2Changed = float2Fixed(num2);\r\n var baseNum = digitLength(num1) + digitLength(num2);\r\n var leftValue = num1Changed * num2Changed;\r\n checkBoundary(leftValue);\r\n return leftValue / Math.pow(10, baseNum);\r\n});\r\n/**\r\n * Accurate addition.\r\n *\r\n * @param nums The numbers to add\r\n */\r\nvar plus = createOperation(function (num1, num2) {\r\n // 取最大的小数位\r\n var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));\r\n // 把小数都转为整数然后再计算\r\n return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;\r\n});\r\n/**\r\n * Accurate subtraction.\r\n *\r\n * @param nums The numbers to subtract\r\n */\r\nvar minus = createOperation(function (num1, num2) {\r\n var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));\r\n return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;\r\n});\r\n/**\r\n * Accurate division.\r\n *\r\n * @param nums The numbers to divide\r\n */\r\nvar divide = createOperation(function (num1, num2) {\r\n var num1Changed = float2Fixed(num1);\r\n var num2Changed = float2Fixed(num2);\r\n checkBoundary(num1Changed);\r\n checkBoundary(num2Changed);\r\n // fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正\r\n return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));\r\n});\r\n/**\r\n * Accurate rounding method.\r\n *\r\n * @param num The number to round\r\n * @param decimal An integer specifying the decimal digits\r\n */\r\nfunction round(num, decimal) {\r\n var base = Math.pow(10, decimal);\r\n var result = divide(Math.round(Math.abs(times(num, base))), base);\r\n if (num < 0 && result !== 0) {\r\n result = times(result, -1);\r\n }\r\n return result;\r\n}\r\nvar _boundaryCheckingState = true;\r\n/**\r\n * Whether to check the bounds of number, default is enabled.\r\n *\r\n * @param flag The value to indicate whether is enabled\r\n */\r\nfunction enableBoundaryChecking(flag) {\r\n if (flag === void 0) { flag = true; }\r\n _boundaryCheckingState = flag;\r\n}\r\nvar index = {\r\n strip: strip,\r\n plus: plus,\r\n minus: minus,\r\n times: times,\r\n divide: divide,\r\n round: round,\r\n digitLength: digitLength,\r\n float2Fixed: float2Fixed,\r\n enableBoundaryChecking: enableBoundaryChecking,\r\n};\n\nexports.strip = strip;\nexports.plus = plus;\nexports.minus = minus;\nexports.times = times;\nexports.divide = divide;\nexports.round = round;\nexports.digitLength = digitLength;\nexports.float2Fixed = float2Fixed;\nexports.enableBoundaryChecking = enableBoundaryChecking;\nexports['default'] = index;\n"]}
\ No newline at end of file
module.exports = Behavior(
{
data: {
afterType:{
1:'我要退款退货',
2:'我要退款(无需退货)'
}
}
})
\ No newline at end of file
module.exports = {}
import kfMixin from './kfMixin'
import orderMixin from './orderMixin'
import afterSaleMixin from './afterSaleMixin'
module.exports = {
kfMixin,
orderMixin,
afterSaleMixin,
}
// const kf_list = [{
// sapCode: 5036,
// url: 'https://work.weixin.qq.com/kfid/kfc82ffd378b8649621'
// },
// {
// sapCode: 5028,
// url: 'https://work.weixin.qq.com/kfid/kfcd636da4134201fbb'
// },
// {
// sapCode: 5016,
// url: 'https://work.weixin.qq.com/kfid/kfcdef92056fc8ef091'
// },
// ]
module.exports = Behavior({
data: {},
methods: {
filterKfList(data) {
let showKF = false,
customerlist = [],
kfUrl = ''
if (data.customerServerType) {
if (data.customerServerType == 1)
customerlist[0] = {
thumbAvatar: data.customerServerAvatar,
staffName: data.customerServerName,
qrCode: data.customerServerOrCode
}
else kfUrl = data.customerServerUrl
showKF = true
}
this.setData({
showKF,
kfUrl,
customerlist
})
},
openKF(e) {
let { kfUrl, widgetStatus } = this.data
if (kfUrl)
wx.openCustomerServiceChat({
extInfo: {
url: kfUrl
},
corpId: 'wx51bda2e574d24a91',
success(res) {
console.log(res)
},
fail({ errMsg }) {
console.log(errMsg)
wx.$api.showToast(errMsg)
}
})
else
this.setData({
widgetStatus: !widgetStatus
})
}
}
})
module.exports = Behavior({
data: {
//1:待付款;2:已支付;3:已关闭;4:已发货;5:已收货;6:待发货;7:待安装;8:已安装;9:售后中;10:售后完成
statusEnum: {
1: '待付款',
2: '已支付',
3: '已关闭',
4: '已发货',
5: '已收货',
6: '待发货',
7: '待安装',
8: '已安装',
9: '售后中',
10: '售后完成'
},
/**售后状态 1:待审核;2:审核通过;3:审核不通过;4:待确认收到退货;5:退款中;6:已退款;7:退款失败;8已取消 */
afterSaleStatus: {
1: '待审核',
2: '审核通过',
3: '审核不通过',
4: '待确认收到退货',
5: '退款中',
6: '已退款',
7: '退款失败',
8: '已取消'
},
/**权益&套餐 */
cardStatus: {
0: '未支付',
1: '已支付',
2: '待收货',
3: '已完成',
4: '售后中',
5: '退款失败',
6: '已退款'
},
reStatus: {
2: '充值中',
3: '充值成功',
4: '退款中',
6: '充值失败',
}
}
})
\ No newline at end of file
dist: trusty
language: node_js
node_js:
- 8
script:
- npm test
addons:
firefox: "49.0"
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
# number-precision [![npm version](https://badge.fury.io/js/number-precision.svg)](http://badge.fury.io/js/number-precision) [![Build Status](https://travis-ci.org/nefe/number-precision.svg)](https://travis-ci.org/nefe/number-precision) [![codecov](https://codecov.io/gh/nefe/number-precision/branch/master/graph/badge.svg)](https://codecov.io/gh/nefe/number-precision)
Perform addition, subtraction, multiplication and division operations precisely using javascript
### Why
```js
0.1 + 0.2 = 0.30000000000000004
1.0 - 0.9 = 0.09999999999999998
0.105.toFixed(2) = 0.1 // not 0.11
```
### Install
```
npm install number-precision --save
```
### Methods
```js
NP.strip(num) // strip a number to nearest right number
NP.plus(num1, num2, num3, ...) // addition, num + num2 + num3, two numbers is required at least.
NP.minus(num1, num2, num3, ...) // subtraction, num1 - num2 - num3
NP.times(num1, num2, num3, ...) // multiplication, num1 * num2 * num3
NP.divide(num1, num2, num3, ...) // division, num1 / num2 / num3
NP.round(num, ratio) // round a number based on ratio
```
### Usage
```js
import NP from 'number-precision'
NP.strip(0.09999999999999998); // = 0.1
NP.plus(0.1, 0.2); // = 0.3, not 0.30000000000000004
NP.plus(2.3, 2.4); // = 4.7, not 4.699999999999999
NP.minus(1.0, 0.9); // = 0.1, not 0.09999999999999998
NP.times(3, 0.3); // = 0.9, not 0.8999999999999999
NP.times(0.362, 100); // = 36.2, not 36.199999999999996
NP.divide(1.21, 1.1); // = 1.1, not 1.0999999999999999
NP.round(0.105, 2); // = 0.11, not 0.1
```
PS: If you want to get rid of `XXX is beyond boundary when transfer to integer, the results may not be accurate`, use this at the beginning of your app to turn off boundary checking.
```js
NP.enableBoundaryChecking(false); // default param is true
```
### License
MIT
"use strict";
/**
* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
*
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.enableBoundaryChecking = exports.float2Fixed = exports.digitLength = exports.round = exports.divide = exports.times = exports.minus = exports.plus = exports.strip = void 0;
/**
* Correct the given number to specifying significant digits.
*
* @param num The input number
* @param precision An integer specifying the number of significant digits
*
* @example strip(0.09999999999999998) === 0.1 // true
*/
function strip(num, precision) {
if (precision === void 0) { precision = 15; }
return +parseFloat(Number(num).toPrecision(precision));
}
exports.strip = strip;
/**
* Return digits length of a number.
*
* @param num The input number
*/
function digitLength(num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
return len > 0 ? len : 0;
}
exports.digitLength = digitLength;
/**
* Convert the given number to integer, support scientific notation.
* The number will be scale up if it is decimal.
*
* @param num The input number
*/
function float2Fixed(num) {
if (num.toString().indexOf('e') === -1) {
return Number(num.toString().replace('.', ''));
}
var dLen = digitLength(num);
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
}
exports.float2Fixed = float2Fixed;
/**
* Log a warning if the given number is out of bounds.
*
* @param num The input number
*/
function checkBoundary(num) {
if (_boundaryCheckingState) {
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
console.warn(num + " is beyond boundary when transfer to integer, the results may not be accurate");
}
}
}
/**
* Create an operation to support rest params.
*
* @param operation The original operation
*/
function createOperation(operation) {
return function () {
var nums = [];
for (var _i = 0; _i < arguments.length; _i++) {
nums[_i] = arguments[_i];
}
var first = nums[0], others = nums.slice(1);
return others.reduce(function (prev, next) { return operation(prev, next); }, first);
};
}
/**
* Accurate multiplication.
*
* @param nums The numbers to multiply
*/
var times = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
checkBoundary(leftValue);
return leftValue / Math.pow(10, baseNum);
});
exports.times = times;
/**
* Accurate addition.
*
* @param nums The numbers to add
*/
var plus = createOperation(function (num1, num2) {
// 取最大的小数位
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
// 把小数都转为整数然后再计算
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
});
exports.plus = plus;
/**
* Accurate subtraction.
*
* @param nums The numbers to subtract
*/
var minus = createOperation(function (num1, num2) {
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
});
exports.minus = minus;
/**
* Accurate division.
*
* @param nums The numbers to divide
*/
var divide = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
checkBoundary(num1Changed);
checkBoundary(num2Changed);
// fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
});
exports.divide = divide;
/**
* Accurate rounding method.
*
* @param num The number to round
* @param decimal An integer specifying the decimal digits
*/
function round(num, decimal) {
var base = Math.pow(10, decimal);
var result = divide(Math.round(Math.abs(times(num, base))), base);
if (num < 0 && result !== 0) {
result = times(result, -1);
}
return result;
}
exports.round = round;
var _boundaryCheckingState = true;
/**
* Whether to check the bounds of number, default is enabled.
*
* @param flag The value to indicate whether is enabled
*/
function enableBoundaryChecking(flag) {
if (flag === void 0) { flag = true; }
_boundaryCheckingState = flag;
}
exports.enableBoundaryChecking = enableBoundaryChecking;
exports.default = {
strip: strip,
plus: plus,
minus: minus,
times: times,
divide: divide,
round: round,
digitLength: digitLength,
float2Fixed: float2Fixed,
enableBoundaryChecking: enableBoundaryChecking,
};
//# sourceMappingURL=index.js.map
\ No newline at end of file
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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"}
\ No newline at end of file
/**
* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
*
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
*/
declare type NumberType = number | string;
/**
* Correct the given number to specifying significant digits.
*
* @param num The input number
* @param precision An integer specifying the number of significant digits
*
* @example strip(0.09999999999999998) === 0.1 // true
*/
declare function strip(num: NumberType, precision?: number): number;
/**
* Return digits length of a number.
*
* @param num The input number
*/
declare function digitLength(num: NumberType): number;
/**
* Convert the given number to integer, support scientific notation.
* The number will be scale up if it is decimal.
*
* @param num The input number
*/
declare function float2Fixed(num: NumberType): number;
/**
* Accurate multiplication.
*
* @param nums The numbers to multiply
*/
declare const times: (...nums: NumberType[]) => number;
/**
* Accurate addition.
*
* @param nums The numbers to add
*/
declare const plus: (...nums: NumberType[]) => number;
/**
* Accurate subtraction.
*
* @param nums The numbers to subtract
*/
declare const minus: (...nums: NumberType[]) => number;
/**
* Accurate division.
*
* @param nums The numbers to divide
*/
declare const divide: (...nums: NumberType[]) => number;
/**
* Accurate rounding method.
*
* @param num The number to round
* @param decimal An integer specifying the decimal digits
*/
declare function round(num: NumberType, decimal: number): number;
/**
* Whether to check the bounds of number, default is enabled.
*
* @param flag The value to indicate whether is enabled
*/
declare function enableBoundaryChecking(flag?: boolean): void;
export { strip, plus, minus, times, divide, round, digitLength, float2Fixed, enableBoundaryChecking };
declare const _default: {
strip: typeof strip;
plus: (...nums: NumberType[]) => number;
minus: (...nums: NumberType[]) => number;
times: (...nums: NumberType[]) => number;
divide: (...nums: NumberType[]) => number;
round: typeof round;
digitLength: typeof digitLength;
float2Fixed: typeof float2Fixed;
enableBoundaryChecking: typeof enableBoundaryChecking;
};
export default _default;
/**
* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
*
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
*/
/**
* Correct the given number to specifying significant digits.
*
* @param num The input number
* @param precision An integer specifying the number of significant digits
*
* @example strip(0.09999999999999998) === 0.1 // true
*/
function strip(num, precision) {
if (precision === void 0) { precision = 15; }
return +parseFloat(Number(num).toPrecision(precision));
}
/**
* Return digits length of a number.
*
* @param num The input number
*/
function digitLength(num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
return len > 0 ? len : 0;
}
/**
* Convert the given number to integer, support scientific notation.
* The number will be scale up if it is decimal.
*
* @param num The input number
*/
function float2Fixed(num) {
if (num.toString().indexOf('e') === -1) {
return Number(num.toString().replace('.', ''));
}
var dLen = digitLength(num);
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
}
/**
* Log a warning if the given number is out of bounds.
*
* @param num The input number
*/
function checkBoundary(num) {
if (_boundaryCheckingState) {
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
console.warn(num + " is beyond boundary when transfer to integer, the results may not be accurate");
}
}
}
/**
* Create an operation to support rest params.
*
* @param operation The original operation
*/
function createOperation(operation) {
return function () {
var nums = [];
for (var _i = 0; _i < arguments.length; _i++) {
nums[_i] = arguments[_i];
}
var first = nums[0], others = nums.slice(1);
return others.reduce(function (prev, next) { return operation(prev, next); }, first);
};
}
/**
* Accurate multiplication.
*
* @param nums The numbers to multiply
*/
var times = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
checkBoundary(leftValue);
return leftValue / Math.pow(10, baseNum);
});
/**
* Accurate addition.
*
* @param nums The numbers to add
*/
var plus = createOperation(function (num1, num2) {
// 取最大的小数位
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
// 把小数都转为整数然后再计算
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
});
/**
* Accurate subtraction.
*
* @param nums The numbers to subtract
*/
var minus = createOperation(function (num1, num2) {
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
});
/**
* Accurate division.
*
* @param nums The numbers to divide
*/
var divide = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
checkBoundary(num1Changed);
checkBoundary(num2Changed);
// fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
});
/**
* Accurate rounding method.
*
* @param num The number to round
* @param decimal An integer specifying the decimal digits
*/
function round(num, decimal) {
var base = Math.pow(10, decimal);
var result = divide(Math.round(Math.abs(times(num, base))), base);
if (num < 0 && result !== 0) {
result = times(result, -1);
}
return result;
}
var _boundaryCheckingState = true;
/**
* Whether to check the bounds of number, default is enabled.
*
* @param flag The value to indicate whether is enabled
*/
function enableBoundaryChecking(flag) {
if (flag === void 0) { flag = true; }
_boundaryCheckingState = flag;
}
var index = {
strip: strip,
plus: plus,
minus: minus,
times: times,
divide: divide,
round: round,
digitLength: digitLength,
float2Fixed: float2Fixed,
enableBoundaryChecking: enableBoundaryChecking,
};
export { strip, plus, minus, times, divide, round, digitLength, float2Fixed, enableBoundaryChecking };
export default index;
var NP = (function (exports) {
'use strict';
/**
* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
*
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
*/
/**
* Correct the given number to specifying significant digits.
*
* @param num The input number
* @param precision An integer specifying the number of significant digits
*
* @example strip(0.09999999999999998) === 0.1 // true
*/
function strip(num, precision) {
if (precision === void 0) { precision = 15; }
return +parseFloat(Number(num).toPrecision(precision));
}
/**
* Return digits length of a number.
*
* @param num The input number
*/
function digitLength(num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
return len > 0 ? len : 0;
}
/**
* Convert the given number to integer, support scientific notation.
* The number will be scale up if it is decimal.
*
* @param num The input number
*/
function float2Fixed(num) {
if (num.toString().indexOf('e') === -1) {
return Number(num.toString().replace('.', ''));
}
var dLen = digitLength(num);
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
}
/**
* Log a warning if the given number is out of bounds.
*
* @param num The input number
*/
function checkBoundary(num) {
if (_boundaryCheckingState) {
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
console.warn(num + " is beyond boundary when transfer to integer, the results may not be accurate");
}
}
}
/**
* Create an operation to support rest params.
*
* @param operation The original operation
*/
function createOperation(operation) {
return function () {
var nums = [];
for (var _i = 0; _i < arguments.length; _i++) {
nums[_i] = arguments[_i];
}
var first = nums[0], others = nums.slice(1);
return others.reduce(function (prev, next) { return operation(prev, next); }, first);
};
}
/**
* Accurate multiplication.
*
* @param nums The numbers to multiply
*/
var times = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
checkBoundary(leftValue);
return leftValue / Math.pow(10, baseNum);
});
/**
* Accurate addition.
*
* @param nums The numbers to add
*/
var plus = createOperation(function (num1, num2) {
// 取最大的小数位
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
// 把小数都转为整数然后再计算
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
});
/**
* Accurate subtraction.
*
* @param nums The numbers to subtract
*/
var minus = createOperation(function (num1, num2) {
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
});
/**
* Accurate division.
*
* @param nums The numbers to divide
*/
var divide = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
checkBoundary(num1Changed);
checkBoundary(num2Changed);
// fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
});
/**
* Accurate rounding method.
*
* @param num The number to round
* @param decimal An integer specifying the decimal digits
*/
function round(num, decimal) {
var base = Math.pow(10, decimal);
var result = divide(Math.round(Math.abs(times(num, base))), base);
if (num < 0 && result !== 0) {
result = times(result, -1);
}
return result;
}
var _boundaryCheckingState = true;
/**
* Whether to check the bounds of number, default is enabled.
*
* @param flag The value to indicate whether is enabled
*/
function enableBoundaryChecking(flag) {
if (flag === void 0) { flag = true; }
_boundaryCheckingState = flag;
}
var index = {
strip: strip,
plus: plus,
minus: minus,
times: times,
divide: divide,
round: round,
digitLength: digitLength,
float2Fixed: float2Fixed,
enableBoundaryChecking: enableBoundaryChecking,
};
exports.strip = strip;
exports.plus = plus;
exports.minus = minus;
exports.times = times;
exports.divide = divide;
exports.round = round;
exports.digitLength = digitLength;
exports.float2Fixed = float2Fixed;
exports.enableBoundaryChecking = enableBoundaryChecking;
exports['default'] = index;
return exports;
}({}));
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
/**
* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
*
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
*/
/**
* Correct the given number to specifying significant digits.
*
* @param num The input number
* @param precision An integer specifying the number of significant digits
*
* @example strip(0.09999999999999998) === 0.1 // true
*/
function strip(num, precision) {
if (precision === void 0) { precision = 15; }
return +parseFloat(Number(num).toPrecision(precision));
}
/**
* Return digits length of a number.
*
* @param num The input number
*/
function digitLength(num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
return len > 0 ? len : 0;
}
/**
* Convert the given number to integer, support scientific notation.
* The number will be scale up if it is decimal.
*
* @param num The input number
*/
function float2Fixed(num) {
if (num.toString().indexOf('e') === -1) {
return Number(num.toString().replace('.', ''));
}
var dLen = digitLength(num);
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
}
/**
* Log a warning if the given number is out of bounds.
*
* @param num The input number
*/
function checkBoundary(num) {
if (_boundaryCheckingState) {
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
console.warn(num + " is beyond boundary when transfer to integer, the results may not be accurate");
}
}
}
/**
* Create an operation to support rest params.
*
* @param operation The original operation
*/
function createOperation(operation) {
return function () {
var nums = [];
for (var _i = 0; _i < arguments.length; _i++) {
nums[_i] = arguments[_i];
}
var first = nums[0], others = nums.slice(1);
return others.reduce(function (prev, next) { return operation(prev, next); }, first);
};
}
/**
* Accurate multiplication.
*
* @param nums The numbers to multiply
*/
var times = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
checkBoundary(leftValue);
return leftValue / Math.pow(10, baseNum);
});
/**
* Accurate addition.
*
* @param nums The numbers to add
*/
var plus = createOperation(function (num1, num2) {
// 取最大的小数位
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
// 把小数都转为整数然后再计算
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
});
/**
* Accurate subtraction.
*
* @param nums The numbers to subtract
*/
var minus = createOperation(function (num1, num2) {
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
});
/**
* Accurate division.
*
* @param nums The numbers to divide
*/
var divide = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
checkBoundary(num1Changed);
checkBoundary(num2Changed);
// fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
});
/**
* Accurate rounding method.
*
* @param num The number to round
* @param decimal An integer specifying the decimal digits
*/
function round(num, decimal) {
var base = Math.pow(10, decimal);
var result = divide(Math.round(Math.abs(times(num, base))), base);
if (num < 0 && result !== 0) {
result = times(result, -1);
}
return result;
}
var _boundaryCheckingState = true;
/**
* Whether to check the bounds of number, default is enabled.
*
* @param flag The value to indicate whether is enabled
*/
function enableBoundaryChecking(flag) {
if (flag === void 0) { flag = true; }
_boundaryCheckingState = flag;
}
var index = {
strip: strip,
plus: plus,
minus: minus,
times: times,
divide: divide,
round: round,
digitLength: digitLength,
float2Fixed: float2Fixed,
enableBoundaryChecking: enableBoundaryChecking,
};
exports.strip = strip;
exports.plus = plus;
exports.minus = minus;
exports.times = times;
exports.divide = divide;
exports.round = round;
exports.digitLength = digitLength;
exports.float2Fixed = float2Fixed;
exports.enableBoundaryChecking = enableBoundaryChecking;
exports['default'] = index;
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
\ No newline at end of file
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.NP = {})));
}(this, (function (exports) { 'use strict';
/**
* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
*
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
*/
/**
* Correct the given number to specifying significant digits.
*
* @param num The input number
* @param precision An integer specifying the number of significant digits
*
* @example strip(0.09999999999999998) === 0.1 // true
*/
function strip(num, precision) {
if (precision === void 0) { precision = 15; }
return +parseFloat(Number(num).toPrecision(precision));
}
/**
* Return digits length of a number.
*
* @param num The input number
*/
function digitLength(num) {
// Get digit length of e
var eSplit = num.toString().split(/[eE]/);
var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
return len > 0 ? len : 0;
}
/**
* Convert the given number to integer, support scientific notation.
* The number will be scale up if it is decimal.
*
* @param num The input number
*/
function float2Fixed(num) {
if (num.toString().indexOf('e') === -1) {
return Number(num.toString().replace('.', ''));
}
var dLen = digitLength(num);
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
}
/**
* Log a warning if the given number is out of bounds.
*
* @param num The input number
*/
function checkBoundary(num) {
if (_boundaryCheckingState) {
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
console.warn(num + " is beyond boundary when transfer to integer, the results may not be accurate");
}
}
}
/**
* Create an operation to support rest params.
*
* @param operation The original operation
*/
function createOperation(operation) {
return function () {
var nums = [];
for (var _i = 0; _i < arguments.length; _i++) {
nums[_i] = arguments[_i];
}
var first = nums[0], others = nums.slice(1);
return others.reduce(function (prev, next) { return operation(prev, next); }, first);
};
}
/**
* Accurate multiplication.
*
* @param nums The numbers to multiply
*/
var times = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
var baseNum = digitLength(num1) + digitLength(num2);
var leftValue = num1Changed * num2Changed;
checkBoundary(leftValue);
return leftValue / Math.pow(10, baseNum);
});
/**
* Accurate addition.
*
* @param nums The numbers to add
*/
var plus = createOperation(function (num1, num2) {
// 取最大的小数位
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
// 把小数都转为整数然后再计算
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
});
/**
* Accurate subtraction.
*
* @param nums The numbers to subtract
*/
var minus = createOperation(function (num1, num2) {
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
});
/**
* Accurate division.
*
* @param nums The numbers to divide
*/
var divide = createOperation(function (num1, num2) {
var num1Changed = float2Fixed(num1);
var num2Changed = float2Fixed(num2);
checkBoundary(num1Changed);
checkBoundary(num2Changed);
// fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
});
/**
* Accurate rounding method.
*
* @param num The number to round
* @param decimal An integer specifying the decimal digits
*/
function round(num, decimal) {
var base = Math.pow(10, decimal);
var result = divide(Math.round(Math.abs(times(num, base))), base);
if (num < 0 && result !== 0) {
result = times(result, -1);
}
return result;
}
var _boundaryCheckingState = true;
/**
* Whether to check the bounds of number, default is enabled.
*
* @param flag The value to indicate whether is enabled
*/
function enableBoundaryChecking(flag) {
if (flag === void 0) { flag = true; }
_boundaryCheckingState = flag;
}
var index = {
strip: strip,
plus: plus,
minus: minus,
times: times,
divide: divide,
round: round,
digitLength: digitLength,
float2Fixed: float2Fixed,
enableBoundaryChecking: enableBoundaryChecking,
};
exports.strip = strip;
exports.plus = plus;
exports.minus = minus;
exports.times = times;
exports.divide = divide;
exports.round = round;
exports.digitLength = digitLength;
exports.float2Fixed = float2Fixed;
exports.enableBoundaryChecking = enableBoundaryChecking;
exports['default'] = index;
Object.defineProperty(exports, '__esModule', { value: true });
})));
{
"_from": "number-precision",
"_id": "number-precision@1.6.0",
"_inBundle": false,
"_integrity": "sha512-05OLPgbgmnixJw+VvEh18yNPUo3iyp4BEWJcrLu4X9W05KmMifN7Mu5exYvQXqxxeNWhvIF+j3Rij+HmddM/hQ==",
"_location": "/number-precision",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "number-precision",
"name": "number-precision",
"escapedName": "number-precision",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/number-precision/-/number-precision-1.6.0.tgz",
"_shasum": "e309d28f80871d36ac9f6ecd974e13afb1ec0de0",
"_spec": "number-precision",
"_where": "D:\\2023\\07\\海马刀",
"author": {
"name": "cam song"
},
"ava": {
"files": [
"build-test/**/*.test.js"
]
},
"bugs": {
"url": "https://github.com/nefe/number-precision/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Perform addition, subtraction, multiplication and division operations precisely using javascript",
"devDependencies": {
"ava": "^3.8.2",
"braces": ">=2.3.1",
"codecov": "^3.1.0",
"nyc": "^15.0.1",
"pre-commit": "^1.2.2",
"rollup": "^0.52.2",
"rollup-plugin-typescript": "^0.8.1",
"rollup-plugin-typescript2": "^0.8.4",
"rollup-watch": "^4.3.1",
"tslint": "^5.8.0",
"typescript": "^3.8.3"
},
"homepage": "https://github.com/nefe/number-precision",
"keywords": [
"number precision",
"floating problem",
"rounding error"
],
"license": "MIT",
"main": "build/index.js",
"module": "build/index.es.js",
"name": "number-precision",
"pre-commit": [
"tslint"
],
"repository": {
"type": "git",
"url": "git+https://github.com/nefe/number-precision.git"
},
"scripts": {
"build": "rollup -c",
"posttest": "codecov -f coverage/*.json -t 072762c4-c5bc-4393-bcd9-71eac9e7725b",
"prepublish": "rm -rf build && tsc && npm run build",
"test": "tsc -p tsconfig.test.json && nyc --reporter=lcov --reporter=text --reporter=json ava && rm -rf .nyc_output",
"tslint": "tslint ./src/**/*.ts --fix",
"watch": "rollup -cw"
},
"types": "build/index.d.ts",
"version": "1.6.0"
}
import typescript from 'rollup-plugin-typescript2'
export default {
input: './src/index.ts',
output: [
{
format: 'iife',
name: 'NP',
dest: './build/index.iife.js'
},
{
format: 'umd',
name: 'NP',
dest: './build/index.umd.js'
},
{
format: 'cjs',
dest: './build/index.js'
},
{
format: 'es',
dest: './build/index.es.js'
}
],
plugins: [typescript({cacheRoot: `${require('temp-dir')}/.rpt2_cache`})]
}
/**
* @desc 解决浮动运算问题,避免小数点后产生多位数和计算精度损失。
*
* 问题示例:2.3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
*/
type NumberType = number | string;
/**
* Correct the given number to specifying significant digits.
*
* @param num The input number
* @param precision An integer specifying the number of significant digits
*
* @example strip(0.09999999999999998) === 0.1 // true
*/
function strip(num: NumberType, precision = 15): number {
return +parseFloat(Number(num).toPrecision(precision));
}
/**
* Return digits length of a number.
*
* @param num The input number
*/
function digitLength(num: NumberType): number {
// Get digit length of e
const eSplit = num.toString().split(/[eE]/);
const len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
return len > 0 ? len : 0;
}
/**
* Convert the given number to integer, support scientific notation.
* The number will be scale up if it is decimal.
*
* @param num The input number
*/
function float2Fixed(num: NumberType): number {
if (num.toString().indexOf('e') === -1) {
return Number(num.toString().replace('.', ''));
}
const dLen = digitLength(num);
return dLen > 0 ? strip(Number(num) * Math.pow(10, dLen)) : Number(num);
}
/**
* Log a warning if the given number is out of bounds.
*
* @param num The input number
*/
function checkBoundary(num: number) {
if (_boundaryCheckingState) {
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
console.warn(`${num} is beyond boundary when transfer to integer, the results may not be accurate`);
}
}
}
/**
* Create an operation to support rest params.
*
* @param operation The original operation
*/
function createOperation(operation: (n1: NumberType, n2: NumberType) => number): (...nums: NumberType[]) => number {
return (...nums: NumberType[]) => {
const [first, ...others] = nums;
return others.reduce((prev, next) => operation(prev, next), first) as number;
};
}
/**
* Accurate multiplication.
*
* @param nums The numbers to multiply
*/
const times = createOperation((num1, num2) => {
const num1Changed = float2Fixed(num1);
const num2Changed = float2Fixed(num2);
const baseNum = digitLength(num1) + digitLength(num2);
const leftValue = num1Changed * num2Changed;
checkBoundary(leftValue);
return leftValue / Math.pow(10, baseNum);
});
/**
* Accurate addition.
*
* @param nums The numbers to add
*/
const plus = createOperation((num1, num2) => {
// 取最大的小数位
const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
// 把小数都转为整数然后再计算
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
});
/**
* Accurate subtraction.
*
* @param nums The numbers to subtract
*/
const minus = createOperation((num1, num2) => {
const baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
});
/**
* Accurate division.
*
* @param nums The numbers to divide
*/
const divide = createOperation((num1, num2) => {
const num1Changed = float2Fixed(num1);
const num2Changed = float2Fixed(num2);
checkBoundary(num1Changed);
checkBoundary(num2Changed);
// fix: 类似 10 ** -4 为 0.00009999999999999999,strip 修正
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
});
/**
* Accurate rounding method.
*
* @param num The number to round
* @param decimal An integer specifying the decimal digits
*/
function round(num: NumberType, decimal: number): number {
const base = Math.pow(10, decimal);
let result = divide(Math.round(Math.abs(times(num, base))), base);
if (num < 0 && result !== 0) {
result = times(result, -1);
}
return result;
}
let _boundaryCheckingState = true;
/**
* Whether to check the bounds of number, default is enabled.
*
* @param flag The value to indicate whether is enabled
*/
function enableBoundaryChecking(flag = true) {
_boundaryCheckingState = flag;
}
export { strip, plus, minus, times, divide, round, digitLength, float2Fixed, enableBoundaryChecking };
export default {
strip,
plus,
minus,
times,
divide,
round,
digitLength,
float2Fixed,
enableBoundaryChecking,
};
{
"compilerOptions": {
"module": "commonjs",
"strict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es5",
"es6"
],
"target": "es5",
"outDir": "build",
"sourceMap": true,
"declaration": true
},
"include": [
"src/*.ts"
],
"exclude": [
"node_modules"
]
}
{
"compilerOptions": {
"module": "commonjs",
"strict": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es5",
"es6"
],
"target": "es5",
"outDir": "build-test",
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
{
"extends": ["tslint:recommended"],
"rules": {
"arrow-parens": false,
"arrow-return-shorthand": [true],
"import-spacing": true,
"interface-name": [false],
"interface-over-type-literal": false,
"linebreak-style": [true, "LF"],
"max-classes-per-file": [false],
"member-access": [false],
"no-require-imports": true,
"object-literal-sort-keys": false,
"ordered-imports": [false],
"no-console": false,
"prefer-const": true,
"quotemark": [true, "single", "jsx-double"],
"space-before-function-paren": [true, {
"anonymous": "always",
"asyncArrow": "always",
"constructor": "never",
"method": "never",
"named": "never"
}],
"variable-name": [
true,
"ban-keywords",
"check-format",
"allow-pascal-case",
"allow-leading-underscore"
]
}
}
{
"requires": true,
"name": "hmd",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"glsx-map-sdk": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/glsx-map-sdk/-/glsx-map-sdk-0.2.0.tgz",
"integrity": "sha512-uEFlXvJEDofYjasR4mwkmF5yNTRs5QA2ZAynGPHiKpKdpjQkVFPJH0zGupmQEkxmh4f5B0wPbDobHvLgld7mVw=="
},
"number-precision": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/number-precision/-/number-precision-1.6.0.tgz",
"integrity": "sha512-05OLPgbgmnixJw+VvEh18yNPUo3iyp4BEWJcrLu4X9W05KmMifN7Mu5exYvQXqxxeNWhvIF+j3Rij+HmddM/hQ=="
}
}
}
......@@ -3,7 +3,8 @@
"version": "1.0.0",
"main": "app.js",
"dependencies": {
"glsx-map-sdk": "^0.2.0"
"glsx-map-sdk": "^0.2.0",
"number-precision": "^1.6.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
......
Component({
/**
* 组件的属性列表
*/
properties: {
show: {
type: Boolean,
observer: function (n) {
if (n) setTimeout(() => {}, 0.5 * 1000)
}
},
only: {
type: Boolean,
value: true
},
couponData: {
type: Object,
observer(n) {
if (n.length)
this.setData({
noData: true
})
return n
}
},
order: {
type: Number
},
defaultData: String
},
observers: {
couponData: function (newVal) {
return newVal
}
},
/**
* 组件的初始数据
*/
data: {
noData: false,
IMGURL: wx.$imgUrl
},
/**
* 组件的方法列表
*/
methods: {
getCoupon(e) {
let {merchantId} = wx.p.storage.get('merchant_info')
let { item } = e.currentTarget.dataset
wx.p.wxApi.showLoading('领取中...')
wx.p.api.shopmallApi
.getCoupon({
couponIdList: [item.couponId],
receiveWay: 1,
receiveSource: 3,
merchantId: Number(merchantId)
})
.then(({ code, data, message }) => {
console.log(data)
wx.hideLoading()
if (code == '0') {
wx.showToast({
title: '领取成功',
icon: 'none'
})
let thisPage = wx.p.router.getPageInstance()
if (thisPage.getGoodscouponList) thisPage.getGoodscouponList()
}
})
},
// 更换优惠券
selectCoupon(e) {
let { index } = e.currentTarget.dataset
for (let i = 0; i < this.data.couponData.length; i++) {
if (index == i) {
this.data.couponData[i].isChecked = !this.data.couponData[i].isChecked
} else {
this.data.couponData[i].isChecked = false
}
this.setData({
couponData: this.data.couponData
})
}
},
//确认
confirm() {
this.triggerEvent('click', this.data.couponData)
this.setData({
couponData: this.data.couponData
})
}
},
lifetimes: {
attached() {}
}
})
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
<popup title="优惠详情" show="{{show}}" only="{{only}}" bindconfirm="confirm" height="75%">
<view class="coupon-box">
<view class="box">
<scroll-view style="height:100%;" scroll-y>
<block wx:if="{{noData}}">
<view class="coupon-wrap" wx:for="{{couponData}}" wx:key="index">
<view class="left_icon_box">
<image webp wx:if="{{true}}" class="left_bg" src="{{IMGURL}}coupons/coupons_active.png?v={{img_version}}" />
<image webp wx:else class="left_bg" src="{{IMGURL}}coupons/coupons.png?v={{img_version}}" />
<view class="left_text_one left_text_two">
<text class="price_icon">¥</text>
<text>{{(item.denomination)/100}}</text>
</view>
<view class="left_text_five left_text_three" wx:if="{{item.full}}">满{{(item.full)/100}}可用</view>
</view>
<view class="main_box">
<view class="title_text">{{item.couponName}}</view>
<view class="h4_text" wx:if="{{item.useBarriers == 1}}">无限制</view>
<view class="h4_text" wx:if="{{item.useBarriers == 2}}">满减</view>
<!-- 未领取,effectiveType == 1,就显示effectiveDays有效,effectiveType == 2 显示时间段,effectiveType == 3 无限制 -->
<view class="h4_text drive" wx:if="{{item.couponStatus == 0&&item.effectiveType == 1}}">领取后{{item.effectiveDays}}天内有效</view>
<view class="h4_text drive" wx:if="{{item.couponStatus == 0&&item.effectiveType == 2}}">{{item.effectiveStartTime}}-{{item.effectiveEndTime}}</view>
<view class="h4_text drive" wx:if="{{item.couponStatus == 0&&item.effectiveType == 3}}">无期限</view>
<!-- 已领取,effectiveType == 1 或者2,都显示时间段,effectiveType == 3 无限制 -->
<view class="h4_text drive" wx:if="{{item.couponStatus == 1&&item.effectiveType == 1||item.couponStatus == 1&&item.effectiveType == 2 }}">{{item.effectiveStartTime}}-{{item.effectiveEndTime}}</view>
<view class="h4_text drive" wx:if="{{item.couponStatus == 1&&item.effectiveType == 3}}">无期限</view>
</view>
<block wx:if="{{order == 0}}">
<view class="box_btn box_btn_color" bindtap="toDetail" wx:if="{{item.couponStatus == 0&&item.residueAmount >0}}" data-item="{{item}}" bindtap="getCoupon">领取</view>
<view class="box_btn_color_been_gray " bind:tap="toDetail" wx:elif="{{item.couponStatus != 1&&item.residueAmount ==0}}">已抢光</view>
<view class="box_btn_color_been" bind:tap="toDetail" wx:elif="{{item.couponStatus == 1}}">已领取</view>
<view class="already" wx:if="{{item.couponStatus == 1}}">
<image webp src="{{IMGURL}}coupons/been.png?v={{img_version}}" />
</view>
</block>
<block wx:else>
<view class="circle-selected" data-item="{{item}}" data-index="{{index}}" wx:if="{{item.isChecked}}" bindtap="selectCoupon">
<image webp src="{{IMGURL}}coupons/select.png?v={{img_version}}" />
</view>
<view class="noSelect" data-item="{{item}}" data-index="{{index}}" wx:if="{{!item.isChecked}}" bindtap="selectCoupon"></view>
</block>
</view>
</block>
<!-- <block>
<view class="dissatisfy">以下不满足使用条件</view>
<view class="coupon-wrap gray" >
<view class="left_icon_box">
<image webp class="left_bg" src="../../packageMall/images/coupons.png" />
<view class="left_text_one left_text_two">
<text class="price_icon">¥</text>
<text>50</text>
</view>
<view class="left_text_five left_text_three">满99可用</view>
</view>
<view class="main_box">
<view class="title_text">优惠券名称</view>
<view class="h4_text">满300减50,仅限会场商品</view>
<view class="h4_text drive">无限期</view>
</view>
<view class="circle-gray"></view>
<view class="reason">不可用原因:仅可购买XXX商品A</view>
</view>
</block> -->
</scroll-view>
</view>
</view>
<view wx:if="{{!noData}}" class="no_data">
<image webp class="nodata_bg" src="{{IMGURL}}coupons/no_card_bg.png?v={{img_version}}" />
<view class="nodata_text">暂无优惠券</view>
</view>
</popup>
\ No newline at end of file
/* components/CarBrands/CarBrands.wxss */
.coupon-wrap {
width: 686rpx;
height: 196rpx;
background: rgba(252, 91, 50, 0.05);
border-radius: 8rpx;
box-sizing: border-box;
padding: 20rpx;
display: flex;
align-items: center;
position: relative;
margin-top: 24rpx;
}
.gray {
width: 686rpx;
height: 196rpx;
background: rgba(201, 202, 204, 0.1) !important;
border-radius: 8rpx;
box-sizing: border-box;
padding: 20rpx;
display: flex;
align-items: center;
position: relative;
margin-top: 24rpx;
}
.left_icon_box {
width: 156rpx;
height: 156rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}
.left_bg {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 156rpx;
height: 156rpx;
z-index: 1;
}
.left_text_one {
font-size: 36rpx;
font-weight: 600;
color: #FFFFFF;
z-index: 2;
}
.left_text_two {
display: flex;
align-items: flex-end;
}
.left_text_four {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.left_text_three {
font-size: 28rpx;
margin-top: 6rpx;
width:156rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
text-align: center;
}
.left_text_five {
font-size: 28rpx;
color: #FFFFFF;
z-index: 2;
}
.anText {
font-size: 70rpx;
/* color: rgba(white, white, white, 0.45); */
font-weight: 600;
color: #FFF;
opacity: 0.45;
}
.price_icon {
font-size: 20rpx;
margin-right: 4rpx;
margin-bottom: 7rpx;
}
.main_box {
height: 156rpx;
box-sizing: border-box;
padding: 4rpx 0 4rpx 20rpx;
}
.box_btn {
position: absolute;
right: 20rpx;
top: 50%;
transform: translate(0, -50%);
width: 132rpx;
height: 50rpx;
background: #B1B1B3;
border-radius: 22rpx;
color: #FFF;
font-size: 20rpx;
text-align: center;
line-height: 50rpx;
}
.box_btn_color {
background: var(--btnColor);
color: #FFFFFF;
}
.box_btn_color_grey {
background: #B1B1B3;
}
.title_text {
color: #282829;
font-weight: 600;
color: #282829;
font-size: 28rpx;
width: 420rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.box_btn_color_been {
font-size: 28rpx;
font-weight: 400;
color: var(--btnColor);
line-height: 40rpx;
white-space: nowrap;
position: absolute;
right: 20rpx;
top: 50%;
transform: translate(0, -50%);
}
.h4_text {
font-weight: 400;
color: #B1B1B3;
font-size: 24rpx;
}
.drive {
margin-top: 38rpx;
}
.y-center {
display: flex;
align-items: center;
}
.no_data {
padding-top: 48rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.nodata_bg {
width: 320rpx;
height: 320rpx;
}
.nodata_text {
color: #B1B1B3;
font-size: 28rpx;
line-height: 44rpx;
margin-top: 8rpx;
}
.already {
width: 75rpx;
height: 74rpx;
position: absolute;
bottom: 0;
right: 0;
z-index: 99;
}
.dissatisfy {
font-size: 28rpx;
font-weight: 500;
color: #282829;
line-height: 44rpx;
margin-top: 32rpx;
}
.circle-gray {
width: 40rpx;
height: 40rpx;
background: #E3E3E6;
border: 2rpx solid rgba(177, 177, 179, 1);
border-radius: 50%;
}
.reason {
width: 686rpx;
height: 60rpx;
background: rgba(253, 194, 62, 0.06);
font-size: 24rpx;
font-weight: 400;
color: #F13C3D;
line-height: 60rpx;
padding: 0 20rpx;
box-sizing: border-box;
position: absolute;
bottom: -60rpx;
left: 0;
}
.reason::before {
content: '!';
width: 28rpx;
height: 28rpx;
border: 1rpx solid #F13C3D;
color: #F13C3D;
box-sizing: border-box;
border-radius: 50%;
display: inline-block;
text-align: center;
line-height: 24rpx;
margin-right: 12rpx;
}
.circle-selected {
width: 40rpx;
height: 40rpx;
}
.noSelect {
width: 40rpx;
height: 40rpx;
background: #ffffff;
border: 2rpx solid rgba(177, 177, 179, 1);
border-radius: 50%;
}
.box{
height:55vh;
overflow-y: scroll;
padding-bottom: 50rpx;
}
.box_btn_color_been_gray{
font-size: 28rpx;
font-weight: 400;
color: #B1B1B3;
line-height: 40rpx;
white-space: nowrap;
position: absolute;
right: 20rpx;
top: 50%;
transform: translate(0, -50%);
}
\ No newline at end of file
// components/Sku/Sku.js
import { centsToyuan } from '~/utils/format'
Component({
/**
* 组件的属性列表
*/
properties: {
show: {
type: Boolean,
observer(n) {
if (n)
this.setData({
close: false
})
}
},
showName: String,
skuData: {
type: Object,
observer(n) {
this.setDefaultSku(n)
}
},
isActivity: Boolean
},
/**
* 组件的初始数据
*/
data: {
goodsNumber: 1
},
/**
* 组件的方法列表
*/
methods: {
noScroll() {},
setDefaultSku(skuData) {
let { isActivity } = this.data
let { specificationList } = skuData
let [specificationDetailList] = isActivity ? skuData.specificationExtraList : skuData.specificationDetailList
let defaultGoods = specificationDetailList.specificationData.split('&')
specificationList.map(e => {
defaultGoods.map(i => {
let [key, value] = i.split('-')
if (key == e.specificationName) {
e.specificationValueList.map(c => {
if (c.specificationValue == value) c.active = true
})
}
})
})
specificationDetailList.retailPrice = centsToyuan(specificationDetailList.retailPrice)
this.setData({
skuObj: skuData,
goodsInfo: specificationDetailList
})
},
choose(e) {
let { ind, index } = e.currentTarget.dataset
let {
skuObj: { specificationList, id, specificationExtraList },
isActivity
} = this.data
let activeList = []
if (specificationList[index].specificationValueList[ind].active) return
specificationList[index].specificationValueList.map(i => (i.active = false))
specificationList[index].specificationValueList[ind].active = true
specificationList.map(i => {
i.specificationValueList.map(c => {
if (c.active) activeList.push(`${i.specificationName}-${c.specificationValue}`)
})
})
let specificationData = activeList.join('&')
this.setData({
[`skuObj.specificationList[${index}]`]: specificationList[index]
})
if (isActivity) {
specificationExtraList.map((i, i_index) => {
if (i.specificationData == specificationData) {
let retailPrice = i.retailPrice
if (i_index != 0) retailPrice = centsToyuan(i.retailPrice)
this.setData({
goodsInfo: {
retailPrice,
stock: i.stock,
specificationData,
specificationKey: i.specificationKey
}
})
}
})
} else {
wx.p.api.shopmallApi
.getGoodsSpecificationExtra({
goodsId: id,
specificationData
})
.then(data => {
data.retailPrice = centsToyuan(data.retailPrice)
this.setData({
goodsInfo: data
})
console.log(this.data.goodsInfo)
})
}
this.setData({
goodsNumber: 1
})
const thisPage = wx.p.router.getPageInstance()
thisPage.setData({
activeSku: specificationData
})
},
changeCount(e) {
let goodsNumber = e.detail
this.setData({
goodsNumber
})
},
closeSku() {
let thisPage = wx.p.router.getPageInstance()
let { showName } = this.data
this.setData({
close: true
})
setTimeout(() => {
thisPage.setData({
[showName]: false
})
}, 0.5 * 1000)
},
click(e) {
let { type } = e.currentTarget.dataset
let {
goodsInfo: { goodsId, specificationKey, stock },
goodsNumber
} = this.data
if (stock === 0) return
this.triggerEvent(type, {
goodsId,
specificationKey,
goodsNumber,
stock
})
this.closeSku()
}
}
})
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
<view class="sku" catchtouchmove="noScroll" hidden="{{!show}}">
<view class="sku-bg" bindtap="closeSku"></view>
<view class="sku-box isFullSucreen {{close?'close':''}}">
<scroll-view class="sku-content" scroll-y>
<view class="view">
<view class="goods-box">
<view class="preview">
<image webp src="{{skuObj.goodsImage || skuObj.activityImg}}"></image>
</view>
<view class="goods-info">
<view class="price">
<text class="unit">¥</text>{{goodsInfo.retailPrice}}
</view>
<view class="count">
<block wx:if="{{goodsInfo.stock}}">
有货(库存{{goodsInfo.stock}})
</block>
<block wx:else>无货</block>
</view>
<view class="active text-hide">已选:{{goodsInfo.specificationData}}</view>
</view>
</view>
<view class="sku-list">
<block wx:for="{{skuObj.specificationList}}" wx:key="index">
<view class="sku-title">{{item.specificationName}}</view>
<view class="sku-item">
<block wx:for="{{item.specificationValueList}}" wx:key="ind" wx:for-index="ind" wx:for-item="i">
<view class="item text-center {{i.active?'active':''}} {{i.stock ===0?'disabled':''}}" bindtap="choose" data-index="{{index}}"
data-ind="{{ind}}">{{i.specificationValue}}</view>
</block>
</view>
</block>
<view class="sku-title">
数量
<stepper count="{{goodsNumber}}" max="{{goodsInfo.stock}}" bindchange="changeCount"></stepper>
</view>
<view class="sku-title">
发货
<view class="value">快递:{{skuObj.expressFee||'免运费(请以提交订单时为准)'}}</view>
</view>
</view>
</view>
</scroll-view>
<view class="sku-btn-box">
<view class="sku-btn">
<block wx:if="{{!isActivity}}">
<view class="join text-center {{goodsInfo.stock === 0?'disabled':''}}" bindtap="click" data-type="join">加入购物车</view>
</block>
<view class="pay text-center {{goodsInfo.stock === 0?'disabled':''}} " bindtap="click" data-type="pay">立即购买</view>
</view>
</view>
</view>
</view>
\ No newline at end of file
/* components/Sku/Sku.wxss */
@import '/style/common.wxss';
.sku {
position: fixed;
left: 0;
bottom: 0;
right: 0;
top: 0;
z-index: 9;
}
.sku-bg {
position: absolute;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, .5);
}
.sku-box {
position: absolute;
width: 100%;
height: 76%;
background: #FFFFFF;
border-radius: 16rpx 16rpx 0 0;
left: 0;
animation: show-sku-box .5s forwards;
z-index: 2;
}
.sku-box.close {
animation: hide-popup-box .5s forwards;
}
.sku-box.isFullSucreen {
padding-bottom: constant(safe-area-inset-bottom) !important;
padding-bottom: env(safe-area-inset-bottom) !important;
}
@keyframes show-sku-box {
0% {
bottom: -100%;
}
100% {
bottom: 0;
}
}
@keyframes hide-popup-box {
0% {
bottom: 0;
}
100% {
bottom: -100%;
}
}
.sku-content {
box-sizing: border-box;
height: calc(100% - 100rpx);
}
.sku-content .view {
padding: 0 40rpx;
}
.sku-content .goods-box {
display: flex;
align-items: center;
position: sticky;
background-color: #fff;
z-index: 2;
top: 0;
padding-bottom: 18rpx;
}
.sku-content .goods-box .preview {
width: 180rpx;
height: 180rpx;
border-radius: 4rpx;
margin-right: 40rpx;
overflow: hidden;
margin-top: 40rpx;
}
.sku-content .goods-box .goods-info {
width: calc(100% - 220rpx);
}
.sku-content .goods-box .price {
color: var(--btnColor);
font-size: 64rpx;
margin-bottom: 10rpx;
}
.sku-content .goods-box .price .unit {
font-size: 40rpx;
}
.sku-content .goods-box .count {
color: #B9BABB;
font-size: 20rpx;
margin-bottom: var(--borderRadius);
}
.sku-content .goods-box .active {
font-size: 20rpx;
color: #707071;
}
.sku-box .sku-list {
padding-bottom: 40rpx;
}
.sku-box .sku-title {
color: #2D2D2E;
font-weight: 500;
padding-top: var(--margin);
display: flex;
align-items: center;
justify-content: space-between;
}
.sku-title .value {
color: #565759;
font-weight: normal;
}
.sku-box .sku-item {
display: flex;
flex-wrap: wrap;
}
.sku-box .sku-item .item {
height: 52rpx;
background: #F7F8FA;
padding: 0 20rpx;
margin: 20rpx 20rpx 0 0;
font-size: 24rpx;
color: #656566;
border: 2rpx solid #F7F8FA;
box-sizing: border-box;
border-radius: 4rpx;
}
.sku-box .sku-item .item.active {
border-color: rgb(252, 91, 50);
color: rgb(252, 91, 50);
background-color: rgba(252, 91, 50, .06);
}
.sku-btn-box {
height: 100rpx;
padding: 10rpx var(--margin);
}
.sku-btn {
border-radius: var(--borderRadius);
display: flex;
overflow: hidden;
}
.sku-btn .join,
.sku-btn .pay {
flex: 1;
height: 80rpx;
color: #fff;
}
.sku-btn .join {
background-color: #FDC23E;
}
.sku-btn .pay {
background-color: var(--btnColor);
}
.disabled{
background-color: #B1B1B3 !important;
/* border-color: #B1B1B3 !important; */
color: #000000!important;
}
\ No newline at end of file
{
"navigationStyle": "custom",
"usingComponents": {
"coupon-goods": "../../components/CouponGoods/CouponGoods",
"sku": "../../components/Sku/Sku"
}
}
\ No newline at end of file
/* packageMall/pages/detail/detail.wxss */
.flex {
display: flex;
align-items: center;
position: relative;
}
.navigation-bar {
position: fixed;
top: 0;
left: 0;
z-index: 2;
}
.empty-page {
box-sizing: border-box;
width: 100%;
height: calc(100vh - 128rpx);
padding-top: 128rpx;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-size: 28rpx;
color: #ACACAC;
}
.empty-img {
width: 446rpx;
height: 240rpx;
margin-bottom: 60rpx;
}
.navigation {
width: 100%;
height: 100%;
position: relative;
}
.navigation .back {
width: 64rpx;
height: 64rpx;
background: rgba(255, 255, 255, 0.5);
border-radius: var(--margin);
position: absolute;
left: 20rpx;
}
.navigation .back .icon {
width: 36rpx;
height: 36rpx;
}
.navigation .text {
max-width: 50%;
font-size: 32rpx;
color: #333333;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-weight: 500;
box-sizing: border-box;
text-align: center;
letter-spacing: 1rpx;
}
.box {
margin-bottom: 16rpx;
background-color: #fff;
}
.banner-box {
height: 750rpx;
position: relative;
}
.banner {
height: 100%;
}
.dot-box {
position: absolute;
bottom: 24rpx;
border-radius: 2rpx;
overflow: hidden;
display: flex;
}
.banner video {
width: 100%;
height: 100%;
}
.dot {
width: 20rpx;
height: var(--borderRadius);
background: rgba(255, 255, 255, 0.3);
transition: all .5s;
}
.dot.active {
background-color: #fff;
}
.activity-box {
height: 100rpx;
position: relative;
}
.activity-box .activity-bg {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
}
.activity-box .activity-info {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
z-index: 2;
display: flex;
align-items: center;
justify-content: space-between;
box-sizing: border-box;
padding: 0 23rpx 0 15rpx;
color: #fff;
}
.activity-box .activity-info .price,
.activity-box .activity-info .now,
.activity-box .activity-info .text {
display: flex;
font-size: 24rpx;
}
.activity-box .activity-info .price {
align-items: baseline;
}
.activity-box .activity-info .text {
align-items: center;
}
.activity-box .activity-info .now {
font-size: 40rpx;
align-items: baseline;
margin-left: var(--borderRadius);
}
.activity-box .activity-info .now .num {
font-size: 60rpx;
line-height: 60rpx;
letter-spacing: -2rpx;
}
.activity-box .activity-info .activity-unit {
font-size: 40rpx;
margin-left: 6rpx;
transform: translateY(-5rpx);
}
.activity-box .activity-info .count {
opacity: .5;
font-size: 20rpx;
transform: translateY(-5rpx);
}
.activity-box .activity-info .text .old {
padding: 0 12rpx;
height: 28rpx;
background: #FFEAD1;
border-radius: 14rpx;
font-size: 20rpx;
color: var(--themeColor);
flex-direction: column;
margin-left: 6rpx;
}
.activity-box .activity-info .activity-time {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 20rpx;
color: var(--themeColor);
animation: show-activity-time .5s forwards;
}
@keyframes show-activity-time {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.activity-box .activity-info .activity-time .time {
font-size: 24rpx;
display: flex;
align-items: center;
justify-content: flex-end;
color: var(--themeColor);
margin-top: 10rpx;
}
.activity-box .activity-info .activity-time .day {
margin-right: var(--borderRadius);
}
.activity-box .activity-info .time-box {
background: var(--themeColor);
border-radius: 4rpx;
width: 36rpx;
height: 36rpx;
color: #fff;
}
.activity-box .activity-info .unit {
text-align: center;
width: 16rpx;
}
.activity-time .finished {
font-size: 32rpx;
}
.goods-info {
padding: 28rpx 40rpx 32rpx;
}
.goods-info .price {
margin-bottom: 2rpx;
}
.goods-info .price,
.goods-info .price .now {
display: flex;
align-items: baseline;
}
.goods-info .price .now {
font-size: 64rpx;
color: var(--btnColor);
margin-right: 8rpx;
line-height: 64rpx;
}
.goods-info .price .now .unit {
font-size: 40rpx;
}
.goods-info .price .now .up {
transform: translateY(-2rpx);
}
.goods-info .price .old {
color: #B1B1B3;
text-decoration: line-through;
}
.goods-info .name {
font-size: 36rpx;
font-weight: 500;
position: relative;
width: 85%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.goods-info .count {
margin-top: 20rpx;
font-size: 24rpx;
color: #B1B1B3;
display: flex;
position: relative;
}
.goods-info .count view:nth-child(2) {
margin-left: 100rpx;
}
.goods-param {
padding: 0 40rpx;
}
.goods-param .item {
position: relative;
height: 98rpx;
border-bottom: 2rpx solid #EFF0F2;
display: flex;
align-items: center;
font-size: 24rpx;
}
.goods-param .item:last-child {
border-bottom: none;
}
.goods-param .item .label {
width: 136rpx;
color: #656566;
}
.goods-param .item .value {
width: 490rpx;
color: #3B3B3D;
}
.goods-param .item .coupon {
font-size: 24rpx;
padding: 0 20rpx;
font-weight: 500;
color: var(--btnColor);
line-height: 40rpx;
height: 40rpx;
width: auto;
background: rgba(252, 91, 50, 0.12);
border-radius: 4rpx;
box-sizing: border-box;
}
.goods-param .address {
height: 134rpx;
align-items: flex-start;
box-sizing: border-box;
padding: var(--margin) 0;
position: relative;
}
.goods-param .address .tips {
position: absolute;
color: #B1B1B3;
left: 136rpx;
bottom: var(--margin);
}
.goods-param .item .icon-mine-arrow {
margin-left: auto;
transform: scale(1.3) translateY(9rpx);
}
.goods-param .address .icon-mine-arrow {
position: absolute;
right: 0;
top: 50%;
transform: scale(1.3) translateY(0);
}
.activity-detail {
background-color: #fff;
}
.activity-detail .title {
display: flex;
align-items: center;
padding: 0 40rpx 20rpx;
}
.activity-detail .title .icon {
width: 32rpx;
height: 32rpx;
margin-right: var(--borderRadius);
}
.detail-time {
margin-bottom: 20rpx;
}
.content {
font-size: 24rpx;
background-color: #fff;
padding: 0 40rpx;
}
.content:first-of-type,
.activity-detail .title:first-of-type {
padding-top: 40rpx;
}
.content:last-of-type {
padding-bottom: 40rpx;
}
.goods-comment {
padding: 40rpx 32rpx;
}
.goods-comment .comment-head {
display: flex;
align-items: center;
justify-content: space-between;
padding-bottom: 12rpx;
}
.goods-comment .comment-content {
font-size: 28rpx;
font-weight: 400;
color: #282829;
line-height: 40rpx;
padding: 0 0 20rpx 0;
white-space:normal;
word-break:break-all;
}
.goods-comment .comment-head .comment-total {
font-size: 32rpx;
font-weight: 500;
color: #282829;
line-height: 44rpx;
}
.comment-all {
font-size: 24rpx;
font-weight: 400;
color: #3B3B3D;
line-height: 34rpx;
display: flex;
align-items: center;
}
.comment-all .icon-mine-arrow {
margin-left: 12rpx;
}
.comment-user {
padding: 16rpx 0 20rpx 0;
display: flex;
align-items: center;
}
.comment-user .user-portrait {
width: 72rpx;
height: 72rpx;
margin-right: 16rpx;
background-color: #333333;
border-radius: 50%;
}
.user-portrait image{
border-radius: 50%;
}
.comment-user .user-info .name {
font-size: 32rpx;
font-weight: 600;
color: #282829;
line-height: 44rpx;
}
.comment-user .user-info .comment-time {
font-size: 20rpx;
font-weight: 400;
color: #B1B1B3;
line-height: 28rpx;
}
.goods-comment .comment-images {
display: flex;
align-items: center;
flex-wrap: wrap;
margin-right: -40rpx;
}
.goods-comment .comment-images .icon {
width: 160rpx;
height: 160rpx;
border-radius: 8rpx;
box-sizing: border-box;
margin-right: 16rpx;
background-color: #e7e7e7;
margin-bottom: 10rpx;
}
.goods-comment .comment-images .icon image {
border-radius: 8rpx;
}
.share {
width: 108rpx;
height: 34rpx;
background: rgba(252, 91, 50, 0.1);
border-radius: 4rpx;
font-size: 24rpx;
color: var(--btnColor);
line-height: 34rpx;
display: flex;
align-items: center;
position: absolute;
right: 0;
padding-left: 12rpx;
box-sizing: border-box;
}
.share text {
flex-shrink: 0;
}
.icon-goods-share {
transform: scale(0.54);
}
.model {
position: fixed;
left: 0;
right: 0;
top: 0;
right: 0;
background: rgba(0, 0, 0, 0.5);
width: 100%;
height: 100%;
z-index: 999999;
display: flex;
align-items: center;
justify-content: center;
}
.poster {
width: 540rpx;
height: 860rpx;
border-radius: 8rpx;
}
.hidden{
height:100%;
overflow: hidden;
}
.shop {
height: 62rpx;
background-color: white;
padding: 30rpx;
display: flex;
align-items: center;
border-bottom: 2rpx solid #F7F8FA;
}
.shop .right {
width: 24rpx;
height: 18rpx;
margin: 0 14rpx 0 26rpx;
}
.shop .processBox {
display: flex;
}
.shop .processBox .describe {
margin-left: 8rpx;
}
.shop .processBox .describe .describeTop {
font-size: 24rpx;
color: #333333;
}
.shop .processBox .describe .describeBottom {
font-size: 20rpx;
color: #999999;
}
.shop .processBox image {
width: 60rpx;
height: 60rpx;
}
.goods-param .items {
min-height: 34rpx;
display: flex;
font-size: 24rpx;
padding: 32rpx 0;
}
.goods-param .items .labels {
width: 136rpx;
color: #656566;
}
.goods-param .items .values {
width: 490rpx;
color: #3B3B3D;
}
.tab-widget{
width: 100%;
height: 88rpx;
background: white;
position: fixed;
left: 0;
top: 88rpx;
right: 0;
z-index: 999;
}
.tab-widget .tab-item{
width: 50%;
height: 100%;
position: relative;
}
.tab-widget .tab-item .text{
font-size: 28rpx;
color: #656566;
line-height: 40rpx;
}
.tab-widget .tab-item .text-ative{
font-weight: 500;
font-size: 28rpx;
color: #2C2C2C;
}
.tab-widget .tab-item .line{
position: absolute;
left: 50%;
bottom: 0;
transform: translateX(-50%);
width: 66rpx;
height: 6rpx;
background: var(--btnColor);
border-radius: 2rpx;
}
\ No newline at end of file
<view class="navigation-bar">
<navigation-bar custom navStyle="{{navStyle}}" bindnavbarReady="navbarReady" page-title="{{isActivity?goodsInfo.activityName:goodsInfo.goodsName}}">
<view class="navigation">
<view class="back text-center y-center" bindtap="back">
<glsx-image webp src="mall/{{showHomeBtn?'home':'back'}}.png" class="icon"></glsx-image>
</view>
</view>
</navigation-bar>
</view>
<view class="empty-page" wx:if="{{!goodsFlag && !isLoading}}">
<glsx-image webp class="empty-img" src="mall/active-empty.png" />
活动重新配置中,请稍后重试
</view>
<block wx:if="{{goodsFlag}}">
<view class="{{posterUrl==''?'layout':'layout hidden'}} " style="padding-bottom:{{padding_bottom + 20}}px;">
<view class="banner-box">
<swiper class="banner" bindchange="changeBanner">
<block wx:for="{{goodsInfo.goodsDetailImageList}}" wx:key="index">
<swiper-item>
<block wx:if="{{item.resType == 1}}">
<image webp src="{{item.content}}" bindtap="previewImage" data-current="{{item.content}}" data-item="{{goodsInfo.goodsDetailImageList}}"></image>
</block>
<block wx:elif="{{item.resType == 3}}">
<video src="{{item.content}}"></video>
</block>
</swiper-item>
</block>
</swiper>
<block wx:if="{{goodsInfo.goodsDetailImageList.length > 1}}">
<view class="dot-box x-center">
<block wx:for="{{goodsInfo.goodsDetailImageList}}" wx:key="index">
<view class="dot {{bannerIndex == index ? 'active':''}}">
</view>
</block>
</view>
</block>
</view>
<block wx:if="{{isActivity}}">
<view class="activity-box">
<view class="activity-info">
<view class="price-info">
<view class="price">
<text>秒杀价</text>
<view class="text">
<view class="now">
<text>¥</text>
<view class="num">{{goodsInfo.retailPrice}}</view>
<block wx:if="{{goodsInfo.unit}}">
<view class="activity-unit">{{goodsInfo.unit}}</view>
</block>
</view>
<view class="old text-center">
限时直降{{goodsInfo.priceReduce}}
</view>
</view>
</view>
<view class="count">已售出{{goodsInfo.saleAmount || 0}}件</view>
</view>
<!-- activityStatus:1:未开始,2进行中,3已结束 -->
<block wx:if="{{goodsInfo.activityStatus != 3}}">
<view class="activity-time" wx:if="{{timeFlag}}">
<view class="title">{{activityTime.type}}还剩:</view>
<view class="time">
<view class="day">{{activityTime.day || ''}}</view>
<block wx:for="{{activityTime.dayList}}" wx:key="index">
<view class="time-box text-center">
{{item}}
</view>
<view class="unit" wx:if="{{index < 2}}"> :</view>
</block>
</view>
</view>
</block>
<block wx:else>
<view class="activity-time">
<view class="finished">{{finished}}</view>
</view>
</block>
</view>
<view class="activity-bg">
<glsx-image webp src="mall/activity.png"></glsx-image>
</view>
</view>
</block>
<view class="goods-info box">
<block wx:if="{{!isActivity}}">
<view class="price">
<view class="now">
<text class="unit">¥</text>
<block wx:if="{{activeSku}}">
{{goodsInfo.skuPrice}}
<text class="unit up">起</text>
</block>
<block wx:else>{{goodsInfo.retailPrice}}</block>
</view>
<view class="old">¥{{goodsInfo.originalPrice}}</view>
</view>
</block>
<view class="flex">
<view class="name"> {{isActivity?goodsInfo.activityName:goodsInfo.goodsName}}
</view>
</view>
<block wx:if="{{!isActivity}}">
<view class="count">
<view>剩余: {{goodsInfo.goodsStock || goodsInfo.specificationDetailList[0].stock || 0}}</view>
<view>销售: {{goodsInfo.goodsStatistics.saleAmount || 0}}</view>
</view>
</block>
</view>
<view class="goods-param box">
<block wx:if="{{!isActivity}}">
<block wx:if="{{couponData.length>0}}">
<view class="item" bindtap="showCouponFun">
<view class="label">优惠</view>
<view class="value coupon">优惠券</view>
<view class="sprite-icon icon-mine-arrow"></view>
</view>
</block>
</block>
<block wx:if="{{activeSku}}">
<view class="item" bindtap="showSkuFun">
<view class="label">已选</view>
<view class="value text-hide">{{activeSku}}</view>
<view class="sprite-icon icon-mine-arrow"></view>
</view>
</block>
<block wx:if="{{goodsInfo.deliveryType != 1}}">
<view class="item address" bindtap="jump" data-url="/packageMine/pages/address/index/index" data-is-choose-address>
<view class="label">配送</view>
<view class="value text-hide">
<block wx:if="{{addressFlag}}">
{{contactAddress||'填写地址'}}
</block>
</view>
<view class="tips">支付后,预计48小时内发货</view>
<view class="sprite-icon icon-mine-arrow"></view>
</view>
</block>
<block wx:if="{{goodsInfo.deliveryType != 1}}">
<view class="item">
<view class="label">运费</view>
<view class="value text-hide">
<block wx:if="{{goodsInfo.expressFee}}">{{goodsInfo.expressFee}}元</block>
<block wx:else>免运费(请以提交订单时为准)</block>
</view>
</view>
</block>
<block wx:if="{{isActivity && goodsInfo.limitPurchaseFlag == 2}}">
<view class="item">
<view class="label">说明</view>
<view class="value text-hide">
<text>此商品活动期间每人限购{{goodsInfo.limitPurchaseNumber}}件</text>
</view>
</view>
</block>
<block wx:if="{{goodsInfo.serviceDesc}}">
<view class="items">
<view class="labels">服务说明</view>
<view class="values">
<text>{{goodsInfo.serviceDesc}}</text>
</view>
</view>
</block>
</view>
<view class="activity-detail">
<block wx:if="{{isActivity}}">
<view class="title">
<view class="sprite-icon icon-goods-time"></view>
活动时间
</view>
<view class="content detail-time">
{{goodsInfo.startTime}} - {{goodsInfo.endTime}}
</view>
<view class="title">
<view class="sprite-icon icon-goods-text"></view>
活动详情
</view>
</block>
<block wx:for="{{goodsInfo.goodsDescList}}" wx:key="index">
<view class="content">
<block wx:if="{{item.resType == 1}}">
<image webp src="{{item.content}}" mode="widthFix" bindtap="previewImage" data-current="{{item.content}}" data-item="{{goodsInfo.goodsDescList}}" lazy-load></image>
</block>
<block wx:elif="{{item.resType == 2}}">
{{item.content}}
</block>
<block wx:else>
<video src="{{item.content}}" style="height:{{item.height}}px;"></video>
</block>
</view>
</block>
</view>
</view>
</block>
<coupon-goods show="{{showCoupon}}" only="{{only}}" couponData="{{couponData}}" bindclick="showCouponFun"></coupon-goods>
<block wx:if="{{navHeight && goodsFlag}}">
<goods-action bindready="goodsActionReady" pay-disabled="{{goodsInfo.activityStatus != 2 }}" stock="{{goodsInfo.goodsStock === 0}}" buyFlag="{{goodsInfo.buyFlag == 2}}" bindclick="goodsActionClick" hideShop="{{isActivity}}"></goods-action>
<block wx:if="{{activeSku}}">
<sku show="{{showSku}}" showName="showSku" isActivity="{{isActivity}}" skuData="{{goodsInfo}}" bindpay="pay" bindjoin="join"></sku>
</block>
</block>
\ No newline at end of file
// packageMall/pages/search/search.js
Page({
/**
* 页面的初始数据
*/
data: {
searchList: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData(options)
this.getSearchList(options.value)
},
getSearchList(value) {
wx.p.wxApi.showLoading()
let {
goodsList
} = this.data
const searchList = []
goodsList.map(e => {
if (e.goodsName.indexOf(value) != -1) searchList.push(e)
})
this.setData({
searchList,
flag: true
})
wx.hideLoading()
},
search(e) {
this.getSearchList(e.detail)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
}
})
\ No newline at end of file
{
"usingComponents": {
"search-box": "/pages/tab/mall/components/SearchBox/SearchBox",
"goods": "/pages/tab/mall/components/Goods/Goods"
}
}
\ No newline at end of file
/* packageMall/pages/search/search.wxss */
.box{
display: flex;
flex-wrap: wrap;
justify-content: space-between;
padding: var(--margin) 60rpx;
}
.goods{
width: 252rpx;
padding: 18rpx;
margin-bottom: 18rpx;
background-color: #fff;
}
\ No newline at end of file
<view class="layout">
<view class="sticky">
<search-box bindsearch="search" search-type="2" value="{{value}}"></search-box>
</view>
<view class="box">
<block wx:if="{{flag}}">
<block wx:if="{{searchList.length}}">
<block wx:key="index" wx:for="{{searchList}}">
<view class="goods">
<goods item="{{item}}"></goods>
</view>
</block>
</block>
<block wx:else>
<view class="list-nothing ">
<view class="list-not">没找到相关商品</view>
</view>
</block>
</block>
</view>
</view>
\ No newline at end of file
Page({
data: {
couponsList: []
},
toReciveAll() {
let para = {
couponIdList: this.data.ids
}
wx.p.api.couponsApi.toReciveCard(para).then(res => {
if (res) {
wx.p.router.go('/packageMine/pages/coupon/success/success')
}
})
},
/**获取礼券 */
getCoupons() {
let para = {
discountTypes: [3]
}
let ids = []
wx.p.api.couponsApi.getHomeCardData(para).then(res => {
res.list.map(item => {
if (item.effectiveStartTime) {
item.effectiveStartTime = new Date(item.effectiveStartTime).format('yyyy.MM.dd')
item.effectiveEndTime = new Date(item.effectiveEndTime).format('yyyy.MM.dd')
}
ids.push(item.id)
return item
})
this.setData({
couponsList: res.list,
ids
})
})
},
onLoad() {
this.getCoupons()
}
})
{
"navigationBarTitleText": "领券中心",
"usingComponents": {
"coupon-item": "../components/CouponsItem/element"
}
}
\ No newline at end of file
page {
background: #F7F8FA;
}
.center-page {
box-sizing: border-box;
padding: 0 32rpx;
}
.btn_wrapper {
/* width: calc(100% - 64rpx); */
width: 100%;
background: var(--btnColor);
height: 88rpx;
text-align: center;
line-height: 88rpx;
border-radius: 8rpx;
font-size: 32rpx;
color: #FFFFFF;
margin-top: 100rpx;
margin-bottom: 210rpx;
/* position: fixed;
bottom: 210rpx;
left: 50%;
transform: translate(-50%, 0);
z-index: 10; */
}
\ No newline at end of file
<view class="center-page">
<block wx:for="{{couponsList}}" wx:key="index">
<coupon-item mode="center" coupons="{{item}}"></coupon-item>
</block>
<view class="btn_wrapper" bind:tap="toReciveAll">一键领取</view>
</view>
\ No newline at end of file
Component({
properties: {
coupons: {
type: Object,
value: {}
},
mode: {
type: String,
value: 'coupon' //coupon卡券 center领券中心
},
btnStatus: {
type: Number,
value: 0
},
useMemberType: Number,
hideBtn: Boolean,
couponStyle: String
},
data: {
// 2 折扣券,3 代金券,4 兑换券,7 服务券
IMGURL: wx.$imgUrl
},
methods: {
toRecive() {
let para = {
couponIdList: [this.data.coupons.id]
}
wx.p.api.couponsApi.toReciveCard(para).then(res => {
if (res) {
wx.p.router.go('/packageMine/pages/coupon/success/success')
}
})
},
toDetail() {
let {
coupons,
useMemberType
} = this.data, {
discountType,
useChannel,
id
} = coupons, detailInfo = {
xx: 'xx'
}
if (discountType == 2 || discountType == 4) {
wx.$router.go('/packageMall/pages/coupon/coupon', {
userCouponId: id,
useMemberType,
detailInfo
})
return
}
/**线上商品代金券 */
if (discountType == 3 && useChannel == 1) {
wx.$router.go('/packageMine/pages/coupon/recommend/recommend', {
couponInfo: coupons
})
return
}
wx.$router.go('/packageMine/pages/coupon/detail/detail', {
item: coupons
})
}
}
})
\ No newline at end of file
{
"component": true
}
\ No newline at end of file
<!-- <view class="box_wrapper" style="{{couponStyle}}; background-image: url({{btnStatus == 0 ? couponBaseList[coupons.discountType]:unCouponBaseList[coupons.discountType]}});"> -->
<view class="box_wrapper" style="{{couponStyle}}">
<view class="bg">
<image webp src="{{IMGURL}}mine/coupon/{{btnStatus == 0 ? '' :'un-'}}coupon-{{coupons.discountType}}.png?v={{img_version}}"></image>
</view>
<view class="container">
<view class="{{coupons.discountType==4 || coupons.discountType==7 ? '':'left_icon_box'}}">
<!-- <image wx:if="{{btnStatus==0}}" class="left_bg" src="../../packageMine/images/coupons/coupons_active.png" />
<image wx:else class="left_bg" src="../../packageMine/images/coupons/coupons.png" /> -->
<!-- <view wx:if="{{coupons.discountType==7}}" class="left_text_one left_text_four">
<text class="anText">券</text>
<text wx:if="{{coupons.useType&&coupons.effectiveType!=3}}">{{ coupons.usedAmount }}/{{ coupons.useAllAmount }}</text>
<text wx:else>不限次数</text>
</view> -->
<view wx:if="{{coupons.discountType==3}}" class="left_text_one left_text_two {{btnStatus == 0 ? 'brightColor':'darkColor'}}">
<text class="price_icon">¥</text>
<text>{{coupons.denomination}}</text>
</view>
<view wx:if="{{coupons.discountType==2}}" class="left_text_one left_text_two {{btnStatus == 0 ? 'brightColor':'darkColor'}}">
<!-- <text class="anText">券</text> -->
<text class="anText" wx:if="{{coupons.discountIntensity}}">{{coupons.discountIntensity}}</text>
<text class="discount" wx:if="{{coupons.discountIntensity}}">折</text>
</view>
<!-- <view class="left_text_one">8.5折</view> -->
<!-- <view class="left_text_one left_text_two">
</view> -->
<!-- <view class="left_text_one left_text_three">满99可用</view> -->
</view>
<view class="main_box {{coupons.discountType==4 || coupons.discountType==7 ? 'leftMargin':''}}">
<view class="title_text {{btnStatus == 0 ? 'brightColor':'darkColor'}}">{{coupons.couponName}}</view>
<view wx:if="{{coupons.useType==0 && coupons.discountType==7}}" class="h4_text {{btnStatus == 0 ? 'describeColor':'darkColor'}}">不限次数</view>
<view wx:if="{{coupons.useType==1 && coupons.discountType==7}}" class="h4_text {{btnStatus == 0 ? 'describeColor':'darkColor'}}">可用{{coupons.useAmount}}次</view>
<view wx:if="{{coupons.useType==2 && coupons.discountType==7}}" class="h4_text {{btnStatus == 0 ? 'describeColor':'darkColor'}}">{{coupons.useLimitDays}}天可用{{coupons.useAmount}}次</view>
<!-- <view wx:if="{{coupons.discountType==3}}" style="height:1px" class="drive"></view> -->
<view wx:if="{{coupons.useBarriers==1 && coupons.discountType!=4}}" class="h4_text {{btnStatus == 0 ? 'describeColor':'darkColor'}}">无门槛</view>
<view wx:if="{{coupons.useBarriers==2 && coupons.discountType!=4}}" class="h4_text {{btnStatus == 0 ? 'describeColor':'darkColor'}}">满{{coupons.full}}元可用</view>
<view wx:if="{{coupons.effectiveType==3}}" class="h4_text {{btnStatus == 0 ? 'describeColor':'darkColor'}}">永久有效</view>
<view wx:if="{{coupons.effectiveType==2}}" class="h4_text {{btnStatus == 0 ? 'describeColor':'darkColor'}}">{{coupons.receiveStartTime}}-{{coupons.receiveEndTime}}</view>
<view wx:if="{{coupons.effectiveType==1}}" class="h4_text {{btnStatus == 0 ? 'describeColor':'darkColor'}}">有效期至{{coupons.receiveEndTime}}</view>
<!-- <view wx:else class="h4_text drive">{{coupons.receiveStartTime}}-{{coupons.receiveEndTime}}</view> -->
<!-- <view wx:if="{{coupons.effectiveType==1}}" class="h4_text drive">{{coupons.effectiveStartTime}}-{{coupons.effectiveEndTime}}</view> -->
</view>
<!-- <view wx:if="{{mode=='center'}}" class="box_btn box_btn_color" bind:tap="toRecive">领取</view> -->
<block wx:if="{{!hideBtn}}">
<view wx:if="{{mode=='coupon'&&btnStatus==0}}" class="box_btn box_btn_color" bind:tap="toDetail">去使用</view>
<view wx:if="{{mode=='coupon'&&btnStatus==1}}" class="box_btn box_btn_color box_btn_color_grey" bind:tap="toDetail">去查看</view>
<view wx:if="{{mode=='coupon'&&btnStatus==2}}" class="box_btn box_btn_color box_btn_color_grey" bind:tap="toDetail">去查看</view>
</block>
</view>
</view>
\ No newline at end of file
page {
background: white;
}
.box_wrapper {
width: 100%;
height: 162rpx;
/* background: #FFFFFF; */
/* border-radius: 8rpx; */
margin-top: 19rpx;
display: flex;
align-items: center;
position: relative;
box-sizing: border-box;
background-size: cover;
}
.left_icon_box {
width: 156rpx;
height: 156rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}
.left_bg {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 156rpx;
height: 156rpx;
z-index: 1;
}
.left_text_one {
font-size: 48rpx;
font-weight: 600;
z-index: 2;
}
.left_text_two {
display: flex;
align-items: flex-end;
}
.left_text_four {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.left_text_three {
font-size: 20rpx;
margin-top: 6rpx;
}
.left_tran {
transform: translateX(-120rpx);
}
.anText {
font-size: 48rpx;
/* color: rgba(white, white, white, 0.45); */
font-weight: 600;
/* color: #FFF; */
/* opacity: 0.45; */
}
.price_icon {
font-size: 24rpx;
/* margin-right: 4rpx; */
margin-bottom: 7rpx;
font-weight: 500;
}
.main_box {
height: 156rpx;
box-sizing: border-box;
padding: 24rpx 24rpx 24rpx 0rpx;
justify-content: space-evenly;
display: flex;
flex-direction: column;
z-index: 1;
}
.box_btn {
position: absolute;
right: 47rpx;
top: 50%;
transform: translate(0, -50%);
width: 120rpx;
height: 44rpx;
/* background: #B1B1B3; */
text-align: center;
line-height: 44rpx;
font-size: 28rpx;
font-weight: 600;
}
.box_btn_color {
/* background: var(--btnColor); */
color: var(--btnColor);
}
.box_btn_color_grey {
color: #6D6D6D;
}
.title_text {
color: #282829;
font-weight: 600;
color: #282829;
font-size: 28rpx;
width: 309rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.h4_text {
font-weight: 400;
color: #B1B1B3;
font-size: 20rpx;
}
.leftMargin {
padding-left: 32rpx;
}
.brightColor {
color: var(--btnColor);
}
.darkColor {
color: #6D6D6D;
}
.describeColor {
color: #D83C14;
}
.discount {
font-size: 20rpx;
font-weight: 500;
margin-bottom: 10rpx;
}
.box_wrapper .bg{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.box_wrapper .container {
display: flex;
align-items: center;
position: relative;
z-index: 1;
width: 100%;
height: 100%;
}
import QR from '~/lib/wxqrcode'
Page({
data: {
coupon: {
discountType: 7
},
detailInfo: {},
failure: false,
future: false,
dayDiff: 0,
hourDiff: 0,
minDiff: 0
},
jump(e) {
let { item } = e.currentTarget.dataset
wx.openLocation({
latitude: item.lat,
longitude: item.lng,
name: item.merchantName,
address: item.merchantAddress
})
},
getDetailData(id) {
let para = {
userCouponId: id
}
wx.$api.showLoading('加载中...')
wx.p.api.couponsApi.couponsDetail(para).then(res => {
wx.hideLoading()
let qrcodeURL = QR.createQrCodeImg(`t=2&c=${res.verificationCode}`)
let failure = false
let future = false
res.receiveTime = new Date(res.receiveTime).format('yyyy.MM.dd hh:mm:ss')
res.verificationCode = res.verificationCode.replace(/(.{4})/g, '$1 ')
if (res.couponState == 2) {
failure = true
} else if (res.couponState == 1) {
failure = false
} else if (res.couponState == 3) {
future = true
} else if (res.couponState == 4) {
future = true
} else if (res.couponState == 5) {
failure = true
}
let dayDiff = 0
let hourDiff = 0
let minDiff = 0
if (future) {
dayDiff = res.nextLimitDays
hourDiff = res.nextLimitHours
minDiff = res.nextLimitMin
}
if (res.list.length) {
res.list.map(el => {
el.verificationTime = new Date(el.verificationTime).format('yyyy-MM-dd hh:mm:ss')
return el
})
}
res.receiveEndTime = new Date(res.receiveEndTime).format('yyyy.MM.dd hh:mm:ss')
res.receiveStartTime = new Date(res.receiveStartTime).format('yyyy.MM.dd hh:mm:ss')
this.setData({
detailInfo: res,
future,
failure,
dayDiff,
hourDiff,
minDiff,
qrcodeURL,
coupon: res,
flag: true
})
})
},
onLoad(options) {
let couponInfo = options.item
this.getDetailData(couponInfo.id)
this.setData({
couponInfo
})
// wx.$Track.setTrack(
// {
// couponInfo
// },
// 6
// )
}
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!