detail.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. this.loading = false
  200. res.data.specs.forEach(obj => {
  201. obj.show = true
  202. obj.specs.forEach((spec, index) => {
  203. obj.active = false
  204. spec.key = obj.id + spec.name + index
  205. })
  206. })
  207. this.detail = res.data
  208. this.specs = res.data.specs
  209. })
  210. },
  211. viewer() {
  212. this.$api.product.viewer(this.id).then(res => {
  213. })
  214. }
  215. },
  216. onLoad(options) {
  217. this.id = options.id
  218. this.getDetail()
  219. this.viewer()
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. .product-detail {
  225. padding: 20rpx 20rpx 0;
  226. width: 710rpx;
  227. height: 100vh;
  228. .cases{
  229. .full-img{
  230. width: 710rpx;
  231. margin-bottom: 10rpx;
  232. }
  233. }
  234. .file{
  235. .header{
  236. padding: 20rpx 0;
  237. .left{
  238. text{
  239. margin-left: 10rpx;
  240. font-size: 32rpx;
  241. }
  242. }
  243. }
  244. .content{
  245. padding: 10rpx 20rpx 30rpx;
  246. display: none;
  247. .file-item{
  248. padding: 10rpx 0 20rpx 30rpx;
  249. color: #333;
  250. font-size: 26rpx;
  251. }
  252. &.show{
  253. display: flex;
  254. }
  255. }
  256. }
  257. .price{
  258. margin: 50rpx 0;
  259. .number{
  260. max-width: 320rpx;
  261. }
  262. }
  263. .specs{
  264. padding-bottom: 80rpx;
  265. .spec-item{
  266. color: #333;
  267. margin-bottom: 30rpx;
  268. .group-name{
  269. padding: 10rpx 20rpx 40rpx 0 ;
  270. text{
  271. font-size: 32rpx;
  272. font-weight: 600;
  273. }
  274. }
  275. .specs-content{
  276. .spec{
  277. margin: 0 5rpx 10rpx;
  278. min-width: 130rpx;
  279. padding: 10rpx 30rpx;
  280. transition: .5s;
  281. &.active{
  282. background: #030303;
  283. color: #fff;
  284. }
  285. }
  286. }
  287. }
  288. }
  289. .float-btn{
  290. position: fixed;
  291. bottom: 120rpx;
  292. right: 10rpx;
  293. }
  294. .float-view{
  295. position: fixed;
  296. width: 220rpx;
  297. height: 260rpx;
  298. background: #fff;
  299. bottom: 220rpx;
  300. right: 30rpx;
  301. box-shadow: 0 0 20rpx rgba(0,0,0,.1);
  302. border-radius: 30rpx;
  303. display: none;
  304. transition: .5s;
  305. padding: 10rpx;
  306. &.show{
  307. display: flex;
  308. }
  309. .icon-close{
  310. position: absolute;
  311. right: -10rpx;
  312. top: -10rpx;
  313. }
  314. .view-item{
  315. position: relative;
  316. padding: 20rpx 0;
  317. &:last-child:after{
  318. content: unset;
  319. }
  320. &:after{
  321. content: "";
  322. position: absolute;
  323. width: 68%;
  324. bottom: 0;
  325. left: 28%;
  326. height: 1rpx;
  327. background: #EFEFEF;
  328. }
  329. text{
  330. margin-left: 16rpx;
  331. color: #333333;
  332. }
  333. }
  334. }
  335. }
  336. </style>