active.vue 12 KB

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