index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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="e => currentNum = e.current">
  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:1rpx solid #EAEAEA;">
  49. <view class="con" @click="handleOpenOrClose(1)">
  50. <view class="title1">
  51. <view class="txt">
  52. 商品描述
  53. </view>
  54. <image class="add" :src="addOrLessIcon1" mode="" :style="{height:addOrLessIcon1=='/static/index/shortLine.png'
  55. ?'2rpx':'22rpx'}"></image>
  56. </view>
  57. <view class="des" v-if="show1">
  58. <u-parse :content="content1"></u-parse>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="bot">
  64. <view class="left">
  65. <view class="price">
  66. ¥{{Number( totalPrice).toFixed(0)}}
  67. </view>
  68. <image src="/static/index/arrDown.png" mode=""></image>
  69. </view>
  70. <button open-type="share" class="right">
  71. 一键下单
  72. </button>
  73. </view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import {
  79. getMyCollectDetailReq,
  80. } from '@/api/my/index.js'
  81. import {
  82. addCollReq,
  83. cancelCollReq,
  84. getGoodsPriceReq,
  85. postOrderReq,
  86. } from '@/api/test/index.js'
  87. export default {
  88. components: {
  89. },
  90. data() {
  91. return {
  92. picUrl: this.$picUrl,
  93. picBase: this.$picBase,
  94. currIndex: 0,
  95. currIndex1: 0,
  96. currIndex2: 0,
  97. show1: true,
  98. addOrLessIcon1: '/static/index/shortLine.png',
  99. lovePic: '/static/mall/love.png',
  100. content: null,
  101. currentNum: 0,
  102. bannerList: [],
  103. totalCount: 0,
  104. content1: '',
  105. totalPrice: 0,
  106. navBarTitle: '',
  107. ids: [],
  108. cutdownRatio: 1,
  109. // sku
  110. skuParams: {
  111. "attrs": {},
  112. "sku": []
  113. },
  114. saveCheckedObj: null,
  115. fullCheckArr: [],
  116. watchValue: null,
  117. conditions: [],
  118. }
  119. },
  120. async onLoad(o) {
  121. // o.id = 17
  122. if (o.id) {
  123. // this.ids = JSON.parse(o.ids)
  124. this.navBarTitle = '首页'
  125. let res = await getMyCollectDetailReq({
  126. id: o.id
  127. })
  128. if (res.code == 0) {
  129. console.log('我的收藏详情', res);
  130. this.skuParams = res.data.sku_params || {
  131. "attrs": {},
  132. "sku": []
  133. }
  134. // 动态生成判断条件对象数组
  135. let c = []
  136. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  137. c.push({
  138. key: item,
  139. value: null
  140. })
  141. })
  142. this.conditions = c
  143. // 动态生成用于判断选中激活项的对象
  144. let saveCheckedObj = {}
  145. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  146. // saveCheckedObj[item] = null
  147. saveCheckedObj[item] = this.skuParams.attrs[item][0]
  148. })
  149. this.saveCheckedObj = saveCheckedObj
  150. // 动态生成用于判断sku参数是否全部选中的中间数组
  151. this.fullCheckArr = new Array(Object.keys(this.skuParams.attrs).length).fill(0)
  152. //回显默认值
  153. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  154. this.handleC(item, index, this.skuParams.attrs[item][0])
  155. })
  156. this.content = res.data
  157. this.bannerList = this.content.images
  158. this.totalCount = this.content.collect_total_count
  159. if (this.content.isCollect) {
  160. this.lovePic = "/static/mall/love.png"
  161. } else {
  162. this.lovePic = "/static/mall/no_love.png"
  163. }
  164. this.content1 = this.content.content
  165. } else {
  166. uni.showToast({
  167. title: res.message,
  168. icon: 'none'
  169. })
  170. }
  171. } else {
  172. let res = await getMyCollectDetailReq({
  173. id: getApp().Sid
  174. })
  175. if (res.code == 0) {
  176. console.log('我的收藏详情', res);
  177. // this.skuParams = res.data.sku_params
  178. this.skuParams = res.data.sku_params || {
  179. "attrs": {},
  180. "sku": []
  181. }
  182. // 动态生成判断条件对象数组
  183. let c = []
  184. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  185. c.push({
  186. key: item,
  187. value: null
  188. })
  189. })
  190. this.conditions = c
  191. // 动态生成用于判断选中激活项的对象
  192. let saveCheckedObj = {}
  193. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  194. // saveCheckedObj[item] = null
  195. saveCheckedObj[item] = this.skuParams.attrs[item][0]
  196. })
  197. this.saveCheckedObj = saveCheckedObj
  198. // 动态生成用于判断sku参数是否全部选中的中间数组
  199. this.fullCheckArr = new Array(Object.keys(this.skuParams.attrs).length).fill(0)
  200. //回显默认值
  201. Object.keys(this.skuParams.attrs).forEach((item, index) => {
  202. this.handleC(item, index, this.skuParams.attrs[item][0])
  203. })
  204. this.content = res.data
  205. this.bannerList = this.content.images
  206. this.totalCount = this.content.collect_total_count
  207. if (this.content.isCollect) {
  208. this.lovePic = "/static/mall/love.png"
  209. } else {
  210. this.lovePic = "/static/mall/no_love.png"
  211. }
  212. this.content1 = this.content.content
  213. } else {
  214. uni.showToast({
  215. title: res.message,
  216. icon: 'none'
  217. })
  218. }
  219. }
  220. },
  221. onShow() {
  222. this.cutdownRatio = this.$getCutDown()
  223. },
  224. onShareAppMessage(params) {
  225. if (params.from === 'button' || params.from === 'menu') {
  226. return {
  227. title: this.content.name,
  228. imageUrl: this.$picBase + this.content.cover,
  229. path: '/pages/my/collectDetail/index?id=' + this.content.id,
  230. mpId: this.$appId,
  231. type: this.$shareType,
  232. }
  233. }
  234. },
  235. watch: {
  236. watchValue(n, o) {
  237. let showPrice = this.fullCheckArr.every((item, index) => {
  238. return item == 1
  239. })
  240. if (showPrice) {
  241. const filterResult = this.skuParams.sku.filter(item => {
  242. return this.conditions.every(condition => {
  243. const attrValues = this.skuParams.attrs[condition.key];
  244. return attrValues.includes(item[condition.key]) && item[condition.key] ===
  245. condition.value;
  246. });
  247. });
  248. this.totalPrice = filterResult[0].price * this.cutdownRatio
  249. // console.log('所求价格:', filterResult[0].price);
  250. }
  251. }
  252. },
  253. methods: {
  254. handleC(item, index, item1) {
  255. this.fullCheckArr[index] = 1
  256. // 声东击西强行触发监听
  257. this.watchValue = Date.now()
  258. this.saveCheckedObj[item] = item1
  259. //此处个条件对象数组条件赋值(key==外围数组key)
  260. this.conditions.forEach((item2, index2) => {
  261. if (item2.key == item) {
  262. item2.value = item1
  263. }
  264. })
  265. },
  266. async handleCol() {
  267. if (this.lovePic == "/static/mall/no_love.png") {
  268. let res = await addCollReq({
  269. id: this.content.id,
  270. })
  271. if (res.code == 0) {
  272. console.log('添加收藏返回值: ', res);
  273. this.$toast('收藏成功')
  274. this.totalCount += 1
  275. if (this.lovePic == "/static/mall/love.png") {
  276. this.lovePic = "/static/mall/no_love.png"
  277. } else {
  278. this.lovePic = "/static/mall/love.png"
  279. }
  280. } else {
  281. uni.showToast({
  282. title: res.message,
  283. icon: 'none'
  284. })
  285. }
  286. } else {
  287. let res = await cancelCollReq({
  288. id: this.content.id,
  289. })
  290. if (res.code == 0) {
  291. console.log('取消收藏返回值: ', res);
  292. this.$toast('取消收藏成功')
  293. this.totalCount -= 1
  294. if (this.lovePic == "/static/mall/love.png") {
  295. this.lovePic = "/static/mall/no_love.png"
  296. } else {
  297. this.lovePic = "/static/mall/love.png"
  298. }
  299. } else {
  300. uni.showToast({
  301. title: res.message,
  302. icon: 'none'
  303. })
  304. }
  305. }
  306. },
  307. handleOpenOrClose(i) {
  308. if (this['addOrLessIcon' + i] == '/static/index/shortLine.png') {
  309. this['addOrLessIcon' + i] = '/static/index/add.png'
  310. this['show' + i] = false
  311. } else if (this['addOrLessIcon' + i] == '/static/index/add.png') {
  312. this['addOrLessIcon' + i] = '/static/index/shortLine.png'
  313. this['show' + i] = true
  314. }
  315. },
  316. }
  317. }
  318. </script>
  319. <style lang="scss" scoped>
  320. @import "./index.scss";
  321. </style>