useGoods.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_url_index = require("../url/index.js");
  4. const sheep_util_index = require("../util/index.js");
  5. function formatSales(type, num) {
  6. let prefix = type !== "exact" && num < 10 ? "销量" : "已售";
  7. return formatNum(prefix, type, num);
  8. }
  9. function formatStock(type, num) {
  10. return formatNum("库存", type, num);
  11. }
  12. function formatNum(prefix, type, num) {
  13. num = num || 0;
  14. if (type === "exact") {
  15. return prefix + num;
  16. }
  17. if (num < 10) {
  18. return `${prefix}≤10`;
  19. }
  20. let pow = Math.pow(10, `${num}`.length - 1);
  21. return `${prefix}${num / pow * pow}+`;
  22. }
  23. const VIDEO_SUFFIX_LIST = [".avi", ".mp4"];
  24. function formatGoodsSwiper(urlList) {
  25. return (urlList == null ? void 0 : urlList.filter((url) => url).map((url, key) => {
  26. const isVideo = VIDEO_SUFFIX_LIST.some((suffix) => url.includes(suffix));
  27. const type = isVideo ? "video" : "image";
  28. const src = sheep_url_index.$url.cdn(url);
  29. return { type, src };
  30. })) || [];
  31. }
  32. function formatOrderColor(order) {
  33. if (order.status === 0) {
  34. return "info-color";
  35. }
  36. if (order.status === 10 || order.status === 20 || order.status === 30 && !order.commentStatus) {
  37. return "warning-color";
  38. }
  39. if (order.status === 30 && order.commentStatus) {
  40. return "success-color";
  41. }
  42. return "danger-color";
  43. }
  44. function formatOrderStatus(order) {
  45. if (order.status === 0) {
  46. return "待付款";
  47. }
  48. if (order.status === 10 && order.deliveryType === 1 || order.status === 10 && order.deliveryType === 3) {
  49. return "待发货";
  50. }
  51. if (order.status === 10 && order.deliveryType === 2) {
  52. return "待核销";
  53. }
  54. if (order.status === 20) {
  55. return "待收货";
  56. }
  57. if (order.status === 30 && !order.commentStatus) {
  58. return "待评价";
  59. }
  60. if (order.status === 30 && order.commentStatus) {
  61. return "已完成";
  62. }
  63. return "已关闭";
  64. }
  65. function formatOrderStatusDescription(order) {
  66. if (order.status === 0) {
  67. return `请在 ${sheep_util_index.formatDate(order.payExpireTime)} 前完成支付`;
  68. }
  69. if (order.status === 10) {
  70. return "商家未发货,请耐心等待";
  71. }
  72. if (order.status === 20) {
  73. return "商家已发货,请耐心等待";
  74. }
  75. if (order.status === 30 && !order.commentStatus) {
  76. return "已收货,快去评价一下吧";
  77. }
  78. if (order.status === 30 && order.commentStatus) {
  79. return "交易完成,感谢您的支持";
  80. }
  81. return "交易关闭";
  82. }
  83. function handleOrderButtons(order) {
  84. order.buttons = [];
  85. if (order.type === 3) {
  86. order.buttons.push("combination");
  87. }
  88. if (order.status === 20) {
  89. order.buttons.push("express");
  90. order.buttons.push("confirm");
  91. }
  92. if (order.logisticsId > 0) {
  93. order.buttons.push("express");
  94. }
  95. if (order.status === 0) {
  96. order.buttons.push("cancel");
  97. order.buttons.push("pay");
  98. }
  99. if (order.status === 30 && !order.commentStatus) {
  100. order.buttons.push("comment");
  101. }
  102. if (order.status === 40) {
  103. order.buttons.push("delete");
  104. }
  105. }
  106. function formatAfterSaleStatus(afterSale) {
  107. if (afterSale.status === 10) {
  108. return "申请售后";
  109. }
  110. if (afterSale.status === 20) {
  111. return "商品待退货";
  112. }
  113. if (afterSale.status === 30) {
  114. return "商家待收货";
  115. }
  116. if (afterSale.status === 40) {
  117. return "等待退款";
  118. }
  119. if (afterSale.status === 50) {
  120. return "退款成功";
  121. }
  122. if (afterSale.status === 61) {
  123. return "买家取消";
  124. }
  125. if (afterSale.status === 62) {
  126. return "商家拒绝";
  127. }
  128. if (afterSale.status === 63) {
  129. return "商家拒收货";
  130. }
  131. return "未知状态";
  132. }
  133. function formatAfterSaleStatusDescription(afterSale) {
  134. if (afterSale.status === 10) {
  135. return "退款申请待商家处理";
  136. }
  137. if (afterSale.status === 20) {
  138. return "请退货并填写物流信息";
  139. }
  140. if (afterSale.status === 30) {
  141. return "退货退款申请待商家处理";
  142. }
  143. if (afterSale.status === 40) {
  144. return "等待退款";
  145. }
  146. if (afterSale.status === 50) {
  147. return "退款成功";
  148. }
  149. if (afterSale.status === 61) {
  150. return "退款关闭";
  151. }
  152. if (afterSale.status === 62) {
  153. return `商家不同意退款申请,拒绝原因:${afterSale.auditReason}`;
  154. }
  155. if (afterSale.status === 63) {
  156. return `商家拒绝收货,不同意退款,拒绝原因:${afterSale.auditReason}`;
  157. }
  158. return "未知状态";
  159. }
  160. function handleAfterSaleButtons(afterSale) {
  161. afterSale.buttons = [];
  162. if ([10, 20, 30].includes(afterSale.status)) {
  163. afterSale.buttons.push("cancel");
  164. }
  165. if (afterSale.status === 20) {
  166. afterSale.buttons.push("delivery");
  167. }
  168. }
  169. function useDurationTime(toTime, fromTime = "") {
  170. toTime = getDayjsTime(toTime);
  171. if (fromTime === "") {
  172. fromTime = common_vendor.dayjs();
  173. }
  174. let duration = common_vendor.ref(toTime - fromTime);
  175. if (duration.value > 0) {
  176. setTimeout(() => {
  177. if (duration.value > 0) {
  178. duration.value -= 1e3;
  179. }
  180. }, 1e3);
  181. }
  182. let durationTime = common_vendor.dayjs.duration(duration.value);
  183. return {
  184. h: (durationTime.months() * 30 * 24 + durationTime.days() * 24 + durationTime.hours()).toString().padStart(2, "0"),
  185. m: durationTime.minutes().toString().padStart(2, "0"),
  186. s: durationTime.seconds().toString().padStart(2, "0"),
  187. ms: durationTime.$ms
  188. };
  189. }
  190. function getDayjsTime(time) {
  191. time = time.toString();
  192. if (time.indexOf("-") > 0) {
  193. return common_vendor.dayjs(time);
  194. }
  195. if (time.length > 10) {
  196. return common_vendor.dayjs(parseInt(time));
  197. }
  198. if (time.length === 10) {
  199. return common_vendor.dayjs.unix(parseInt(time));
  200. }
  201. }
  202. function fen2yuan(price) {
  203. return (price / 100).toFixed(2);
  204. }
  205. function fen2yuan6(price) {
  206. return (price / 100).toFixed(6);
  207. }
  208. function points2point(point) {
  209. return (point / 1e6).toFixed(3).slice(0, -1);
  210. }
  211. function convertProductPropertyList(skus) {
  212. let result = [];
  213. for (const sku of skus) {
  214. if (!sku.properties) {
  215. continue;
  216. }
  217. for (const property of sku.properties) {
  218. let resultProperty = result.find((item) => item.id === property.propertyId);
  219. if (!resultProperty) {
  220. resultProperty = {
  221. id: property.propertyId,
  222. name: property.propertyName,
  223. values: []
  224. };
  225. result.push(resultProperty);
  226. }
  227. let resultValue = resultProperty.values.find((item) => item.id === property.valueId);
  228. if (!resultValue) {
  229. resultProperty.values.push({
  230. id: property.valueId,
  231. name: property.valueName
  232. });
  233. }
  234. }
  235. }
  236. return result;
  237. }
  238. function formatRewardActivityRule(activity, rule) {
  239. if (activity.conditionType === 10) {
  240. return `满 ${fen2yuan(rule.limit)} 元减 ${fen2yuan(rule.discountPrice)} 元`;
  241. }
  242. if (activity.conditionType === 20) {
  243. return `满 ${rule.limit} 件减 ${fen2yuan(rule.discountPrice)} 元`;
  244. }
  245. return "";
  246. }
  247. exports.convertProductPropertyList = convertProductPropertyList;
  248. exports.fen2yuan = fen2yuan;
  249. exports.fen2yuan6 = fen2yuan6;
  250. exports.formatAfterSaleStatus = formatAfterSaleStatus;
  251. exports.formatAfterSaleStatusDescription = formatAfterSaleStatusDescription;
  252. exports.formatGoodsSwiper = formatGoodsSwiper;
  253. exports.formatOrderColor = formatOrderColor;
  254. exports.formatOrderStatus = formatOrderStatus;
  255. exports.formatOrderStatusDescription = formatOrderStatusDescription;
  256. exports.formatRewardActivityRule = formatRewardActivityRule;
  257. exports.formatSales = formatSales;
  258. exports.formatStock = formatStock;
  259. exports.handleAfterSaleButtons = handleAfterSaleButtons;
  260. exports.handleOrderButtons = handleOrderButtons;
  261. exports.points2point = points2point;
  262. exports.useDurationTime = useDurationTime;