index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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">
  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/phoneyellow.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">
  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>
  92. </template>
  93. <script setup>
  94. import {computed, ref} from 'vue';
  95. import { onLoad, onShow, onReachBottom } from "@dcloudio/uni-app";
  96. import { getSbmerchantInfo } from "@/api/merchant.js";
  97. import {
  98. getGroomList as getGroomListApi,
  99. } from "@/api/store.js";
  100. // 获取实时金价
  101. import useRealGoldPrice from "@/hooks/useRealGoldPrice";
  102. // 实时价格处理
  103. const {
  104. realGoldprice, // 黄金实时销售价(基础)
  105. realPtprice, // 铂金实时销售价(基础)
  106. realAgprice, // 白银实时销售价(基础)
  107. } = useRealGoldPrice({});
  108. const query = ref({});
  109. const merchantInfo = ref({});
  110. const tabList = ref([
  111. {name:'推荐商品'},
  112. {name:'商品分类'}
  113. ])
  114. const goodsList = ref([]);
  115. const goodType = ref(1);
  116. // Pagination
  117. const params = ref({
  118. page: 1,
  119. limit: 10,
  120. });
  121. const loading = ref(false);
  122. const goodScroll = ref(true);
  123. const calculatedProducts = computed(() => {
  124. // 计算逻辑与原代码一致,但基于响应式数据 products
  125. return goodsList.value.map((product) => {
  126. // 1. 将price字符串转为数字
  127. const price = Number(product.price);
  128. // 2. 计算乘积
  129. const total = (price + product.sales) * realGoldprice.value;
  130. // 3. 向上取整到两位小数(先放大100倍取整,再缩小100倍)
  131. const roundedTotal = Math.ceil(total * 100) / 100;
  132. // 4. 格式化保留两位小数
  133. const formattedTotal = roundedTotal.toFixed(2);
  134. return {
  135. ...product,
  136. calculatedTotal: formattedTotal, // 新增计算结果字段
  137. };
  138. });
  139. });
  140. const isNoDataState = computed(() => {
  141. return goodsList.value.length === 0 && !loading.value;
  142. });
  143. onLoad((options) => {
  144. query.value = options;
  145. getSbmerchantInfoFn();
  146. getGroomList();
  147. });
  148. onReachBottom(() => {
  149. getGroomList();
  150. });
  151. const getSbmerchantInfoFn = () => {
  152. let data = {
  153. merchantId:query.value.merchantId
  154. }
  155. getSbmerchantInfo(data).then((res) => {
  156. console.log(res);
  157. merchantInfo.value = res.data;
  158. })
  159. }
  160. const tabChange = (item) => {
  161. console.log('item',item)
  162. }
  163. // Product Lists
  164. const getGroomList = async () => {
  165. if (!goodScroll.value) return;
  166. try {
  167. loading.value = true;
  168. query.value.merchantId!='' ? params.value.merchantId = query.value.merchantId:'';
  169. const { data } = await getGroomListApi(goodType.value, params.value);
  170. goodsList.value = [...goodsList.value, ...data.productList.list] || [];
  171. goodScroll.value = data.productList.list.length >= params.value.limit;
  172. params.value.page++;
  173. } catch (err) {
  174. console.error(err);
  175. } finally {
  176. loading.value = false;
  177. }
  178. };
  179. </script>
  180. <style scoped lang="scss">
  181. .container{
  182. padding: 30rpx;
  183. box-sizing: border-box;
  184. }
  185. .store-card{
  186. background: #ffffff;
  187. border-radius: 16rpx;
  188. padding: 20rpx;
  189. margin-bottom: 10rpx;
  190. .info-top{
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. background-color: #F9F7F0;
  195. border-radius: 16rpx;
  196. .left{
  197. width: 140rpx;
  198. .storeImg{
  199. width: 100rpx;
  200. height: 100rpx;
  201. }
  202. }
  203. .center{
  204. width: 70%;
  205. .name{
  206. font-size: 32rpx;
  207. color: #333;line-height: 60rpx;
  208. }
  209. }
  210. }
  211. .desc{
  212. font-size: 24rpx;
  213. color: #666;
  214. line-height: 40rpx;
  215. padding: 20rpx 0;
  216. }
  217. .tel{
  218. font-size: 28rpx;
  219. color:#333;
  220. line-height: 40rpx;
  221. .phone{
  222. width: 34rpx;
  223. vertical-align: middle;
  224. }
  225. }
  226. }
  227. .mr20{
  228. margin-right: 20rpx;
  229. }
  230. .fr{
  231. float: right;
  232. }
  233. .index-product-wrapper {
  234. //padding: 0 30rpx;
  235. margin-bottom: 110rpx;
  236. min-height: 700rpx;
  237. margin-top: 30rpx;
  238. //background: #fff;
  239. &.on {
  240. min-height: 1500rpx;
  241. }
  242. .list-box {
  243. display: flex;
  244. flex-wrap: wrap;
  245. justify-content: space-between;
  246. .item {
  247. width: 48.99%;
  248. height: 490rpx;
  249. background-color: #ffffff;
  250. box-shadow: 0rpx 3rpx 13rpx 0rpx rgba(0, 0, 0, 0.13);
  251. border-radius: 20rpx;
  252. margin-bottom: 20rpx;
  253. overflow: hidden;
  254. display: flex;
  255. flex-direction: column;
  256. justify-content: space-between;
  257. .pictrue {
  258. position: relative;
  259. image {
  260. width: 100%;
  261. height: 330rpx;
  262. }
  263. }
  264. .text-info {
  265. padding: 10rpx 20rpx 15rpx;
  266. .title {
  267. color: #222222;
  268. display: flex;
  269. align-items: center;
  270. justify-items: space-between;
  271. .tip {
  272. width: 61rpx;
  273. height: auto;
  274. font-size: 22rpx;
  275. display: flex;
  276. justify-content: center;
  277. align-items: center;
  278. color: #ffffff;
  279. position: relative;
  280. margin-right: 5rpx;
  281. background-color: #ef4800;
  282. border-radius: 5rpx;
  283. }
  284. .text{
  285. width: 80%;
  286. }
  287. .weight{
  288. background-color: rgba(197, 128, 3, 0.10);
  289. color: #C58003;
  290. font-size: 24rpx;
  291. padding: 8rpx 16rpx;
  292. border-radius: 8rpx;
  293. float: right;
  294. }
  295. }
  296. .bottom-row {
  297. color: $theme-color;
  298. display: flex;
  299. justify-content: space-between;
  300. align-items: center;
  301. font-size: 28rpx;
  302. margin: 10rpx 0 0;
  303. .price {
  304. padding-bottom: 4rpx;
  305. font-weight: 800;
  306. white-space: nowrap;
  307. font-size: 28rpx;
  308. color: #f16327;
  309. }
  310. .sales {
  311. color: #b4b4b4;
  312. font-size: 22rpx;
  313. white-space: nowrap;
  314. color: #6e6e6e;
  315. }
  316. }
  317. }
  318. }
  319. &.on {
  320. display: flex;
  321. }
  322. }
  323. }
  324. .no-data {
  325. margin: 150rpx auto 0;
  326. text-align: center;
  327. img {
  328. width: 65%;
  329. height: auto;
  330. }
  331. }
  332. .mores-txt {
  333. width: 100%;
  334. align-items: center;
  335. justify-content: center;
  336. height: 70rpx;
  337. color: #999;
  338. font-size: 24rpx;
  339. .iconfont {
  340. margin-top: 2rpx;
  341. font-size: 20rpx;
  342. }
  343. }
  344. </style>