index.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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="1124rpx" 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">
  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 parmsList" v-if="navBarTitle" :key="index">
  35. <view class="con">
  36. <view class="title">
  37. {{item.title}}
  38. </view>
  39. <view class="list">
  40. <view class="item" v-for="(item1,index1) in item.list" :class="[index1==ids[index]?'act':'']"
  41. @click="">
  42. {{item1.data}}
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="parmasBox" v-for="(item,index) in parmsList" :key="index" v-if="!navBarTitle">
  48. <view class="con">
  49. <view class="title">
  50. {{item.title}}
  51. </view>
  52. <view class="list">
  53. <view class="item" v-for="(item1,index1) in item.list" :class="[item1.isSelect?'act':'']"
  54. @click="handleSel(item.list,index1,item[index],index)" :key="index1">
  55. {{item1.data}}
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="parmasBox" style="border-bottom: none;">
  61. <view class="con" @click="handleOpenOrClose(1)">
  62. <view class="title1">
  63. <view class="txt">
  64. 商品描述
  65. </view>
  66. <image class="add" :src="addOrLessIcon1" mode="" :style="{height:addOrLessIcon1=='/static/index/shortLine.png'
  67. ?'2rpx':'22rpx'}"></image>
  68. </view>
  69. <view class="des" v-if="show1">
  70. <u-parse :content="content1"></u-parse>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="bot" v-if="!navBarTitle">
  76. <view class="left">
  77. <view class="price">
  78. ¥{{totalPrice.toFixed(2)}}
  79. </view>
  80. <image src="/static/index/arrDown.png" mode=""></image>
  81. </view>
  82. <button open-type="share" class="right">
  83. 分享
  84. </button>
  85. </view>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. import {
  91. getMyCollectDetailReq,
  92. } from '@/api/my/index.js'
  93. import {
  94. addCollReq,
  95. cancelCollReq,
  96. getGoodsPriceReq,
  97. postOrderReq,
  98. } from '@/api/test/index.js'
  99. export default {
  100. components: {
  101. },
  102. data() {
  103. return {
  104. picUrl: this.$picUrl,
  105. picBase: this.$picBase,
  106. currIndex: 0,
  107. currIndex1: 0,
  108. currIndex2: 0,
  109. show1: false,
  110. addOrLessIcon1: '/static/index/add.png',
  111. lovePic: '/static/mall/love.png',
  112. content: null,
  113. currentNum: 0,
  114. bannerList: [],
  115. totalCount: 0,
  116. content1: '',
  117. parmsList: [],
  118. checkFullSel1: [],
  119. checkFullSel: 0,
  120. totalPrice: 0,
  121. parmsObj: {},
  122. navBarTitle: '',
  123. ids: [],
  124. cutdownRatio: 1
  125. }
  126. },
  127. async onLoad(o) {
  128. // o.id = 1
  129. if (o.id) {
  130. this.ids = JSON.parse(o.ids)
  131. this.navBarTitle = '首页'
  132. let res = await getMyCollectDetailReq({
  133. id: o.id
  134. })
  135. if (res.code == 0) {
  136. console.log('我的收藏详情', res);
  137. this.content = res.data
  138. this.bannerList = this.content.images
  139. this.totalCount = this.content.collect_total_count
  140. if (this.content.isCollect) {
  141. this.lovePic = "/static/mall/love.png"
  142. } else {
  143. this.lovePic = "/static/mall/no_love.png"
  144. }
  145. this.content1 = this.content.content
  146. this.parmsList = this.content.skuParams
  147. this.parmsList.forEach((item, index) => {
  148. this.parmsObj[item.title] = null
  149. this.checkFullSel1.push(0)
  150. })
  151. } else {
  152. uni.showToast({
  153. title: res.message,
  154. icon: 'none'
  155. })
  156. }
  157. } else {
  158. let res = await getMyCollectDetailReq({
  159. id: getApp().Sid
  160. })
  161. if (res.code == 0) {
  162. console.log('我的收藏详情', res);
  163. this.content = res.data
  164. this.bannerList = this.content.images
  165. this.totalCount = this.content.collect_total_count
  166. if (this.content.isCollect) {
  167. this.lovePic = "/static/mall/love.png"
  168. } else {
  169. this.lovePic = "/static/mall/no_love.png"
  170. }
  171. this.content1 = this.content.content
  172. this.parmsList = this.content.skuParams
  173. this.parmsList.forEach((item, index) => {
  174. this.parmsObj[item.title] = null
  175. this.checkFullSel1.push(0)
  176. })
  177. } else {
  178. uni.showToast({
  179. title: res.message,
  180. icon: 'none'
  181. })
  182. }
  183. }
  184. },
  185. onShow() {
  186. this.cutdownRatio = this.$getCutDown()
  187. },
  188. onShareAppMessage(params) {
  189. let ids = []
  190. this.parmsList.forEach((item, index) => {
  191. item.list.forEach((item1, index1) => {
  192. if (item1.isSelect) {
  193. ids.push(index1)
  194. }
  195. })
  196. })
  197. console.log('选中的二维iindex数组', ids);
  198. if (params.from === 'button' || params.from === 'menu') {
  199. return {
  200. title: this.content.name,
  201. imageUrl: this.$picBase + this.content.cover,
  202. path: '/pages/my/collectDetail/index?id=' + this.content.id + '&ids=' + JSON.stringify(ids),
  203. mpId: this.$appId,
  204. type: this.$shareType,
  205. }
  206. }
  207. },
  208. watch: {
  209. checkFullSel: {
  210. async handler(n, o) {
  211. let res = this.checkFullSel1.every((item, index) => {
  212. return item == 1
  213. })
  214. if (res) {
  215. let parms = []
  216. Object.keys(this.parmsObj).forEach((item4, index8) => {
  217. parms.push(this.parmsObj[item4])
  218. })
  219. console.log(parms);
  220. let res = await getGoodsPriceReq({
  221. goods_id: this.content.id,
  222. stock: parms
  223. })
  224. if (res.code == 0) {
  225. console.log(res);
  226. this.totalPrice = res.data * this.cutdownRatio
  227. } else {
  228. uni.showToast({
  229. title: res.message,
  230. icon: 'none'
  231. })
  232. }
  233. }
  234. },
  235. }
  236. },
  237. methods: {
  238. handleSel(item, index1, outer, pindex) {
  239. console.log('this.checkFullSel1', this.checkFullSel1);
  240. this.checkFullSel = Date.now()
  241. item.forEach(async (item2, index) => {
  242. item2.isSelect = 0
  243. if (index == index1) {
  244. item[index1].isSelect = 1
  245. this.parmsObj[item[index1].title] = {
  246. classify: item[index1].title,
  247. value: item[index1].data
  248. }
  249. this.checkFullSel1[pindex] = 1
  250. }
  251. })
  252. },
  253. async handleCol() {
  254. if (this.lovePic == "/static/mall/no_love.png") {
  255. let res = await addCollReq({
  256. id: this.content.id,
  257. })
  258. if (res.code == 0) {
  259. console.log('添加收藏返回值: ', res);
  260. this.$toast('收藏成功')
  261. this.totalCount += 1
  262. if (this.lovePic == "/static/mall/love.png") {
  263. this.lovePic = "/static/mall/no_love.png"
  264. } else {
  265. this.lovePic = "/static/mall/love.png"
  266. }
  267. } else {
  268. uni.showToast({
  269. title: res.message,
  270. icon: 'none'
  271. })
  272. }
  273. } else {
  274. let res = await cancelCollReq({
  275. id: this.content.id,
  276. })
  277. if (res.code == 0) {
  278. console.log('取消收藏返回值: ', res);
  279. this.$toast('取消收藏成功')
  280. this.totalCount -= 1
  281. if (this.lovePic == "/static/mall/love.png") {
  282. this.lovePic = "/static/mall/no_love.png"
  283. } else {
  284. this.lovePic = "/static/mall/love.png"
  285. }
  286. } else {
  287. uni.showToast({
  288. title: res.message,
  289. icon: 'none'
  290. })
  291. }
  292. }
  293. },
  294. handleOpenOrClose(i) {
  295. if (this['addOrLessIcon' + i] == '/static/index/shortLine.png') {
  296. this['addOrLessIcon' + i] = '/static/index/add.png'
  297. this['show' + i] = false
  298. } else if (this['addOrLessIcon' + i] == '/static/index/add.png') {
  299. this['addOrLessIcon' + i] = '/static/index/shortLine.png'
  300. this['show' + i] = true
  301. }
  302. },
  303. }
  304. }
  305. </script>
  306. <style lang="scss" scoped>
  307. @import "./index.scss";
  308. </style>