product.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template name="product">
  2. <gracePage headerBG="#FFFFFF" footerBg="#FFFFFF" :customHeader="false">
  3. <view slot="gBody" style="padding-bottom:120rpx;">
  4. <!-- 轮播图 -->
  5. <swiper class="grace-swiper" autoplay="true" indicator-dots
  6. indicator-color="rgba(255, 255, 255, 1)" indicator-active-color="#3688FF"
  7. style="height:399rpx" interval="5000">
  8. <swiper-item class="grace-swiper-item" v-for="(v, k) in item.goods.pic" :key="k">
  9. <image :src="v" mode="widthFix" class="grace-swiper-image" style="height:auto"></image>
  10. </swiper-item>
  11. </swiper>
  12. <!-- 商品标题 分享按钮 -->
  13. <view class="grace-product-padding grace-space-between grace-flex-vcenter">
  14. <text class="grace-product-title grace-bold">{{item.goods.name}}</text>
  15. </view>
  16. <!-- 价格 -->
  17. <view class="grace-product-padding">
  18. <view class="grace-nowrap grace-flex-vcenter">
  19. <text class="grace-product-price">¥{{item.goods.price.min.price}}</text>
  20. <text class="grace-text grace-gray grace-line-through" style="margin-left:30rpx;">¥{{item.goods.price.min.s_price}}</text>
  21. </view>
  22. <view class="grace-space-between grace-flex-vcenter" v-if="item.goods.type == 1">
  23. <text class="grace-text-small grace-gray" v-if="item.goods.freight">运费 ¥{{item.goods.freight.price}}</text>
  24. <text class="grace-text-small grace-gray">已售 {{item.goods.sell_num}} 件</text>
  25. </view>
  26. </view>
  27. <view class="grace-common-line"></view>
  28. <!-- 底部信息切换导航 -->
  29. <view class="grace-product-padding">
  30. <graceNavBar :items="navItems" lineHeight="80rpx" :isCenter="true"
  31. :currentIndex="active" :size="200" activeLineBg="#FF7900" textAlign="center"
  32. activeColor="#FF7900" activeLineWidth="200rpx" activeLineHeight="2rpx"
  33. :margin="10" @change="navChange"></graceNavBar>
  34. </view>
  35. <!-- 详情 请根据项目情况自行改进 可以使用 富文本-->
  36. <view class="grace-product-padding" :hidden="active == 1">
  37. <dever-content :item="item.goods.content_array" :pics="item.goods.content_pic" :skeleton="false"></dever-content>
  38. </view>
  39. <!-- 评论区 -->
  40. <view class="grace-comments grace-product-padding" :hidden="active == 0">
  41. <view class="grace-comments-items" v-for="(v, k) in fetch.info" :key="k">
  42. <image :src="v.user.avatar" class="grace-comments-face"></image>
  43. <view class="grace-comments-body">
  44. <view class="grace-comments-header">
  45. <text class="grace-comments-header-text">{{v.user.username}}</text>
  46. <text class="grace-comments-info-text">{{v.cdate_string}}</text>
  47. </view>
  48. <text class="grace-comments-content">{{v.content}}</text>
  49. <view class="grace-comments-imgs" v-if="v.pic">
  50. <view class="grace-comments-image" v-for="(v1, k1) in v.pic" :key="k1">
  51. <image :src="v1" mode="widthFix" class="grace-comments-img" @click="Dever.viewPic(v.pic, v1)" style="height:auto"></image>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <!-- 属性选择 -->
  58. <graceBottomDialog :show="attrIsShow" @closeDialog="closeAttr">
  59. <form @submit="attrSubmit" style="box-sizing:border-box; padding:10rpx 25rpx;" class="grace-form" slot="content">
  60. <!-- 关闭按钮 -->
  61. <view class="grace-nowrap grace-flex-end">
  62. <text class="grace-icons icon-close" @tap="closeAttr"></text>
  63. </view>
  64. <!-- 头部商品信息 -->
  65. <view class="grace-product-attr-info">
  66. <image class= "grace-product-attr-info-image" mode="widthFix"
  67. :src="item.goods.pic_cover" style="height:auto"></image>
  68. <view class="grace-product-attr-info-body">
  69. <text class="grace-product-attr-info-title">{{item.goods.name}}</text>
  70. <view class="grace-nowrap grace-flex-vcenter">
  71. <text class="grace-product-price">¥{{payPrice}}</text>
  72. <text class="grace-text grace-gray" style="margin-left:30rpx;">库存:{{kuNum}}件</text>
  73. </view>
  74. </view>
  75. </view>
  76. <!-- 属性列表区 -->
  77. <scroll-view style="height:700rpx;" scroll-y>
  78. <block v-for="(v, k) in item.goods.sell_attr" :key="k">
  79. <view class="grace-title grace-margin-top">{{v.name}}</view>
  80. <view><graceSelectTags selectedColor="#FF0036" :items="v.option_sku" type="radio" @change="change"></graceSelectTags></view>
  81. </block>
  82. <view class="grace-margin-top"><text class="grace-title">购买数量</text></view>
  83. <view style="margin-bottom: 40rpx;">
  84. <graceNumberBox :value="buyNum" v-on:change="buyNumChange"></graceNumberBox>
  85. </view>
  86. </scroll-view>
  87. <view class="grace-product-attr-btn">
  88. <button type="warn" style="background-color:#FF0036;" class="grace-button grace-border-radius" formType="submit">立即购买</button>
  89. </view>
  90. </form>
  91. </graceBottomDialog>
  92. <y-Fab :bottom="20" :right="140" v-if="!attrIsShow" @click="buyNow" bgColor="#e55d52" text="购买"></y-Fab>
  93. <y-Fab :bottom="20" :right="260" v-if="!attrIsShow" @click="showModal" bgColor="#0fa5e5" text="评价"></y-Fab>
  94. <block v-if="index == -1">
  95. <y-Fab :bottom="20" :right="20" v-if="!attrIsShow" @click="back" text="返回"></y-Fab>
  96. </block>
  97. <view v-if="showComment">
  98. <publish :title="title" :is_upload="true" @hideModal="hideModal" @getRefresh="getRefresh" :type="key" :type_id="item.goods.id" :api="api"></publish>
  99. </view>
  100. </view>
  101. <!-- 底部 -->
  102. </gracePage>
  103. </template>
  104. <script>
  105. import deverContent from '@/lib/dever/components/content.vue';
  106. import publish from '@/lib/dever/components/publish.vue';
  107. import copyText from "@/lib/clipboard.thorui.js";
  108. export default {
  109. name: "product",
  110. props: {
  111. control : {
  112. type : Object,
  113. value : null
  114. },
  115. bottom : {
  116. type : Object,
  117. value : null
  118. },
  119. item : {
  120. type : Object,
  121. value : null
  122. },
  123. index : 0
  124. },
  125. data() {
  126. return {
  127. title : '发表新评价',
  128. api : 'app/community/?l=api.addComment',
  129. key : 'content/product',
  130. // 切换导航
  131. navItems : ['商品详情', '最新评价'],
  132. active:0,
  133. // 购买选择属性层展示
  134. attrIsShow : false,
  135. attr : '',
  136. attrKey : '',
  137. skuId : 0,
  138. attrSelect : {},
  139. payPrice : 0,
  140. buyNum : 1,
  141. kuNum : 9999,
  142. showComment : false,
  143. fetch : {
  144. info : [],
  145. }
  146. }
  147. },
  148. created() {
  149. },
  150. mounted() {
  151. this.bottom[this.index] = this;
  152. this.getData(1);
  153. },
  154. methods:{
  155. getData : function(page) {
  156. if (this.active == 0) {
  157. return;
  158. }
  159. this.Dever.page([page, 'info'], this, 'app/community/?l=api.comment', {type:this.key,type_id:this.item.goods.id,user:true});
  160. },
  161. // 导航切换
  162. navChange : function(e){
  163. this.active = e;
  164. if (e == 1) {
  165. this.getData(1);
  166. }
  167. },
  168. //打开属性视图
  169. buyNow : function() {
  170. if (this.item.goods.type == 1) {
  171. this.attrIsShow = true;
  172. } else {
  173. //this.Dever.alert('加入到口袋里');
  174. var name = this.item.goods.type_name;
  175. uni.showModal({
  176. content: '该商品是'+name+'平台商品,是否立刻去购买?',
  177. cancelText: '取消',
  178. confirmText: '去购买',
  179. success: res => {
  180. if (res.confirm) {
  181. if (this.item.goods.type == 2 || this.item.goods.type == 4) {
  182. this.copy(this.item.goods.code);
  183. this.Dever.alert('已复制,请打开' + name + 'APP即可看到该商品');
  184. } else {
  185. this.Dever.location(this.item.goods.link);
  186. }
  187. }
  188. }
  189. });
  190. }
  191. },
  192. copy : function(value) {
  193. var self = this;
  194. copyText.getClipboardData(value, function(res) {
  195. });
  196. },
  197. back : function() {
  198. uni.navigateBack();
  199. },
  200. // 关闭属性
  201. closeAttr : function() {
  202. this.attrIsShow = false;
  203. },
  204. // 属性选择
  205. change : function (e) {
  206. var temp = e.split('-');
  207. this.attrSelect[temp[0]] = e;
  208. this.getAttrKey();
  209. },
  210. // 购买数量变化
  211. buyNumChange : function (e) {
  212. this.buyNum = e[0];
  213. this.getAttrKey();
  214. },
  215. // 属性提交
  216. attrSubmit : function(e) {
  217. //后续操作
  218. uni.showToast({
  219. title:"属性已经收集,请观察控制台",
  220. icon:"none"
  221. });
  222. var data = {};
  223. data.goods = this.item.goods.id;
  224. data.price = this.payPrice;
  225. data.num = this.buyNum;
  226. data.sku = this.skuId;
  227. console.log(data);
  228. //如果想关闭属性
  229. //this.closeAttr();
  230. },
  231. // 获取属性key
  232. getAttrKey : function() {
  233. var key = [];
  234. for (var i in this.attrSelect) {
  235. key.push(this.attrSelect[i]);
  236. }
  237. this.attrKey = key.join('_');
  238. if (this.item.goods.price.list[this.attrKey]) {
  239. this.payPrice = parseFloat(this.item.goods.price.list[this.attrKey].price) * this.buyNum;
  240. this.kuNum = this.item.goods.price.list[this.attrKey].num;
  241. this.skuId = this.item.goods.price.list[this.attrKey].id;
  242. }
  243. },
  244. showModal : function() {
  245. this.showComment = true;
  246. },
  247. hideModal : function() {
  248. this.showComment = false;
  249. },
  250. getRefresh : function(cate_id, type, type_id, content) {
  251. this.getData(1);
  252. this.hideModal();
  253. }
  254. },
  255. components:{deverContent, publish, copyText}
  256. }
  257. </script>
  258. <style>
  259. .grace-common-line{height:16rpx;}
  260. .grace-product-padding{padding:20rpx 25rpx;}
  261. .grace-product-title{line-height:44rpx; font-size:28rpx;}
  262. .grace-product-share{width:80rpx; height:80rpx; text-align:center; font-size:40rpx; color:#FF7900; line-height:80rpx; flex-shrink:0; margin-left:12px;}
  263. .grace-product-share:after{width:0; height:0;}
  264. .grace-product-price{color:#FF7900; line-height:60rpx; font-size:30rpx; font-weight:bold;}
  265. .grace-product-info-img{width:100%;}
  266. .grace-product-attr-info{overflow:hidden; display:flex; justify-content:space-between; border-bottom:1px solid #F1F1F3; padding-bottom:26rpx;}
  267. .grace-product-attr-info-image{width:120rpx; height:auto; margin-right:10px; flex-shrink:0;}
  268. .grace-product-attr-info-body{width:700rpx;}
  269. .grace-product-attr-info-title{width:100%; font-size:28rpx; color:#333333; display:block;}
  270. .grace-product-attr-info-stone{width:100%; font-size:20rpx; margin-top:8rpx; color:#666666; display:block;}
  271. .icon-close{font-size:30rpx; line-height:80rpx; color:#888888;}
  272. /* 调整宫格大小 */
  273. .grace-grids-items{padding:6rpx 0; width:120rpx;}
  274. .grace-grids-icon{height:50rpx; line-height:50rpx; font-size:40rpx; color:#6B7375;}
  275. .grace-grids-text{line-height:28rpx; font-size:20rpx; margin-top:2px; color:#6B7375;}
  276. .grace-footer-active{color:#FF0036;}
  277. .page-buy {
  278. position: fixed;
  279. right: 120rpx;
  280. bottom: 30rpx;
  281. width: 80rpx;
  282. height: 80rpx;
  283. background: rgb(229, 93, 82);
  284. border-radius: 80rpx;
  285. color: #fff;
  286. font-size: 30rpx;
  287. line-height: 80rpx;
  288. text-align: center;
  289. z-index: 2000;
  290. }
  291. </style>