coupon.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <view class="container" v-if="total !== null">
  3. <!-- 头部优惠券总数量区域 -->
  4. <view class="header">
  5. 可使用优惠券
  6. <text>{{ total }}张</text>
  7. </view>
  8. <!-- 优惠券列表区域 -->
  9. <scroll-view class="body" scroll-y @scrolltolower="scrolltolower">
  10. <!-- 每一张优惠券区域 -->
  11. <view class="body_item" v-for="item in list" :key="item.id">
  12. <img src="../../static/my/couponTitle.png" />
  13. <view class="item_type" v-if="item.type === 2">折扣卷</view>
  14. <view class="item_type" v-if="item.type === 1">代金卷</view>
  15. <view class="item_box">
  16. <view class="box_left">
  17. <view class="left_title">{{ item.name }}</view>
  18. <view class="left_tags">
  19. <view class="tag">有限期至{{ item.effectiveEndDate.slice(0, 10) }}</view>
  20. <view class="tag" v-if="item.hotelIds.includes('-1')">全名宿</view>
  21. <view class="tag" v-else @click="handleClickTag(item.hotelIds)">
  22. 指定名宿
  23. <img src="../../static/index/right2.png" />
  24. </view>
  25. </view>
  26. </view>
  27. <view class="box_right">
  28. <view class="right_info">
  29. <view class="info_top">{{ item.type === 1 ? '¥' + item.deductionPrice : item.rebatePrice + '折' }}</view>
  30. <view class="info_bottom" :class="{ color: item.meetPrice === 0 }">{{ item.meetPrice === 0 ? '无门槛' : '满' + item.meetPrice + '可用' }}</view>
  31. <view class="info_bottom">
  32. {{ item.type === 2 ? '最多减免' + item.maxDeduction : '' }}
  33. </view>
  34. </view>
  35. <view class="right_radio">
  36. <radio style="transform: scale(0.8)" color="#096562" :checked="item.isCheck" @click="handleChange(item)" />
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </scroll-view>
  42. <!-- 底部确定按钮区域 -->
  43. <view class="foot_btn" @click="handleConfirm">确定</view>
  44. <!-- 指定民宿弹窗区域 -->
  45. <uni-popup ref="popup" type="center" :is-mask-click="false">
  46. <view class="popup_body">
  47. <view class="popup_header">
  48. <img src="../../static/my/popup_title.png" />
  49. <view class="header_title">指定民宿</view>
  50. <img src="../../static/my/popup_title.png" />
  51. </view>
  52. <view class="popup_center">{{ hotels }}</view>
  53. <view class="popup_btn" @click="handleClose">我知道了</view>
  54. </view>
  55. </uni-popup>
  56. </view>
  57. </template>
  58. <script>
  59. export default {
  60. data() {
  61. return {
  62. list: [],
  63. hotelId: '',
  64. page: 1,
  65. rows: 10,
  66. total: null,
  67. // 指定民宿信息
  68. hotels: '',
  69. totalPrice: null,
  70. complaintId: null
  71. }
  72. },
  73. onLoad(options) {
  74. this.hotelId = options.id
  75. this.totalPrice = options.totalPrice
  76. this.complaintId = options.complaintId
  77. this.getCouponNum()
  78. },
  79. methods: {
  80. scrolltolower() {
  81. if (this.list.length < this.total) {
  82. this.page++
  83. this.getCouponNum()
  84. } else {
  85. uni.showToast({
  86. title: '没有更多数据了',
  87. icon: 'none'
  88. })
  89. }
  90. },
  91. // 确定按钮回调
  92. async handleConfirm() {
  93. let temObj = this.list.find((ele) => ele.isCheck)
  94. if (temObj) {
  95. const res = await this.$myRequest({
  96. url: '/mhotel/hcuseCoupons.action',
  97. method: 'post',
  98. data: {
  99. id: temObj.id,
  100. complaintId: temObj.complaintId,
  101. totalPrice: this.totalPrice
  102. }
  103. })
  104. // console.log(res)
  105. if (res.code === 200) {
  106. uni.$emit('choose', { data: res.data })
  107. }
  108. } else {
  109. uni.$emit('choose', { data: { discountAmount: 0 } })
  110. }
  111. uni.navigateBack(1)
  112. },
  113. // 点击指定民宿tag回调
  114. async handleClickTag(ids) {
  115. const res = await this.$myRequest({
  116. url: '/mhotel/hcdesignatedHotel.action',
  117. data: {
  118. hotelIds: ids.join()
  119. }
  120. })
  121. // console.log(res)
  122. if (res.code === 200) {
  123. this.hotels = res.data.name
  124. }
  125. this.$refs.popup.open()
  126. },
  127. async getCouponNum() {
  128. const res = await this.$myRequest({
  129. url: '/mhotel/hcusefulCoupon.action',
  130. data: {
  131. hotelId: this.hotelId,
  132. page: this.page,
  133. rows: this.rows,
  134. userId: uni.getStorageSync('userInfo').id
  135. }
  136. })
  137. // console.log(res);
  138. if (res.code === 200) {
  139. this.list = [...this.list, ...res.page.pageList]
  140. this.total = res.page.total
  141. this.list.forEach((ele, index) => {
  142. ele.hotelIds = ele.hotelIds.split(',')
  143. this.$set(ele, 'isCheck', false)
  144. })
  145. if (this.complaintId !== 'undefined') {
  146. const num = this.list.findIndex((e) => e.complaintId === this.complaintId)
  147. this.list[num].isCheck = true
  148. }
  149. }
  150. },
  151. handleChange(item) {
  152. if (item.isCheck) {
  153. item.isCheck = !item.isCheck
  154. } else {
  155. this.list.forEach((ele) => {
  156. if (item.id === ele.id) {
  157. ele.isCheck = true
  158. } else {
  159. ele.isCheck = false
  160. }
  161. })
  162. }
  163. },
  164. // 点击弹窗我知道了按钮回调
  165. handleClose() {
  166. this.$refs.popup.close()
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss" scoped>
  172. .container {
  173. box-sizing: border-box;
  174. padding: 0 30rpx;
  175. height: 100vh;
  176. background-color: #f7f7f7;
  177. .header {
  178. display: flex;
  179. align-items: center;
  180. height: 100rpx;
  181. font-size: 32rpx;
  182. text {
  183. margin-top: 10rpx;
  184. margin-left: 15rpx;
  185. color: #808080;
  186. font-size: 24rpx;
  187. }
  188. }
  189. .body {
  190. height: calc(100vh - 245rpx);
  191. overflow-y: auto;
  192. .body_item {
  193. position: relative;
  194. margin-bottom: 10rpx;
  195. padding-bottom: 10rpx;
  196. width: 690rpx;
  197. border-radius: 15rpx;
  198. background-color: #fff;
  199. img {
  200. width: 100rpx;
  201. height: 36rpx;
  202. }
  203. .item_type {
  204. position: absolute;
  205. top: 0;
  206. left: 14rpx;
  207. font-size: 24rpx;
  208. font-weight: bold;
  209. color: #fff;
  210. }
  211. .item_box {
  212. padding: 0 25rpx;
  213. display: flex;
  214. .box_left {
  215. flex: 6;
  216. overflow: hidden;
  217. .left_title {
  218. margin: 12rpx 0;
  219. font-size: 36rpx;
  220. font-weight: bold;
  221. overflow: hidden;
  222. text-overflow: ellipsis;
  223. white-space: nowrap;
  224. }
  225. .left_tags {
  226. display: flex;
  227. flex-wrap: wrap;
  228. color: #808080;
  229. font-size: 24rpx;
  230. .tag {
  231. display: flex;
  232. align-items: center;
  233. margin-right: 32rpx;
  234. margin-bottom: 15rpx;
  235. img {
  236. margin-top: 4rpx;
  237. margin-left: 4rpx;
  238. width: 28rpx;
  239. height: 28rpx;
  240. }
  241. }
  242. }
  243. }
  244. .box_right {
  245. flex: 2;
  246. display: flex;
  247. .right_info {
  248. flex: 1;
  249. display: flex;
  250. flex-direction: column;
  251. width: 100rpx;
  252. color: #ff5733;
  253. .info_top {
  254. margin-top: 10rpx;
  255. font-size: 36rpx;
  256. }
  257. .info_bottom {
  258. margin-top: 10rpx;
  259. font-size: 20rpx;
  260. }
  261. .color {
  262. color: #a6a6a6;
  263. }
  264. }
  265. .right_radio {
  266. display: flex;
  267. justify-content: center;
  268. align-items: center;
  269. width: 40rpx;
  270. }
  271. }
  272. }
  273. }
  274. }
  275. .foot_btn {
  276. display: flex;
  277. justify-content: center;
  278. align-items: center;
  279. margin: 32rpx 0 17rpx;
  280. width: 690rpx;
  281. height: 96rpx;
  282. color: #fff;
  283. font-size: 32rpx;
  284. font-weight: bold;
  285. border-radius: 64rpx;
  286. background-color: #096562;
  287. }
  288. .popup_body {
  289. display: flex;
  290. flex-direction: column;
  291. align-items: center;
  292. width: 481rpx;
  293. height: 404rpx;
  294. border-radius: 22.5rpx;
  295. background-color: #fff;
  296. .popup_header {
  297. display: flex;
  298. justify-content: center;
  299. align-items: center;
  300. height: 123rpx;
  301. font-size: 34rpx;
  302. font-weight: bold;
  303. color: #0f194d;
  304. img {
  305. width: 16rpx;
  306. height: 16rpx;
  307. }
  308. .header_title {
  309. margin: 0 10rpx;
  310. }
  311. }
  312. .popup_center {
  313. box-sizing: border-box;
  314. padding: 0 20rpx;
  315. height: 135rpx;
  316. color: rgba(15, 25, 77, 0.6);
  317. font-size: 28rpx;
  318. font-weight: bold;
  319. }
  320. .popup_btn {
  321. display: flex;
  322. justify-content: center;
  323. align-items: center;
  324. width: 396rpx;
  325. height: 76rpx;
  326. color: #fff;
  327. font-size: 26rpx;
  328. border-radius: 43rpx;
  329. background: linear-gradient(90deg, #0bc196 0%, #096562 100%);
  330. }
  331. }
  332. }
  333. </style>