active.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <view>
  3. <view class="banner_box">
  4. <image class="banner_img" :src="activeInfo.banner_img" ></image>
  5. </view>
  6. <view class="active_info">
  7. <view class="active_name">{{activeInfo.name}}</view>
  8. <view class="active_time">活动时间:{{activeInfo.start_date}} ~ {{activeInfo.end_date}}</view>
  9. <view class="active_citys" v-if="activeInfo.city_ids">活动范围:{{activeInfo.city_ids}}</view>
  10. </view>
  11. <view class="active_coupon">
  12. <view class="active_subtitle">优惠券</view>
  13. <view class="coupon_list">
  14. <view class="coupon_item" v-for="(item,index) in activeInfo.coupon_list" :key="index">
  15. <view class="left_box">
  16. <view class="rebate" v-if="item.rebate_type == 1" > ¥{{item.rebate}}</view>
  17. <view class="rebate" v-if="item.rebate_type == 2" > 打 {{item.rebate}} 折</view>
  18. <view class="rebate" v-if="item.rebate_type == 3" > 赠 <text v-if="item.rebate_scope.length">{{item.rebate_scope[0].product_name}}</text> </view>
  19. <view class="std_pay">满 ¥{{item.std_pay}} 可用</view>
  20. <view class="coupon_exp">有效期:{{item.exp_time}}</view>
  21. </view>
  22. <view class="right_box">
  23. <button class="get_btn" v-if="item.is_have == 0" @click="getCoupon(index)">立即领取</button>
  24. <button class="get_btn" v-if="item.is_have == 1" @click="toUse(item)">去使用</button>
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. <view class="active_product" v-if="activeInfo.product_list.length" >
  30. <view class="active_subtitle">活动商品</view>
  31. <view class="product_list" :class="show_more_product?'more':''">
  32. <view class="product_item" v-for="(item,index) in activeInfo.product_list" :key="index" >
  33. <image class="product_image" :src="item.thumb" mode=""></image>
  34. <view class="product_name"><text>{{item.product_name}}</text></view>
  35. <view class="stock_price">
  36. <view class="product_price" >
  37. <text >¥ {{item.price}} </text>
  38. </view>
  39. <view class="product_stock">剩{{item.stock}}个</view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="more_product" v-if="!show_more_product" @click.stop="show_more_product = true">
  44. <uni-icons type="down" size="20" ></uni-icons>
  45. </view>
  46. </view>
  47. <view class="active_rule" v-if="activeInfo.active_rule">
  48. <view class="active_subtitle">活动规则</view>
  49. <view class="active_rule_info">
  50. <rich-text class="rich_text" :nodes="activeInfo.active_rule"></rich-text>
  51. </view>
  52. </view>
  53. <view class="" style="height: 10rpx;"></view>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. // 是否显示更多的产品
  61. show_more_product:false,
  62. // 活动信息
  63. activeInfo:{
  64. id:0,
  65. name:"",
  66. banner_img:"",
  67. active_rule:"",
  68. status:0,
  69. start_time:0,
  70. end_time:0,
  71. city_ids:"",
  72. allow_join:0,
  73. start_date:"",
  74. end_date:"",
  75. coupon_list:[],
  76. product_list:[],
  77. },
  78. // 请求参数
  79. requestParam:{
  80. id:0
  81. },
  82. }
  83. },
  84. onLoad(param) {
  85. this.requestParam.id = param.id;
  86. // 如果有scene参数的话,获取其中的ID
  87. if( param.scene ) {
  88. // 转键值对参数
  89. let scene = this.$http.strToParam(param.scene);
  90. // 如果没有传入ID,但是传入了场景ID,获取场景ID
  91. if( !param.id && scene.id ) this.requestParam.id = scene.id;
  92. }
  93. // #ifdef MP-WEIXIN
  94. //分享按钮
  95. uni.showShareMenu({
  96. withShareTicket: true,
  97. menus: ['shareAppMessage', 'shareTimeline']
  98. })
  99. // #endif
  100. },
  101. onShareAppMessage(obj) {
  102. return {
  103. title: this.activeInfo.name,
  104. path: '/pages/coupon/active?id='+this.requestParam.id,
  105. }
  106. },
  107. onShow() {
  108. // 登录提示
  109. if( !this.$checkAccess.alterLogin() ) return ;
  110. // 如果存在产品ID的话
  111. if( this.requestParam.id > 0) {
  112. // 请求详情
  113. this.$http.request('api/coupon_active/get_detail',this.requestParam).then((re)=>{
  114. // 成功渲染数据
  115. if( re.code == 'success' ) {
  116. // 刷新数据
  117. this.activeInfo = re.data;
  118. // 列表大于2.显示
  119. if( re.data.product_list.length <= 2 ) this.show_more_product = true;
  120. }else{
  121. if( re.code != 'no_login' ){
  122. uni.showModal({
  123. content:re.msg,
  124. showCancel:false,
  125. })
  126. }
  127. }
  128. });
  129. }else{
  130. uni.showModal({
  131. content:"未知的活动ID",
  132. showCancel:false,
  133. })
  134. }
  135. },
  136. methods: {
  137. toUse(item){
  138. // 没有范围
  139. if( item.type_id == 2 ){
  140. uni.switchTab({url:"/pages/index/index"});
  141. return;
  142. }
  143. // 只有一个商品,直接跳转到对应商品
  144. if( item.product_scope.length == 1 ){
  145. uni.navigateTo({
  146. url:"/pages/product/index?product_id="+item.product_scope[0]
  147. })
  148. return;
  149. }
  150. // 没有范围
  151. if( item.product_scope.length > 1 ){
  152. uni.navigateTo({
  153. url:"/pages/coupon/product?coupon_id="+item.coupon_id
  154. });
  155. return;
  156. }
  157. },
  158. getCoupon(index){
  159. // 获取对应的数据
  160. let couponId = this.activeInfo.coupon_list[index].coupon_id;
  161. // 如果不能参与
  162. if( !this.activeInfo.allow_join ) {
  163. uni.showModal({
  164. content:"暂不可参与活动",
  165. showCancel:false,
  166. })
  167. return;
  168. }
  169. // 如果存在优惠券
  170. if( couponId > 0) {
  171. // 请求详情
  172. this.$http.request('api/custom_coupon/get_coupon',{coupon_id:couponId}).then((re)=>{
  173. // 成功渲染数据
  174. if( re.code == 'success' ) {
  175. this.activeInfo.coupon_list[index].is_have = 1;
  176. }else{
  177. uni.showModal({
  178. content:re.msg,
  179. showCancel:false,
  180. })
  181. }
  182. });
  183. }else{
  184. uni.showModal({
  185. content:"请选择要领取的优惠券",
  186. showCancel:false,
  187. })
  188. }
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang="less">
  194. .banner_box{
  195. width: 750rpx;
  196. height: 240rpx;
  197. display: block;
  198. overflow: hidden;
  199. margin: 0rpx auto;
  200. .banner_img{
  201. width: 750rpx;
  202. height: 240rpx;
  203. }
  204. }
  205. .active_info{
  206. width: 750rpx;
  207. display: block;
  208. overflow: hidden;
  209. margin: 0rpx auto;
  210. padding: 10rpx 35rpx;
  211. background-color: #FFFFFF;
  212. .active_name{
  213. display: block;
  214. height: 60rpx;
  215. font-size: 36rpx;
  216. font-weight: bold;
  217. line-height: 60rpx;
  218. overflow: hidden;
  219. white-space: nowrap;
  220. text-overflow: ellipsis;
  221. }
  222. .active_time{
  223. display: block;
  224. height: 40rpx;
  225. font-size: 26rpx;
  226. line-height: 40rpx;
  227. overflow: hidden;
  228. white-space: nowrap;
  229. text-overflow: ellipsis;
  230. }
  231. .active_citys{
  232. display: block;
  233. max-height: 80rpx;
  234. font-size: 26rpx;
  235. line-height: 40rpx;
  236. overflow: hidden;
  237. white-space: nowrap;
  238. text-overflow: ellipsis;
  239. }
  240. }
  241. .active_coupon{
  242. display: block;
  243. overflow: hidden;
  244. margin-top: 20rpx;
  245. padding: 0rpx 35rpx;
  246. .active_subtitle{
  247. display: block;
  248. height: 80rpx;
  249. overflow: hidden;
  250. font-size: 32rpx;
  251. font-weight: bold;
  252. line-height: 80rpx;
  253. }
  254. .coupon_list{
  255. display: block;
  256. overflow: hidden;
  257. .coupon_item{
  258. display: block;
  259. height: 140rpx;
  260. overflow: hidden;
  261. padding: 10rpx 25rpx;
  262. border-radius: 15rpx;
  263. margin-bottom: 10rpx;
  264. background-color: #FFFFFF;
  265. .left_box{
  266. float: left;
  267. width: 400rpx;
  268. height: 140rpx;
  269. display: block;
  270. .rebate{
  271. color: #E03519;
  272. height: 60rpx;
  273. overflow: hidden;
  274. font-size: 36rpx;
  275. line-height: 60rpx;
  276. font-weight: bold;
  277. white-space: nowrap;
  278. text-overflow: ellipsis;
  279. }
  280. .std_pay{
  281. color: #666666;
  282. height: 40rpx;
  283. font-size: 24rpx;
  284. line-height: 40rpx;
  285. }
  286. .coupon_exp{
  287. color: #666666;
  288. height: 40rpx;
  289. font-size: 24rpx;
  290. line-height: 40rpx;
  291. }
  292. }
  293. .right_box{
  294. float: right;
  295. width: 160rpx;
  296. height: 60rpx;
  297. display: block;
  298. margin-top: 40rpx;
  299. .get_btn{
  300. display: block;
  301. width: 160rpx;
  302. height: 60rpx;
  303. color: #FFFFFF;
  304. font-size: 26rpx;
  305. line-height: 60rpx;
  306. text-align: center;
  307. padding: 0rpx 0rpx;
  308. border-radius: 10rpx;
  309. background-color: #E03519;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. .active_product{
  316. display: block;
  317. overflow: hidden;
  318. margin-top: 10rpx;
  319. padding: 0rpx 35rpx;
  320. .active_subtitle{
  321. display: block;
  322. height: 80rpx;
  323. overflow: hidden;
  324. font-size: 32rpx;
  325. font-weight: bold;
  326. line-height: 80rpx;
  327. }
  328. .product_list{
  329. display: block;
  330. height: 520rpx;
  331. overflow: hidden;
  332. .product_item{
  333. float: left;
  334. width: 320rpx;
  335. height: 480rpx;
  336. display: block;
  337. overflow: hidden;
  338. margin-top: 20rpx;
  339. margin-right: 40rpx;
  340. background-color: #FFFFFF;
  341. border-radius: 20rpx;
  342. .product_image{
  343. width: 320rpx;
  344. height: 320rpx;
  345. }
  346. .product_name{
  347. height: 80rpx;
  348. font-size: 30rpx;
  349. line-height: 40rpx;
  350. overflow: hidden;
  351. margin: 0rpx 0rpx;
  352. padding: 0rpx 10rpx;
  353. text-overflow: ellipsis;
  354. }
  355. .stock_price{
  356. color: #dddddd;
  357. font-size: 20rpx;
  358. overflow: hidden;
  359. line-height: 30rpx;
  360. padding: 0rpx 10rpx;
  361. .product_price{
  362. float: left;
  363. color: red;
  364. font-size: 30rpx;
  365. line-height: 60rpx;
  366. .product_market{
  367. font-size: 24rpx;
  368. color: #999999;
  369. line-height: 30rpx;
  370. vertical-align: top;
  371. text-decoration: line-through;
  372. }
  373. }
  374. .product_stock{
  375. float: right;
  376. font-size: 20rpx;
  377. line-height: 60rpx;
  378. }
  379. }
  380. }
  381. .product_item:nth-child(even){
  382. margin-right: 0rpx;
  383. }
  384. }
  385. .product_list.more{
  386. height: auto !important;
  387. }
  388. .more_product{
  389. z-index: 8;
  390. left: 0rpx;
  391. top: -10rpx;
  392. height: 40rpx;
  393. display: block;
  394. font-size: 20rpx;
  395. line-height: 40rpx;
  396. text-align: center;
  397. position: relative;
  398. border-radius: 5rpx;
  399. background-color: rgba(0, 0, 0, 0.1);
  400. }
  401. }
  402. .active_rule{
  403. display: block;
  404. overflow: hidden;
  405. margin-top: 10rpx;
  406. padding: 0rpx 35rpx;
  407. margin-bottom: 160rpx;
  408. .active_subtitle{
  409. display: block;
  410. height: 80rpx;
  411. overflow: hidden;
  412. font-size: 32rpx;
  413. font-weight: bold;
  414. line-height: 80rpx;
  415. }
  416. .active_rule_info{
  417. display: block;
  418. overflow: hidden;
  419. font-size: 24rpx;
  420. min-height: 500rpx;
  421. line-height: 40rpx;
  422. border-radius: 10rpx;
  423. padding: 20rpx 20rpx;
  424. box-sizing: border-box;
  425. background-color: #FFFFFF;
  426. .rich_text{
  427. white-space: break-spaces;
  428. }
  429. }
  430. }
  431. </style>