1. 修复价格获取的bug,应该获取诊所|药店价格而不是总仓库的

This commit is contained in:
李琦
2026-06-01 11:06:52 +08:00
parent 105f9eafa2
commit 550332d963
10 changed files with 179 additions and 63 deletions

30
common/utils/drug.js Normal file
View File

@@ -0,0 +1,30 @@
export function isWesternRxDrug(drug) {
return drug && drug.type == 2 && (drug.is_otc === 0 || drug.is_otc === '0');
}
export function isHealthFood(drug) {
return drug && (drug.type == 3 || drug.category_type === 'health_food');
}
export function canShowFunction(drug, prescriptionApproved) {
if (isHealthFood(drug)) return false;
if (isWesternRxDrug(drug)) return !!prescriptionApproved;
return true;
}
export function canShowUsage(drug, prescriptionApproved) {
if (isHealthFood(drug)) return false;
if (isWesternRxDrug(drug)) return !!prescriptionApproved;
return drug && drug.type != 3;
}
export function canShowInstruction(drug, prescriptionApproved) {
if (isWesternRxDrug(drug)) return !!prescriptionApproved;
return true;
}
export function isPrescriptionApprovedStatus(data) {
if (!data) return false;
const ps = data.prescription_status ?? data.status;
return data.status === true || ps === 1 || ps === '1' || ps === 3 || ps === '3' || ps === 4 || ps === '4';
}

View File

@@ -164,7 +164,7 @@
<view class="prod-bottom">
<view class="price-box">
<text class="price-symbol">¥</text>
<text>{{ item.price || (item.drug && item.drug.drugStoreDrug ? item.drug.drugStoreDrug.price : '0.00') }}</text>
<text>{{ item.price || '0.00' }}</text>
</view>
<!-- 简化点击事件防止 template 编译错误 -->
<view class="buy-btn" @click.stop="handleAddToCart(item)">

View File

