merchant.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <view class="container">
  3. <!-- 商家信息-->
  4. <view class="merchant-info">
  5. <view class="store-card">
  6. <view class="info-top">
  7. <view class="left">
  8. <image class="storeImg" :src="merchantInfo.merchantLogo" mode="aspectFill"></image>
  9. </view>
  10. <view class="center">
  11. <view class="name">{{merchantInfo.merchantName}}</view>
  12. </view>
  13. </view>
  14. <view class="desc">{{merchantInfo.merchantDescribe}}</view>
  15. <view class="tel" @click="makePhoneCall">
  16. <image class="phone2 mr20" src="@/static/images/phone2.png"></image>
  17. <text>联系电话:{{merchantInfo.merchantPhone}}</text>
  18. <image class="phone fr" src="@/static/images/phone.png"></image>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 商品-->
  23. <up-tabs :list="tabList"
  24. @click="tabChange"
  25. lineColor="#333333"
  26. :itemStyle="{
  27. flex:1,
  28. height:'44px',
  29. }"
  30. :activeStyle="{
  31. color: '#333333',
  32. fontWeight: 'bold',
  33. transform: 'scale(1.05)'
  34. }"
  35. :inactiveStyle="{
  36. color: '#666666',
  37. transform: 'scale(1)'
  38. }"></up-tabs>
  39. <!-- 商品列表-->
  40. <view class="index-product-wrapper" v-if="tabActive == '0'">
  41. <view
  42. class="list-box animated"
  43. :class="goodsList.length > 0 ? 'fadeIn on' : ''"
  44. >
  45. <view
  46. class="item"
  47. v-for="(item, index) in calculatedProducts"
  48. :key="index"
  49. @click="goDetail(item)"
  50. >
  51. <view class="pictrue">
  52. <image :src="item.image" mode=""></image>
  53. </view>
  54. <view class="text-info">
  55. <view class="title" >
  56. <view class="text line1">{{ item.storeName }}</view>
  57. <view class="weight">{{ item.weight }}g</view>
  58. </view>
  59. <view class="bottom-row">
  60. <!-- <text class="price">工费: {{ item.price }}/克</text> -->
  61. <text class="price">¥ {{ item.totalPrice }}</text>
  62. <text class="sales" style="color:#666;">
  63. 销量:{{ Number(item.sales || 0) + Number(item.ficti || 0) }}件
  64. </text>
  65. <!-- <view class="txt">券</view> -->
  66. </view>
  67. <view class="bottom-row">
  68. <!-- <text class="price">工费: {{ item.price }}/克</text> -->
  69. <text class="sales">工费:¥{{ item.totalLaborCost }}</text>
  70. <text class="sales">
  71. 附加费:¥{{ item.additionalAmount }}
  72. </text>
  73. <!-- <view class="txt">券</view> -->
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="loadingicon acea-row row-center-wrapper" v-if="goodScroll">
  79. <text
  80. class="loading iconfont icon-jiazai"
  81. :hidden="loading == false"
  82. ></text>
  83. </view>
  84. <view class="no-data" v-if="isNoDataState">
  85. <image
  86. src="https://my-go-easy-im.oss-cn-shenzhen.aliyuncs.com/goeasy-im-%E6%B0%B4%E8%B4%9D%E5%95%86%E5%9F%8E/zhanwu_20250827104005_1720_6.png"
  87. />
  88. </view>
  89. <view class="mores-txt flex" v-if="!goodScroll && !isNoDataState">
  90. <text>我是有底线的</text>
  91. </view>
  92. </view>
  93. <view class="index-product-wrapper" v-show="tabActive == '1'">
  94. <merchantCate ref="merchantCateRef" :merchant-id="query.merchantId || merchantInfo.id" />
  95. </view>
  96. </view>
  97. </template>
  98. <script setup>
  99. import {computed, nextTick, ref} from 'vue';
  100. import { onLoad, onShow, onReachBottom } from "@dcloudio/uni-app";
  101. import { getSbmerchantInfo } from "@/api/merchant.js";
  102. import merchantCate from "./components/merchant_cate.vue"
  103. import { getGroomList as getGroomListApi, } from "@/api/store.js";
  104. import { footprintScan } from "@/api/merchant.js";
  105. import { useAppStore } from "@/stores/app";
  106. const appStore = useAppStore();
  107. // 获取实时金价
  108. import useRealGoldPrice from "@/hooks/useRealGoldPrice";
  109. // 实时价格处理
  110. const {
  111. realGoldprice, // 黄金实时销售价(基础)
  112. realPtprice, // 铂金实时销售价(基础)
  113. realAgprice, // 白银实时销售价(基础)
  114. } = useRealGoldPrice({});
  115. const query = ref({});
  116. const merchantInfo = ref({});
  117. const tabList = ref([
  118. {name:'推荐商品',code:'0'},
  119. {name:'商品分类',code:'1'}
  120. ])
  121. const tabActive = ref('0');
  122. const goodsList = ref([]);
  123. const goodType = ref(1);
  124. // Pagination
  125. const params = ref({
  126. page: 1,
  127. limit: 10,
  128. });
  129. const loading = ref(false);
  130. const goodScroll = ref(true);
  131. const merchantCateRef = ref()
  132. const calculatedProducts = computed(() => {
  133. // 计算逻辑与原代码一致,但基于响应式数据 products
  134. return goodsList.value.map((product) => {
  135. // 1. 将price字符串转为数字
  136. const price = Number(product.price);
  137. // 2. 计算乘积
  138. const total = (price + product.sales) * realGoldprice.value;
  139. // 3. 向上取整到两位小数(先放大100倍取整,再缩小100倍)
  140. const roundedTotal = Math.ceil(total * 100) / 100;
  141. // 4. 格式化保留两位小数
  142. const formattedTotal = roundedTotal.toFixed(2);
  143. const totalLaborCost = Number(product.totalLaborCost);
  144. const additionalAmount = Number(product.additionalAmount);
  145. const totalPrice = (totalLaborCost+additionalAmount).toFixed(2);
  146. return {
  147. ...product,
  148. calculatedTotal: formattedTotal, // 新增计算结果字段
  149. totalPrice
  150. };
  151. });
  152. });
  153. const isNoDataState = computed(() => {
  154. return goodsList.value.length === 0 && !loading.value;
  155. });
  156. onLoad((options) => {
  157. query.value = options;
  158. getSbmerchantInfoFn();
  159. getGroomList();
  160. });
  161. onReachBottom(() => {
  162. getGroomList();
  163. });
  164. const getSbmerchantInfoFn = async () => {
  165. let data = {
  166. merchantId:query.value.merchantId
  167. }
  168. let obj ={
  169. merchantId:query.value.merchantId,
  170. userId:appStore?.userInfo?.userId
  171. }
  172. if(appStore?.userInfo?.userId){
  173. await footprintScan(obj)
  174. appStore.USERINFO();
  175. }
  176. // 当浏览的店铺主页不是上次浏览店铺时,才改变状态
  177. if(query.value.merchantId != appStore?.userInfo?.lastVisitedMerchantId){
  178. appStore.setIndexRefersh(true)
  179. }
  180. getSbmerchantInfo(data).then((res) => {
  181. console.log(res);
  182. merchantInfo.value = res.data;
  183. })
  184. }
  185. const tabChange = (item) => {
  186. console.log('item',item)
  187. tabActive.value = item.code;
  188. if(item.code==1){
  189. try {
  190. setTimeout(()=>{
  191. nextTick(()=>{
  192. merchantCateRef.value.infoScroll();
  193. })
  194. },500)
  195. } catch (error) {
  196. console.log(error)
  197. //TODO handle the exception
  198. }
  199. }
  200. }
  201. // Product Lists
  202. const getGroomList = async () => {
  203. if (!goodScroll.value) return;
  204. try {
  205. loading.value = true;
  206. query.value.merchantId!='' ? params.value.merchantId = query.value.merchantId:'';
  207. const { data } = await getGroomListApi(goodType.value, params.value);
  208. goodsList.value = [...goodsList.value, ...data.productList.list] || [];
  209. goodScroll.value = data.productList.list.length >= params.value.limit;
  210. params.value.page++;
  211. } catch (err) {
  212. console.error(err);
  213. } finally {
  214. loading.value = false;
  215. }
  216. };
  217. // 在methods部分添加:
  218. const makePhoneCall = () => {
  219. if (!merchantInfo.value.merchantPhone) {
  220. uni.showToast({
  221. title: '暂无联系电话',
  222. icon: 'none'
  223. });
  224. return;
  225. }
  226. // 显示确认弹窗
  227. uni.showModal({
  228. title: '拨打电话',
  229. content: `是否拨打 ${merchantInfo.value.merchantPhone}?`,
  230. success: (res) => {
  231. if (res.confirm) {
  232. // 调用拨打电话API
  233. uni.makePhoneCall({
  234. phoneNumber: merchantInfo.value.merchantPhone,
  235. success: () => {
  236. console.log('拨打电话成功');
  237. },
  238. fail: (err) => {
  239. console.log('拨打电话失败:', err);
  240. uni.showToast({
  241. title: '拨打电话失败',
  242. icon: 'none'
  243. });
  244. }
  245. });
  246. }
  247. }
  248. });
  249. };
  250. const goDetail = async (item) => {
  251. uni.navigateTo({ url: `/pages/goods/goods_details/index?id=${item.id}` });
  252. };
  253. </script>
  254. <style scoped lang="scss">
  255. .container{
  256. //padding: 30rpx;
  257. //box-sizing: border-box;
  258. }
  259. .merchant-info{
  260. padding: 16rpx 16rpx 0;
  261. }
  262. .store-card{
  263. background: #ffffff;
  264. border-radius: 16rpx;
  265. padding: 20rpx;
  266. .info-top{
  267. display: flex;
  268. justify-content: center;
  269. align-items: center;
  270. background-color: #F9F7F0;
  271. border-radius: 16rpx;
  272. padding: 20rpx 0;
  273. .left{
  274. width: 140rpx;
  275. .storeImg{
  276. width: 100rpx;
  277. height: 100rpx;
  278. border-radius: 50%;
  279. }
  280. }
  281. .center{
  282. width: 70%;
  283. .name{
  284. font-size: 32rpx;
  285. color: #333;line-height: 60rpx;
  286. }
  287. }
  288. }
  289. .desc{
  290. font-size: 24rpx;
  291. color: #666;
  292. line-height: 40rpx;
  293. padding: 20rpx 0;
  294. }
  295. .tel{
  296. font-size: 28rpx;
  297. color:#333;
  298. line-height: 40rpx;
  299. .phone2{
  300. width: 32rpx;
  301. height: 32rpx;
  302. }
  303. .phone{
  304. width: 40rpx;
  305. height: 40rpx;
  306. vertical-align: middle;
  307. }
  308. }
  309. }
  310. .mr20{
  311. margin-right: 20rpx;
  312. }
  313. .fr{
  314. float: right;
  315. }
  316. .index-product-wrapper {
  317. padding: 0 16rpx 16rpx;
  318. margin-bottom: 110rpx;
  319. min-height: 700rpx;
  320. margin-top: 16rpx;
  321. //background: #fff;
  322. position: relative;
  323. &.on {
  324. min-height: 1500rpx;
  325. }
  326. .list-box {
  327. display: flex;
  328. flex-wrap: wrap;
  329. justify-content: space-between;
  330. .item {
  331. width: 48.99%;
  332. // height: 490rpx;
  333. background-color: #ffffff;
  334. // box-shadow: 0rpx 3rpx 13rpx 0rpx rgba(0, 0, 0, 0.13);
  335. border-radius: 16rpx;
  336. margin-bottom: 16rpx;
  337. overflow: hidden;
  338. display: flex;
  339. flex-direction: column;
  340. justify-content: space-between;
  341. .pictrue {
  342. position: relative;
  343. image {
  344. width: 100%;
  345. height: 330rpx;
  346. }
  347. }
  348. .text-info {
  349. padding: 16rpx 8rpx;
  350. .title {
  351. color: #333;
  352. display: flex;
  353. align-items: center;
  354. justify-items: space-between;
  355. .tip {
  356. width: 61rpx;
  357. height: auto;
  358. font-size: 22rpx;
  359. display: flex;
  360. justify-content: center;
  361. align-items: center;
  362. color: #ffffff;
  363. position: relative;
  364. margin-right: 5rpx;
  365. background-color: #ef4800;
  366. border-radius: 5rpx;
  367. }
  368. .text{
  369. width: 80%;
  370. }
  371. .weight{
  372. background-color: rgba(197, 128, 3, 0.10);
  373. color: #C58003;
  374. font-size: 24rpx;
  375. padding: 8rpx 16rpx;
  376. border-radius: 8rpx;
  377. float: right;
  378. }
  379. }
  380. .bottom-row {
  381. color: $theme-color;
  382. display: flex;
  383. justify-content: space-between;
  384. align-items: center;
  385. font-size: 28rpx;
  386. margin: 10rpx 0 0;
  387. .price {
  388. padding-bottom: 4rpx;
  389. font-weight: 800;
  390. white-space: nowrap;
  391. font-size: 28rpx;
  392. color: #f16327;
  393. }
  394. .sales {
  395. color: #b4b4b4;
  396. font-size: 22rpx;
  397. white-space: nowrap;
  398. color: #6e6e6e;
  399. }
  400. }
  401. }
  402. }
  403. &.on {
  404. display: flex;
  405. }
  406. }
  407. }
  408. .no-data {
  409. margin: 150rpx auto 0;
  410. text-align: center;
  411. img {
  412. width: 65%;
  413. height: auto;
  414. }
  415. }
  416. .mores-txt {
  417. width: 100%;
  418. align-items: center;
  419. justify-content: center;
  420. height: 70rpx;
  421. color: #999;
  422. font-size: 24rpx;
  423. .iconfont {
  424. margin-top: 2rpx;
  425. font-size: 20rpx;
  426. }
  427. }
  428. </style>