merchant.vue 10 KB

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