detail.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <view class="wrap" v-if="hasLoad">
  3. <u-navbar title="礼品详情" :placeholder="true" bgColor="rgba(255,255,255,0.3)" leftText="返回" :autoBack="true" titleStyle="font-weight:bold;color:#7a5831"></u-navbar>
  4. <view class="carousel">
  5. <swiper indicator-dots circular="true" duration="400">
  6. <swiper-item class="swiper-item" v-for="(item, index) in state.photo_list" :key="index">
  7. <view class="image-wrapper">
  8. <image :src="item" mode="aspectFill"></image>
  9. </view>
  10. </swiper-item>
  11. </swiper>
  12. </view>
  13. <view class="info">
  14. <view class="b-title">{{ state.name }}</view>
  15. <view class="b-data">
  16. <view class="s-worth" v-if="state.order_worth > 0">价值 {{ state.order_worth }}元</view>
  17. <view class="s-count">
  18. <view class="s-left">库存 {{ state.count_left }}</view>
  19. <view class="s-gain">已兑 {{ state.count_gain }}</view>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="specs" v-if="state.spec_list">
  24. <view class="b-title">选择规格</view>
  25. <view class="b-items">
  26. <view class="b-item" v-for="(item, index) in state.spec_list" :key="index" :class="{ 'f-active': index == specIndex }" @click="onSpecSelect(index)">
  27. {{ item.name }}
  28. </view>
  29. </view>
  30. <view class="b-data">
  31. <view class="s-left">库存 {{ state.spec_list[specIndex].count_left }}</view>
  32. <view class="s-gain">已兑 {{ state.spec_list[specIndex].count_gain }}</view>
  33. </view>
  34. </view>
  35. <view class="content">
  36. <view class="b-title">
  37. <view class="iconfont icon-line"></view>
  38. <view class="s-tit">奖品详情</view>
  39. <view class="iconfont icon-line"></view>
  40. </view>
  41. <view class="b-rich">
  42. <rich-text :nodes="goodContent"></rich-text>
  43. </view>
  44. </view>
  45. <view class="navbar">
  46. <view class="b-action">
  47. <view class="s-exchange f-disable" v-if="state.order_state == 1">兑换未开始</view>
  48. <view class="s-exchange f-disable" v-else-if="state.order_state == 2">兑换已结束</view>
  49. <view class="s-exchange f-disable" v-else-if="state.order_state == 3">兑换机会不足</view>
  50. <view class="s-exchange f-disable" v-else-if="state.order_state == 4">已兑换完</view>
  51. <view class="s-exchange" @click="onExchange()" v-else>立即兑换</view>
  52. </view>
  53. </view>
  54. <!-- 加载中 -->
  55. <load-more :loadingType="loadingType" :loadingText="loadingText" :top="300"></load-more>
  56. </view>
  57. </template>
  58. <script>
  59. import { getDetail } from '@/service/api/gift.js';
  60. import { formatRichText } from '@/common/util.js';
  61. // import mixinsCommon from '@/mixins/common.js';
  62. // import mixinsAuth from '../../mixins/auth.js';
  63. export default {
  64. // mixins: [mixinsCommon, mixinsAuth],
  65. data() {
  66. return {
  67. state: {},
  68. specIndex: 0,
  69. hasLoad: false,
  70. loadingType: 1,
  71. loadingText: ''
  72. };
  73. },
  74. onLoad(options) {
  75. this.loadDetail(options.gift_id);
  76. },
  77. computed: {
  78. goodContent() {
  79. return formatRichText(this.state.content);
  80. }
  81. },
  82. methods: {
  83. loadDetail(giftId) {
  84. getDetail(giftId).then(([err, res]) => {
  85. console.log('getDetail', err, res);
  86. if (!err) {
  87. this.hasLoad = true;
  88. this.loadingType = -1;
  89. this.state = res;
  90. // if (err.code == 0) {
  91. // uni.navigateTo({
  92. // url: '/answer_pages/home/dashboard'
  93. // });
  94. // }
  95. } else {
  96. this.loadingType = 3;
  97. this.loadingText = err.data.msg || '加载失败';
  98. }
  99. });
  100. },
  101. onExchange() {
  102. let specId = this.state.spec_list ? this.state.spec_list[this.specIndex].id : 0;
  103. uni.navigateTo({
  104. url: '/answer_pages/gift/exchange?gift_id=' + this.state.id + '&spec_id=' + specId
  105. });
  106. },
  107. onSpecSelect(index) {
  108. this.specIndex = index;
  109. this.state.order_worth = this.state.spec_list[this.specIndex].worth;
  110. }
  111. }
  112. };
  113. </script>
  114. <style lang="scss">
  115. // page {
  116. // padding-bottom: env(safe-area-inset-bottom);
  117. // background: $pq-bg-color;
  118. // }
  119. .wrap {
  120. }
  121. .carousel {
  122. height: 500upx;
  123. position: relative;
  124. swiper {
  125. height: 100%;
  126. }
  127. .swiper-item {
  128. display: flex;
  129. justify-content: center;
  130. align-content: center;
  131. height: 320upx;
  132. overflow: hidden;
  133. image {
  134. width: 100%;
  135. height: 100%;
  136. }
  137. }
  138. .image-wrapper {
  139. width: 100%;
  140. height: 100%;
  141. }
  142. }
  143. .info {
  144. padding: 30upx;
  145. background: #fff;
  146. .b-title {
  147. font-size: 28upx;
  148. }
  149. .b-data {
  150. margin-top: 20upx;
  151. display: flex;
  152. align-items: center;
  153. justify-content: space-between;
  154. .s-worth {
  155. color: #999;
  156. font-size: 24upx;
  157. }
  158. .s-count {
  159. color: #999;
  160. font-size: 24upx;
  161. display: flex;
  162. align-items: center;
  163. .s-left {
  164. }
  165. .s-gain {
  166. margin-left: 40upx;
  167. }
  168. }
  169. }
  170. }
  171. .specs {
  172. margin-top: 30upx;
  173. padding: 30upx;
  174. background: #fff;
  175. .b-title {
  176. font-size: 30upx;
  177. }
  178. .b-items {
  179. margin-top: 30upx;
  180. .b-item {
  181. margin-right: 20upx;
  182. padding: 0 40upx;
  183. height: 60upx;
  184. line-height: 60upx;
  185. display: inline-block;
  186. background: #fff;
  187. border: 1upx solid #e4eaf1;
  188. color: #667085;
  189. font-size: 26upx;
  190. &.f-active {
  191. background: #da5650;
  192. border: none;
  193. color: #fff;
  194. }
  195. }
  196. }
  197. .b-data {
  198. margin-top: 30upx;
  199. color: #666;
  200. font-size: 24upx;
  201. display: flex;
  202. align-items: center;
  203. .s-left {
  204. }
  205. .s-gain {
  206. margin-left: 40upx;
  207. }
  208. }
  209. }
  210. .content {
  211. margin-top: 30upx;
  212. .b-title {
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. .iconfont {
  217. color: #ccc;
  218. }
  219. .s-tit {
  220. margin: 0 20upx;
  221. font-size: 24upx;
  222. color: #666;
  223. }
  224. }
  225. .b-rich {
  226. margin-top: 30upx;
  227. padding: 30upx 0;
  228. background: #fff;
  229. font-size: 28upx;
  230. }
  231. }
  232. .navbar {
  233. position: fixed;
  234. left: 0;
  235. bottom: 0;
  236. width: 100%;
  237. height: 100upx;
  238. background: #fff;
  239. // border-top: 1upx solid #f6f6f6;
  240. display: flex;
  241. align-items: center;
  242. justify-content: space-between;
  243. .b-action {
  244. flex: 1;
  245. .s-exchange {
  246. background: #da5650;
  247. height: 100upx;
  248. padding: 0 60upx;
  249. line-height: 100upx;
  250. font-size: 30upx;
  251. color: #fff;
  252. letter-spacing: 4upx;
  253. text-align: center;
  254. &.f-disable {
  255. background: rgba(218, 86, 80, 0.8);
  256. }
  257. }
  258. }
  259. }
  260. </style>