merchant.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. <template>
  2. <view class="container">
  3. <!-- 商家信息-->
  4. <view class="padding20">
  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 padding30" 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">
  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. await footprintScan(obj)
  173. appStore.USERINFO();
  174. // 当浏览的店铺主页不是上次浏览店铺时,才改变状态
  175. if(query.value.merchantId != appStore.userInfo.lastVisitedMerchantId){
  176. appStore.setIndexRefersh(true)
  177. }
  178. getSbmerchantInfo(data).then((res) => {
  179. console.log(res);
  180. merchantInfo.value = res.data;
  181. })
  182. }
  183. const tabChange = (item) => {
  184. console.log('item',item)
  185. tabActive.value = item.code;
  186. if(item.code==1){
  187. try {
  188. setTimeout(()=>{
  189. nextTick(()=>{
  190. merchantCateRef.value.infoScroll();
  191. })
  192. },500)
  193. } catch (error) {
  194. console.log(error)
  195. //TODO handle the exception
  196. }
  197. }
  198. }
  199. // Product Lists
  200. const getGroomList = async () => {
  201. if (!goodScroll.value) return;
  202. try {
  203. loading.value = true;
  204. query.value.merchantId!='' ? params.value.merchantId = query.value.merchantId:'';
  205. const { data } = await getGroomListApi(goodType.value, params.value);
  206. goodsList.value = [...goodsList.value, ...data.productList.list] || [];
  207. goodScroll.value = data.productList.list.length >= params.value.limit;
  208. params.value.page++;
  209. } catch (err) {
  210. console.error(err);
  211. } finally {
  212. loading.value = false;
  213. }
  214. };
  215. // 在methods部分添加:
  216. const makePhoneCall = () => {
  217. if (!merchantInfo.value.merchantPhone) {
  218. uni.showToast({
  219. title: '暂无联系电话',
  220. icon: 'none'
  221. });
  222. return;
  223. }
  224. // 显示确认弹窗
  225. uni.showModal({
  226. title: '拨打电话',
  227. content: `是否拨打 ${merchantInfo.value.merchantPhone}?`,
  228. success: (res) => {
  229. if (res.confirm) {
  230. // 调用拨打电话API
  231. uni.makePhoneCall({
  232. phoneNumber: merchantInfo.value.merchantPhone,
  233. success: () => {
  234. console.log('拨打电话成功');
  235. },
  236. fail: (err) => {
  237. console.log('拨打电话失败:', err);
  238. uni.showToast({
  239. title: '拨打电话失败',
  240. icon: 'none'
  241. });
  242. }
  243. });
  244. }
  245. }
  246. });
  247. };
  248. const goDetail = async (item) => {
  249. uni.navigateTo({ url: `/pages/goods/goods_details/index?id=${item.id}` });
  250. };
  251. </script>
  252. <style scoped lang="scss">
  253. .container{
  254. //padding: 30rpx;
  255. //box-sizing: border-box;
  256. }
  257. .store-card{
  258. background: #ffffff;
  259. border-radius: 16rpx;
  260. padding: 20rpx;
  261. margin-bottom: 10rpx;
  262. .info-top{
  263. display: flex;
  264. justify-content: center;
  265. align-items: center;
  266. background-color: #F9F7F0;
  267. border-radius: 16rpx;
  268. padding: 20rpx 0;
  269. .left{
  270. width: 140rpx;
  271. .storeImg{
  272. width: 100rpx;
  273. height: 100rpx;
  274. border-radius: 50%;
  275. }
  276. }
  277. .center{
  278. width: 70%;
  279. .name{
  280. font-size: 32rpx;
  281. color: #333;line-height: 60rpx;
  282. }
  283. }
  284. }
  285. .desc{
  286. font-size: 24rpx;
  287. color: #666;
  288. line-height: 40rpx;
  289. padding: 20rpx 0;
  290. }
  291. .tel{
  292. font-size: 28rpx;
  293. color:#333;
  294. line-height: 40rpx;
  295. .phone2{
  296. width: 32rpx;
  297. height: 32rpx;
  298. }
  299. .phone{
  300. width: 40rpx;
  301. height: 40rpx;
  302. vertical-align: middle;
  303. }
  304. }
  305. }
  306. .mr20{
  307. margin-right: 20rpx;
  308. }
  309. .fr{
  310. float: right;
  311. }
  312. .index-product-wrapper {
  313. //padding: 0 30rpx;
  314. margin-bottom: 110rpx;
  315. min-height: 700rpx;
  316. margin-top: 30rpx;
  317. //background: #fff;
  318. position: relative;
  319. &.on {
  320. min-height: 1500rpx;
  321. }
  322. .list-box {
  323. display: flex;
  324. flex-wrap: wrap;
  325. justify-content: space-between;
  326. .item {
  327. width: 48.99%;
  328. height: 490rpx;
  329. background-color: #ffffff;
  330. box-shadow: 0rpx 3rpx 13rpx 0rpx rgba(0, 0, 0, 0.13);
  331. border-radius: 20rpx;
  332. margin-bottom: 20rpx;
  333. overflow: hidden;
  334. display: flex;
  335. flex-direction: column;
  336. justify-content: space-between;
  337. .pictrue {
  338. position: relative;
  339. image {
  340. width: 100%;
  341. height: 330rpx;
  342. }
  343. }
  344. .text-info {
  345. padding: 10rpx 20rpx 15rpx;
  346. .title {
  347. color: #222222;
  348. display: flex;
  349. align-items: center;
  350. justify-items: space-between;
  351. .tip {
  352. width: 61rpx;
  353. height: auto;
  354. font-size: 22rpx;
  355. display: flex;
  356. justify-content: center;
  357. align-items: center;
  358. color: #ffffff;
  359. position: relative;
  360. margin-right: 5rpx;
  361. background-color: #ef4800;
  362. border-radius: 5rpx;
  363. }
  364. .text{
  365. width: 80%;
  366. }
  367. .weight{
  368. background-color: rgba(197, 128, 3, 0.10);
  369. color: #C58003;
  370. font-size: 24rpx;
  371. padding: 8rpx 16rpx;
  372. border-radius: 8rpx;
  373. float: right;
  374. }
  375. }
  376. .bottom-row {
  377. color: $theme-color;
  378. display: flex;
  379. justify-content: space-between;
  380. align-items: center;
  381. font-size: 28rpx;
  382. margin: 10rpx 0 0;
  383. .price {
  384. padding-bottom: 4rpx;
  385. font-weight: 800;
  386. white-space: nowrap;
  387. font-size: 28rpx;
  388. color: #f16327;
  389. }
  390. .sales {
  391. color: #b4b4b4;
  392. font-size: 22rpx;
  393. white-space: nowrap;
  394. color: #6e6e6e;
  395. }
  396. }
  397. }
  398. }
  399. &.on {
  400. display: flex;
  401. }
  402. }
  403. }
  404. .no-data {
  405. margin: 150rpx auto 0;
  406. text-align: center;
  407. img {
  408. width: 65%;
  409. height: auto;
  410. }
  411. }
  412. .mores-txt {
  413. width: 100%;
  414. align-items: center;
  415. justify-content: center;
  416. height: 70rpx;
  417. color: #999;
  418. font-size: 24rpx;
  419. .iconfont {
  420. margin-top: 2rpx;
  421. font-size: 20rpx;
  422. }
  423. }
  424. </style>