Commit 34aee901 by 李伟康

我的订单

1 parent daa50a73
Showing 62 changed files with 3584 additions and 69 deletions
...@@ -54,4 +54,13 @@ module.exports = { ...@@ -54,4 +54,13 @@ module.exports = {
getUserAddressDefault() { getUserAddressDefault() {
return api.fetch('scrm.api.carlife.weapp.userAddress.getDefault') return api.fetch('scrm.api.carlife.weapp.userAddress.getDefault')
}, },
/**. 分页查询订单 */
getOrderList(data) {
return api.post({
method: `scrm.api.shopmall.weapp.order.page`,
pageSize: 99999,
...data
})
},
} }
\ No newline at end of file \ No newline at end of file
...@@ -67,4 +67,18 @@ module.exports = { ...@@ -67,4 +67,18 @@ module.exports = {
...data ...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
})
},
} }
\ No newline at end of file \ No newline at end of file
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
{ {
"pagePath": "pages/tab/equity/index", "pagePath": "pages/tab/equity/index",
"text": "权益", "text": "权益",
"iconPath": "assets/images/mall.png", "iconPath": "assets/images/equity.png",
"selectedIconPath": "assets/images/mall_active.png" "selectedIconPath": "assets/images/equity_active.png"
}, },
{ {
"pagePath": "pages/tab/mall/index", "pagePath": "pages/tab/mall/index",
...@@ -74,7 +74,14 @@ ...@@ -74,7 +74,14 @@
"pages/index/index", "pages/index/index",
"pages/setting/index", "pages/setting/index",
"pages/address/index/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"
] ]
} }
], ],
......
// components/Tab/Tab.js // components/Tab/Tab.js
import {componentsMixin } from '../../mixins/index'
Component({ Component({
behaviors:[componentsMixin],
/** /**
* 组件的属性列表 * 组件的属性列表
*/ */
......
/* components/Tab/Tab.wxss */ /* components/Tab/Tab.wxss */
@import "../../common.wxss"; @import "../../assets/style/common.wxss";
.tab-box { .tab-box {
display: flex; display: flex;
......
...@@ -4,7 +4,7 @@ var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexport ...@@ -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__ = 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_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; }; 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封装类 * @Descripttion: api封装类
* @version: 1.0.0 * @version: 1.0.0
...@@ -225,8 +225,8 @@ class GlMapApi { ...@@ -225,8 +225,8 @@ class GlMapApi {
} }
if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });exports.default = GlMapApi; if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });exports.default = GlMapApi;
}, function(modId) {var map = {"./request":1689247481139}; return __REQUIRE__(map[modId], modId); }) }, function(modId) {var map = {"./request":1689250267951}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689247481139, function(require, module, exports) { __DEFINE__(1689250267951, function(require, module, exports) {
/* /*
* @Descripttion: 定义一个Request类,用于封装请求高德地图API的方法 * @Descripttion: 定义一个Request类,用于封装请求高德地图API的方法
* @version: 1.0.0 * @version: 1.0.0
...@@ -340,8 +340,8 @@ class Request { ...@@ -340,8 +340,8 @@ class Request {
} }
if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });exports.default = 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); }) }, function(modId) { var map = {"./lib/md5":1689250267952,"./lib/qs":1689250267953,"./constants":1689250267954,"./helper":1689250267955}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689247481140, function(require, module, exports) { __DEFINE__(1689250267952, function(require, module, exports) {
(function () { (function () {
...@@ -1017,7 +1017,7 @@ __DEFINE__(1689247481140, function(require, module, exports) { ...@@ -1017,7 +1017,7 @@ __DEFINE__(1689247481140, function(require, module, exports) {
} }
})(); })();
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); }) }, 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){ (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 = { ...@@ -1658,7 +1658,7 @@ module.exports = {
}); });
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); }) }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689247481142, function(require, module, exports) { __DEFINE__(1689250267954, function(require, module, exports) {
/* /*
* @Descripttion: 常量类 * @Descripttion: 常量类
* @version: 1.0.0 * @version: 1.0.0
...@@ -1671,7 +1671,7 @@ __DEFINE__(1689247481142, function(require, module, exports) { ...@@ -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' }; 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); }) }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
__DEFINE__(1689247481143, function(require, module, exports) { __DEFINE__(1689250267955, function(require, module, exports) {
/* /*
* @Descripttion:帮助类 * @Descripttion:帮助类
* @version: 1.0.0 * @version: 1.0.0
...@@ -1684,7 +1684,7 @@ __DEFINE__(1689247481143, function(require, module, exports) { ...@@ -1684,7 +1684,7 @@ __DEFINE__(1689247481143, function(require, module, exports) {
if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });var isMiniprogram = exports.isMiniprogram = !window; if (!exports.__esModule) Object.defineProperty(exports, "__esModule", { value: true });var isMiniprogram = exports.isMiniprogram = !window;
}, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); }) }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
return __REQUIRE__(1689247481138); return __REQUIRE__(1689250267950);
})() })()
//miniprogram-npm-outsideDeps=["./stringify","./parse","./formats","./utils"] //miniprogram-npm-outsideDeps=["./stringify","./parse","./formats","./utils"]
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map
\ No newline at end of file \ 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 \ 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 \ No newline at end of file
module.exports = Behavior(
{
data: {
afterType:{
1:'我要退款退货',
2:'我要退款(无需退货)'
}
}
})
\ No newline at end of file \ No newline at end of file
module.exports = {} import orderMixin from './orderMixin'
import afterSaleMixin from './afterSaleMixin'
module.exports = {
orderMixin,
afterSaleMixin,
}
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 \ 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 \ 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 \ 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 \ 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, "lockfileVersion": 1,
"requires": true,
"dependencies": { "dependencies": {
"glsx-map-sdk": { "glsx-map-sdk": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/glsx-map-sdk/-/glsx-map-sdk-0.2.0.tgz", "resolved": "https://registry.npmjs.org/glsx-map-sdk/-/glsx-map-sdk-0.2.0.tgz",
"integrity": "sha512-uEFlXvJEDofYjasR4mwkmF5yNTRs5QA2ZAynGPHiKpKdpjQkVFPJH0zGupmQEkxmh4f5B0wPbDobHvLgld7mVw==" "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 @@ ...@@ -3,7 +3,8 @@
"version": "1.0.0", "version": "1.0.0",
"main": "app.js", "main": "app.js",
"dependencies": { "dependencies": {
"glsx-map-sdk": "^0.2.0" "glsx-map-sdk": "^0.2.0",
"number-precision": "^1.6.0"
}, },
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
......
// packageMine/pages/order/afterSaleDetail/afterSaleDetail.js
Page({
/**
* 页面的初始数据
*/
data: {
refundStatus: {
1: '待处理',
2: '待发货',
3: '待确认收到退货',
4: '退款中',
5: '已退款',
6: '退款失败',
7: '审核不通过'
},
// 退款状态1:待处理,2待发货,3待确认收到退货,4:退款中,5:已退款,6:退款失败,7:审核不通过
afterSaleObj: [
{
title: '售后类型',
key: 'refundType',
enum: {
1: '我要退款退货',
2: '我要退款(无需退货)'
}
},
{
title: '售后商品',
isArray: true,
key: 'goodsNames'
},
{
title: '申请金额',
key: 'refundPrice'
},
{
title: '申请时间',
key: 'time'
},
{
title: '申请描述',
key: 'remark'
},
{
title: '订单编号',
key: 'orderCode'
}
]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.p.router.getData(orderCode => {
this.getOrderRefundDetail(orderCode)
})
},
getOrderRefundDetail(orderCode) {
wx.p.wxApi.showLoading('加载中...')
wx.p.api.shopmallApi.getOrderRefundDetail(orderCode).then(data => {
wx.hideLoading()
console.log(data)
if (data.refundStatus == 2 && data.refundType == 1) {
wx.p.router.redirectTo('/packageMine/pages/order/afterSale_step_three/afterSale_step_three', data)
return
}
data.time = new Date(data.createdDate).format('yyyy-MM-dd hh:mm:ss')
this.setData({
orderInfo: data
})
})
},
confirm() {
let { orderInfo } = this.data
console.log(orderInfo)
wx.p.router.go('/packageMine/pages/order/afterSale_step_two/afterSale_step_two', orderInfo)
},
previewImage(e) {
let params = e.currentTarget.dataset
wx.p.wxApi.previewImage(params)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {}
})
{
"navigationBarTitleText": "售后详情"
}
\ No newline at end of file \ No newline at end of file
.layout {
padding: 32rpx;
}
.status-box {
text-align: center;
}
.status-box .icon {
margin: 80rpx auto 84rpx;
width: 140rpx;
height: 140rpx;
}
.status-box .title {
font-size: 40rpx;
font-weight: 500;
}
.status-box .tips {
margin: 20rpx 0 59rpx;
color: #656566;
}
.box {
border-radius: 8rpx;
background-color: #fff;
}
.text-box {
padding: 32rpx 24rpx;
border-bottom: 2rpx solid #EFF0F2;
}
.text-box .item{
margin-bottom: 12rpx;
display: flex;
align-items: flex-start;
}
.text-box .item .label{
width: 140rpx;
}
.text-box .item .value{
color: #656566;
width: calc(100% - 150rpx);
}
.photo-box {
padding: 40rpx 0 28rpx 20rpx;
display: flex;
flex-wrap: wrap;
}
.photo-box .item {
width: 200rpx;
height: 200rpx;
background: #D8D8D8;
margin: 0 20rpx 20rpx 0;
}
\ No newline at end of file \ No newline at end of file
<block wx:if="{{orderInfo}}">
<view class="layout isFullSucreen">
<view class="status-box">
<!-- 退款状态1:待处理,2待发货,3待确认收到退货,4:退款中,5:已退款,6:退款失败,7:审核不通过 -->
<view class="icon">
<block wx:if="{{orderInfo.refundStatus == 5}}">
<glsx-image webp src="mine/order/success.png"></glsx-image>
</block>
<block wx:elif="{{orderInfo.refundStatus <5}}">
<glsx-image webp src="mine/order/wait.png"></glsx-image>
</block>
<block wx:else>
<glsx-image webp src="mine/order/error.png"></glsx-image>
</block>
</view>
<view class="title">{{refundStatus[orderInfo.refundStatus]}}</view>
<view class="tips">
<block wx:if="{{orderInfo.refundStatus == 5}}">
钱款将原路退回至您的账户
</block>
<block wx:elif="{{orderInfo.refundStatus > 5 }}">退款不成功,您可以再次提交退款申请重试</block>
<block wx:else>等待平台处理</block>
</view>
</view>
<view class="box">
<view class="text-box">
<block wx:for="{{afterSaleObj}}" wx:key="index">
<view class="item">
<view class="label">{{item.title}}:</view>
<view class="value">
<block wx:if="{{item.enum}}">
{{item.enum[orderInfo[item.key]]}}
</block>
<block wx:elif="{{item.isArray}}">
<block wx:for="{{orderInfo[item.key]}}" wx:key="index" wx:for-item="i">
<text>{{i}};</text>
</block>
</block>
<block wx:else>
{{orderInfo[item.key] || ''}}
</block>
</view>
</view>
</block>
<block wx:if="{{orderInfo.deliveryCompany}}">
<view class="item">
<view class="label">快递公司:</view>
<view class="value">{{orderInfo.deliveryCompany}}</view>
</view>
<view class="item">
<view class="label">快递单号:</view>
<view class="value">{{orderInfo.deliveryNumber}}</view>
</view>
</block>
</view>
<block wx:if="{{orderInfo.imgUrls && orderInfo.imgUrls.length}}">
<view class="photo-box">
<block wx:for="{{orderInfo.imgUrls}}" wx:key="index">
<view class="item" bindtap="previewImage" data-current="{{item}}" data-urls="{{orderInfo.imgUrls}}">
<image webp src="{{item}}"></image>
</view>
</block>
</view>
</block>
</view>
<block wx:if="{{orderInfo.refundStatus >5}}">
<view class="default-btn" bindtap="confirm">重新提交</view>
</block>
</view>
</block>
\ No newline at end of file \ No newline at end of file
import { afterSaleMixin } from '~/mixins/index'
Page({
behaviors: [afterSaleMixin],
/**
* 页面的初始数据
*/
data: {
afterSaleList: [
{
active: true,
value: 2
},
{
value: 1
}
]
},
choose(e) {
let { index } = e.currentTarget.dataset
let { afterSaleList } = this.data
afterSaleList.map(i => (i.active = false))
afterSaleList[index].active = true
this.setData({
afterSaleList
})
},
click() {
let {
orderObj,
data: { afterSaleList }
} = this
orderObj.refundType = 2
afterSaleList.map(e => {
if (e.active) orderObj.refundType = e.value
})
wx.p.router.go('/packageMine/pages/order/afterSale_step_two/afterSale_step_two', orderObj)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.orderObj = options
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {}
})
{
"navigationBarTitleText": "申请售后"
}
\ No newline at end of file \ No newline at end of file
/* packageMine/pages/order/afterSale_step_one/afterSale_step_one.wxss *//* packageMine/pages/order/afterSale_step_one/afterSale_step_one.wxss */
.layout {
padding: 24rpx var(--margin);
}
.title {
font-size: 32rpx;
font-weight: 500;
margin-bottom: 40rpx;
}
.item {
border: 4rpx solid transparent;
height: 152rpx;
position: relative;
background-color: #fff;
font-size: 40rpx;
margin-bottom: var(--margin);
border-radius: 8rpx;
overflow: hidden;
}
.item.active{
border-color: var(--btnColor);
}
.default-btn{
margin: 220rpx auto 0;
}
.active .icon{
position: absolute;
top: 0;
right: 0;
width: 64rpx;
height: 64rpx;
}
\ No newline at end of file \ No newline at end of file
<view class="layout">
<view class="title">请选择售后类型</view>
<view class="box">
<block wx:for="{{afterSaleList}}" wx:key="index">
<view class="item text-center {{item.active?'active':''}}" bindtap="choose" data-index="{{index}}">
{{afterType[item.value]}}
<view class="icon">
<image webp src="{{IMGURL}}mine/active.png?v={{img_version}}"></image>
</view>
</view>
</block>
</view>
</view>
<view class="default-btn" bindtap="click">确定</view>
\ No newline at end of file \ No newline at end of file
// packageMine/pages/order/afterSale_step_three/afterSale_step_three.js
Page({
/**
* 页面的初始数据
*/
data: {},
onLoad(options) {
this.setData({
orderInfo: options
})
},
input(e) {
let { value } = e.detail
let { key } = e.currentTarget.dataset
this.setData({
[`params.${key}`]: value
})
},
confirm() {
let { orderInfo, params } = this.data
if (!params.deliveryCompany && !params.deliveryNumber) {
wx.p.wxApi.showToast('请填写快递公司、单号')
return
}
params.id = orderInfo.id
wx.p.wxApi.showLoading('提交申请中...')
wx.p.api.shopmallApi.addDelivery(params).then(data => {
console.log(data)
wx.p.wxApi.showToast('申请成功!')
setTimeout(() => {
wx.p.router.back(prevPage => {
prevPage.clearData()
})
}, 1.5 * 1000)
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {}
})
{
"navigationBarTitleText": "申请售后"
}
\ No newline at end of file \ No newline at end of file
/* packageMine/pages/order/afterSale_step_three/afterSale_step_three.wxss */
.layout {
padding: 0 32rpx;
}
.title {
padding: 32rpx 0 24rpx;
}
.address {
background: #EFF0F2;
border-radius: 8rpx;
overflow-y: scroll;
box-sizing: border-box;
padding: 28rpx 32rpx;
line-height: 40rpx;
}
.box {
height: 216rpx;
background-color: #fff;
border-radius: 8rpx;
position: relative;
}
.box::after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 654rpx;
height: 2rpx;
background: #EFF0F2;
transform: translate(-50%,-50%);
}
.item {
height: 108rpx;
display: flex;
align-items: center;
box-sizing: border-box;
}
.item .label{
width: 224rpx;
text-indent: 32rpx;
}
.item .input{
width: calc(100% - 256rpx);
}
.btn {
margin: 48rpx auto 20rpx;
width: 332rpx;
height: 80rpx;
background: var(--btnColor);
border-radius: 8rpx;
color: #fff;
}
.disabled{
background-color: #999;
}
\ No newline at end of file \ No newline at end of file
<view class="layout">
<view class="title">请将收到的货物发回以下地址</view>
<view class="address">
<view>地址:{{orderInfo.contactAddress}}</view>
<view>收货人:{{orderInfo.contactName}}</view>
<view>联系电话:{{orderInfo.contactPhone}}</view>
</view>
<view class="title">请输入您的快递信息</view>
<view class="box">
<view class="item">
<view class="label">快递公司</view>
<input class="input" type="text" placeholder="请输入" bindinput="input" data-key="deliveryCompany" />
</view>
<view class="item">
<view class="label">快递单号</view>
<input class="input" type="text" placeholder="请输入" bindinput="input" data-key="deliveryNumber" />
</view>
</view>
<view class="btn text-center {{params.deliveryCompany && params.deliveryNumber?'':'disabled'}}" bindtap="confirm">提交申请
</view>
</view>
\ No newline at end of file \ No newline at end of file
import {
afterSaleMixin
} from '~/mixins/index'
Page({
behaviors: [afterSaleMixin],
/**
* 页面的初始数据
*/
data: {
imgUrls: []
},
previewImage(e) {
let params = e.currentTarget.dataset
wx.p.wxApi.previewImage(params)
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let imgUrls = []
if (options.imgUrls) imgUrls = options.imgUrls
this.setData({
orderObj: options,
imgUrls,
maxPrice: options.refundPrice
})
},
input(e) {
this.setData({
'orderObj.remark': e.detail.value
})
},
noScroll() {},
changePrice() {
this.setData({
showPriceInput: true
})
},
blur(e) {
const rex = /^(([1-9]{1}\d*)|(0{1}))(\.\d{2})$/
console.log(e)
let {
value
} = e.detail
let {
maxPrice
} = this.data
if (value > maxPrice) value = maxPrice
if (value < 0) value = 0
if (!rex.test(value)) value = maxPrice
this.setData({
'orderObj.refundPrice': Number(value).toFixed(2),
showPriceInput: false
})
},
del(e) {
let {
index
} = e.currentTarget.dataset
let {
imgUrls
} = this.data
imgUrls.splice(index, 1)
this.setData({
imgUrls
})
},
upLoad() {
let _this = this
let {
imgUrls
} = this.data
wx.chooseImage({
count: 1
}).then(res => {
let [tempFiles] = res.tempFilePaths
let imgType = tempFiles.split('.')[1]
let type = imgType == 'unknown' ? 'jpg' : imgType
wx.getFileSystemManager().readFile({
filePath: tempFiles, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success(_res) {
wx.p.wxApi.showLoading('上传中...')
commonApi
.uploadImg({
file: `${type}@${_res.data}`
})
.then(img => {
wx.p.wxApi.hideLoading()
console.log(img)
imgUrls.push(img)
_this.setData({
imgUrls
})
})
}
})
})
},
confirm() {
let {
orderObj,
imgUrls
} = this.data
orderObj.imgUrls = imgUrls
console.log(orderObj)
wx.p.api.shopmallApi.afterSale(orderObj).then(({
code,
data,
message
}) => {
if (code == '0') {
wx.p.wxApi.showToast('申请成功!')
setTimeout(() => {
wx.p.router.back(prevPage => {
prevPage.clearData()
}, 2)
}, 1.5 * 1000)
} else {
wx.p.wxApi.showToast(message)
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {}
})
\ No newline at end of file \ No newline at end of file
{
"navigationBarTitleText": "申请售后"
}
\ No newline at end of file \ No newline at end of file
/* packageMine/pages/order/afterSale_step_two/afterSale_step_two.wxss */
.layout {
padding: 0 var(--margin) 24rpx;
}
.title {
font-weight: 500;
font-size: 32rpx;
padding: 24rpx 0;
}
.box {
background: #FFFFFF;
border-radius: 8rpx;
}
.type {
height: 104rpx;
background: #EFF0F2;
border-radius: 8rpx;
font-size: 40rpx;
}
.description {
height: 460rpx;
box-sizing: border-box;
padding: 28rpx 32rpx;
}
.price-box {
height: 100rpx;
display: flex;
align-items: center;
justify-content: space-between;
margin: 24rpx 0 8rpx;
box-sizing: border-box;
padding: 0 32rpx;
}
.price-box .value {
font-size: 24rpx;
color: var(--btnColor);
display: flex;
align-items: center;
}
.price-box .value .price {
margin-right: 28rpx;
font-size: 36rpx;
}
.upload-box {
min-height: 260rpx;
box-sizing: border-box;
padding: 30rpx 0 0 22rpx;
}
.upload-box .one {
width: 100%;
height: 260rpx;
}
.upload-box.flex {
display: flex;
flex-wrap: wrap;
}
.upload-box .icon {
width: 84rpx;
height: 64rpx;
}
.upload-box .item {
width: 200rpx;
height: 200rpx;
background: #D8D8D8;
margin-bottom: 30rpx;
margin-right: 20rpx;
position: relative;
}
.item .del {
position: absolute;
width: 72rpx;
height: 72rpx;
right: -32rpx;
top: -32rpx;
}
.upload-box .item .del .icon {
width: 36rpx;
height: 36rpx;
}
.upload-box .upload-item {
background-color: #fff;
border: 2rpx solid #D8D8D8;
box-sizing: border-box;
}
.btn {
margin: 48rpx auto 20rpx;
width: 332rpx;
height: 80rpx;
background: var(--btnColor);
border-radius: 8rpx;
color: #fff;
}
.price-input-box {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 2;
background-color: rgba(0, 0, 0, .7);
}
.price-input {
width: 100%;
height: 72rpx;
background-color: #fff;
box-sizing: border-box;
padding: 0 40rpx;
display: flex;
align-items: center;
}
\ No newline at end of file \ No newline at end of file
<view class="layout isFullSucreen">
<view class="title">售后类型</view>
<view class="type text-center">
{{afterType[orderObj.refundType]}}
</view>
<view class="title">申请描述</view>
<view class="description box">
<gl-textarea maxlength="230" value="{{orderObj.remark}}" bindinput="input" showWordLimit customMaxLength></gl-textarea>
</view>
<view class="price-box box">
申请金额
<view class="value" bindtap="changePrice">
<view class="price">¥{{orderObj.refundPrice}}</view>
修改金额
</view>
</view>
<view class="title">上传图片</view>
<view class="upload-box box flex">
<block wx:if="{{imgUrls.length < 1}}">
<view class="one text-center" bindtap="upLoad">
<view class="icon">
<image webp src="{{IMGURL}}mine/camera.png?v={{img_version}}"></image>
</view>
</view>
</block>
<block wx:else>
<block wx:for="{{imgUrls}}" wx:key="index">
<view class="item" catchtap="previewImage" data-current="{{item}}" data-urls="{{imgUrls}}">
<image webp src="{{item}}"></image>
<view class="del text-center" catchtap="del" data-index="{{index}}">
<view class="icon">
<image webp src="{{IMGURL}}mine/del.png?v={{img_version}}"></image>
</view>
</view>
</view>
</block>
<block wx:if="{{imgUrls.length < 5}}">
<view class="upload-item item text-center" bindtap="upLoad">
<view class="icon">
<image webp src="{{IMGURL}}mine/camera.png?v={{img_version}}"></image>
</view>
</view>
</block>
</block>
</view>
<view class="btn text-center" bindtap="confirm">提交申请</view>
</view>
<block wx:if="{{showPriceInput}}">
<view class="price-input-box" catchtouchmove="noScroll">
<view class="price-input">
<input type="digit" bindblur="blur" value="{{orderObj.refundPrice}}" focus="{{showPriceInput}}" class="input"
adjust-position="{{false}}" />
</view>
</view>
</block>
\ No newline at end of file \ No newline at end of file
// packageMine/pages/order/complete/complete.js
Page({
/**
* 页面的初始数据
*/
data: {
success: false,
count: 5
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (options.success) {
this.setData(options)
this.countdown()
} else {
this.setData({
params: options.params
})
}
},
countdown() {
this.timer = setInterval(() => {
let { count } = this.data
if (count == 0) {
clearInterval(this.timer)
wx.p.router.reLaunch('/packageMine/pages/order/index/index')
return
}
this.setData({
count: --count
})
}, 1 * 1000)
},
pay() {
let { params } = this.data
let _this = this
wx.requestPayment({
...params,
success(res) {
_this.setData({
success: true
})
_this.countdown()
},
fail(res) {
if (res.errMsg == 'requestPayment:fail cancel') {
wx.$api.showToast('取消支付')
}
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
if (this.timer) clearInterval(this.timer)
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
if (this.timer) clearInterval(this.timer)
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {}
})
{
"usingComponents": {}
}
\ No newline at end of file \ No newline at end of file
/* packageMine/pages/order/complete/complete.wxss */
page {
background-color: #fff;
}
.layout {
display: flex;
align-items: center;
flex-direction: column;
}
.icon {
width: 140rpx;
height: 140rpx;
margin: 112rpx 0 84rpx;
}
.title {
font-size: 40rpx;
font-weight: 500;
margin-bottom: 64rpx;
}
.text {
color: #656566;
font-size: 32rpx;
}
.tips {
color: #B9BABB;
margin-top: 20rpx;
}
.pay {
width: 332rpx;
height: 80rpx;
background: var(--btnColor);
border-radius: 8rpx;
color: #fff;
margin-top: 112rpx;
}
\ No newline at end of file \ No newline at end of file
<view class="layout">
<view class="icon">
<glsx-image webp src="mine/order/{{success?'success':'error'}}.png"></glsx-image>
</view>
<view class="title">{{success?'支付成功':'支付失败'}}</view>
<block wx:if="{{success}}">
<view class="text">您的订单已支付成功,请耐心等待商品发货!</view>
<view class="tips">{{count}}秒后自动跳转到商城订单</view>
</block>
<block wx:else>
<view class="pay text-center" bindtap="pay">重新支付</view>
</block>
</view>
\ No newline at end of file \ No newline at end of file
// packageMine/pages/order/detail/detail.js
import QR from '~/utils/lib/wxqrcode'
import {
orderMixin
} from '~/mixins/index'
import {
iosTimeFormat,
} from '~/utils/format'
Page({
behaviors: [orderMixin],
/**
* 页面的初始数据
*/
data: {
couponsList: [],
orderObj: [{
label: '下单日期',
key: 'time'
},
{
label: '订单编号',
key: 'orderCode'
},
{
label: '收货地址',
key: 'shipAddress',
alignItems: 'flex-start'
},
{
label: '订单状态',
key: 'orderStatus',
enum: true
}
],
deliveryStatus: {
1: '待发货',
2: '已发货',
3: '已收货'
}
},
onRoute(orderCode) {
if (Object.keys(orderCode).length !== 0) {
console.log(orderCode)
this.getOrderDetail(orderCode)
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (options && options.orderCode) {
let orderCode = options.orderCode
this.getOrderDetail(orderCode)
}
},
getOrderDetail(orderCode) {
let {
orderObj
} = this.data
wx.p.wxApi.showLoading('加载中...')
wx.p.api.shopmallApi.getOrderDetail(orderCode).then(data => {
wx.hideLoading()
console.log(data)
data.time = new Date(iosTimeFormat(data.createdDate)).format('yyyy.MM.dd hh:mm:ss')
data.orderGoods.map(e => {
e.retailPrice = Number(e.retailPrice).toFixed(2)
if (e.activityPrice) e.activityPrice = Number(e.activityPrice).toFixed(2)
})
data.orderPrice = Number(data.orderPrice).toFixed(2)
data.expressFee = Number(data.expressFee).toFixed(2)
data.payPrice = Number(data.payPrice).toFixed(2)
if (data.orderSource == 4) {
orderObj[2] = {
label: '商户订单号',
key: 'outTradeNo',
}
}
this.setData({
orderInfo: data,
orderObj
})
if (data.deliveryType == 1 && data.orderVerification) this.setQr(data.orderVerification.verificationCode)
if (data.relatedUserCoupon) {
let list = data.relatedUserCoupon.map(item => {
item.receiveStartTime = new Date(iosTimeFormat(item.receiveStartTime)).format('yyyy.MM.dd')
if (item.effectiveType == 1) {
item.receiveEndTime = new Date(iosTimeFormat(item.receiveEndTime)).format('yyyy.MM.dd hh:mm:ss')
} else {
item.receiveEndTime = new Date(iosTimeFormat(item.receiveEndTime)).format('yyyy.MM.dd')
}
return item
})
this.setData({
couponsList: list
})
}
})
},
toDetail() {
let [temp] = this.data.orderInfo.relatedUserCoupon, {
discountType,
useChannel,
id
} = temp, detailInfo = {
xx: 'xx'
}
if (discountType == 2 || discountType == 4) {
wx.p.router.go('/packageMall/pages/coupon/coupon', {
userCouponId: id,
useMemberType: this.data.useMemberType,
detailInfo
})
return
}
/**线上商品代金券 */
if (discountType == 3 && useChannel == 1) {
if (this.data.useMemberType == 1) {
wx.p.wxApi.showToast('代金券已使用')
return
}
wx.p.router.go('/packageMine/pages/coupon/recommend/recommend', {
couponInfo: temp
})
return
}
wx.p.router.go('/packageMine/pages/coupon/detail/detail', {
item: temp
})
},
setQr(data) {
this.setData({
qr: QR.createQrCodeImg(`t=1&c=${data}`)
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {}
})
\ No newline at end of file \ No newline at end of file
{
"navigationBarTitleText": "订单详情"
}
\ No newline at end of file \ No newline at end of file
/* packageMine/pages/order/detail/detail.wxss */
.layout {
padding: 24rpx 32rpx 68rpx;
}
.status-box {
height: 98rpx;
font-size: 36rpx;
color: #2C2C2C;
margin-bottom: 6rpx;
}
.status-box .icon{
width: 50rpx;
height: 52rpx;
margin-right: 12rpx;
}
.box {
background-color: #fff;
border-radius: var(--borderRadius);
margin-top: 20rpx;
padding: 24rpx 24rpx 40rpx;
}
.box:first-of-type{
margin-top: 0;
}
.box .title {
font-size: 32rpx;
padding-bottom: 24rpx;
font-weight: 500;
}
.box .item {
display: flex;
align-items: center;
font-size: 24rpx;
min-height: 48rpx;
line-height: 48rpx;
}
.box .item.flex-start {
align-items: flex-start;
}
.box .item .label {
width: 150rpx;
}
.box .item .value {
width: calc(100% - 150rpx);
color: #656566;
}
.box .goods {
margin-top: 40rpx;
display: flex;
align-items: center;
height: 160rpx;
}
.box .goods .icon {
width: 160rpx;
height: 100%;
overflow: hidden;
border-radius: var(--borderRadius);
margin-right: 20rpx;
}
.box .goods .info {
width: calc(100% - 180rpx);
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.box .goods .info .name {
font-size: 30rpx;
color: #333;
}
.box .goods .info .specification{
font-size: 24rpx;
color: #B1B1B3;
}
.box .goods .info .price {
display: flex;
justify-content: space-between;
color: var(--btnColor);
font-weight: 500;
font-weight: 500;
}
.box .goods .info .price .count {
color: #656566;
font-weight: normal;
}
.price-item {
height: 60rpx;
display: flex;
justify-content: space-between;
align-items: center;
color: #656566;
font-size: 24rpx;
}
.price-item.line {
border-bottom: 2rpx solid #E3E3E6;
margin-bottom: 12rpx;
}
.price-item .price {
font-size: 28rpx;
color: var(--btnColor);
font-weight: 500;
}
.price-item .sum{
font-size: 34rpx;
font-weight: 500;
}
.price-item .unit{
font-size: 28rpx;
}
.discounts {
position: relative;
}
.discounts .selected {
height: 40rpx;
background: rgba(252, 91, 50, 0.12);
border-radius: 4rpx;
font-size: 24rpx;
font-weight: 500;
color: #FC5B32;
line-height: 40rpx;
padding: 0 20rpx;
position: absolute;
left: 104rpx;
top: 50%;
transform: translate(0, -50%);
}
.qr-box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.qr-box .qr {
width: 250rpx;
height: 250rpx;
background: #FFF;
border: 2rpx solid #979797;
box-sizing: border-box;
padding: 10rpx;
}
.qr-box .code {
font-size: 64rpx;
margin: 20rpx 0;
color: var(--btnColor);
}
.qr-box .tips {
color: #656566;
font-size: 24rpx;
padding-bottom: 28rpx;
}
.box_wrapper {
width: 100%;
height: 150rpx;
margin-top: 19rpx;
display: flex;
align-items: center;
position: relative;
box-sizing: border-box;
background-size: cover;
}
.box_wrapper .bg{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.box_wrapper .info{
position: relative;
z-index: 2;
width: 100%;
height: 100%;
}
.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: 20rpx;
margin-top: 6rpx;
}
.anText {
font-size: 70rpx;
/* color: rgba(white, white, white, 0.45); */
font-weight: 600;
color: #FC5B32;
/* opacity: 0.45; */
}
.price_icon {
font-size: 24rpx;
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;
text-align: center;
line-height: 44rpx;
font-size: 28rpx;
font-weight: 600;
z-index: 2;
}
.box_btn_color {
color: var(--btnColor);
}
.box_btn_color_grey {
color: #6D6D6D;
}
.title_text {
color: #282829;
font-weight: 600;
color: #282829;
font-size: 28rpx;
width: 420rpx;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.h4_text {
font-weight: 400;
color: #B1B1B3;
font-size: 24rpx;
}
.brightColor {
color: #FC5B32;
}
.darkColor {
color: #6D6D6D;
}
.describeColor {
color: #D83C14;
}
.discount {
font-size: 20rpx;
font-weight: 500;
margin-bottom: 10rpx;
}
.leftMargin {
padding-left: 32rpx;
}
\ No newline at end of file \ No newline at end of file
<block wx:if="{{orderInfo}}">
<view class="layout">
<view class="box">
<view class="status-box text-center">
<view class="icon">
<!-- // 订单状态(1:待付款;2:已支付;3:已关闭;4:已发货;5:已收货;6:待审核;7:审核通过;8:审核不通过;9:待确认收到退货;10:退款中;11:已退款;12:退款失败) -->
<block wx:if="{{orderInfo.orderStatus == 1||orderInfo.orderStatus == 13||orderInfo.orderStatus==14}}">
<glsx-image webp src="mine/order-wait.png"></glsx-image>
</block>
<block wx:elif="{{orderInfo.orderStatus == 2||orderInfo.orderStatus == 4 }}">
<glsx-image webp src="mine/order-receiving.png"></glsx-image>
</block>
<block wx:elif="{{orderInfo.orderStatus == 5||orderInfo.orderStatus == 15}}">
<glsx-image webp src="mine/order-success.png"></glsx-image>
</block>
<block wx:else>
<glsx-image webp src="mine/order-lose.png"></glsx-image>
</block>
</view>
{{statusEnum[orderInfo.orderStatus]}}
</view>
<block wx:if="{{orderInfo.deliveryCompany}}">
<view class="title">发货信息</view>
<view class="item">
<view class="label">物流信息:</view>
<view class="value">{{orderInfo.deliveryCompany || ''}}{{orderInfo.deliveryNumber || ''}}</view>
</view>
<view class="item">
<view class="label">物流进度:</view>
<view class="value">
{{deliveryStatus[orderInfo.deliveryStatus]}}
</view>
</view>
</block>
</view>
<view class="box">
<view class="title">订单信息</view>
<block wx:for="{{orderObj}}" wx:key="index">
<view class="item {{item.alignItems}}">
<view class="label">{{item.label}}:</view>
<view class="value">
<block wx:if="{{item.enum}}">
{{statusEnum[orderInfo[item.key]]|| ''}}
</block>
<block wx:else>{{orderInfo[item.key] || ''}}</block>
</view>
</view>
</block>
</view>
<view class=" box">
<view class="title">订单商品</view>
<view class="merchantName text-hide">
{{orderInfo.merchantName}}
</view>
<block wx:key="index" wx:for="{{orderInfo.orderGoods}}">
<view class="goods">
<view class="icon">
<image webp src="{{orderInfo.orderSource == 5?orderInfo.activityBigImg:item.goodsImage}}"></image>
</view>
<view class="info">
<view>
<view class="name text-hide">{{orderInfo.orderSource == 5?orderInfo.activityName:item.goodsName}}</view>
<view class="specification">{{item.specificationData || ''}}</view>
</view>
<view class="price">
¥{{orderInfo.orderSource == 5?orderInfo.payPrice:(item.activityPrice || item.retailPrice)}}
<view class="count">x{{orderInfo.orderSource == 5? 1: item.goodsNumber}}</view>
</view>
</view>
</view>
</block>
</view>
<view class="box" wx:if="{{orderInfo.orderSource!=5}}">
<view class="title">订单金额</view>
<view class="price-item">
商品总价:
<view class="price"><text class="unit">¥</text>{{orderInfo.orderPrice}}</view>
</view>
<view class="price-item line">
运费:
<view class="price"><text class="unit">¥</text>{{orderInfo.expressFee}}</view>
</view>
<view class="price-item line discounts" wx:if="{{orderInfo.subOrderCoupon.denomination}}">
优惠:
<view class="selected">已选一张</view>
<view class="price"><text class="unit">¥</text>{{(orderInfo.subOrderCoupon.discountAmount)/100}}</view>
</view>
<view class="price-item">
订单金额:
<view class="price sum"><text class="unit">¥</text>{{orderInfo.payPrice}}</view>
</view>
</view>
<!-- deliveryType 结算方式(1:到店核销,2:快递发货) -->
<block wx:if="{{orderInfo.deliveryType == 1 && qr && !orderInfo.relatedUserCoupon}}">
<view class="box">
<view class="title">核销码</view>
<view class="qr-box">
<view class="qr">
<image webp src="{{qr}}"></image>
</view>
<view class="code">{{orderInfo.orderVerification.verificationCode}}</view>
<view class="tips">请将核销码拿给店员,避免泄露给他人</view>
</view>
</view>
</block>
<view class="box" wx:if="{{orderInfo.relatedUserCoupon}}">
<view class="title">关联优惠券</view>
<block wx:for="{{couponsList}}" wx:key="index">
<view class="box_wrapper">
<glsx-image webp src="mine/coupon/{{item.usedAmount == 0?'':'un-'}}coupon-{{item.discountType}}.png" class="bg"></glsx-image>
<view class="info flex">
<view class="{{item.discountType==4 || item.discountType==7 ? '':'left_icon_box'}}">
<view wx:if="{{item.discountType==3}}" class="left_text_one left_text_two {{item.usedAmount == 0 ? 'brightColor':'darkColor'}}">
<text class="price_icon">¥</text>
<text>{{item.denomination}}</text>
</view>
<view wx:if="{{item.discountType==2}}" class="left_text_one left_text_two {{item.usedAmount == 0 ? 'brightColor':'darkColor'}}">
<text class="anText">{{item.discountIntensity / 100}}</text>
<text class="discount">折</text>
</view>
</view>
<view class="main_box {{item.discountType==4 || item.discountType==7 ? 'leftMargin':''}}">
<view class="title_text {{item.usedAmount == 0 ? 'brightColor':'darkColor'}}">{{item.couponName}}</view>
<view wx:if="{{item.useType==0 && coupons.discountType==7}}" class="h4_text {{item.usedAmount == 0 ? 'describeColor':'darkColor'}}">不限次数</view>
<view wx:if="{{item.useType==1 && coupons.discountType==7}}" class="h4_text {{item.usedAmount == 0 ? 'describeColor':'darkColor'}}">可用{{item.useAmount}}次</view>
<view wx:if="{{item.useType==2 && coupons.discountType==7}}" class="h4_text {{item.usedAmount == 0 ? 'describeColor':'darkColor'}}">{{item.useLimitDays}}天可用{{item.useAmount}}次</view>
<view wx:if="{{item.useBarriers==1 && item.discountType!=4}}" class="h4_text {{item.usedAmount == 0 ? 'describeColor':'darkColor'}}">无门槛</view>
<view wx:if="{{item.useBarriers==2 && item.discountType!=4}}" class="h4_text {{item.usedAmount == 0 ? 'describeColor':'darkColor'}}">满{{item.full}}元可用</view>
<view wx:if="{{item.effectiveType==3}}" class="h4_text {{item.usedAmount == 0 ? 'describeColor':'darkColor'}}">永久有效</view>
<view wx:if="{{item.effectiveType==2}}" class="h4_text {{item.usedAmount == 0 ? 'describeColor':'darkColor'}}">{{item.receiveStartTime}}-{{item.receiveEndTime}}</view>
<view wx:if="{{item.effectiveType==1}}" class="h4_text {{item.usedAmount == 0 ? 'describeColor':'darkColor'}}">有效至{{item.receiveEndTime}}</view>
</view>
<block wx:if="{{!hideBtn}}">
<view wx:if="{{item.usedAmount==0}}" class="box_btn box_btn_color" bind:tap="toDetail">去使用</view>
<view wx:if="{{item.usedAmount==1}}" class="box_btn box_btn_color box_btn_color_grey" bind:tap="toDetail">去查看</view>
<view wx:if="{{item.usedAmount==2}}" class="box_btn box_btn_color box_btn_color_grey" bind:tap="toDetail">去查看</view>
</block>
</view>
</view>
</block>
</view>
</view>
</block>
\ No newline at end of file \ No newline at end of file
{
"navigationStyle": "custom",
"usingComponents": {
"tab": "/components/Tab/Tab"
}
}
\ No newline at end of file \ No newline at end of file
/* packageMine/pages/order/index/index.wxss */
.sticky-box {
background-color: #fff;
}
.tab {
position: fixed;
top: 0;
left: 0;
width: 100%;
background-color: #fff;
z-index: 2;
transition: all 0.4s;
}
.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;
}
.search-box {
position: absolute;
left: 80rpx;
width: 420rpx;
height: 72rpx;
background: #f7f8fa;
border-radius: 36rpx;
display: flex;
align-items: center;
box-sizing: border-box;
padding: 0 16rpx 0 var(--margin);
}
.search-box .icon {
width: 40rpx;
height: 100%;
}
.search-box .input {
width: calc(100% - 98rpx);
}
.search-box .clear-box {
width: 58rpx;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.search-box .clear-box .clear {
width: 32rpx;
height: 32rpx;
opacity: 0.7;
}
.placeholder-class {
color: #c8c9cc;
}
.layout {
padding: 24rpx var(--margin) 40rpx;
}
.layout .item {
position: relative;
padding-left: 24rpx;
margin-bottom: 20rpx;
background-color: #fff;
box-sizing: border-box;
border-radius: var(--borderRadius);
display: flex;
flex-direction: column;
}
.layout .item .top {
height: 82rpx;
display: flex;
align-items: center;
justify-content: space-between;
padding-right: 24rpx;
position: relative;
}
.delivery-icon {
position: absolute;
width: 106rpx;
height: 80rpx;
left: 366rpx;
bottom: 0;
}
.layout .item .top .name {
width: 366rpx;
}
.layout .item .content-top {
border-top: 2rpx solid #eff0f2;
}
.layout .item .content {
border-top: 2rpx solid #eff0f2;
border-bottom: 2rpx solid #eff0f2;
}
.content-bottom {
border-bottom: 2rpx solid #eff0f2;
}
.layout .item .goods {
height: 208rpx;
padding: 24rpx 24rpx 24rpx 0;
box-sizing: border-box;
display: flex;
}
.addTo {
border-bottom: 2rpx solid #eff0f2;
}
.layout .item .goods .btn {
display: flex;
align-items: center;
justify-content: center;
width: 124rpx;
height: 46rpx;
border-radius: 25rpx;
border: 2rpx solid #b1b1b3;
font-size: 24rpx;
margin-left: 12rpx;
color: #656566;
position: absolute;
bottom: 0;
right: 0;
}
.layout .item .goods .confirm {
border-color: var(--btnColor);
color: var(--btnColor);
font-weight: 500;
}
.layout .item .icon {
width: 160rpx;
height: 160rpx;
margin-right: 20rpx;
border-radius: 8rpx;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.background-X {
background-color: rgb(244, 244, 244);
}
.layout .item .info {
width: calc(100% - 180rpx);
height: 160rpx;
display: flex;
flex-direction: column;
position: relative;
}
.layout .item .info .info-top,
.layout .item .info .info-bottom {
display: flex;
align-items: center;
justify-content: space-between;
}
.layout .item .info .info-top .price {
color: var(--btnColor);
font-size: 36rpx;
letter-spacing: -2rpx;
font-weight: 500;
flex-shrink: 0;
}
.layout .item .info .info-top .price .unit {
font-size: 24rpx;
}
.layout .item .info .info-bottom {
margin-top: 4rpx;
font-size: 24rpx;
color: #707071;
}
.layout .item .info .info-bottom .number {
margin-left: auto;
}
.layout .item .info .info-bottom .specification {
color: #b1b1b3;
}
.layout .item .status {
color: #b1b1b3;
font-size: 24rpx;
color: #282829;
}
.layout .item .bottom {
height: 80rpx;
display: flex;
align-items: center;
font-size: 24rpx;
color: #656566;
}
.layout .item .bottom .price {
color: var(--btnColor);
font-weight: 500;
}
.layout .item .btn-box {
position: absolute;
right: 24rpx;
bottom: 16rpx;
display: flex;
align-items: center;
justify-content: flex-end;
}
.layout .item .btn-box .btn {
display: flex;
align-items: center;
justify-content: center;
width: 124rpx;
height: 46rpx;
border-radius: 25rpx;
border: 2rpx solid #b1b1b3;
font-size: 24rpx;
margin-left: 12rpx;
color: #656566;
}
.layout .item .btn-box .pay {
background-color: var(--btnColor);
color: #fff;
border-color: var(--btnColor);
}
.layout .item .btn-box .empty{
color: var(--btnColor);
background-color: #fff;
}
.layout .item .btn-box .confirm {
border-color: var(--btnColor);
color: var(--btnColor);
font-weight: 500;
}
.userProfile {
background-color: #fff;
font-size: 24rpx;
margin: 0;
padding: 0;
font-weight: 500;
line-height: 46rpx;
}
.layout .coupon-item {
height: 202rpx;
background: #fefffe;
border-radius: 8rpx;
margin-bottom: 36rpx;
padding: 20rpx;
box-sizing: border-box;
position: relative;
}
.layout .coupon-item .orderPrices {
position: absolute;
color: #fc5b32;
font-size: 48rpx;
right: 32rpx;
}
.layout .coupon-item .orderPrices text {
font-size: 36rpx;
}
.layout .coupon-item .icon {
width: 162rpx;
height: 162rpx;
margin-right: 20rpx;
}
.layout .coupon-item .info {
width: 360rpx;
height: 100%;
color: #b1b1b3;
font-size: 24rpx;
}
.layout .coupon-item .info .name {
font-size: 28rpx;
font-weight: 500;
color: #282829;
}
.layout .coupon-item .info .order-btn {
width: 138rpx;
height: 48rpx;
background: #fc5b32;
border-radius: 24rpx;
margin-top: 40rpx;
color: #ffffff;
font-size: 24rpx;
}
.imageHeight {
height: 99rpx !important;
}
.imageStraight {
width: 92rpx;
height: 92rpx;
border-radius: 50%;
}
\ No newline at end of file \ No newline at end of file
...@@ -10,8 +10,7 @@ Component({ ...@@ -10,8 +10,7 @@ Component({
data: {}, data: {},
lifetimes: { lifetimes: {
ready() { ready() {
// this.getMerchantDetail() this.getMerchantDetail()
this.toCheckMember()
} }
}, },
/** /**
...@@ -19,40 +18,16 @@ Component({ ...@@ -19,40 +18,16 @@ Component({
*/ */
methods: { methods: {
getMerchantDetail() { getMerchantDetail() {
const merchantId = wx.$storage.get('srcm_shopmall_merchant_id') const {
mineApi merchantId
.getMerchantDetail() } = wx.p.storage.get('merchant_info')
.then(data => { wx.p.api.mineApi.getMerchantDetail({
if (data.bussinessBegintime) { merchantId
data.bussinessBegintime = data.bussinessBegintime.split(':')[0] + ':' + data.bussinessBegintime.split(':')[1] }).then(data => {
}
if (data.bussinessEndtime) {
data.bussinessEndtime = data.bussinessEndtime.split(':')[0] + ':' + data.bussinessEndtime.split(':')[1]
}
this.setData({ this.setData({
merchantDetail: data merchantDetail: data
}) })
this.getConsultantInfo() this.toCheckMember()
})
},
// 获取当前用户服务顾问
getConsultantInfo() {
let merchantId = wx.$storage.get('srcm_shopmall_merchant_id')
if (merchantId) {
merchantId = Number(JSON.parse(merchantId))
}
let data = {
merchantId: merchantId
}
mineApi.getConsultantInfo(data).then(({
code,
data
}) => {
if (code == '0') {
this.setData({
consultant: data
})
}
}) })
}, },
// 获取用户会员信息 // 获取用户会员信息
...@@ -95,9 +70,7 @@ Component({ ...@@ -95,9 +70,7 @@ Component({
}) })
}, },
toBuyMember() { toBuyMember() {
wx.navigateTo({ wx.p.router.go('/packageEquity/pages/open/open')
url: '/packageShopmall/packageEquity/pages/open/open'
})
} }
} }
}) })
\ No newline at end of file \ No newline at end of file
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
<view class="store-img"> <view class="store-img">
<glsx-image src="home/store-icon.png"></glsx-image> <glsx-image src="home/store-icon.png"></glsx-image>
</view> </view>
<view class="store-name">海马刀酒类旗舰店</view> <view class="store-name">{{merchantDetail.merchantName}}</view>
<view class="store-phone" bindtap="callPhone"> <view class="store-phone" bindtap="callPhone">
<glsx-image src="home/store-phone.png"></glsx-image> <glsx-image src="home/store-phone.png" ></glsx-image>
</view> </view>
</view> </view>
<view class="equity-box"> <view class="equity-box">
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
display: flex; display: flex;
z-index: 2; z-index: 2;
align-items: center; align-items: center;
position: relative;
} }
.store-img { .store-img {
...@@ -29,9 +30,12 @@ ...@@ -29,9 +30,12 @@
} }
.store-phone { .store-phone {
margin-left: auto; position: absolute;
width: 56rpx; right: 16rpx;
height: 56rpx; top: 50%;
transform: translateY(-50%);
width: 80rpx;
height: 104rpx;
} }
.equity-box { .equity-box {
......
...@@ -39,17 +39,10 @@ Component({ ...@@ -39,17 +39,10 @@ Component({
*/ */
methods: { methods: {
goOrder(e) { goOrder(e) {
let userInfo = wx.$util.getUserInfo() let tabIndex = e.currentTarget.dataset.key + 1
if (userInfo) { wx.p.router.go('/packageMine/pages/order/index/index',{
let index = e.currentTarget.dataset.key + 1 tabIndex
wx.navigateTo({
url: '/packageShopmall/packageMine/pages/order/index/index?tabIndex=' + (index || '')
}) })
} else {
wx.navigateTo({
url: '/pages/Login/Login'
})
}
} }
} }
}) })
\ No newline at end of file \ No newline at end of file
...@@ -9,11 +9,15 @@ class RouterBefore { ...@@ -9,11 +9,15 @@ class RouterBefore {
onShow = thisPage.onShow onShow = thisPage.onShow
thisPage.onLoad = function () { thisPage.onLoad = function () {
const event = getApp().globalData.ROUTE_QUERY const event = getApp().globalData.ROUTE_QUERY
const userInfo = wx.p.storage.get('userInfo')
let options = { let options = {
...event, ...event,
...arguments[0] ...arguments[0]
} }
getApp().globalData.ROUTE_QUERY = {} getApp().globalData.ROUTE_QUERY = {}
this.setData({
userInfo
})
onLoad && onLoad.apply(this, [options]), (this.options = options) onLoad && onLoad.apply(this, [options]), (this.options = options)
} }
thisPage.onShow = function () { thisPage.onShow = function () {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!