useGoods.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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) {
  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(orderInfo.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("confirm");
  90. }
  91. if (order.logisticsId > 0) {
  92. order.buttons.push("express");
  93. }
  94. if (order.status === 0) {
  95. order.buttons.push("cancel");
  96. order.buttons.push("pay");
  97. }
  98. if (order.status === 30 && !order.commentStatus) {
  99. order.buttons.push("comment");
  100. }
  101. if (order.status === 40) {
  102. order.buttons.push("delete");
  103. }
  104. }
  105. function formatAfterSaleStatus(afterSale) {
  106. if (afterSale.status === 10) {
  107. return "申请售后";
  108. }
  109. if (afterSale.status === 20) {
  110. return "商品待退货";
  111. }
  112. if (afterSale.status === 30) {
  113. return "商家待收货";
  114. }
  115. if (afterSale.status === 40) {
  116. return "等待退款";
  117. }
  118. if (afterSale.status === 50) {
  119. return "退款成功";
  120. }
  121. if (afterSale.status === 61) {
  122. return "买家取消";
  123. }
  124. if (afterSale.status === 62) {
  125. return "商家拒绝";
  126. }
  127. if (afterSale.status === 63) {
  128. return "商家拒收货";
  129. }
  130. return "未知状态";
  131. }
  132. function formatAfterSaleStatusDescription(afterSale) {
  133. if (afterSale.status === 10) {
  134. return "退款申请待商家处理";
  135. }
  136. if (afterSale.status === 20) {
  137. return "请退货并填写物流信息";
  138. }
  139. if (afterSale.status === 30) {
  140. return "退货退款申请待商家处理";
  141. }
  142. if (afterSale.status === 40) {
  143. return "等待退款";
  144. }
  145. if (afterSale.status === 50) {
  146. return "退款成功";
  147. }
  148. if (afterSale.status === 61) {
  149. return "退款关闭";
  150. }
  151. if (afterSale.status === 62) {
  152. return `商家不同意退款申请,拒绝原因:${afterSale.auditReason}`;
  153. }
  154. if (afterSale.status === 63) {
  155. return `商家拒绝收货,不同意退款,拒绝原因:${afterSale.auditReason}`;
  156. }
  157. return "未知状态";
  158. }
  159. function handleAfterSaleButtons(afterSale) {
  160. afterSale.buttons = [];
  161. if ([10, 20, 30].includes(afterSale.status)) {
  162. afterSale.buttons.push("cancel");
  163. }
  164. if (afterSale.status === 20) {
  165. afterSale.buttons.push("delivery");
  166. }
  167. }
  168. function useDurationTime(toTime, fromTime = "") {
  169. toTime = getDayjsTime(toTime);
  170. if (fromTime === "") {
  171. fromTime = common_vendor.dayjs();
  172. }
  173. let duration = common_vendor.ref(toTime - fromTime);
  174. if (duration.value > 0) {
  175. setTimeout(() => {
  176. if (duration.value > 0) {
  177. duration.value -= 1e3;
  178. }
  179. }, 1e3);
  180. }
  181. let durationTime = common_vendor.dayjs.duration(duration.value);
  182. return {
  183. h: (durationTime.months() * 30 * 24 + durationTime.days() * 24 + durationTime.hours()).toString().padStart(2, "0"),
  184. m: durationTime.minutes().toString().padStart(2, "0"),
  185. s: durationTime.seconds().toString().padStart(2, "0"),
  186. ms: durationTime.$ms
  187. };
  188. }
  189. function getDayjsTime(time) {
  190. time = time.toString();
  191. if (time.indexOf("-") > 0) {
  192. return common_vendor.dayjs(time);
  193. }
  194. if (time.length > 10) {
  195. return common_vendor.dayjs(parseInt(time));
  196. }
  197. if (time.length === 10) {
  198. return common_vendor.dayjs.unix(parseInt(time));
  199. }
  200. }
  201. function fen2yuan(price) {
  202. return (price / 100).toFixed(2);
  203. }
  204. function convertProductPropertyList(skus) {
  205. let result = [];
  206. for (const sku of skus) {
  207. if (!sku.properties) {
  208. continue;
  209. }
  210. for (const property of sku.properties) {
  211. let resultProperty = result.find((item) => item.id === property.propertyId);
  212. if (!resultProperty) {
  213. resultProperty = {
  214. id: property.propertyId,
  215. name: property.propertyName,
  216. values: []
  217. };
  218. result.push(resultProperty);
  219. }
  220. let resultValue = resultProperty.values.find((item) => item.id === property.valueId);
  221. if (!resultValue) {
  222. resultProperty.values.push({
  223. id: property.valueId,
  224. name: property.valueName
  225. });
  226. }
  227. }
  228. }
  229. return result;
  230. }
  231. function formatRewardActivityRule(activity, rule) {
  232. if (activity.conditionType === 10) {
  233. return `满 ${fen2yuan(rule.limit)} 元减 ${fen2yuan(rule.discountPrice)} 元`;
  234. }
  235. if (activity.conditionType === 20) {
  236. return `满 ${rule.limit} 件减 ${fen2yuan(rule.discountPrice)} 元`;
  237. }
  238. return "";
  239. }
  240. exports.convertProductPropertyList = convertProductPropertyList;
  241. exports.fen2yuan = fen2yuan;
  242. exports.formatAfterSaleStatus = formatAfterSaleStatus;
  243. exports.formatAfterSaleStatusDescription = formatAfterSaleStatusDescription;
  244. exports.formatGoodsSwiper = formatGoodsSwiper;
  245. exports.formatOrderColor = formatOrderColor;
  246. exports.formatOrderStatus = formatOrderStatus;
  247. exports.formatOrderStatusDescription = formatOrderStatusDescription;
  248. exports.formatRewardActivityRule = formatRewardActivityRule;
  249. exports.formatSales = formatSales;
  250. exports.formatStock = formatStock;
  251. exports.handleAfterSaleButtons = handleAfterSaleButtons;
  252. exports.handleOrderButtons = handleOrderButtons;
  253. exports.useDurationTime = useDurationTime;