merchant.vue 11 KB

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