product.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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">运费 ¥{{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" style="margin-left:30rpx;" v-if="freight_price > 0">运费 ¥{{freight_price}}</text>
  73. <text class="grace-text grace-gray" style="margin-left:30rpx;">库存:{{kuNum}}件</text>
  74. </view>
  75. </view>
  76. </view>
  77. <view v-if="item.goods.mode > 0">
  78. <view class="grace-form-item grace-border-b">
  79. <text class="grace-form-label">配送方式</text>
  80. <view class="grace-form-body" style="padding:20rpx 0;">
  81. <radio-group name="danxuan" @change="setMode">
  82. <label class="grace-check-item-v" v-if="item.goods.mode == 1 || item.goods.mode == 3"><radio value="1" checked></radio><text style="margin-left:10rpx;">快递</text></label>
  83. <label class="grace-check-item-v" v-if="item.goods.mode == 2 || item.goods.mode == 3"><radio value="2"></radio><text style="margin-left:10rpx;">自提</text></label>
  84. </radio-group>
  85. </view>
  86. </view>
  87. <view class="grace-wrap" style="margin-top: 20rpx;">
  88. <view class="grace-capsule margin" v-if="(item.goods.mode == 1 || item.goods.mode == 3) && mode == 1" @click="openDialog">
  89. <text class="grace-capsule-icon">地址</text>
  90. <text class="grace-capsule-text">{{fetch.area_name}}{{fetch.address}}</text>
  91. </view>
  92. <view class="grace-capsule margin" v-if="(item.goods.mode == 2 || item.goods.mode == 3) && mode == 2">
  93. <text class="grace-capsule-icon grace-icon-br" style="background:#E76B61;">自提</text>
  94. <picker @change="storeChange" :value="store_index" :range="store_data">
  95. <text class="picker grace-capsule-text grace-text-br" style="border-color:#E76B61; color:#E76B61;">
  96. {{store_data[store_index]}}
  97. </text>
  98. </picker>
  99. </view>
  100. </view>
  101. </view>
  102. <!-- 属性列表区 -->
  103. <scroll-view style="height:700rpx;" scroll-y>
  104. <block v-for="(v, k) in item.goods.sell_attr" :key="k" v-if="item.goods.price_type == 2">
  105. <view class="grace-title grace-margin-top">{{v.name}}</view>
  106. <view><graceSelectTags selectedColor="#FF0036" :items="v.option_sku" type="radio" @change="change"></graceSelectTags></view>
  107. </block>
  108. <view class="grace-margin-top"><text class="grace-title">购买数量</text></view>
  109. <view style="margin-bottom: 40rpx;">
  110. <graceNumberBox :minNum="1" :maxNum="kuNum" :value="buyNum" v-on:change="buyNumChange"></graceNumberBox>
  111. </view>
  112. </scroll-view>
  113. <view class="grace-product-attr-btn">
  114. <button type="warn" style="background-color:#FF0036;" class="grace-button grace-border-radius" formType="submit">立即购买</button>
  115. </view>
  116. </form>
  117. </graceBottomDialog>
  118. <graceDialog ref="graceDialog" :isTitle="true" :isCloseBtn="false" :title="`收货地址`" v-on:closeDialog="closeDialog">
  119. <view class="content2" slot="content">
  120. <form class="grace-form grace-margin-top">
  121. <view class="grace-form-item grace-border-b">
  122. <text class="grace-form-label">您的姓名</text>
  123. <view class="grace-form-body">
  124. <input type="text" class="grace-form-input" name="name" v-model="fetch.address_contact" placeholder="请填写联系姓名"></input>
  125. </view>
  126. </view>
  127. <view class="grace-form-item grace-border-b">
  128. <text class="grace-form-label">联系电话</text>
  129. <view class="grace-form-body">
  130. <input type="number" class="grace-form-input" name="mobile" v-model="fetch.address_mobile" placeholder="请填写联系电话"></input>
  131. </view>
  132. </view>
  133. <view class="grace-form-item grace-border-b">
  134. <text class="grace-form-label">所在地区</text>
  135. <view class="grace-form-body" @tap="openPicker">
  136. <input type="text" class="grace-form-input" name="area" :value="fetch.area_name" disabled placeholder="请选择所在地区"></input>
  137. </view>
  138. </view>
  139. <view class="grace-form-item">
  140. <text class="grace-form-label">详细地址</text>
  141. <view class="grace-form-body">
  142. <input type="text" class="grace-form-input" name="address" v-model="fetch.address" placeholder="请填写详细地址"></input>
  143. </view>
  144. </view>
  145. </form>
  146. </view>
  147. <view slot="btns" class="grace-space-between">
  148. <text class="grace-dialog-buttons" @tap="closeDialog">关闭</text>
  149. <text class="grace-dialog-buttons grace-blue" @tap="setAddress">确认</text>
  150. </view>
  151. </graceDialog>
  152. <y-Fab :bottom="20" :right="140" v-if="!attrIsShow" @click="buyNow" bgColor="#e55d52" text="购买"></y-Fab>
  153. <y-Fab :bottom="20" :right="260" v-if="!attrIsShow" @click="showModal" bgColor="#0fa5e5" text="评价"></y-Fab>
  154. <block v-if="index == -1">
  155. <y-Fab :bottom="20" :right="20" v-if="!attrIsShow" @click="back" text="返回"></y-Fab>
  156. </block>
  157. <view v-if="showComment">
  158. <dever-publish :title="title" :is_upload="true" @hideModal="hideModal" @getRefresh="getRefresh" :type="key" :type_id="item.goods.id" :api="api"></dever-publish>
  159. </view>
  160. <graceAddressPicker v-if="address_default.length > 0" :value="address_default" :show="graceAddressPickerShow" @confirm="pickerConfirm" @close="closePicker" cancelTColor="关闭"></graceAddressPicker>
  161. </view>
  162. <!-- 底部 -->
  163. </gracePage>
  164. </template>
  165. <script>
  166. import deverContent from '@/lib/dever/components/content.vue';
  167. import deverPublish from '@/lib/dever/components/publish.vue';
  168. import copyText from "@/lib/clipboard.thorui.js";
  169. export default {
  170. name: "product",
  171. props: {
  172. control : {
  173. type : Object,
  174. value : null
  175. },
  176. bottom : {
  177. type : Object,
  178. value : null
  179. },
  180. item : {
  181. type : Object,
  182. value : null
  183. },
  184. index : 0
  185. },
  186. data() {
  187. return {
  188. title : '发表新评价',
  189. api : 'app/community/?l=api.addComment',
  190. key : 'content/product',
  191. // 切换导航
  192. navItems : ['商品详情', '最新评价'],
  193. active:0,
  194. // 购买选择属性层展示
  195. attrIsShow : false,
  196. attr : '',
  197. attrKey : '',
  198. skuId : 0,
  199. attrSelect : {},
  200. payPrice : 0,
  201. buyNum : 1,
  202. kuNum : 9999,
  203. showComment : false,
  204. fetch : {
  205. info : [],
  206. address : '',
  207. area_name : '',
  208. store : [],
  209. },
  210. mode : -1,
  211. store_data : [],
  212. store_index : 0,
  213. store_relation : [],
  214. freight_price : 0,
  215. old_freight_price : 0,
  216. graceAddressPickerShow : false,
  217. address_default : [],
  218. }
  219. },
  220. created() {
  221. },
  222. mounted() {
  223. this.bottom[this.index] = this;
  224. if (this.item.goods.freight) {
  225. this.freight_price = this.item.goods.freight.price;
  226. }
  227. if (this.item.goods.mode == 1 || this.item.goods.mode == 3) {
  228. this.mode = 1;
  229. } else if (this.item.goods.mode == 2 || this.item.goods.mode == 3) {
  230. this.mode = 2;
  231. }
  232. this.getInfo();
  233. this.getData(1);
  234. },
  235. methods:{
  236. openPicker : function() {
  237. this.graceAddressPickerShow = true;
  238. },
  239. pickerConfirm : function(e){
  240. if (e.names[0] == e.names[1]) {
  241. this.fetch.area_name = e.names[1] + ' ' + e.names[2];
  242. } else {
  243. this.fetch.area_name = e.names[0] + ' ' + e.names[1] + ' ' + e.names[2];
  244. }
  245. this.fetch.area_name += ' ';
  246. this.fetch.area_id = e.codes[0] + ',' + e.codes[1] + ',' + e.codes[2];
  247. this.closePicker();
  248. },
  249. closePicker : function () {
  250. this.graceAddressPickerShow = false;
  251. },
  252. // 获取地理位置,运费等信息
  253. getInfo : function() {
  254. var self = this;
  255. var data = {};
  256. data.goods_id = this.item.goods.id;
  257. data.noloading = 1;
  258. this.Dever.get(this, 'app/user/?l=api.goods', data, function(t) {
  259. self.address_default = self.fetch.area_id.split(',');
  260. if (t && t.store) {
  261. var j = 0;
  262. for (var i in t.store) {
  263. self.store_data[j] = t.store[i].name;
  264. self.store_relation[j] = i;
  265. j++;
  266. }
  267. }
  268. });
  269. /*
  270. this.Dever.getLocation('wgs84', '', function(t) {
  271. if (t && t.longitude && t.longitude) {
  272. }
  273. });
  274. */
  275. },
  276. getData : function(page) {
  277. if (this.active == 0) {
  278. return;
  279. }
  280. this.Dever.page([page, 'info'], this, 'app/community/?l=api.comment', {type:this.key,type_id:this.item.goods.id,user:true});
  281. },
  282. // 导航切换
  283. navChange : function(e){
  284. this.active = e;
  285. if (e == 1) {
  286. this.getData(1);
  287. }
  288. },
  289. storeChange : function(e) {
  290. this.store_index = e.detail.value;
  291. },
  292. //打开属性视图
  293. buyNow : function() {
  294. if (this.item.goods.platform == 1) {
  295. this.attrIsShow = true;
  296. } else {
  297. //this.Dever.alert('加入到口袋里');
  298. var name = this.item.goods.platform_name;
  299. uni.showModal({
  300. content: '该商品是'+name+'平台商品,是否立刻去购买?',
  301. cancelText: '取消',
  302. confirmText: '去购买',
  303. success: res => {
  304. if (res.confirm) {
  305. if (this.item.goods.platform == 2 || this.item.goods.platform == 4) {
  306. this.copy(this.item.goods.code);
  307. this.Dever.alert('已复制,请打开' + name + 'APP即可购买该商品');
  308. } else {
  309. this.Dever.location(this.item.goods.link);
  310. }
  311. }
  312. }
  313. });
  314. }
  315. },
  316. copy : function(value) {
  317. var self = this;
  318. copyText.getClipboardData(value, function(res) {
  319. });
  320. },
  321. back : function() {
  322. uni.navigateBack();
  323. },
  324. // 关闭属性
  325. closeAttr : function() {
  326. this.attrIsShow = false;
  327. },
  328. // 属性选择
  329. change : function (e) {
  330. var temp = e.split('-');
  331. this.attrSelect[temp[0]] = e;
  332. this.getAttrKey();
  333. },
  334. // 购买数量变化
  335. buyNumChange : function (e) {
  336. this.buyNum = e[0];
  337. this.getAttrKey();
  338. },
  339. // 属性提交
  340. attrSubmit : function(e) {
  341. //后续操作
  342. uni.showToast({
  343. title:"属性已经收集,请观察控制台",
  344. icon:"none"
  345. });
  346. var data = {};
  347. data.goods_id = this.item.goods.id;
  348. data.price = this.payPrice;
  349. data.num = this.buyNum;
  350. data.sku = this.skuId;
  351. data.code = this.Dever.config.code;
  352. data.mode = this.mode;
  353. if (this.mode == 2) {
  354. var store = this.fetch.store[this.store_relation[this.store_index]].id;
  355. data.store_id = store;
  356. }
  357. console.log(data);
  358. return;
  359. //如果想关闭属性
  360. //this.closeAttr();
  361. this.Dever.post('app/user/?l=pay.product', data, function(t) {
  362. console.info(t);
  363. });
  364. },
  365. // 获取属性key
  366. getAttrKey : function() {
  367. var key = [];
  368. for (var i in this.attrSelect) {
  369. key.push(this.attrSelect[i]);
  370. }
  371. this.attrKey = key.join('_');
  372. if (this.item.goods.price_type == 1) {
  373. this.kuNum = parseInt(this.item.goods.num);
  374. this.skuId = 0;
  375. this.payPrice = parseFloat(this.item.goods.price.min.price) * this.buyNum;
  376. } else if (this.item.goods.price_type == 2 && this.item.goods.price.list[this.attrKey]) {
  377. this.kuNum = parseInt(this.item.goods.price.list[this.attrKey].num);
  378. this.skuId = this.item.goods.price.list[this.attrKey].id;
  379. this.payPrice = parseFloat(this.item.goods.price.list[this.attrKey].price) * this.buyNum;
  380. }
  381. if (this.item.goods.freight) {
  382. var freight_price = 0;
  383. this.item.goods.freight.first_num = parseInt(this.item.goods.freight.first_num);
  384. var price = parseFloat(this.item.goods.freight.first_price);
  385. if (this.buyNum > this.item.goods.freight.first_num) {
  386. var num = this.buyNum - this.item.goods.freight.first_num;
  387. price = parseFloat(price + (this.item.goods.freight.next_price*num));
  388. }
  389. if (this.item.goods.freight.type == 2) {
  390. freight_price = this.payPrice*(price/100);
  391. } else {
  392. freight_price = price;
  393. }
  394. if (this.mode == 2) {
  395. this.old_freight_price = freight_price;
  396. } else {
  397. this.freight_price = freight_price;
  398. }
  399. } else {
  400. }
  401. return true;
  402. },
  403. showModal : function() {
  404. this.showComment = true;
  405. },
  406. hideModal : function() {
  407. this.showComment = false;
  408. },
  409. getRefresh : function(cate_id, type, type_id, content) {
  410. this.getData(1);
  411. this.hideModal();
  412. },
  413. setMode : function(e) {
  414. this.mode = e.detail.value;
  415. if (this.mode == 2) {
  416. //获取当前位置的自提点
  417. this.old_freight_price = this.freight_price;
  418. this.freight_price = 0;
  419. } else {
  420. this.freight_price = this.old_freight_price;
  421. }
  422. },
  423. openDialog : function() {
  424. this.$refs.graceDialog.open();
  425. },
  426. closeDialog : function() {
  427. this.$refs.graceDialog.hide();
  428. },
  429. setAddress : function() {
  430. var data = {};
  431. data.code = this.Dever.config.code;
  432. data.goods_id = this.item.goods.id;
  433. data.price = this.payPrice;
  434. data.num = this.buyNum;
  435. data.address_contact = this.fetch.address_contact;
  436. data.address_mobile = this.fetch.address_mobile;
  437. data.address = this.fetch.address;
  438. data.area_id = this.fetch.area_id;
  439. data.noloading = 1;
  440. this.closeDialog();
  441. var self = this;
  442. this.Dever.post('app/user/?l=api.saveAddress', data, function(t) {
  443. console.info(t);
  444. self.item.goods.freight = t;
  445. self.getAttrKey();
  446. });
  447. }
  448. },
  449. components:{deverContent, deverPublish, copyText}
  450. }
  451. </script>
  452. <style>
  453. .grace-common-line{height:16rpx;}
  454. .grace-product-padding{padding:20rpx 25rpx;}
  455. .grace-product-title{line-height:44rpx; font-size:28rpx;}
  456. .grace-product-share{width:80rpx; height:80rpx; text-align:center; font-size:40rpx; color:#FF7900; line-height:80rpx; flex-shrink:0; margin-left:12px;}
  457. .grace-product-share:after{width:0; height:0;}
  458. .grace-product-price{color:#FF7900; line-height:60rpx; font-size:30rpx; font-weight:bold;}
  459. .grace-product-info-img{width:100%;}
  460. .grace-product-attr-info{overflow:hidden; display:flex; justify-content:space-between; border-bottom:1px solid #F1F1F3; padding-bottom:26rpx;}
  461. .grace-product-attr-info-image{width:120rpx; height:auto; margin-right:10px; flex-shrink:0;}
  462. .grace-product-attr-info-body{width:700rpx;}
  463. .grace-product-attr-info-title{width:100%; font-size:28rpx; color:#333333; display:block;}
  464. .grace-product-attr-info-stone{width:100%; font-size:20rpx; margin-top:8rpx; color:#666666; display:block;}
  465. .icon-close{font-size:30rpx; line-height:80rpx; color:#888888;}
  466. /* 调整宫格大小 */
  467. .grace-grids-items{padding:6rpx 0; width:120rpx;}
  468. .grace-grids-icon{height:50rpx; line-height:50rpx; font-size:40rpx; color:#6B7375;}
  469. .grace-grids-text{line-height:28rpx; font-size:20rpx; margin-top:2px; color:#6B7375;}
  470. .grace-footer-active{color:#FF0036;}
  471. .page-buy {
  472. position: fixed;
  473. right: 120rpx;
  474. bottom: 30rpx;
  475. width: 80rpx;
  476. height: 80rpx;
  477. background: rgb(229, 93, 82);
  478. border-radius: 80rpx;
  479. color: #fff;
  480. font-size: 30rpx;
  481. line-height: 80rpx;
  482. text-align: center;
  483. z-index: 2000;
  484. }
  485. .block1{line-height:80rpx; display:block; width:100%; text-align:center; font-size:28rpx;}
  486. .block2{line-height:66rpx; display:block; width:100%; text-align:center; font-size:28rpx;}
  487. .margin{margin:10rpx 10rpx 0 0;}
  488. .grace-border-b{border-color:#F8F8F8;}
  489. .grace-check-item-v{width:100%; padding:15rpx 15rpx;}
  490. .content1{padding:25rpx; font-size:26rpx; text-align:center; line-height:60rpx;background-color:#F8F8F8; display:block;}
  491. .content2{padding-left:30rpx; padding-right:80rpx; line-height:50rpx; font-size:26rpx;}
  492. /* 图片形式 */
  493. .demo-img{width:580rpx; height:850rpx;}
  494. .grace-dialog-buttons{width:700rpx; line-height:88rpx; height:88rpx; display:block; overflow:hidden; text-align:center; font-size:26rpx; color:#999999;}
  495. .grace-capsule-icon {
  496. white-space: nowrap;
  497. overflow: hidden;
  498. text-overflow: ellipsis;
  499. }
  500. .grace-capsule-text {
  501. white-space: nowrap;
  502. overflow: hidden;
  503. text-overflow: ellipsis;
  504. word-break: break-all;
  505. display: -webkit-box; /** 对象作为伸缩盒子模型显示 **/
  506. -webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/
  507. -webkit-line-clamp: 1; /** 显示的行数 **/
  508. }
  509. </style>