acdr-ui/dist/dev/mp-weixin/sheep/hooks/useGoods.js.map

1 line
16 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{"version":3,"file":"useGoods.js","sources":["../../../../../src/sheep/hooks/useGoods.js"],"sourcesContent":["import { ref } from 'vue'\r\nimport dayjs from 'dayjs'\r\nimport $url from '@/sheep/url'\r\nimport { formatDate } from '@/sheep/util'\r\n\r\n/**\r\n * 格式化销量\r\n * @param {'exact' | string} type 格式类型exact=精确值,其它=大致数量\r\n * @param {number} num 销量\r\n * @return {string} 格式化后的销量字符串\r\n */\r\nexport function formatSales(type, num) {\r\n const prefix = type !== 'exact' && num < 10 ? '销量' : '已售'\r\n return formatNum(prefix, type, num)\r\n}\r\n\r\n/**\r\n * 格式化兑换量\r\n * @param {'exact' | string} type 格式类型exact=精确值,其它=大致数量\r\n * @param {number} num 销量\r\n * @return {string} 格式化后的销量字符串\r\n */\r\nexport function formatExchange(type, num) {\r\n return formatNum('已兑换', type, num)\r\n}\r\n\r\n/**\r\n * 格式化库存\r\n * @param {'exact' | any} type 格式类型exact=精确值,其它=大致数量\r\n * @param {number} num 销量\r\n * @return {string} 格式化后的销量字符串\r\n */\r\nexport function formatStock(type, num) {\r\n return formatNum('库存', type, num)\r\n}\r\n\r\n/**\r\n * 格式化数字\r\n * @param {string} prefix 前缀\r\n * @param {'exact' | string} type 格式类型exact=精确值,其它=大致数量\r\n * @param {number} num 销量\r\n * @return {string} 格式化后的销量字符串\r\n */\r\nexport function formatNum(prefix, type, num) {\r\n num = num || 0\r\n // 情况一:精确数值\r\n if (type === 'exact') {\r\n return prefix + num\r\n }\r\n // 情况二:小于等于 10\r\n if (num < 10) {\r\n return `${prefix}≤10`\r\n }\r\n // 情况三:大于 10除第一位外其它位都显示为0\r\n // 例如100 - 199 显示为 100+\r\n // 9000 - 9999 显示为 9000+\r\n const numStr = num.toString()\r\n const first = numStr[0]\r\n const other = '0'.repeat(numStr.length - 1)\r\n return `${prefix}${first}${other}+`\r\n}\r\n\r\n// 格式化价格\r\nexport function formatPrice(e) {\r\n return e.length === 1 ? e[0] : e.join('~')\r\n}\r\n\r\n// 视频格式后缀列表\r\nconst VIDEO_SUFFIX_LIST = ['.avi', '.mp4']\r\n\r\n/**\r\n * 转换商品轮播的链接列表:根据链接的后缀,判断是视频链接还是图片链接\r\n *\r\n * @param {string[]} urlList 链接列表\r\n * @return {{src: string, type: 'video' | 'image' }[]} 转换后的链接列表\r\n */\r\nexport function formatGoodsSwiper(urlList) {\r\n return (\r\n urlList\r\n ?.filter((url) => url)\r\n .map((url, key) => {\r\n const isVideo = VIDEO_SUFFIX_LIST.some((suffix) => url.includes(suffix))\r\n const type = isVideo ? 'video' : 'image'\r\n const src = $url.cdn(url)\r\n return { type, src }\r\n }) || []\r\n )\r\n}\r\n\r\n/**\r\n * 格式化订单状态的颜色\r\n *\r\n * @param order 订单\r\n * @return {string} 颜色的 class 名称\r\n */\r\nexport function formatOrderColor(order) {\r\n if (order.status === 0) {\r\n return 'info-color'\r\n }\r\n if (order.status === 10 || order.status === 20 || (order.status === 30 && !order.commentStatus)) {\r\n return 'warning-color'\r\n }\r\n if (order.status === 30 && order.commentStatus) {\r\n return 'success-color'\r\n }\r\n return 'danger-color'\r\n}\r\n\r\n/**\r\n * 格式化订单状态\r\n *\r\n * @param order 订单\r\n */\r\nexport function formatOrderStatus(order) {\r\n if (order.status === 0) {\r\n return '待付款'\r\n }\r\n if (order.status === 10 && order.deliveryType === 1) {\r\n return '待发货'\r\n }\r\n if (order.status === 10 && order.deliveryType === 2) {\r\n return '待核销'\r\n }\r\n if (order.status === 20) {\r\n return '待收货'\r\n }\r\n if (order.status === 30 && !order.commentStatus) {\r\n return '待评价'\r\n }\r\n if (order.status === 30 && order.commentStatus) {\r\n return '已完成'\r\n }\r\n return '已关闭'\r\n}\r\n\r\n/**\r\n * 格式化订单状态的描述\r\n *\r\n * @param order 订单\r\n */\r\nexport function formatOrderStatusDescription(order) {\r\n if (order.status === 0) {\r\n return `请在 ${formatDate(order.payExpireTime)} 前完成支付`\r\n }\r\n if (order.status === 10) {\r\n return '商家未发货,请耐心等待'\r\n }\r\n if (order.status === 20) {\r\n return '商家已发货,请耐心等待'\r\n }\r\n if (order.status === 30 && !order.commentStatus) {\r\n return '已收货,快去评价一下吧'\r\n }\r\n if (order.status === 30 && order.commentStatus) {\r\n return '交易完成,感谢您的支持'\r\n }\r\n return '交易关闭'\r\n}\r\n\r\n/**\r\n * 处理订单的 button 操作按钮数组\r\n *\r\n * @param order 订单\r\n */\r\nexport function handleOrderButtons(order) {\r\n order.buttons = []\r\n if (order.type === 3) {\r\n // 查看拼团\r\n order.buttons.push('combination')\r\n }\r\n if (order.status === 20) {\r\n // 确认收货\r\n order.buttons.push('confirm')\r\n }\r\n if (order.logisticsId > 0) {\r\n // 查看物流\r\n order.buttons.push('express')\r\n }\r\n if (order.status === 0) {\r\n // 取消订单 / 发起支付\r\n order.buttons.push('cancel')\r\n order.buttons.push('pay')\r\n }\r\n if (order.status === 30 && !order.commentStatus) {\r\n // 发起评价\r\n order.buttons.push('comment')\r\n }\r\n if (order.status === 40) {\r\n // 删除订单\r\n order.buttons.push('delete')\r\n }\r\n}\r\n\r\n/**\r\n * 格式化售后状态\r\n *\r\n * @param afterSale 售后\r\n */\r\nexport function formatAfterSaleStatus(afterSale) {\r\n if (afterSale.status === 10) {\r\n return '申请售后'\r\n }\r\n if (afterSale.status === 20) {\r\n return '商品待退货'\r\n }\r\n if (afterSale.status === 30) {\r\n return '商家待收货'\r\n }\r\n if (afterSale.status === 40) {\r\n return '等待退款'\r\n }\r\n if (afterSale.status === 50) {\r\n return '退款成功'\r\n }\r\n if (afterSale.status === 61) {\r\n return '买家取消'\r\n }\r\n if (afterSale.status === 62) {\r\n return '商家拒绝'\r\n }\r\n if (afterSale.status === 63) {\r\n return '商家拒收货'\r\n }\r\n return '未知状态'\r\n}\r\n\r\n/**\r\n * 格式化售后状态的描述\r\n *\r\n * @param afterSale 售后\r\n */\r\nexport function formatAfterSaleStatusDescription(afterSale) {\r\n if (afterSale.status === 10) {\r\n return '退款申请待商家处理'\r\n }\r\n if (afterSale.status === 20) {\r\n return '请退货并填写物流信息'\r\n }\r\n if (afterSale.status === 30) {\r\n return '退货退款申请待商家处理'\r\n }\r\n if (afterSale.status === 40) {\r\n return '等待退款'\r\n }\r\n if (afterSale.status === 50) {\r\n return '退款成功'\r\n }\r\n if (afterSale.status === 61) {\r\n return '退款关闭'\r\n }\r\n if (afterSale.status === 62) {\r\n return `商家不同意退款申请,拒绝原因:${afterSale.auditReason}`\r\n }\r\n if (afterSale.status === 63) {\r\n return `商家拒绝收货,不同意退款,拒绝原因:${afterSale.auditReason}`\r\n }\r\n return '未知状态'\r\n}\r\n\r\n/**\r\n * 处理售后的 button 操作按钮数组\r\n *\r\n * @param afterSale 售后\r\n */\r\nexport function handleAfterSaleButtons(afterSale) {\r\n afterSale.buttons = []\r\n if ([10, 20, 30].includes(afterSale.status)) {\r\n // 取消订单\r\n afterSale.buttons.push('cancel')\r\n }\r\n if (afterSale.status === 20) {\r\n // 退货信息\r\n afterSale.buttons.push('delivery')\r\n }\r\n}\r\n\r\n/**\r\n * 倒计时\r\n * @param toTime 截止时间\r\n * @param fromTime 起始时间,默认当前时间\r\n * @return {{s: string, ms: number, h: string, m: string}} 持续时间\r\n */\r\nexport function useDurationTime(toTime, fromTime = '') {\r\n toTime = getDayjsTime(toTime)\r\n if (fromTime === '') {\r\n fromTime = dayjs()\r\n }\r\n const duration = ref(toTime - fromTime)\r\n if (duration.value > 0) {\r\n setTimeout(() => {\r\n if (duration.value > 0) {\r\n duration.value -= 1000\r\n }\r\n }, 1000)\r\n }\r\n\r\n const durationTime = dayjs.duration(duration.value)\r\n return {\r\n h: (durationTime.months() * 30 * 24 + durationTime.days() * 24 + durationTime.hours())\r\n .toString()\r\n .padStart(2, '0'),\r\n m: durationTime.minutes().toString().padStart(2, '0'),\r\n s: durationTime.seconds().toString().padStart(2, '0'),\r\n ms: durationTime.$ms,\r\n }\r\n}\r\n\r\n/**\r\n * 转换为 Dayjs\r\n * @param {any} time 时间\r\n * @return {dayjs.Dayjs}\r\n */\r\nfunction getDayjsTime(time) {\r\n time = time.toString()\r\n if (time.indexOf('-') > 0) {\r\n // 'date'\r\n return dayjs(time)\r\n }\r\n if (time.length > 10) {\r\n // 'timestamp'\r\n return dayjs(parseInt(time))\r\n }\r\n if (time.length === 10) {\r\n // 'unixTime'\r\n return dayjs.unix(parseInt(time))\r\n }\r\n}\r\n\r\n/**\r\n * 将分转成元\r\n *\r\n * @param price 分,例如说 100 分\r\n * @returns {string} 元,例如说 1.00 元\r\n */\r\nexport function fen2yuan(price) {\r\n return (price / 100.0).toFixed(2)\r\n}\r\n\r\n/**\r\n * 从商品 SKU 数组中,转换出商品属性的数组\r\n *\r\n * 类似结构:[{\r\n * id: // 属性的编号\r\n * name: // 属性的名字\r\n * values: [{\r\n * id: // 属性值的编号\r\n * name: // 属性值的名字\r\n * }]\r\n * }]\r\n *\r\n * @param skus 商品 SKU 数组\r\n */\r\nexport function convertProductPropertyList(skus) {\r\n const result = []\r\n for (const sku of skus) {\r\n if (!sku.properties) {\r\n continue\r\n }\r\n for (const property of sku.properties) {\r\n // ① 先处理属性\r\n let resultProperty = result.find((item) => item.id === property.propertyId)\r\n if (!resultProperty) {\r\n resultProperty = {\r\n id: property.propertyId,\r\n name: property.propertyName,\r\n values: [],\r\n }\r\n result.push(resultProperty)\r\n }\r\n // ② 再处理属性值\r\n const resultValue = resultProperty.values.find((item) => item.id === property.valueId)\r\n if (!resultValue) {\r\n resultProperty.values.push({\r\n id: property.valueId,\r\n name: property.valueName,\r\n })\r\n }\r\n }\r\n }\r\n return result\r\n}\r\n\r\n/**\r\n * 格式化满减送活动的规则\r\n *\r\n * @param activity 活动信息\r\n * @param rule 优惠规格\r\n * @returns {string} 规格字符串\r\n */\r\nexport function formatRewardActivityRule(activity, rule) {\r\n if (activity.conditionType === 10) {\r\n return `满 ${fen2yuan(rule.limit)} 元减 ${fen2yuan(rule.discountPrice)} 元`\r\n }\r\n if (activity.conditionType === 20) {\r\n return `满 ${rule.limit} 件减 ${fen2yuan(rule.discountPrice)} 元`\r\n }\r\n return ''\r\n}\r\n"],"names":["$url","formatDate","dayjs","ref"],"mappings":";;;;AAWO,SAAS,YAAY,MAAM,KAAK;AACrC,QAAM,SAAS,SAAS,WAAW,MAAM,KAAK,OAAO;AACrD,SAAO,UAAU,QAAQ,MAAM,GAAG;AACpC;AAkBO,SAAS,YAAY,MAAM,KAAK;AACrC,SAAO,UAAU,MAAM,MAAM,GAAG;AAClC;AASO,SAAS,UAAU,QAAQ,MAAM,KAAK;AAC3C,QAAM,OAAO;AAEb,MAAI,SAAS,SAAS;AACpB,WAAO,SAAS;AAAA,EACjB;AAED,MAAI,MAAM,IAAI;AACZ,WAAO,GAAG,MAAM;AAAA,EACjB;AAID,QAAM,SAAS,IAAI,SAAU;AAC7B,QAAM,QAAQ,OAAO,CAAC;AACtB,QAAM,QAAQ,IAAI,OAAO,OAAO,SAAS,CAAC;AAC1C,SAAO,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK;AAClC;AAQA,MAAM,oBAAoB,CAAC,QAAQ,MAAM;AAQlC,SAAS,kBAAkB,SAAS;AACzC,UACE,mCACI,OAAO,CAAC,QAAQ,KACjB,IAAI,CAAC,KAAK,QAAQ;AACjB,UAAM,UAAU,kBAAkB,KAAK,CAAC,WAAW,IAAI,SAAS,MAAM,CAAC;AACvE,UAAM,OAAO,UAAU,UAAU;AACjC,UAAM,MAAMA,gBAAAA,KAAK,IAAI,GAAG;AACxB,WAAO,EAAE,MAAM,IAAK;AAAA,EACrB,OAAK,CAAE;AAEd;AAQO,SAAS,iBAAiB,OAAO;AACtC,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO;AAAA,EACR;AACD,MAAI,MAAM,WAAW,MAAM,MAAM,WAAW,MAAO,MAAM,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