merchant.vue 12 KB

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