index.vue 8.9 KB

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