1. <template>
  2. <div class="item_detail">
  3. <van-swipe :autoplay="3000" indicator-color="white">
  4. <van-swipe-item v-for="(item,index) in goods.pictureList" v-bind:key="index"><img :src="item.url"></van-swipe-item>
  5. </van-swipe>
  6. <div class="buy-area">
  7. <h2 class="title">
  8. <!-- OGAWA 奥佳华 舒行者全自动按摩椅 OG-7105 泰式定 位拉抻按摩椅 -->
  9. {{goods.title}}
  10. </h2>
  11. <p class="des">
  12. <!-- 透彻拉筋放松,舒畅全身;如儿时摇篮般的舒适体验;压肩揉按,抚慰颈部疲劳 -->
  13. {{goods.desc}}
  14. </p>
  15. <div class="point">
  16. {{goods.minScorePrice}} 积分
  17. </div>
  18. </div>
  19. <div class="detail-title">
  20. <span>
  21. 商品详情
  22. </span>
  23. </div>
  24. <div class="content" v-html="goods.detail">
  25.  
  26. </div>
  27. <van-goods-action>
  28. <van-goods-action-big-btn primary @click="doBuyNow" text="立即兑换" />
  29. </van-goods-action>
  30. <div v-show="showBase">
  31. <div class="alertBox">
  32. <div class="mainbox">
  33. <i class="van-icon van-icon-close icon-pos" @click="doClose"></i>
  34. <div v-for="(item,n) in itemList" v-bind:key="n">
  35. <div class="stand-title">
  36. {{item.specNameTitle}}
  37. </div>
  38. <div class="stand-cont clearfix">
  39. <div class="item" v-for="(oItem,index) in item.valueList" :class="[oItem.notShowFlag == 1 ? 'disabled' : '',subIndex[n] == index ? 'active': '']" @click="select(n,index,item.specNameId,oItem.specNameValueId,oItem.notShowFlag)" v-bind:key="index">{{oItem.specNameValueTitle}}</div>
  40. <!-- <div class="item active">红</div>https://blog.csdn.net/yx_cos/article/details/82499389
  41. <div class="item">黑</div>https://blog.csdn.net/panyang01/article/details/76665448 https://blog.csdn.net/this_ITBoy/article/details/82724701
  42. <div class="item disabled">白</div> -->
  43. </div>
  44. </div>
  45. <div class="count clearfix">
  46. <span>
  47. 数量选择
  48. </span>
  49. <van-stepper v-model="value" :max="maxAmount" />
  50. </div>
  51. </div>
  52. <div class="btmBtn" @click="doPay()">
  53. 确认兑换
  54. </div>
  55. </div>
  56. </div>
  57. <div class="van-modal" v-show="showBase" @click="doClose" style="z-index: 10;"></div>
  58. </div>
  59. </template>
  60.  
  61. <script>
  62. // import { GOODS_DETAIL } from '@/api/goods';
  63.  
  64. import {
  65. Swipe,
  66. SwipeItem,
  67. GoodsAction,
  68. GoodsActionBigBtn,
  69. GoodsActionMiniBtn,
  70. Popup,
  71. Sku,
  72. Stepper,
  73. Toast
  74. } from 'vant';
  75.  
  76. export default {
  77. props: {
  78. itemId: [String, Number]
  79. },
  80. data() {return {
  81. value: 1,
  82. showBase: false,
  83. goods: {},
  84. subIndex: [],
  85. accessFlag: true,
  86. itemList: [],
  87. tmpItemList: [],
  88. skuList: [],
  89. tmpStr: "",
  90. specStr1: "",
  91. specStr2: "",
  92. skuId: "",
  93. maxAmount: 1
  94. };
  95. },
  96.  
  97. computed: {
  98.  
  99. },
  100. created() {
  101. // var that = this
  102. // history.pushState(null, null, document.URL);
  103. // window.addEventListener('popstate', function(e) {
  104. // that.$router.replace({path: '/'})
  105. // // history.pushState(null, null, location.protocol+'//'+location.host + '/');
  106. // });
  107. window.scrollTo(0,0)
  108. this.initData();
  109. },
  110. destroyed(){
  111. this.doClose()
  112. },
  113. beforeRouteLeave(to, from, next){
  114. this.doClose()
  115. next();
  116. },
  117. methods: {
  118. initData() {
  119. // this.$reqGet(`${GOODS_DETAIL}`, {
  120. // expand: 'desc,skus,prop_imgs,item_imgs'
  121. // }).then(res => {
  122. // this.goods = res.data.data;
  123. // });
  124. var that = this
  125. this.$reqGet('/product/get-product?productId='+that.itemId).then(function(res) {
  126. console.log(res)
  127. that.goods = res.data.body.productWithList
  128. that.itemList = res.data.body.specValueVOList
  129. that.skuList = res.data.body.skuList
  130. that.tmpItemList = res.data.body.specValueVOList
  131. }).catch(function(err) {
  132. console.log(err)
  133. })
  134. },
  135. doBuyNow() {
  136. this.value = 1
  137. this.showBase = true
  138. document.body.style.height = '100vh'
  139. document.body.style['overflow'] = 'hidden'
  140. document.body.style.position = 'fixed'
  141. this.itemList = JSON.parse(JSON.stringify(this.tmpItemList)) // 隐藏后初始化弹出选中 与 disabled
  142. this.subIndex = [] // 隐藏后初始化弹出选中 与 disabled
  143. },
  144. doClose() {
  145. this.value = 1
  146. this.showBase = false
  147. document.body.style.height = 'unset'
  148. document.body.style['overflow'] = 'auto'
  149. document.body.style.position = ''
  150. this.itemList = this.tmpItemList
  151. },
  152. doPay() {
  153. var that = this
  154. if (this.subIndex.length == 0) {
  155. this.$toast('请选择规格');
  156. return false;
  157. }
  158. if(this.subIndex.length < this.goods.nameList.length) {
  159. this.$toast('请选择规格');
  160. return false;
  161. }
  162. if (that.subIndex.indexOf(-1) > -1) {
  163. this.$toast('请选择规格');
  164. return false
  165. }
  166. // this.tmpStr = this.specStr1 + this.specStr2
  167. // console.log(this.tmpStr,2)
  168. // return false;
  169. // this.skuList.forEach(function (item,index) {
  170. // if (that.tmpStr == item.specStr) {
  171. // that.skuId = item.skuId
  172. // that.maxAmount = item.stock
  173. // if(that.value > that.maxAmount) {
  174. // that.value = that.maxAmount
  175. // return false
  176. // }
  177. // }
  178. // })
  179. if (this.accessFlag) {
  180. this.$reqPost('/order/add-order',{remark:"",products:[{skuId:that.skuId,quantity:that.value}]}).then(function(res) {
  181. console.log(res)
  182. if(res.data.body.status) {
  183. // that.doClose()
  184. that.$router.push({path:'/items/write',query:{skuId:that.skuId,orderNo:res.data.body.data}})
  185. }else{
  186. that.$toast(res.data.body.msg);
  187. that.initData()
  188. }
  189. }).catch(function(err) {
  190. console.log(err)
  191. })
  192. }
  193. },
  194. select(n,index,pid,cid,flag) {
  195. if (flag == 1) {
  196. return false;
  197. }
  198. if (n == 0) {
  199. this.specStr1 = 'nameId'+pid+','+'valueId'+cid+',';
  200. }
  201. if (n == 1) {
  202. this.specStr2 = 'nameId'+pid+','+'valueId'+cid+',';
  203. }
  204. // console.log(this.specStr1,this.specStr2)
  205. if(this.subIndex[n] == index) {
  206. this.subIndex[n] = -1 //去掉选中状态 下面去掉当时选中德str 同时赋值
  207. if (n == 0) {
  208. this.specStr1 = "";
  209. }
  210. if (n == 1) {
  211. this.specStr2 = "";
  212. }
  213. this.$set(this.subIndex, n, -1)
  214. }else {
  215. this.subIndex[n] = index
  216. this.$set(this.subIndex, n, index)
  217. }
  218.  
  219. // 判断规格为两种搭配情况下的stock为0情况下 是否不可点击按钮(disabled) (规格为一种时候 通过后台返回的notShowFlag 判断 规格为两种时候 第二种的notShowFlag 为1)
  220. var that = this
  221. if (this.itemList.length == 2 && n == 0) {
  222. this.itemList[1].valueList.forEach(function(item,index) {
  223. var ppStr1 = that.specStr1 + 'nameId'+that.itemList[1].specNameId+','+'valueId'+item.specNameValueId+','
  224. that.skuList.forEach(function(obj,j) {
  225. // console.log(ppStr1,obj.specStr,obj.stock)
  226. if (ppStr1 == obj.specStr) {
  227. if(obj.stock == 0) {
  228. item.notShowFlag = 1
  229. }else{
  230. item.notShowFlag = 0
  231. }
  232. }
  233. })
  234. })
  235. }
  236. if (this.itemList.length == 2 && n == 1) {
  237. this.itemList[0].valueList.forEach(function(item,index) {
  238. var ppStr2 ='nameId'+that.itemList[0].specNameId+','+'valueId'+item.specNameValueId+','+that.specStr2
  239. that.skuList.forEach(function(obj,j) {
  240. // console.log(ppStr2,obj.specStr,obj.stock)
  241. if (ppStr2 == obj.specStr) {
  242. if(obj.stock == 0) {
  243. item.notShowFlag = 1
  244. }else{
  245. item.notShowFlag = 0
  246. }
  247. }
  248. })
  249. })
  250. }
  251.  
  252. this.tmpStr = this.specStr1 + this.specStr2
  253. // console.log(this.tmpStr,1)
  254. this.skuList.forEach(function (item,index) {
  255. if (that.tmpStr == item.specStr) {
  256. that.skuId = item.skuId
  257. that.maxAmount = item.stock
  258. if(that.value > that.maxAmount) {
  259. that.value = that.maxAmount
  260. return false
  261. }
  262. }
  263. })
  264. // console.log(this.maxAmount,2)
  265. // this.subIndex[n] = index
  266. // this.$set(this.subIndex, n, index)
  267. // console.log(n,index,pid,cid)
  268. }
  269. },
  270.  
  271. components: {
  272. [Popup.name]: Popup,
  273. [Swipe.name]: Swipe,
  274. [SwipeItem.name]: SwipeItem,
  275. [GoodsAction.name]: GoodsAction,
  276. [GoodsActionBigBtn.name]: GoodsActionBigBtn,
  277. [GoodsActionMiniBtn.name]: GoodsActionMiniBtn,
  278. [Sku.name]: Sku,
  279. [Stepper.name]: Stepper,
  280. [Toast.name]: Toast
  281. }
  282. };
  283. </script>
  284.  
  285. <style lang="scss" scoped>
  286. .clearfix::after{
  287. display: block;
  288. content: '';
  289. clear: both;
  290. height: 0;
  291.  
  292. }
  293. .van-swipe{
  294. height: 11.25rem !important;
  295. background: #fff;
  296. }
  297. .van-icon-close:before {
  298. content: "\F015" !important;
  299. }
  300. .van-modal {
  301. position: fixed;
  302. width: 100%;
  303. height: 100%;
  304. top: 0;
  305. left: 0;
  306. background-color: rgba(0,0,0,.7);
  307. }
  308. .buy-area {
  309. padding: 0.36rem;
  310. line-height: 1.9;
  311. background: #fff;
  312. .title {
  313. font-size: 0.42rem;
  314. margin: 0px;
  315. }
  316. .des {
  317. margin: 0px;
  318. padding-top: 0.45rem;
  319. font-size: 0.36rem;
  320. color: #999;
  321. }
  322. .point {
  323. padding-top: 1rem;
  324. color: #ff8400;
  325. font-size: 0.54rem;
  326. }
  327. }
  328. .item_detail {
  329. img {
  330. max-width: 100%;
  331. }
  332. }
  333. .detail-title{
  334. height: 1.6rem;
  335. line-height: 1.6rem;
  336. padding: 0 0.36rem;
  337. background: #fff;
  338. font-size: 0.42rem;
  339. font-weight: bold;
  340. margin-top: 0.3rem;
  341. span {
  342. padding-left: 0.25rem;
  343. display: block;
  344. position: relative;
  345. }
  346. span::before{
  347. display: block;
  348. content: '';
  349. position: absolute;
  350. left: 0;
  351. height: 0.4rem;
  352. width: 2px;
  353. top: 0.6rem;
  354. background: #fd141d;
  355. }
  356. }
  357. .content {
  358. background: #fff;
  359. min-height: 11.25rem;
  360. /deep/ img {
  361. width: 100%;
  362. margin: 0px;
  363. padding: 0px;
  364. vertical-align: middle;
  365. }
  366. /deep/ p {
  367. margin: 0px;
  368. padding: 0px;
  369. }
  370. }
  371. .van-button--danger{
  372. background: #fd141d;
  373. }
  374. .alertBox {
  375. height: auto;
  376. position: fixed;
  377. bottom: 0;
  378. z-index: 11;
  379. background: #fff;
  380. left: 0;
  381. right: 0;
  382. font-size: 0.42rem;
  383. }
  384. .alertBox .mainbox {
  385. max-height: 260px;
  386. overflow-y: scroll;
  387. -webkit-overflow-scrolling: touch;
  388. }
  389. .alertBox .btmBtn {
  390. height: 50px;
  391. line-height: 50px;
  392. text-align: center;
  393. color: #fff;
  394. background: #fd141d;
  395. font-size: 16px;
  396. }
  397. .alertBox .stand-title {
  398. height: 1.6rem;
  399. line-height: 1.6rem;
  400. padding: 0 0.36rem;
  401. border-bottom: 1px #f6f6f9 solid;
  402.  
  403. }
  404. .alertBox .icon-pos {
  405. position: absolute;
  406. right: 0.36rem;
  407. top: 0.6rem;
  408. }
  409. .alertBox .stand-cont {
  410. padding: 0.56rem 0.36rem;
  411. }
  412. .alertBox .stand-cont .item {
  413. float: left;
  414. min-width: 2.4rem;
  415. height: 0.9rem;
  416. border-radius: 0.45rem;
  417. padding: 0 0.45rem;
  418. border: 1px solid #f6f6f9;
  419. background: #f6f6f9;
  420. text-align: center;
  421. line-height: 0.9rem;
  422. margin-right: 0.6rem;
  423. margin-bottom: 0.3rem;
  424. }
  425. .alertBox .stand-cont .item.active {
  426. background: #fff8f8;
  427. border-color: #fd141d;
  428. color: #fd141d;
  429. }
  430. .alertBox .stand-cont .item.disabled {
  431. background: #f6f6f9;
  432. border-color: #f6f6f9;
  433. color: #b4b4b9;
  434. }
  435. .alertBox .count {
  436. padding: 0.6rem 0.36rem;
  437. }
  438. .alertBox span {
  439. display: block;
  440. float: left;
  441. height: 30px;
  442. line-height: 30px;
  443. }
  444. .van-stepper {
  445. float: right;
  446. }
  447. .van-button {
  448. height: 50px;
  449. line-height: 50px;
  450. }
  451. </style>