@@ -371,8 +371,8 @@ export async function articleInfo(params) {
// v1/product-order/list
export async function getOrdlist(params) {
let data = await http('/oldApi/v1/product-order/list', params)
return data
let data = await http('/xkApi/product-order/list', params)
return normalizeXkApiResponse(data)
}
// v1/product-order/list

View File

@@ -234,7 +234,15 @@ function request(url, params, method = 0) {
// 加密
if (params != null) {
if (!params.data) {
params.data = {};
}
params.data = getRes(params.data, false);
const isProductApi = url.indexOf('/product/') !== -1;
if (isProductApi && !params.data.store_id) {
const localStoreId = uni.getStorageSync('store_id');
params.data.store_id = localStoreId || getGuestStoreId();
}
// 如果是guest模式设置store_id优先使用用户传入或本地存储的值
if (isGuestRequest && params.data) {
// 优先使用用户传入的 store_id

View File

@@ -251,6 +251,10 @@ export default {
return ['是', '否'];
},
productPrice() {
const rel = this.productDetail.drug_store_relations;
if (rel && rel.price) {
return parseFloat(rel.price);
}
if (this.productDetail.drug_store_drug && this.productDetail.drug_store_drug.price) {
return parseFloat(this.productDetail.drug_store_drug.price);
}

View File

@@ -70,7 +70,7 @@
</view>
<view class="list_west" v-if="orderInfo.ProductOrder.prescription_type==2||orderInfo.ProductOrder.prescription_type==5||orderInfo.ProductOrder.prescription_type==7">
<view class="list" v-for="(item,index) in orderInfo.ProductOrderItems" :key="item.id">
<view class="list" v-for="(item,index) in orderInfo.ProductOrderItems" :key="item.id" @click.stop="goDrugDetail(item)">
<view class="img">
<image :src="item.drug_image || 'https://xiaokang88.oss-cn-hangzhou.aliyuncs.com/xk-client-wx/static/empty/gwc.png'" mode=""></image>
</view>
@@ -80,13 +80,13 @@
<text
v-if="item.drug && item.drug.specification"
class="drug-spec">{{ item.drug.specification }}</text>
<text v-if="item.drug && item.drug.function">{{ item.drug.function }}</text>
<text v-if="item.drug && item.drug.function && canShowFunction(item.drug, prescriptionStatus)">{{ item.drug.function }}</text>
</view>
<view class="it_info" v-if="orderInfo.ProductOrder.prescription_type==2 && item.drug">
<view class="it_info" v-if="orderInfo.ProductOrder.prescription_type==2 && item.drug && canShowUsage(item.drug, prescriptionStatus)">
{{ item.drug.usage }}
</view>
<!-- 添加查看说明书按钮 -->
<view class="instruction-btn" v-if="prescriptionStatus && item.drug && item.drug.instruction" @click="previewInstruction(item.drug.instruction)">
<view class="instruction-btn" v-if="canShowInstruction(item.drug, prescriptionStatus) && item.drug && item.drug.instruction" @click.stop="previewInstruction(item.drug.instruction)">
<text>查看说明书</text>
</view>
<view class="it_price">
@@ -185,6 +185,7 @@ import {
import { getOrderTextApi } from '../../../request/api/product'
// 导入订单相关接口
import { getPrescriptionStatusApi } from '../../../request/api/order'
import { canShowFunction, canShowUsage, canShowInstruction, isPrescriptionApprovedStatus } from '@/common/utils/drug'
export default {
data() {
@@ -265,6 +266,27 @@ export default {
this.getOrderText();
},
methods: {
canShowFunction,
canShowUsage,
canShowInstruction,
goDrugDetail(item) {
const drugId = item.drug_id || (item.drug && item.drug.id);
if (!drugId) return;
const orderStoreId = (this.orderInfo.ProductOrder && this.orderInfo.ProductOrder.store_id)
|| uni.getStorageSync('store_id')
|| '11001';
const q = [
`id=${encodeURIComponent(drugId)}`,
`store_id=${encodeURIComponent(orderStoreId)}`,
`order_id=${encodeURIComponent(this.order_id || '')}`,
`drug_name=${encodeURIComponent(item.drug_name || '')}`,
`image=${encodeURIComponent(item.drug_image || '')}`,
`price=${encodeURIComponent(item.price || '')}`,
].join('&');
uni.navigateTo({
url: `/subPackages/product/symptoms?${q}`,
});
},
// 获取订单提示文本
getOrderText() {
getOrderTextApi().then((res) => {
@@ -628,8 +650,7 @@ export default {
}).then((res) => {
if (res.data && (res.data.code == 0 || res.data.errcode == 0)) {
const data = res.data.data || res.data.result || {};
const ps = data.prescription_status ?? data.status;
this.prescriptionStatus = data.status === true || ps === 1 || ps === '1' || ps === 3 || ps === '3' || ps === 4 || ps === '4';
this.prescriptionStatus = isPrescriptionApprovedStatus(data);
} else {
this.prescriptionStatus = false;
}

View File

@@ -11,7 +11,7 @@
<!-- 头部 -->
<view class="head">
<u-tabs :list="list" :is-scroll="false" :current="current" @change="onTabChange"></u-tabs>
<u-tabs :list="list" :is-scroll="true" :current="current" @change="onTabChange"></u-tabs>
</view>
<swiper class="order-swiper" :current="current" @change="onSwiperChange">
@@ -25,7 +25,7 @@
:refresher-triggered="isRefreshing"
@refresherrefresh="onRefresherRefresh"
>
<block v-if="current === tabIdx">
<block v-if="Number(current) === tabIdx">
<!-- 空页 orderList.length==0 -->
<view class="empty" v-if="orderList.length==0">
<image src="https://xiaokang88.oss-cn-hangzhou.aliyuncs.com/xk-client-wx/static/empty/orders.png" mode="aspectFit"></image>
@@ -103,11 +103,11 @@
</view>
<view class="_specit">
<!-- 抛弃三元表达式使用 v-if 防小程序编译 BUG -->
<text class="xy_func" v-if="it.drug && it.drug.function">{{ it.drug.function }}</text>
<text class="xy_func" v-if="it.drug && it.drug.function && canShowFunction(it.drug, false)">{{ it.drug.function }}</text>
<text class="xy_func" v-else></text>
<view class="number_specit">
<!-- 最原生最安全的取值方式确保多商品列表下规格渲染不会被吞 -->
<text class="xy_spec" v-if="it.drug && it.drug.specification">{{ it.drug.specification }}1</text>
<text class="xy_spec" v-if="it.drug && it.drug.specification">{{ it.drug.specification }}</text>
<text v-else></text>
<text class="xy_num">x{{it.number}}</text>
</view>
@@ -147,10 +147,6 @@
<view class="order_info active" v-else-if="item.status==2 && item.is_pay==1" @tap.stop="getReceive(item.id)">
签收
</view>
<view class="order_info active" v-else-if="item.is_pay==0 && item.status==0 && item.cancel_status==0"
@tap.stop="goCancel(item.id)">
取消
</view>
<view class="order_info" v-else-if="item.status==9 || item.cancel_status==1">
已取消
</view>
@@ -167,6 +163,11 @@
<view class="order_info active" v-else-if="(item.status===2||item.status===6||item.status===7) && item.is_pay==1 && item.cancel_status==0 && item.delivery_method === 0" @tap.stop="toDevilty(item.id)">
查看物流
</view>
<!-- <view class="order_info active" v-if="item.is_pay==0 && item.status==0 && item.cancel_status==0"-->
<!-- @tap.stop="goCancel(item.id)">-->
<!-- 取消-->
<!-- </view>-->
</view>
</view>
<u-loadmore :status="loadMoreStatus" v-if="orderList.length!=0" margin-top="30" margin-bottom="30" />
@@ -187,6 +188,7 @@ import {
getPayConfig,
postRefundBased
} from '../../../request/api/api';
import { canShowFunction } from '@/common/utils/drug';
export default {
data() {
@@ -207,6 +209,12 @@ export default {
},
{
name: '已完成'
},
{
name: '退款'
},
{
name: '已取消'
}
],
keyword: "",
@@ -231,7 +239,8 @@ export default {
},
onLoad(e) {
this.order_id = e.id
this.change(e.index);
const tabIndex = parseInt(e.index, 10);
this.change(Number.isNaN(tabIndex) ? 0 : tabIndex);
},
computed: {
@@ -240,6 +249,7 @@ export default {
this.scrollTop = e.scrollTop;
},
methods: {
canShowFunction,
// scroll-view 专用下拉刷新响应
onRefresherRefresh() {
this.isRefreshing = true;
@@ -280,24 +290,10 @@ export default {
},
// 点击切换
change(index) {
// console.log(index);
this.current = index;
if (this.current == 0) {
this.status = ''
}
if (this.current == 1) {
// unpaid未支付 wait_send代发货 wait_accept已发货 finished已完成
this.status = 'unpaid'
}
if (this.current == 2) {
this.status = 'wait_send'
}
if (this.current == 3) {
this.status = 'wait_accept'
}
if (this.current == 4) {
this.status = 'finished'
}
const tabIndex = Number(index) || 0;
this.current = tabIndex;
const statusMap = ['', 'unpaid', 'wait_send', 'wait_accept', 'finished', 'refund', 'cancel'];
this.status = statusMap[tabIndex] ?? '';
this.orderList = []
this.page = 1
this.getList()

View File

@@ -97,12 +97,12 @@
</view>
<view class="it">
<view class="it_name">{{item.content.drug_name}}{{item.content.specification}}</view>
<view class="it_info">
<view class="it_info" v-if="canShowUsage(item.content, prescriptionStatus)">
{{item.content.usage}}
</view>
<view
class="instruction-btn"
v-if="prescriptionStatus && item.content && item.content.instruction"
v-if="canShowInstruction(item.content, prescriptionStatus) && item.content && item.content.instruction"
@click="previewInstruction(item.content.instruction)"
>
<text>查看说明书</text>
@@ -206,6 +206,7 @@
// 导入 getOrderTextApi 接口方法
import { getOrderTextApi } from '../../request/api/product'
import { getPrescriptionStatusApi } from '../../request/api/order'
import { canShowUsage, canShowInstruction, isPrescriptionApprovedStatus } from '@/common/utils/drug'
export default {
data() {
@@ -287,6 +288,8 @@
},
methods: {
canShowUsage,
canShowInstruction,
// 获取订单提示文本
getOrderText() {
getOrderTextApi().then((res) => {
@@ -518,8 +521,7 @@
}).then((res) => {
if (res.data && (res.data.code == 0 || res.data.errcode == 0)) {
const data = res.data.data || res.data.result || {}
const ps = data.prescription_status ?? data.status
this.prescriptionStatus = data.status === true || ps === 1 || ps === '1' || ps === 3 || ps === '3' || ps === 4 || ps === '4'
this.prescriptionStatus = isPrescriptionApprovedStatus(data)
} else {
this.prescriptionStatus = false
}

View File

@@ -94,7 +94,7 @@
</view>
<!-- 保健食品不展示用法用量 -->
<view class="info-card" v-if="productDetail.type != 3">
<view class="info-card" v-if="showUsageSection">
<view class="section-title-modern">
<view class="indicator"></view>
<text>用法用量</text>
@@ -104,8 +104,8 @@
</view>
</view>
<!-- 说明书入口 - 处方药不展示 -->
<view class="info-card" v-if="!(productDetail.is_otc == 0 && productDetail.type == 2)">
<!-- 说明书入口 - 处方药未审核通过不展示 -->
<view class="info-card" v-if="showInstructionSection">
<view class="section-title-modern">
<view class="indicator"></view>
<text>说明书</text>
@@ -146,7 +146,7 @@
<view class="footer-placeholder"></view>
<!-- 底部操作栏 -->
<view class="footer-bar safe-area-inset-bottom">
<view class="footer-bar safe-area-inset-bottom" v-if="!hidePurchase">
<view class="icons-area">
<view class="icon-item" @click="goBack">
<u-icon name="home" size="40" color="#606266"></u-icon>
@@ -243,8 +243,9 @@
<script>
// 完整引入原有API
import { getOrderTextApi, getStoreDrugDetailApi } from "@/request/api/product";
import { genOrderApi } from "@/request/api/order";
import { genOrderApi, getPrescriptionStatusApi } from "@/request/api/order";
import { getCartCountsApi, saveCartApi } from "@/request/api/cart";
import { canShowFunction, canShowUsage, canShowInstruction, isPrescriptionApprovedStatus } from '@/common/utils/drug';
export default {
data() {
return {
@@ -291,10 +292,18 @@ export default {
orderText: '本次商品物流配送,由萧康医药提供服务。',
introductionImages: [], // 商品介绍图数组
delegateStoreId: '', // 委托诊所ID
fromOrderId: '',
orderStoreId: '',
prescriptionApproved: false,
hidePurchase: false,
};
},
computed: {
productPrice() {
const rel = this.productDetail.drug_store_relations;
if (rel && rel.price) {
return parseFloat(rel.price);
}
if (this.productDetail.drug_store_drug && this.productDetail.drug_store_drug.price) {
return parseFloat(this.productDetail.drug_store_drug.price);
}
@@ -308,12 +317,23 @@ export default {
return (this.productDetail.supplier && this.productDetail.supplier.name) || '';
},
showFunctionSection() {
if (this.productDetail.category_type === 'health_food') return false;
if (this.productDetail.type == 2 && this.productDetail.is_otc === 0) return false;
return true;
return canShowFunction(this.productDetail, this.prescriptionApproved);
},
showUsageSection() {
return canShowUsage(this.productDetail, this.prescriptionApproved);
},
showInstructionSection() {
return canShowInstruction(this.productDetail, this.prescriptionApproved);
}
},
onLoad(options) {
if (options.store_id) {
this.orderStoreId = options.store_id;
}
if (options.order_id) {
this.fromOrderId = options.order_id;
this.hidePurchase = true;
}
if (options.id) {
this.productDetail.id = options.id;
this.formData.id = options.id;
@@ -327,21 +347,48 @@ export default {
this.productDetail.price = parseFloat(options.price || 0);
// 获取委托诊所ID如果有
this.delegateStoreId = options.delegate_store_id || '';
this.getDetail();
this.initPageData();
} else {
const savedId = uni.getStorageSync('symptoms_id');
if (savedId) {
this.productDetail.id = savedId;
this.formData.id = savedId;
this.getDetail();
this.initPageData();
}
}
this.updateCartCount();
if (!this.hidePurchase) {
this.updateCartCount();
}
},
onShow() {
this.updateCartCount();
if (!this.hidePurchase) {
this.updateCartCount();
}
},
methods: {
initPageData() {
if (this.fromOrderId) {
this.fetchPrescriptionStatus().then(() => {
this.getDetail();
});
} else {
this.getDetail();
}
},
fetchPrescriptionStatus() {
return getPrescriptionStatusApi({
order_id: this.fromOrderId,
}).then((res) => {
if (res.data && (res.data.code == 0 || res.data.errcode == 0)) {
const data = res.data.data || res.data.result || {};
this.prescriptionApproved = isPrescriptionApprovedStatus(data);
} else {
this.prescriptionApproved = false;
}
}).catch(() => {
this.prescriptionApproved = false;
});
},
getOrderText() {
getOrderTextApi().then((res) => {
if (res.data && res.data.result) {
@@ -352,14 +399,27 @@ export default {
})
},
getDetail() {
let that = this;
this.getOrderText();
getStoreDrugDetailApi({
const params = {
id: this.productDetail.id,
}).then((res) => {
store_id: this.orderStoreId || uni.getStorageSync('store_id') || '11001',
};
if (this.fromOrderId) {
params.order_id = this.fromOrderId;
}
getStoreDrugDetailApi(params).then((res) => {
if (res.data.code === 0) {
const data = res.data.result;
Object.assign(this.productDetail, data);
if (data.prescription_approved !== undefined) {
this.prescriptionApproved = !!data.prescription_approved;
}
if (data.hide_purchase !== undefined) {
this.hidePurchase = !!data.hide_purchase;
}
if (data.order_store_id && !this.orderStoreId) {
this.orderStoreId = data.order_store_id;
}
this.productImages = data.image ? [data.image] : [];
if (!this.productDetail.indications && data.function) {
this.productDetail.indications = data.function;

View File

@@ -44,7 +44,7 @@
<!-- 价格与数量控制器 -->
<view class="it_price">
<!-- 显示价格 -->
<text>{{ item.drug.drugstore_drug ? item.drug.drugstore_drug.price : (item.drug.drug_store_relations ? item.drug.drug_store_relations.price : '0.00') }}</text>
<text>{{ item.drug.drug_store_relations ? item.drug.drug_store_relations.price : '0.00' }}</text>
<!-- 步进器点击阻止冒泡防止触发选中 -->
<view class="it_num" @click.stop>
@@ -125,11 +125,8 @@ export default {
const checkedItems = this.cartLists.data.filter(item => item.checked);
checkedItems.forEach(item => {
// 兼容不同字段结构获取价格
let price = 0;
if(item.drug && item.drug.drugstore_drug && item.drug.drugstore_drug.price) {
price = item.drug.drugstore_drug.price;
} else if (item.drug && item.drug.drug_store_relations && item.drug.drug_store_relations.price) {
if (item.drug && item.drug.drug_store_relations && item.drug.drug_store_relations.price) {
price = item.drug.drug_store_relations.price;
}
@@ -158,9 +155,7 @@ export default {
// 获取显示价格,逻辑与模板保持一致
let price = '0';
if (item.drug.drugstore_drug && item.drug.drugstore_drug.price) {
price = item.drug.drugstore_drug.price;
} else if (item.drug.drug_store_relations && item.drug.drug_store_relations.price) {
if (item.drug.drug_store_relations && item.drug.drug_store_relations.price) {
price = item.drug.drug_store_relations.price;
}