merchant.vue 11 KB

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