diff --git a/src/pages/prosperity-shop/goods-categary.vue b/src/pages/prosperity-shop/goods-categary.vue index 043e3e2..884ee3b 100644 --- a/src/pages/prosperity-shop/goods-categary.vue +++ b/src/pages/prosperity-shop/goods-categary.vue @@ -7,7 +7,7 @@ {{ item.status == "0" ? "正常" : "禁用" }} - 编辑 + 编辑 删除 @@ -48,9 +48,9 @@ 父级分类 - + - 提 交 + 保 存 @@ -90,6 +90,7 @@ const getCategaryTree = async () => { categoryTree.value = data ?? [] } +// 新增分类 const addCategary = () => { getCategaryTree() Object.assign(form, { @@ -102,6 +103,7 @@ const addCategary = () => { categaryFormDrawer.value = true } +// 编辑分类 const editCategary = (item) => { getCategaryTree() Object.assign(form, item) @@ -109,18 +111,14 @@ const editCategary = (item) => { categaryFormDrawer.value = true } -const currentNode = (item) => { - // form.parentId = item.categoryId -} - +// 提交保存 const saveCategary = async () => { - console.log(form) if (!form.name) return uni.showToast({ title: "请填写分类名称", icon: "none" }) if (selectedNode.value.id === form.id) return uni.showToast({ title: "父级分类不能是自身", icon: "none" }) try { const params = { ...form, parentId: selectedNode.value.id } uni.showLoading({ title: "保存中..." }) - const { code, data, msg } = await (form.id ? prosperityShopApi.editCategary(params) : prosperityShopApi.addCategary(params)) + const { code, msg } = await (form.id ? prosperityShopApi.editCategary(params) : prosperityShopApi.addCategary(params)) if (code != 0) return uni.showToast({ title: msg || "保存失败", icon: "none" }) uni.showToast({ title: "保存成功", icon: "none" }) categaryFormDrawer.value = false diff --git a/src/pages/prosperity-shop/goods-detail.vue b/src/pages/prosperity-shop/goods-detail.vue index c9ef73c..bd32bfc 100644 --- a/src/pages/prosperity-shop/goods-detail.vue +++ b/src/pages/prosperity-shop/goods-detail.vue @@ -2,20 +2,25 @@ - + ¥ - {{ state.detail.originalPrice.toFixed(2) }} + {{ displayPrice(state.detail.originalPrice, "") }} ¥ - {{ state.detail.spuPrice.toFixed(2) }} + {{ displayPrice(state.detail.spuPrice, "") }} 到手价 约省 - {{ Number(state.detail.originalPrice) - Number(state.detail.spuPrice) }} + {{ displayPrice(Number(state.detail.originalPrice) - Number(state.detail.spuPrice), "") }} 元 + + ¥ + {{ displayPrice(state.detail.skuList[0].price, "") }} + 到手价 + {{ state.detail.status == "0" ? "在售" : "未售" }} @@ -28,7 +33,7 @@ 剩余库存 {{ state.detail.totalStock }} - + 包装单位 {{ item.skuName }} diff --git a/src/pages/prosperity-shop/goods-form.vue b/src/pages/prosperity-shop/goods-form.vue index 27ca485..732ded7 100644 --- a/src/pages/prosperity-shop/goods-form.vue +++ b/src/pages/prosperity-shop/goods-form.vue @@ -74,11 +74,7 @@ 注:图片大小不超过5M - + @@ -96,12 +92,12 @@ - + - + @@ -126,17 +122,17 @@ - + - + - + @@ -175,6 +171,7 @@ import ShopCategaryPicker from "@/sheep/components/shop-categary-picker.vue" import RichTextInput from "@/sheep/components/rich-text-input/rich-text-input.vue" import { onLoad } from "@dcloudio/uni-app" import { filePath } from "@/sheep/utils/file" +import { displayPrice, storePrice } from "@/sheep/utils/formatMoney" const form = reactive({ id: "", @@ -238,21 +235,28 @@ const getGoodsDetail = async (id: string) => { const saleEndTime = data.saleEndTime _saleStartTimeStr.value = saleStartTime _saleEndTimeStr.value = saleEndTime - + // 转换HTML为Markdown格式 - const description = convertHtmlToMarkdown(data.description || '') - console.log('原始HTML:', data.description) - console.log('转换后Markdown:', description) - + const description = convertHtmlToMarkdown(data.description || "") + console.log("原始HTML:", data.description) + console.log("转换后Markdown:", description) + Object.assign(form, { ...data, status: data.status.toString(), priceType: data.priceType.toString(), + spuPrice: displayPrice(data.spuPrice, ""), + originalPrice: displayPrice(data.originalPrice, ""), coverImage, categoryName, saleStartTime, saleEndTime, - skuList, + skuList: data.skuList.map((item: any) => { + return { + ...item, + price: displayPrice(item.price, ""), + } + }), description, }) uni.hideLoading() @@ -260,48 +264,48 @@ const getGoodsDetail = async (id: string) => { // HTML转Markdown函数 const convertHtmlToMarkdown = (html: string): string => { - if (!html) return '' - + if (!html) return "" + // 移除HTML标签,保留文本内容 let markdown = html // 处理标题 - .replace(/]*>(.*?)<\/h1>/gi, '# $1\n') - .replace(/]*>(.*?)<\/h2>/gi, '## $1\n') - .replace(/]*>(.*?)<\/h3>/gi, '### $1\n') - .replace(/]*>(.*?)<\/h4>/gi, '#### $1\n') - .replace(/]*>(.*?)<\/h5>/gi, '##### $1\n') - .replace(/]*>(.*?)<\/h6>/gi, '###### $1\n') + .replace(/]*>(.*?)<\/h1>/gi, "# $1\n") + .replace(/]*>(.*?)<\/h2>/gi, "## $1\n") + .replace(/]*>(.*?)<\/h3>/gi, "### $1\n") + .replace(/]*>(.*?)<\/h4>/gi, "#### $1\n") + .replace(/]*>(.*?)<\/h5>/gi, "##### $1\n") + .replace(/]*>(.*?)<\/h6>/gi, "###### $1\n") // 处理段落 - .replace(/]*>(.*?)<\/p>/gi, '$1\n\n') + .replace(/]*>(.*?)<\/p>/gi, "$1\n\n") // 处理换行 - .replace(//gi, '\n') + .replace(//gi, "\n") // 处理粗体 - .replace(/]*>(.*?)<\/strong>/gi, '**$1**') - .replace(/]*>(.*?)<\/b>/gi, '**$1**') + .replace(/]*>(.*?)<\/strong>/gi, "**$1**") + .replace(/]*>(.*?)<\/b>/gi, "**$1**") // 处理斜体 - .replace(/]*>(.*?)<\/em>/gi, '*$1*') - .replace(/]*>(.*?)<\/i>/gi, '*$1*') + .replace(/]*>(.*?)<\/em>/gi, "*$1*") + .replace(/]*>(.*?)<\/i>/gi, "*$1*") // 处理下划线 - .replace(/]*>(.*?)<\/u>/gi, '__$1__') + .replace(/]*>(.*?)<\/u>/gi, "__$1__") // 处理链接 - .replace(/]*href=["']([^"']*)["'][^>]*>(.*?)<\/a>/gi, '[$2]($1)') + .replace(/]*href=["']([^"']*)["'][^>]*>(.*?)<\/a>/gi, "[$2]($1)") // 处理图片 - 更全面的图片处理 .replace(/]*src=["']([^"']*)["'][^>]*alt=["']([^"']*)["'][^>]*>/gi, (match, src, alt) => { // 直接使用原始URL,不添加额外前缀 - console.log('HTML图片转换 - 原始:', match) - console.log('HTML图片转换 - src:', src) - console.log('HTML图片转换 - alt:', alt) - return `![${alt || '图片'}](${src})` + console.log("HTML图片转换 - 原始:", match) + console.log("HTML图片转换 - src:", src) + console.log("HTML图片转换 - alt:", alt) + return `![${alt || "图片"}](${src})` }) .replace(/]*src=["']([^"']*)["'][^>]*>/gi, (match, src) => { // 直接使用原始URL,不添加额外前缀 - console.log('HTML图片转换 - 原始:', match) - console.log('HTML图片转换 - src:', src) + console.log("HTML图片转换 - 原始:", match) + console.log("HTML图片转换 - src:", src) return `![图片](${src})` }) // 处理列表 .replace(/]*>(.*?)<\/ul>/gis, (match, content) => { - return content.replace(/]*>(.*?)<\/li>/gi, '- $1\n') + return content.replace(/]*>(.*?)<\/li>/gi, "- $1\n") }) .replace(/]*>(.*?)<\/ol>/gis, (match, content) => { let index = 1 @@ -309,30 +313,30 @@ const convertHtmlToMarkdown = (html: string): string => { }) // 处理引用 .replace(/]*>(.*?)<\/blockquote>/gis, (match, content) => { - return content.replace(/\n/g, '\n> ') + '\n' + return content.replace(/\n/g, "\n> ") + "\n" }) // 处理代码 - .replace(/]*>(.*?)<\/code>/gi, '`$1`') - .replace(/]*>(.*?)<\/pre>/gis, '```\n$1\n```') + .replace(/]*>(.*?)<\/code>/gi, "`$1`") + .replace(/]*>(.*?)<\/pre>/gis, "```\n$1\n```") // 处理分割线 - .replace(/]*>/gi, '---\n') + .replace(/]*>/gi, "---\n") // 处理表格(简单处理) .replace(/]*>(.*?)<\/table>/gis, (match, content) => { // 这里可以添加更复杂的表格处理逻辑 return content.replace(/]*>(.*?)<\/tr>/gi, (trMatch, trContent) => { const cells = trContent.match(/]*>(.*?)<\/t[hd]>/gi) if (cells) { - return '| ' + cells.map(cell => cell.replace(/<[^>]*>/g, '')).join(' | ') + ' |\n' + return "| " + cells.map((cell) => cell.replace(/<[^>]*>/g, "")).join(" | ") + " |\n" } - return '' + return "" }) }) // 移除剩余的HTML标签 - .replace(/<[^>]*>/g, '') + .replace(/<[^>]*>/g, "") // 清理多余的换行 - .replace(/\n{3,}/g, '\n\n') + .replace(/\n{3,}/g, "\n\n") .trim() - + return markdown } @@ -379,48 +383,48 @@ const addSkuListItem = () => { // Markdown转HTML函数 const convertMarkdownToHtml = (markdown: string): string => { - if (!markdown) return '' - + if (!markdown) return "" + let html = markdown // 处理标题 - .replace(/^# (.*$)/gim, '

