index.vue 9.0 KB

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