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. saveCheckedObj[item] = this.skuParams.attrs[item][0]
  147. })
  148. this.saveCheckedObj = saveCheckedObj
  149. // 动态生成用于判断sku参数是否全部选中的中间数组
  150. this.fullCheckArr = new Array(Object.keys(this.skuParams.attrs).length).fill(0)
  151. //回显默认值
  152. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  153. this.handleC(item, index, this.skuParams.attrs[item][0])
  154. })
  155. this.content = res.data
  156. this.bannerList = res.data.images
  157. this.totalCount = res.data.collect_total_count
  158. this.content1 = res.data.content
  159. if (this.content.isCollect) {
  160. this.lovePic = "/static/mall/love.png"
  161. } else {
  162. this.lovePic = "/static/mall/no_love.png"
  163. }
  164. } else {
  165. uni.showToast({
  166. title: res.message,
  167. icon: 'none'
  168. })
  169. }
  170. } else {
  171. let res = await getMyGoodsDetailReq({
  172. id: getApp().mallItem.id
  173. // id: 70
  174. })
  175. if (res.code == 0) {
  176. console.log('进入详情返回值666', res);
  177. // this.skuParams = res.data.sku_params
  178. this.skuParams = res.data.sku_params || {
  179. "attrs": {},
  180. "sku": []
  181. }
  182. // this.skuParams = {
  183. // "attrs": {
  184. // "颜色": ['红色', '绿色'],
  185. // "尺寸": ['1cm', '2cm'],
  186. // },
  187. // "sku": [{
  188. // '颜色': '红色',
  189. // '尺寸': '1cm',
  190. // "price": 1
  191. // },
  192. // {
  193. // '颜色': '红色',
  194. // '尺寸': '2cm',
  195. // "price": 2
  196. // },
  197. // {
  198. // '颜色': '绿色',
  199. // '尺寸': '1cm',
  200. // "price": 3
  201. // },
  202. // {
  203. // '颜色': '绿色',
  204. // '尺寸': '2cm',
  205. // "price": 4
  206. // },
  207. // ]
  208. // }
  209. // 动态生成判断条件对象数组
  210. let c = []
  211. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  212. c.push({
  213. key: item,
  214. value: null
  215. })
  216. })
  217. this.conditions = c
  218. // 动态生成用于判断选中激活项的对象
  219. let saveCheckedObj = {}
  220. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  221. // saveCheckedObj[item] = null
  222. saveCheckedObj[item] = this.skuParams.attrs[item][0]
  223. })
  224. console.log('this.skuParams-----', this.skuParams);
  225. this.saveCheckedObj = saveCheckedObj
  226. // 动态生成用于判断sku参数是否全部选中的中间数组
  227. this.fullCheckArr = new Array(Object.keys(this.skuParams.attrs).length).fill(0)
  228. //回显默认值
  229. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  230. this.handleC(item, index, this.skuParams.attrs[item][0])
  231. })
  232. this.content = res.data
  233. this.bannerList = res.data.images
  234. this.totalCount = res.data.collect_total_count
  235. this.content1 = res.data.content
  236. if (this.content.isCollect) {
  237. this.lovePic = "/static/mall/love.png"
  238. } else {
  239. this.lovePic = "/static/mall/no_love.png"
  240. }
  241. } else {
  242. uni.showToast({
  243. title: res.message,
  244. icon: 'none'
  245. })
  246. }
  247. }
  248. },
  249. watch: {
  250. // watchValue: {
  251. // handler(n, o) {
  252. // let showPrice = this.fullCheckArr.every((item, index) => {
  253. // return item == 1
  254. // })
  255. // if (showPrice) {
  256. // this.calcPrice()
  257. // // console.log('所求价格:', filterResult[0].price);
  258. // }
  259. // },
  260. // immediate: true
  261. // }
  262. watchValue(n, o) {
  263. let showPrice = this.fullCheckArr.every((item, index) => {
  264. return item == 1
  265. })
  266. if (showPrice) {
  267. this.calcPrice()
  268. // console.log('所求价格:', filterResult[0].price);
  269. }
  270. }
  271. },
  272. onShow() {
  273. this.cutdownRatio = this.$getCutDown()
  274. },
  275. onShareAppMessage(params) {
  276. if (params.from === 'button' || params.from === 'menu') {
  277. return {
  278. title: this.content.name,
  279. imageUrl: this.$picBase + this.content.cover,
  280. path: '/pages/mall/detail/index?id=' + this.content.id,
  281. mpId: this.$appId,
  282. type: this.$shareType,
  283. }
  284. }
  285. },
  286. methods: {
  287. calcPrice() {
  288. const filterResult = this.skuParams.sku.filter(item => {
  289. return this.conditions.every(condition => {
  290. const attrValues = this.skuParams.attrs[condition.key];
  291. return attrValues.includes(item[condition.key]) && item[condition.key] ===
  292. condition.value;
  293. });
  294. });
  295. this.totalPrice = filterResult[0].price * this.cutdownRatio
  296. },
  297. testShare() {
  298. console.log('parmsList', this.parmsList);
  299. let ids = []
  300. this.parmsList.forEach((item, index) => {
  301. item.list.forEach((item1, index1) => {
  302. if (item1.isSelect) {
  303. ids.push(index1)
  304. }
  305. })
  306. })
  307. console.log('选中的二维iindex数组', ids);
  308. },
  309. handleC(item, index, item1) {
  310. console.log('handleC参数----------', item, index, item1);
  311. this.fullCheckArr[index] = 1
  312. // 声东击西强行触发监听
  313. this.watchValue = Date.now()
  314. this.saveCheckedObj[item] = item1
  315. //此处个条件对象数组条件赋值(key==外围数组key)
  316. this.conditions.forEach((item2, index2) => {
  317. if (item2.key == item) {
  318. item2.value = item1
  319. }
  320. })
  321. },
  322. bannerChange(e) {
  323. this.currentNum = e.current
  324. },
  325. async handleCol() {
  326. if (this.lovePic == "/static/mall/no_love.png") {
  327. let res = await addCollReq({
  328. id: this.content.id,
  329. })
  330. if (res.code == 0) {
  331. console.log('添加收藏返回值: ', res);
  332. this.$toast('收藏成功')
  333. this.totalCount += 1
  334. if (this.lovePic == "/static/mall/love.png") {
  335. this.lovePic = "/static/mall/no_love.png"
  336. } else {
  337. this.lovePic = "/static/mall/love.png"
  338. }
  339. } else {
  340. uni.showToast({
  341. title: res.message,
  342. icon: 'none'
  343. })
  344. }
  345. } else {
  346. let res = await cancelCollReq({
  347. id: this.content.id,
  348. })
  349. if (res.code == 0) {
  350. console.log('取消收藏返回值: ', res);
  351. this.$toast('取消收藏成功')
  352. this.totalCount -= 1
  353. if (this.lovePic == "/static/mall/love.png") {
  354. this.lovePic = "/static/mall/no_love.png"
  355. } else {
  356. this.lovePic = "/static/mall/love.png"
  357. }
  358. } else {
  359. uni.showToast({
  360. title: res.message,
  361. icon: 'none'
  362. })
  363. }
  364. }
  365. },
  366. handleOpenOrClose(i) {
  367. if (this['addOrLessIcon' + i] == '/static/index/shortLine.png') {
  368. this['addOrLessIcon' + i] = '/static/index/add.png'
  369. this['show' + i] = false
  370. } else if (this['addOrLessIcon' + i] == '/static/index/add.png') {
  371. this['addOrLessIcon' + i] = '/static/index/shortLine.png'
  372. this['show' + i] = true
  373. }
  374. },
  375. }
  376. }
  377. </script>
  378. <style lang="scss" scoped>
  379. @import "./index.scss";
  380. </style>