merchant.vue 11 KB

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