detail.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <page-loading :loading="loading">
  3. <scroll-view
  4. class="product-detail"
  5. scroll-x="false"
  6. :scroll-top="scrollTop"
  7. :scroll-into-view="intoView"
  8. scroll-y
  9. >
  10. <!-- 案例 -->
  11. <view id="top" class="cases">
  12. <image
  13. v-for="(item,index) in detail.cases"
  14. :key="index"
  15. class="full-img"
  16. :src="item"
  17. mode="aspectFill"
  18. @click="handlePreview(detail.cases, index)"
  19. />
  20. </view>
  21. <!-- 只有VIP用户和设计师才能查看 资料下载 -->
  22. <template v-if="userInfo.account.type === $const.ACCOUNT_DESIGN || userInfo.account.type === $const.ACCOUNT_VIP">
  23. <u-divider />
  24. <!-- 资料下载 -->
  25. <view id="file" class="file">
  26. <view class="header main-between cross-center">
  27. <view class="left main-left cross-center">
  28. <view class="icon icon-file" />
  29. <text>资料下载</text>
  30. </view>
  31. <view class="icon" @click="fileShow = !fileShow">
  32. <u-icon :name="fileShow?'minus':'plus'" size="36rpx" />
  33. </view>
  34. </view>
  35. <view class="content dir-top-wrap" :class="fileShow?'show':''">
  36. <view
  37. v-for="(item,index) in detail.files"
  38. :key="index"
  39. class="file-item main-between cross-center"
  40. >
  41. <text>{{ item.name }}</text>
  42. <view class="icon icon-download" @click="handleCopy(item)" />
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <!-- 只有VIP用户才能查看 价格 -->
  48. <template v-if="userInfo.account.type === $const.ACCOUNT_VIP">
  49. <u-divider />
  50. <!-- 查看价格 -->
  51. <view id="price" class="price main-between cross-center">
  52. <u-text :text="specsText" color="#B4936D" size="32rpx" :lines="1" />
  53. <view class="number">
  54. <u-text :text="price" mode="price" color="#B4936D" size="36rpx" align="right" />
  55. </view>
  56. </view>
  57. <!-- 规格 -->
  58. <u-divider />
  59. <view class="specs">
  60. <view
  61. v-for="(item, index) in specs"
  62. :key="index"
  63. class="spec-item"
  64. >
  65. <view class="group-name main-between cross-center">
  66. <text>{{ item.name }}</text>
  67. <u-icon :name="item.show?'minus':'plus'" @click="handleOpenSpec(item)" />
  68. </view>
  69. <view v-show="item.show" class="specs-content dir-left-wrap">
  70. <view
  71. v-for="(spec, specIndex) in item.specs"
  72. :key="specIndex"
  73. class="spec main-center cross-center"
  74. :class="{active: spec.active}"
  75. @click="handleSelectSpec(spec)"
  76. >
  77. {{ spec.name }}
  78. </view>
  79. </view>
  80. <u-divider />
  81. </view>
  82. </view>
  83. </template>
  84. <!--定位锚点-->
  85. <view class="float-view dir-top-wrap cross-center" :class="{show: showView}">
  86. <view class="icon icon-close" @click="showView = false" />
  87. <view class="view-item main-left cross-center" @click="scrollIntoView('top')">
  88. <view class="icon icon-up" />
  89. <text>回到顶部</text>
  90. </view>
  91. <view
  92. v-if="userInfo.account.type === $const.ACCOUNT_DESIGN || userInfo.account.type === $const.ACCOUNT_VIP"
  93. class="view-item main-left cross-center"
  94. @click="scrollIntoView('file')"
  95. >
  96. <view class="icon icon-down" />
  97. <text>资料下载</text>
  98. </view>
  99. <view
  100. v-if="userInfo.account.type === $const.ACCOUNT_VIP"
  101. class="view-item main-left cross-center"
  102. @click="scrollIntoView('price')"
  103. >
  104. <view class="icon icon-eye" />
  105. <text>查看价格</text>
  106. </view>
  107. </view>
  108. <view class="float-btn icon icon-float-btn" @click="showView = !showView" />
  109. </scroll-view>
  110. </page-loading>
  111. </template>
  112. <script>
  113. import { mapState } from 'vuex'
  114. import PageLoading from '@/components/PageLoading'
  115. export default {
  116. name: 'ProductDetail',
  117. components: { PageLoading },
  118. data() {
  119. return {
  120. id: '',
  121. loading: true,
  122. intoView: '',
  123. detail: {},
  124. specs: [],
  125. showView: false,
  126. scrollTop: 0,
  127. fileShow: false,
  128. selectedSpecs: []
  129. }
  130. },
  131. computed: {
  132. ...mapState({
  133. userInfo: seate => seate.user.info
  134. }),
  135. price() {
  136. let price = 0
  137. this.selectedSpecs.forEach(obj => {
  138. price += parseFloat(obj.price)
  139. })
  140. return price.toFixed(2)
  141. },
  142. specsText() {
  143. const specs = []
  144. this.selectedSpecs.forEach(obj => {
  145. specs.push(obj.name)
  146. })
  147. return specs.join(' ')
  148. }
  149. },
  150. watch: {
  151. specs: {
  152. handler(val) {
  153. console.log('-->data', val)
  154. },
  155. deep: true,
  156. immediate: true
  157. }
  158. },
  159. methods: {
  160. handlePreview(urls, current) {
  161. uni.previewImage({
  162. current,
  163. urls
  164. })
  165. },
  166. handleCopy(item) {
  167. this.$api.product.download(this.id).then(res => {
  168. this.$util.copyText(item.url)
  169. })
  170. },
  171. handleOpenSpec(item) {
  172. item.show = !item.show
  173. console.log('-->data', item)
  174. this.$forceUpdate()
  175. },
  176. handleSelectSpec(spec) {
  177. spec.active = !spec.active
  178. this.selectedSpecs = []
  179. this.specs.forEach(obj => {
  180. obj.specs.forEach((spec, index) => {
  181. if (spec.active) {
  182. this.selectedSpecs.push(spec)
  183. }
  184. })
  185. })
  186. this.$forceUpdate()
  187. },
  188. scrollIntoView(name) {
  189. this.intoView = name
  190. if (this.timeout) {
  191. clearTimeout(this.timeout)
  192. }
  193. this.timeout = setTimeout(() => {
  194. this.intoView = ''
  195. })
  196. },
  197. getDetail() {
  198. this.$api.product.detail(this.id).then(res => {
  199. wx.setNavigationBarTitle({
  200. title: res.data.name
  201. })
  202. this.loading = false
  203. res.data.specs.forEach(obj => {
  204. obj.show = true
  205. obj.specs.forEach((spec, index) => {
  206. obj.active = false
  207. spec.key = obj.id + spec.name + index
  208. })
  209. })
  210. this.detail = res.data
  211. this.specs = res.data.specs
  212. })
  213. },
  214. viewer() {
  215. this.$api.product.viewer(this.id).then(res => {
  216. })
  217. }
  218. },
  219. onLoad(options) {
  220. this.id = options.id
  221. this.getDetail()
  222. this.viewer()
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .product-detail {
  228. padding: 20rpx 0rpx 120rpx;
  229. height: 100vh;
  230. .cases{
  231. width: 740rpx;
  232. margin: 0 auto;
  233. .full-img{
  234. width: 740rpx;
  235. margin-bottom: -8rpx;
  236. }
  237. }
  238. .file{
  239. width: 710rpx;
  240. margin: 0 auto;
  241. .header{
  242. padding: 20rpx 0;
  243. .left{
  244. text{
  245. margin-left: 10rpx;
  246. font-size: 32rpx;
  247. }
  248. }
  249. }
  250. .content{
  251. padding: 10rpx 20rpx 30rpx;
  252. display: none;
  253. .file-item{
  254. padding: 10rpx 0 20rpx 30rpx;
  255. color: #333;
  256. font-size: 26rpx;
  257. .icon{
  258. padding-right: 150rpx;
  259. }
  260. }
  261. &.show{
  262. display: flex;
  263. }
  264. }
  265. }
  266. .price{
  267. width: 710rpx;
  268. margin: 50rpx auto;
  269. .number{
  270. max-width: 320rpx;
  271. }
  272. }
  273. .specs{
  274. padding-bottom: 80rpx;
  275. width: 710rpx;
  276. margin: 0 auto;
  277. .spec-item{
  278. color: #333;
  279. margin-bottom: 30rpx;
  280. .group-name{
  281. padding: 10rpx 20rpx 40rpx 0 ;
  282. text{
  283. font-size: 32rpx;
  284. font-weight: 600;
  285. }
  286. }
  287. .specs-content{
  288. .spec{
  289. margin: 0 5rpx 10rpx;
  290. min-width: 130rpx;
  291. padding: 10rpx 30rpx;
  292. transition: .5s;
  293. &.active{
  294. background: #030303;
  295. color: #fff;
  296. }
  297. }
  298. }
  299. }
  300. }
  301. .float-btn{
  302. position: fixed;
  303. bottom: 120rpx;
  304. right: 0rpx;
  305. }
  306. .float-view{
  307. position: fixed;
  308. width: 220rpx;
  309. height: 260rpx;
  310. background: #fff;
  311. bottom: 220rpx;
  312. right: 30rpx;
  313. box-shadow: 0 0 20rpx rgba(0,0,0,.1);
  314. border-radius: 30rpx;
  315. display: none;
  316. transition: .5s;
  317. padding: 10rpx;
  318. &.show{
  319. display: flex;
  320. }
  321. .icon-close{
  322. position: absolute;
  323. right: -10rpx;
  324. top: -10rpx;
  325. }
  326. .view-item{
  327. position: relative;
  328. padding: 20rpx 0;
  329. &:last-child:after{
  330. content: unset;
  331. }
  332. &:after{
  333. content: "";
  334. position: absolute;
  335. width: 68%;
  336. bottom: 0;
  337. left: 28%;
  338. height: 1rpx;
  339. background: #EFEFEF;
  340. }
  341. text{
  342. margin-left: 16rpx;
  343. color: #333333;
  344. }
  345. }
  346. }
  347. }
  348. </style>