index.vue 6.7 KB

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