1、detail页面 /items/detail/:id的更多相关文章

  1. 获得同级iframe页面的指定ID元素的几种实现方法

    1.JS实现: var object= window.parent.frames("要获得的iframe的name").contentDocument.getElementById ...

  2. js中对arry数组的各种操作小结 瀑布流AJAX无刷新加载数据列表--当页面滚动到Id时再继续加载数据 web前端url传递值 js加密解密 HTML中让表单input等文本框为只读不可编辑的方法 js监听用户的键盘敲击事件,兼容各大主流浏览器 HTML特殊字符

    js中对arry数组的各种操作小结   最近工作比较轻松,于是就花时间从头到尾的对js进行了详细的学习和复习,在看书的过程中,发现自己平时在做项目的过程中有很多地方想得不过全面,写的不够合理,所以说啊 ...

  3. 2、订单填写页面 /items/write?skuId=10&orderNo=201903211033410001

    <template> <div class="write"> <div class="adr" v-if="addres ...

  4. 关于页面里没有id属性的Javascript上的解决办法

    如果页面上只有Textarea,可以用如下方法来遍历其name属性然后赋给id属性:<script> try{ window.onload = setTextAreaIds();setTe ...

  5. 单页面网站关于id冲突的解决办法

    最近做了一个单页面的网站,所有的页面加载都是通过局部刷新的方式,并且不用iframe,并且我们引入了动态tab页签: 所有的页签里的内容都只是一个元素,都在同一个html页面上,没有任何iframe分 ...

  6. 瀑布流AJAX无刷新加载数据列表--当页面滚动到Id时再继续加载数据

    瀑布流加载显示数据,在当下已经用的很普遍,尤其是我们在做网上商城时,在产品列表页面已经被普遍使用. 对于实现瀑布流布局的解决方案主要有以下两种方式: 1.对每一条显示数据使用绝对定位+浮动的方式,这样 ...

  7. aspx页面控件id上自动加前缀

    公司的一个.net项目,使用的传统aspx页面开发,每个控件上自动加了前缀,最初以为是extjs.net自带的功能,后来研究发现,主要是因为内部使用了母版页.<asp:Content ID=&q ...

  8. jquery 在页面上根据ID定位(jQuery锚点跳转及相关操作) 经典

    1.锚点跳转简介 Edit 锚点其实就是可以让页面定位到某个位置上的点.在高度较高的页面中经常见到.比如百度的百科页面,wiki中的page内容. 我知道实现锚点的跳转有两种形式,一种是a标签+nam ...

  9. 一个页面有相同ID元素的情况分析

    经常会遇到一个页面中有相同定义相同id的情况,从道理上来说,id应该是这个页面中某个元素的唯一标识,所以不应该出现有相同id的情况,否则会产生意想不到的结果.而且各个浏览器的表现也是不一样的.我只做了 ...

随机推荐

  1. datePecker时间控件区间写法

    成交时间: <input type="text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$d ...

  2. spring(二、bean生命周期、用到的设计模式、常用注解)

    spring(二.bean生命周期.用到的设计模式.常用注解) Spring作为当前Java最流行.最强大的轻量级框架,受到了程序员的热烈欢迎.准确的了解Spring Bean的生命周期是非常必要的. ...

  3. 读书笔记--《gongchandang宣言》

    纪念马克思诞辰200周年 末尾 gongchandang人不屑于隐瞒自己的观点和意图.他们公开宣布:他们的目的只有用暴力推翻全部现存的社会制度才能达到. 让统治接机在共产主义革命面前发抖吧. 无产者在 ...

  4. nodeJS网络操作

    var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, ...

  5. requests.get() 的 headers 参数

    官方文档requests.get()方法的定义如下: 源码如下: 看到最后一行return,get方法最后是通过调用requests.request 方法实现的,其实在其它的请求方法如post,put ...

  6. 使用Blend设计出符合效果的WPF界面

    之前不会用blend,感觉好难的,但美工给出的效果自己有没办法实现,所以研究了一下blend,感觉没有想象中的那么难 废话不多说,开始界面设计 今天拿到美工给的一个界面效果图 这个界面说实话,还可以吧 ...

  7. Java_EE面试题

    Java_EE面试题 欢迎到我的Git仓库去提交您觉得优秀的内容! 1.什么是Servlet? Servlet是用来处理客户端请求并产生动态网页内容的Java类.Servlet主要是用来处理或者是存储 ...

  8. 一个基于typelist的typemap

    前面的typelist的e一个小扩展,http://www.cnblogs.com/flytrace/p/3551414.html. 可以插入pair<key_type, value_type& ...

  9. nginx的启动,停止和重启

    启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin]# /usr/local/nginx/sbin/nginx -c /us ...

  10. 关于性能(SEO)

    性能优化有很多方面:细节决定成败,系统慢是由一个又一个的小细节造成的,所以开发初期做好充足的准备,开发中认真负责,不偷工减料,维护期更注重代码质量,这样才会让我妈的系统稳定高效. 1.0 使用CDN( ...