index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <view class="">
  3. <view class="page">
  4. <navBar :backType="navBarTitle" :title="navBarTitle?navBarTitle:'详情'" :back="true" color="black"
  5. background="white" />
  6. <view class="topImg">
  7. <u-swiper type='img' radius="0rpx 0rpx 0rpx 40rpx" :list="bannerList" keyName="image" indicator
  8. indicatorMode="line" :autoplay="true" height="850rpx" imgMode="heightFix" circular
  9. @change="bannerChange">
  10. <view slot="indicator">
  11. </view>
  12. </u-swiper>
  13. <view class="indicatorBox1">
  14. <view class="indicator1">
  15. <view class="indicator1__dot1" style="" v-for="(item, index) in bannerList" :key="index"
  16. :class="[index === currentNum ?'indicator1__dot1--active1':'']">
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="cen">
  22. <image class="water" src="/static/index/water.png" mode=""></image>
  23. <image class="halfC" src="/static/index/halfCircle_275.png" mode=""></image>
  24. <image class="love" :src="lovePic" mode="" @click="handleCol"></image>
  25. <view class="txtBox">
  26. <view class="left" v-if="content.name">
  27. {{content.name}}
  28. </view>
  29. <view class="right">
  30. {{totalCount}}人已收藏
  31. </view>
  32. </view>
  33. </view>
  34. <view class="parmasBox" v-for="(item,index) in Object.keys(skuParams.attrs)">
  35. <view class="con">
  36. <view class="title">
  37. {{item}}
  38. </view>
  39. <view class="list">
  40. <view class="item" @click="handleC(item,index,item1)"
  41. v-for="(item1,index1) in skuParams.attrs[item]"
  42. :class="[item1==saveCheckedObj[item]?'act':'']">
  43. {{item1}}
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <!-- <view class="parmasBox" style="border-bottom: none;"> -->
  49. <view class="parmasBox" style="border-bottom:1rpx solid #EAEAEA">
  50. <view class="con" @click="handleOpenOrClose(1)">
  51. <view class="title1">
  52. <view class="txt">
  53. 商品描述
  54. </view>
  55. <image class="add" :src="addOrLessIcon1" mode="" :style="{height:addOrLessIcon1=='/static/index/shortLine.png'
  56. ?'2rpx':'22rpx'}"></image>
  57. </view>
  58. <view class="des" v-if="show1">
  59. <u-parse :content="content1"></u-parse>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="bot">
  65. <view class="left">
  66. <view class="price">
  67. ¥{{Number( totalPrice).toFixed(0)}}
  68. </view>
  69. <image src="/static/index/arrDown.png" mode=""></image>
  70. </view>
  71. <button open-type="share" class="right">
  72. 一键下单
  73. </button>
  74. </view>
  75. </view>
  76. </view>
  77. </template>
  78. <script>
  79. import {
  80. addCollReq,
  81. cancelCollReq,
  82. getGoodsPriceReq,
  83. getMyGoodsDetailReq,
  84. } from '@/api/test/index.js'
  85. export default {
  86. components: {
  87. },
  88. data() {
  89. return {
  90. currIndex1: 0,
  91. currentNum: 0,
  92. show1: true,
  93. addOrLessIcon1: '/static/index/shortLine.png',
  94. lovePic: '',
  95. content: null,
  96. picBase: this.$picBase,
  97. bannerList: [],
  98. content1: '',
  99. totalPrice: 0,
  100. totalCount: 0,
  101. navBarTitle: '',
  102. ids: [],
  103. cutdownRatio: 1,
  104. // sku
  105. skuParams: {
  106. "attrs": {},
  107. "sku": []
  108. },
  109. saveCheckedObj: null,
  110. fullCheckArr: [],
  111. watchValue: null,
  112. conditions: [],
  113. cutdownRatio: 1,
  114. }
  115. },
  116. async onLoad(o) {
  117. // o.id = 17
  118. this.cutdownRatio = this.$getCutDown()
  119. console.log('哪种折扣价格-商城详情', this.cutdownRatio);
  120. if (o.id) {
  121. // this.ids = JSON.parse(o.ids)
  122. this.navBarTitle = '首页'
  123. let res = await getMyGoodsDetailReq({
  124. id: o.id
  125. })
  126. if (res.code == 0) {
  127. console.log('回显商城详情返回值: ', res);
  128. // this.skuParams = res.data.sku_params
  129. this.skuParams = res.data.sku_params || {
  130. "attrs": {},
  131. "sku": []
  132. }
  133. // 动态生成判断条件对象数组
  134. let c = []
  135. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  136. c.push({
  137. key: item,
  138. value: null
  139. })
  140. })
  141. this.conditions = c
  142. // 动态生成用于判断选中激活项的对象
  143. let saveCheckedObj = {}
  144. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  145. saveCheckedObj[item] = null
  146. })
  147. this.saveCheckedObj = saveCheckedObj
  148. // 动态生成用于判断sku参数是否全部选中的中间数组
  149. this.fullCheckArr = new Array(Object.keys(this.skuParams.attrs).length).fill(0)
  150. this.content = res.data
  151. this.bannerList = res.data.images
  152. this.totalCount = res.data.collect_total_count
  153. this.content1 = res.data.content
  154. if (this.content.isCollect) {
  155. this.lovePic = "/static/mall/love.png"
  156. } else {
  157. this.lovePic = "/static/mall/no_love.png"
  158. }
  159. } else {
  160. uni.showToast({
  161. title: res.message,
  162. icon: 'none'
  163. })
  164. }
  165. } else {
  166. let res = await getMyGoodsDetailReq({
  167. id: getApp().mallItem.id
  168. // id: 70
  169. })
  170. if (res.code == 0) {
  171. console.log('进入详情返回值666', res);
  172. // this.skuParams = res.data.sku_params
  173. this.skuParams = res.data.sku_params || {
  174. "attrs": {},
  175. "sku": []
  176. }
  177. // this.skuParams = {
  178. // "attrs": {
  179. // "颜色": ['红色', '绿色'],
  180. // "尺寸": ['1cm', '2cm'],
  181. // },
  182. // "sku": [{
  183. // '颜色': '红色',
  184. // '尺寸': '1cm',
  185. // "price": 1
  186. // },
  187. // {
  188. // '颜色': '红色',
  189. // '尺寸': '2cm',
  190. // "price": 2
  191. // },
  192. // {
  193. // '颜色': '绿色',
  194. // '尺寸': '1cm',
  195. // "price": 3
  196. // },
  197. // {
  198. // '颜色': '绿色',
  199. // '尺寸': '2cm',
  200. // "price": 4
  201. // },
  202. // ]
  203. // }
  204. // 动态生成判断条件对象数组
  205. let c = []
  206. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  207. c.push({
  208. key: item,
  209. value: null
  210. })
  211. })
  212. this.conditions = c
  213. // 动态生成用于判断选中激活项的对象
  214. let saveCheckedObj = {}
  215. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  216. // saveCheckedObj[item] = null
  217. // saveCheckedObj[item] = this.skuParams.attrs[item][0]
  218. })
  219. console.log('this.skuParams-----', this.skuParams);
  220. this.saveCheckedObj = saveCheckedObj
  221. // 动态生成用于判断sku参数是否全部选中的中间数组
  222. this.fullCheckArr = new Array(Object.keys(this.skuParams.attrs).length).fill(0)
  223. // this.fullCheckArr = new Array(Object.keys(this.skuParams.attrs).length).fill(1)
  224. this.totalPrice = this.skuParams.sku[0].price
  225. // this.handleC(Object.keys(this.skuParams.attrs)[0], 0, this.skuParams.attrs[Object.keys(this
  226. // .skuParams.attrs)[0]][
  227. // 0
  228. // ])
  229. // this.handleC(Object.keys(this.skuParams.attrs)[0], 0, this.skuParams.attrs[Object.keys(this
  230. // .skuParams.attrs)[1]][
  231. // 0
  232. // ])
  233. this.content = res.data
  234. this.bannerList = res.data.images
  235. this.totalCount = res.data.collect_total_count
  236. this.content1 = res.data.content
  237. if (this.content.isCollect) {
  238. this.lovePic = "/static/mall/love.png"
  239. } else {
  240. this.lovePic = "/static/mall/no_love.png"
  241. }
  242. } else {
  243. uni.showToast({
  244. title: res.message,
  245. icon: 'none'
  246. })
  247. }
  248. }
  249. },
  250. watch: {
  251. // watchValue: {
  252. // handler(n, o) {
  253. // let showPrice = this.fullCheckArr.every((item, index) => {
  254. // return item == 1
  255. // })
  256. // if (showPrice) {
  257. // this.calcPrice()
  258. // // console.log('所求价格:', filterResult[0].price);
  259. // }
  260. // },
  261. // immediate: true
  262. // }
  263. watchValue(n, o) {
  264. let showPrice = this.fullCheckArr.every((item, index) => {
  265. return item == 1
  266. })
  267. if (showPrice) {
  268. this.calcPrice()
  269. // console.log('所求价格:', filterResult[0].price);
  270. }
  271. }
  272. },
  273. onShow() {
  274. this.cutdownRatio = this.$getCutDown()
  275. },
  276. onShareAppMessage(params) {
  277. if (params.from === 'button' || params.from === 'menu') {
  278. return {
  279. title: this.content.name,
  280. imageUrl: this.$picBase + this.content.cover,
  281. path: '/pages/mall/detail/index?id=' + this.content.id,
  282. mpId: this.$appId,
  283. type: this.$shareType,
  284. }
  285. }
  286. },
  287. methods: {
  288. calcPrice() {
  289. const filterResult = this.skuParams.sku.filter(item => {
  290. return this.conditions.every(condition => {
  291. const attrValues = this.skuParams.attrs[condition.key];
  292. return attrValues.includes(item[condition.key]) && item[condition.key] ===
  293. condition.value;
  294. });
  295. });
  296. this.totalPrice = filterResult[0].price * this.cutdownRatio
  297. },
  298. testShare() {
  299. console.log('parmsList', this.parmsList);
  300. let ids = []
  301. this.parmsList.forEach((item, index) => {
  302. item.list.forEach((item1, index1) => {
  303. if (item1.isSelect) {
  304. ids.push(index1)
  305. }
  306. })
  307. })
  308. console.log('选中的二维iindex数组', ids);
  309. },
  310. handleC(item, index, item1) {
  311. console.log('handleC参数----------', item, index, item1);
  312. this.fullCheckArr[index] = 1
  313. // 声东击西强行触发监听
  314. this.watchValue = Date.now()
  315. this.saveCheckedObj[item] = item1
  316. //此处个条件对象数组条件赋值(key==外围数组key)
  317. this.conditions.forEach((item2, index2) => {
  318. if (item2.key == item) {
  319. item2.value = item1
  320. }
  321. })
  322. },
  323. bannerChange(e) {
  324. this.currentNum = e.current
  325. },
  326. async handleCol() {
  327. if (this.lovePic == "/static/mall/no_love.png") {
  328. let res = await addCollReq({
  329. id: this.content.id,
  330. })
  331. if (res.code == 0) {
  332. console.log('添加收藏返回值: ', res);
  333. this.$toast('收藏成功')
  334. this.totalCount += 1
  335. if (this.lovePic == "/static/mall/love.png") {
  336. this.lovePic = "/static/mall/no_love.png"
  337. } else {
  338. this.lovePic = "/static/mall/love.png"
  339. }
  340. } else {
  341. uni.showToast({
  342. title: res.message,
  343. icon: 'none'
  344. })
  345. }
  346. } else {
  347. let res = await cancelCollReq({
  348. id: this.content.id,
  349. })
  350. if (res.code == 0) {
  351. console.log('取消收藏返回值: ', res);
  352. this.$toast('取消收藏成功')
  353. this.totalCount -= 1
  354. if (this.lovePic == "/static/mall/love.png") {
  355. this.lovePic = "/static/mall/no_love.png"
  356. } else {
  357. this.lovePic = "/static/mall/love.png"
  358. }
  359. } else {
  360. uni.showToast({
  361. title: res.message,
  362. icon: 'none'
  363. })
  364. }
  365. }
  366. },
  367. handleOpenOrClose(i) {
  368. if (this['addOrLessIcon' + i] == '/static/index/shortLine.png') {
  369. this['addOrLessIcon' + i] = '/static/index/add.png'
  370. this['show' + i] = false
  371. } else if (this['addOrLessIcon' + i] == '/static/index/add.png') {
  372. this['addOrLessIcon' + i] = '/static/index/shortLine.png'
  373. this['show' + i] = true
  374. }
  375. },
  376. }
  377. }
  378. </script>
  379. <style lang="scss" scoped>
  380. @import "./index.scss";
  381. </style>