$1

') - .replace(/^## (.*$)/gim, '

$1

') - .replace(/^### (.*$)/gim, '

$1

') - .replace(/^#### (.*$)/gim, '

$1

') - .replace(/^##### (.*$)/gim, '
$1
') - .replace(/^###### (.*$)/gim, '
$1
') + .replace(/^# (.*$)/gim, "

$1

") + .replace(/^## (.*$)/gim, "

$1

") + .replace(/^### (.*$)/gim, "

$1

") + .replace(/^#### (.*$)/gim, "

$1

") + .replace(/^##### (.*$)/gim, "
$1
") + .replace(/^###### (.*$)/gim, "
$1
") // 处理粗体 - .replace(/\*\*(.*?)\*\*/g, '$1') + .replace(/\*\*(.*?)\*\*/g, "$1") // 处理斜体 - .replace(/\*(.*?)\*/g, '$1') + .replace(/\*(.*?)\*/g, "$1") // 处理链接 .replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1') // 处理图片 .replace(/!\[([^\]]*)\]\(([^)]+)\)/g, '$1') // 处理段落 - .replace(/^(?!<[h1-6]|$1

') + .replace(/^(?!<[h1-6]|$1

") // 处理换行 - .replace(/\n/g, '
') - + .replace(/\n/g, "
") + return html } // 保存 const onsubmit = async (evt: TM.FORM_SUBMIT_RESULT) => { // console.log("校验结果:", evt) - + // 将Markdown格式的description转换为HTML const htmlDescription = convertMarkdownToHtml(form.description) console.log("原始Markdown:", form.description) console.log("转换后HTML:", htmlDescription) - - const submitData = { - ...form, + + const submitData = { + ...form, description: htmlDescription, // 使用转换后的HTML - coverImage: JSON.parse(form.coverImage[0].response).data.url + coverImage: JSON.parse(form.coverImage[0].response).data.url, } console.log("提交的数据:", submitData) - + if (!evt.isPass) return if (form.priceType == "1") { @@ -437,10 +441,18 @@ const onsubmit = async (evt: TM.FORM_SUBMIT_RESULT) => { } try { - const params = { - ...form, + const params = { + ...form, + spuPrice: storePrice(form.spuPrice), + originalPrice: storePrice(form.originalPrice), + skuList: form.skuList.map((item) => { + return { + ...item, + price: storePrice(item.price), + } + }), description: htmlDescription, // 使用转换后的HTML - coverImage: JSON.parse(form.coverImage[0].response).data.url + coverImage: JSON.parse(form.coverImage[0].response).data.url, } uni.showLoading({ title: "提交中..." }) const { code, msg } = await (form.id ? prosperityShopApi.editGoods(params) : prosperityShopApi.addGoods(params)) diff --git a/src/pages/prosperity-shop/goods-manage.vue b/src/pages/prosperity-shop/goods-manage.vue index 12b4310..00ec454 100644 --- a/src/pages/prosperity-shop/goods-manage.vue +++ b/src/pages/prosperity-shop/goods-manage.vue @@ -70,15 +70,24 @@ 库存 {{ v.totalStock }}
- - ¥ - {{ v.originalPrice.toFixed(2) }} - - - ¥ - {{ v.spuPrice.toFixed(2).split(".")[0] }}. - {{ v.spuPrice.toFixed(2).split(".")[1] }} - + + 到手价
@@ -110,6 +119,7 @@ import { prosperityShopApi } from "@/sheep/api" import { hooks } from "@/sheep" import { filePath } from "@/sheep/utils/file" import { onLoad, onShow } from "@dcloudio/uni-app" +import { displayPrice } from "@/sheep/utils/formatMoney" const state = reactive({ params: { diff --git a/src/pages/prosperity-shop/goods-search.vue b/src/pages/prosperity-shop/goods-search.vue index d794b07..c7d4e75 100644 --- a/src/pages/prosperity-shop/goods-search.vue +++ b/src/pages/prosperity-shop/goods-search.vue @@ -49,15 +49,24 @@ 库存 {{ v.totalStock }}
- - ¥ - {{ v.originalPrice.toFixed(2) }} - - - ¥ - {{ v.spuPrice.toFixed(2).split(".")[0] }}. - {{ v.spuPrice.toFixed(2).split(".")[1] }} - + + 到手价
@@ -72,6 +81,7 @@ import { prosperityShopApi } from "@/sheep/api" import { reactive, ref } from "vue" import { filePath } from "@/sheep/utils/file" import { onLoad } from "@dcloudio/uni-app" +import { displayPrice } from "@/sheep/utils/formatMoney" const state = reactive({ params: { diff --git a/src/pages/prosperity-shop/shop-detail.vue b/src/pages/prosperity-shop/shop-detail.vue index 5c531fb..e8c6619 100644 --- a/src/pages/prosperity-shop/shop-detail.vue +++ b/src/pages/prosperity-shop/shop-detail.vue @@ -59,15 +59,24 @@ 库存 {{ v.totalStock }} - - ¥ - {{ v.originalPrice.toFixed(2) }} - - - ¥ - {{ v.spuPrice.toFixed(2).split(".")[0] }}. - {{ v.spuPrice.toFixed(2).split(".")[1] }} - + + 到手价 @@ -84,6 +93,7 @@ import { prosperityShopApi } from "@/sheep/api" import { onLoad } from "@dcloudio/uni-app" import { filePath } from "@/sheep/utils/file" import treeToList from "@/sheep/utils/tree-to-list" +import { displayPrice } from "@/sheep/utils/formatMoney" interface scrollDetail { deltaX: number diff --git a/src/pages/tabbar/prosperityShop.vue b/src/pages/tabbar/prosperityShop.vue index 17adaa1..0ed586c 100644 --- a/src/pages/tabbar/prosperityShop.vue +++ b/src/pages/tabbar/prosperityShop.vue @@ -86,14 +86,16 @@ ¥ - {{ pV.spuPrice.toFixed(2) }} + {{ pV.priceType == "1" ? displayPrice(pV.minPrice, "") : displayPrice(pV.spuPrice, "") }} {{ pV.unit || "" }} - ¥ - {{ pV.originalPrice.toFixed(2) }} + 库存{{ pV.totalStock }} @@ -114,6 +116,7 @@ import { reactive, ref } from "vue" import { filePath } from "@@/utils/file" import { getAppInfo } from "@/sheep/utils/app" import { APPENV } from "@/sheep/constant" +import { displayPrice } from "@/sheep/utils/formatMoney" const state = reactive({ params: { diff --git a/src/sheep/components/shop-categary-picker.vue b/src/sheep/components/shop-categary-picker.vue index c678f5b..940fc87 100644 --- a/src/sheep/components/shop-categary-picker.vue +++ b/src/sheep/components/shop-categary-picker.vue @@ -1,12 +1,12 @@ @@ -23,11 +23,6 @@ defineProps({ const emit = defineEmits(["confirm", "cancel"]) const selectedNode = ref({}) -const selectedCategary = ref({}) - -const currentNode = (item) => { - selectedCategary.value = item -} function onConfirm() { if (!selectedNode.value) { diff --git a/src/sheep/components/shop-categary-tree.vue b/src/sheep/components/shop-categary-tree.vue index c537437..d79fdb7 100644 --- a/src/sheep/components/shop-categary-tree.vue +++ b/src/sheep/components/shop-categary-tree.vue @@ -1,7 +1,11 @@