index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="detail">
  3. <!-- header -->
  4. <cu-custom isBack custom bgColor="bg-gradual-blue"><view slot="content">商品详情</view></cu-custom>
  5. <!-- section -->
  6. <view class="section">
  7. <cu-swiper :value="swiperList" />
  8. <view class="bg-white padding">
  9. <view class="flex align-center">
  10. <view style="flex: auto;" class="text-xl text-bold">{{ detail.name }}</view>
  11. <view @click="favoriteFunc" style="min-width: 100upx;" class="text-center">
  12. <text v-if="dynamic.favorite" class="cuIcon-likefill text-red text-xxl"></text>
  13. <text v-else class="cuIcon-like text-xxl"></text>
  14. </view>
  15. </view>
  16. <view class="flex justify-between align-end margin-top-sm">
  17. <view class="text-price text-red"><cu-price :value="detail.price" size="64" /></view>
  18. <view class="text-grey">销量:{{ detail.sale_count }}</view>
  19. </view>
  20. <!-- <view class="margin-top-sm text-grey">商品详情</view> -->
  21. </view>
  22. <view class="margin-tb-sm padding bg-white flex">
  23. <view style="min-width: 100upx;" class="text-black text-bold">配送至</view>
  24. <view style="flex: auto;">
  25. <view class="text-grey">
  26. 河南省郑州市中原区是否真
  27. <text class="cuIcon-location lg margin-left-sm"></text>
  28. </view>
  29. <view class="">张三 18864585256</view>
  30. </view>
  31. </view>
  32. <view class="padding margin-tb-sm bg-white">
  33. <view class="flex justify-between">
  34. <view class="text-bold text-black text-bold">评价(265)</view>
  35. <view @click="evaluateFunc">
  36. 查看全部
  37. <text class="cuIcon-right"></text>
  38. </view>
  39. </view>
  40. <cu-evaluate :value="evaluate" />
  41. </view>
  42. <view class="bg-white padding-tb">
  43. <view class="text-black text-bold margin-bottom-sm padding-lr">图文介绍</view>
  44. <image
  45. v-for="(item, index) in detailList"
  46. :key="index"
  47. lazy-load="true"
  48. style="width: 100%;vertical-align: top;display: block;"
  49. :src="item"
  50. mode="widthFix"
  51. ></image>
  52. </view>
  53. </view>
  54. <!-- footer -->
  55. <view class="footer">
  56. <view class=" cu-bar bg-white tabbar border shop">
  57. <view @click="favoriteFunc" v-if="dynamic.favorite" class="action text-orange">
  58. <view class="cuIcon-favorfill"></view>
  59. 已收藏
  60. </view>
  61. <view @click="favoriteFunc" v-else class="action ">
  62. <view class="cuIcon-favor"></view>
  63. 收藏
  64. </view>
  65. <view @click="shoppingCart" class="action">
  66. <!-- <view class="cuIcon-cart"><view class="cu-tag badge">99</view></view> -->
  67. 购物车
  68. </view>
  69. <view class="btn-group">
  70. <button @click="show=true" :disabled="bind != 1" class="cu-btn bg-orange round shadow-blur">
  71. <text v-if="shoplock" class="cuIcon-loading2 iconfont-spin"></text>
  72. 添加购买
  73. </button>
  74. </view>
  75. </view>
  76. </view>
  77. <!-- 工具 -->
  78. <cu-goodA :value="value" @addcart="addcart" @buyclicked="buyclicked" :number="number" @changeNum="val=>number=val" :show.sync="show" />
  79. </view>
  80. </template>
  81. <script>
  82. import api from './api.js';
  83. import { mapState } from 'vuex';
  84. export default {
  85. computed: {
  86. ...mapState(['bind']),
  87. value(){
  88. let {name,price,show_image}=this.detail;
  89. return {
  90. name,price,img:show_image
  91. }
  92. }
  93. },
  94. data() {
  95. return {
  96. number:1,
  97. show: false,
  98. shoplock: false,
  99. detail: {},
  100. // 动态操作
  101. dynamic: { favorite: false },
  102. swiperList: [],
  103. detailList: [],
  104. evaluate: {
  105. avator: 'https://gd-hbimg.huaban.com/1f50f2135ba51e4b9aa20caef41860b15005c9386f0b-LxqWsh_fw658/format/webp',
  106. nickname: '用户昵称',
  107. rate: 3,
  108. createTime: '20220622 17:05:30',
  109. detail: "项目 'demo' 编译成功。前端运行日志,请另行在小程序开发工具的控制台查看。",
  110. imgs: [
  111. {
  112. id: 0,
  113. type: 'video',
  114. url: 'https://st0.dancf.com/gaoding/gaoding/229e7928-fb34-4a0c-b12b-b26fc0aba91453332268.mp4'
  115. },
  116. {
  117. id: 1,
  118. type: 'image',
  119. url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84001.jpg'
  120. },
  121. {
  122. id: 2,
  123. type: 'image',
  124. url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big39000.jpg'
  125. },
  126. {
  127. id: 3,
  128. type: 'image',
  129. url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg'
  130. },
  131. {
  132. id: 4,
  133. type: 'image',
  134. url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big25011.jpg'
  135. },
  136. {
  137. id: 5,
  138. type: 'image',
  139. url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big21016.jpg'
  140. },
  141. {
  142. id: 6,
  143. type: 'image',
  144. url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big99008.jpg'
  145. }
  146. ]
  147. }
  148. };
  149. },
  150. async onLoad(options) {
  151. var result = await api.detail(options);
  152. if (result.code != 0) return false;
  153. let { carousel_urls, details_urls, is_collection, ...keys } = result.data;
  154. // 轮播
  155. this.swiperList = carousel_urls.map(item => ({ type: 'image', url: item }));
  156. // 收藏
  157. let dynamic = {};
  158. dynamic['favorite'] = is_collection;
  159. this.dynamic = dynamic;
  160. // 详情
  161. this.detail = keys;
  162. // 图文详情
  163. this.detailList = details_urls;
  164. },
  165. methods: {
  166. // 添加购物车
  167. async addcart(){
  168. var result= await api.shoppingCart({quantity:this.number,commodity_details:this.detail.id});
  169. if(result.code==0){
  170. uni.showToast({
  171. title:"添加成功",
  172. icon:'success'
  173. })
  174. }
  175. },
  176. async buyclicked(){},
  177. async favoriteFunc() {
  178. if (this.bind != 1) return false;
  179. let dynamic = JSON.parse(JSON.stringify(this.dynamic));
  180. dynamic['favorite'] = !dynamic.favorite;
  181. let result;
  182. if (dynamic['favorite']) {
  183. result = await api.favorite({ id: this.detail.id });
  184. } else {
  185. result = await api.unfavorite({ id: this.detail.id });
  186. }
  187. if (result.code != 0) return false;
  188. this.dynamic = dynamic;
  189. },
  190. shoppingCartAdd() {},
  191. shoppingCart() {
  192. uni.switchTab({
  193. url: '/pages/shoppingCart/index'
  194. });
  195. },
  196. evaluateFunc() {
  197. uni.navigateTo({
  198. url: '/detailPages/evaluate/index'
  199. });
  200. }
  201. },
  202. onShareAppMessage() {
  203. return {};
  204. },
  205. onShareTimeline() {
  206. return {};
  207. }
  208. };
  209. </script>
  210. <style lang="scss" scoped>
  211. .detail {
  212. .footer {
  213. height: calc(100rpx + env(safe-area-inset-bottom) / 2);
  214. padding-bottom: calc(env(safe-area-inset-bottom) / 2);
  215. .cu-bar {
  216. position: fixed;
  217. bottom: 0;
  218. left: 0;
  219. width: 100vw;
  220. }
  221. }
  222. }
  223. </style>