product.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. <view class="grace-form-item grace-border-b">
  77. <text class="grace-form-label">配送方式</text>
  78. <view class="grace-form-body" style="padding:20rpx 0;">
  79. <radio-group name="danxuan">
  80. <label class="grace-check-item-v"><radio value="1"></radio>快递</label>
  81. <label class="grace-check-item-v"><radio value="2"></radio>自提</label>
  82. </radio-group>
  83. </view>
  84. </view>
  85. <view class="grace-wrap" style="margin-top: 20rpx;" v-if="item.goods.mode > 0">
  86. <view class="grace-capsule margin" v-if="item.goods.mode == 1 || item.goods.mode == 3">
  87. <text class="grace-capsule-icon">地址</text>
  88. <text class="grace-capsule-text">河北省三河市燕郊开发区理想新城一期南区36号楼</text>
  89. </view>
  90. <view class="grace-capsule margin" v-if="item.goods.mode == 2 || item.goods.mode == 3">
  91. <text class="grace-capsule-icon grace-icon-br" style="background:#E76B61;">自提</text>
  92. <text class="grace-capsule-text grace-text-br" style="border-color:#E76B61; color:#E76B61;">河北省三河市燕郊开发区理想新城一期南区</text>
  93. </view>
  94. </view>
  95. <!-- 属性列表区 -->
  96. <scroll-view style="height:700rpx;" scroll-y>
  97. <block v-for="(v, k) in item.goods.sell_attr" :key="k" v-if="item.goods.price_type == 2">
  98. <view class="grace-title grace-margin-top">{{v.name}}</view>
  99. <view><graceSelectTags selectedColor="#FF0036" :items="v.option_sku" type="radio" @change="change"></graceSelectTags></view>
  100. </block>
  101. <view class="grace-margin-top"><text class="grace-title">购买数量</text></view>
  102. <view style="margin-bottom: 40rpx;">
  103. <graceNumberBox :minNum="1" :maxNum="kuNum" :value="buyNum" v-on:change="buyNumChange"></graceNumberBox>
  104. </view>
  105. </scroll-view>
  106. <view class="grace-product-attr-btn">
  107. <button type="warn" style="background-color:#FF0036;" class="grace-button grace-border-radius" formType="submit">立即购买</button>
  108. </view>
  109. </form>
  110. </graceBottomDialog>
  111. <y-Fab :bottom="20" :right="140" v-if="!attrIsShow" @click="buyNow" bgColor="#e55d52" text="购买"></y-Fab>
  112. <y-Fab :bottom="20" :right="260" v-if="!attrIsShow" @click="showModal" bgColor="#0fa5e5" text="评价"></y-Fab>
  113. <block v-if="index == -1">
  114. <y-Fab :bottom="20" :right="20" v-if="!attrIsShow" @click="back" text="返回"></y-Fab>
  115. </block>
  116. <view v-if="showComment">
  117. <dever-publish :title="title" :is_upload="true" @hideModal="hideModal" @getRefresh="getRefresh" :type="key" :type_id="item.goods.id" :api="api"></dever-publish>
  118. </view>
  119. </view>
  120. <!-- 底部 -->
  121. </gracePage>
  122. </template>
  123. <script>
  124. import deverContent from '@/lib/dever/components/content.vue';
  125. import deverPublish from '@/lib/dever/components/publish.vue';
  126. import copyText from "@/lib/clipboard.thorui.js";
  127. export default {
  128. name: "product",
  129. props: {
  130. control : {
  131. type : Object,
  132. value : null
  133. },
  134. bottom : {
  135. type : Object,
  136. value : null
  137. },
  138. item : {
  139. type : Object,
  140. value : null
  141. },
  142. index : 0
  143. },
  144. data() {
  145. return {
  146. title : '发表新评价',
  147. api : 'app/community/?l=api.addComment',
  148. key : 'content/product',
  149. // 切换导航
  150. navItems : ['商品详情', '最新评价'],
  151. active:0,
  152. // 购买选择属性层展示
  153. attrIsShow : false,
  154. attr : '',
  155. attrKey : '',
  156. skuId : 0,
  157. attrSelect : {},
  158. payPrice : 0,
  159. buyNum : 1,
  160. kuNum : 9999,
  161. showComment : false,
  162. fetch : {
  163. info : [],
  164. }
  165. }
  166. },
  167. created() {
  168. },
  169. mounted() {
  170. this.bottom[this.index] = this;
  171. this.getData(1);
  172. },
  173. methods:{
  174. getData : function(page) {
  175. if (this.active == 0) {
  176. return;
  177. }
  178. this.Dever.page([page, 'info'], this, 'app/community/?l=api.comment', {type:this.key,type_id:this.item.goods.id,user:true});
  179. },
  180. // 导航切换
  181. navChange : function(e){
  182. this.active = e;
  183. if (e == 1) {
  184. this.getData(1);
  185. }
  186. },
  187. //打开属性视图
  188. buyNow : function() {
  189. if (this.item.goods.type == 1) {
  190. this.attrIsShow = true;
  191. } else {
  192. //this.Dever.alert('加入到口袋里');
  193. var name = this.item.goods.type_name;
  194. uni.showModal({
  195. content: '该商品是'+name+'平台商品,是否立刻去购买?',
  196. cancelText: '取消',
  197. confirmText: '去购买',
  198. success: res => {
  199. if (res.confirm) {
  200. if (this.item.goods.type == 2 || this.item.goods.type == 4) {
  201. this.copy(this.item.goods.code);
  202. this.Dever.alert('已复制,请打开' + name + 'APP即可购买该商品');
  203. } else {
  204. this.Dever.location(this.item.goods.link);
  205. }
  206. }
  207. }
  208. });
  209. }
  210. },
  211. copy : function(value) {
  212. var self = this;
  213. copyText.getClipboardData(value, function(res) {
  214. });
  215. },
  216. back : function() {
  217. uni.navigateBack();
  218. },
  219. // 关闭属性
  220. closeAttr : function() {
  221. this.attrIsShow = false;
  222. },
  223. // 属性选择
  224. change : function (e) {
  225. var temp = e.split('-');
  226. this.attrSelect[temp[0]] = e;
  227. this.getAttrKey();
  228. },
  229. // 购买数量变化
  230. buyNumChange : function (e) {
  231. this.buyNum = e[0];
  232. this.getAttrKey();
  233. },
  234. // 属性提交
  235. attrSubmit : function(e) {
  236. //后续操作
  237. uni.showToast({
  238. title:"属性已经收集,请观察控制台",
  239. icon:"none"
  240. });
  241. var data = {};
  242. data.goods_id = this.item.goods.id;
  243. data.price = this.payPrice;
  244. data.num = this.buyNum;
  245. data.sku = this.skuId;
  246. data.code = this.Dever.config.code;
  247. console.log(data);
  248. //如果想关闭属性
  249. //this.closeAttr();
  250. this.Dever.post('app/user/?l=pay.product', data, function(t) {
  251. console.info(t);
  252. });
  253. },
  254. // 获取属性key
  255. getAttrKey : function() {
  256. var key = [];
  257. for (var i in this.attrSelect) {
  258. key.push(this.attrSelect[i]);
  259. }
  260. this.attrKey = key.join('_');
  261. if (this.item.goods.price_type == 1) {
  262. this.kuNum = parseInt(this.item.goods.num);
  263. this.skuId = 0;
  264. this.payPrice = parseFloat(this.item.goods.price.min.price) * this.buyNum;
  265. } else if (this.item.goods.price_type == 2 && this.item.goods.price.list[this.attrKey]) {
  266. this.kuNum = parseInt(this.item.goods.price.list[this.attrKey].num);
  267. this.skuId = this.item.goods.price.list[this.attrKey].id;
  268. this.payPrice = parseFloat(this.item.goods.price.list[this.attrKey].price) * this.buyNum;
  269. }
  270. return true;
  271. },
  272. showModal : function() {
  273. this.showComment = true;
  274. },
  275. hideModal : function() {
  276. this.showComment = false;
  277. },
  278. getRefresh : function(cate_id, type, type_id, content) {
  279. this.getData(1);
  280. this.hideModal();
  281. }
  282. },
  283. components:{deverContent, deverPublish, copyText}
  284. }
  285. </script>
  286. <style>
  287. .grace-common-line{height:16rpx;}
  288. .grace-product-padding{padding:20rpx 25rpx;}
  289. .grace-product-title{line-height:44rpx; font-size:28rpx;}
  290. .grace-product-share{width:80rpx; height:80rpx; text-align:center; font-size:40rpx; color:#FF7900; line-height:80rpx; flex-shrink:0; margin-left:12px;}
  291. .grace-product-share:after{width:0; height:0;}
  292. .grace-product-price{color:#FF7900; line-height:60rpx; font-size:30rpx; font-weight:bold;}
  293. .grace-product-info-img{width:100%;}
  294. .grace-product-attr-info{overflow:hidden; display:flex; justify-content:space-between; border-bottom:1px solid #F1F1F3; padding-bottom:26rpx;}
  295. .grace-product-attr-info-image{width:120rpx; height:auto; margin-right:10px; flex-shrink:0;}
  296. .grace-product-attr-info-body{width:700rpx;}
  297. .grace-product-attr-info-title{width:100%; font-size:28rpx; color:#333333; display:block;}
  298. .grace-product-attr-info-stone{width:100%; font-size:20rpx; margin-top:8rpx; color:#666666; display:block;}
  299. .icon-close{font-size:30rpx; line-height:80rpx; color:#888888;}
  300. /* 调整宫格大小 */
  301. .grace-grids-items{padding:6rpx 0; width:120rpx;}
  302. .grace-grids-icon{height:50rpx; line-height:50rpx; font-size:40rpx; color:#6B7375;}
  303. .grace-grids-text{line-height:28rpx; font-size:20rpx; margin-top:2px; color:#6B7375;}
  304. .grace-footer-active{color:#FF0036;}
  305. .page-buy {
  306. position: fixed;
  307. right: 120rpx;
  308. bottom: 30rpx;
  309. width: 80rpx;
  310. height: 80rpx;
  311. background: rgb(229, 93, 82);
  312. border-radius: 80rpx;
  313. color: #fff;
  314. font-size: 30rpx;
  315. line-height: 80rpx;
  316. text-align: center;
  317. z-index: 2000;
  318. }
  319. .block1{line-height:80rpx; display:block; width:100%; text-align:center; font-size:28rpx;}
  320. .block2{line-height:66rpx; display:block; width:100%; text-align:center; font-size:28rpx;}
  321. .margin{margin:10rpx 10rpx 0 0;}
  322. .grace-border-b{border-color:#F8F8F8;}
  323. .grace-check-item-v{width:100%; padding:15rpx 15rpx;}
  324. </style>