merchant.vue 11 KB

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