coupon.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. console.log(options)
  75. this.hotelId = options.id
  76. this.totalPrice = options.totalPrice
  77. this.complaintId = options.complaintId
  78. this.getCouponNum()
  79. },
  80. methods: {
  81. scrolltolower() {
  82. if (this.list.length < this.total) {
  83. this.page++
  84. this.getCouponNum()
  85. } else {
  86. uni.showToast({
  87. title: '没有更多数据了',
  88. icon: 'none'
  89. })
  90. }
  91. },
  92. // 确定按钮回调
  93. async handleConfirm() {
  94. let temObj = this.list.find((ele) => ele.isCheck)
  95. if (temObj) {
  96. const res = await this.$myRequest({
  97. url: '/mhotel/hcuseCoupons.action',
  98. method: 'post',
  99. data: {
  100. id: temObj.id,
  101. complaintId: temObj.complaintId,
  102. totalPrice: this.totalPrice
  103. }
  104. })
  105. // console.log(res)
  106. if (res.code === 200) {
  107. uni.$emit('choose', { data: res.data })
  108. }
  109. } else {
  110. uni.$emit('choose', { data: { discountAmount: 0 } })
  111. }
  112. uni.navigateBack(1)
  113. },
  114. // 点击指定民宿tag回调
  115. async handleClickTag(ids) {
  116. const res = await this.$myRequest({
  117. url: '/mhotel/hcdesignatedHotel.action',
  118. data: {
  119. hotelIds: ids.join()
  120. }
  121. })
  122. // console.log(res)
  123. if (res.code === 200) {
  124. this.hotels = res.data.name
  125. }
  126. this.$refs.popup.open()
  127. },
  128. async getCouponNum() {
  129. const res = await this.$myRequest({
  130. url: '/mhotel/hcusefulCoupon.action',
  131. data: {
  132. hotelId: this.hotelId,
  133. page: this.page,
  134. rows: this.rows,
  135. userId: uni.getStorageSync('userInfo').id,
  136. totalPrice: this.totalPrice
  137. }
  138. })
  139. // console.log(res);
  140. if (res.code === 200) {
  141. this.list = [...this.list, ...res.page.pageList]
  142. this.total = res.page.total
  143. this.list.forEach((ele, index) => {
  144. ele.hotelIds = ele.hotelIds.split(',')
  145. this.$set(ele, 'isCheck', false)
  146. })
  147. if (this.complaintId !== 'undefined') {
  148. const num = this.list.findIndex((e) => e.complaintId === this.complaintId)
  149. this.list[num].isCheck = true
  150. }
  151. }
  152. },
  153. handleChange(item) {
  154. if (item.isCheck) {
  155. item.isCheck = !item.isCheck
  156. } else {
  157. this.list.forEach((ele) => {
  158. if (item.id === ele.id) {
  159. ele.isCheck = true
  160. } else {
  161. ele.isCheck = false
  162. }
  163. })
  164. }
  165. },
  166. // 点击弹窗我知道了按钮回调
  167. handleClose() {
  168. this.$refs.popup.close()
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .container {
  175. box-sizing: border-box;
  176. padding: 0 30rpx;
  177. height: 100vh;
  178. background-color: #f7f7f7;
  179. .header {
  180. display: flex;
  181. align-items: center;
  182. height: 100rpx;
  183. font-size: 32rpx;
  184. text {
  185. margin-top: 10rpx;
  186. margin-left: 15rpx;
  187. color: #808080;
  188. font-size: 24rpx;
  189. }
  190. }
  191. .body {
  192. height: calc(100vh - 245rpx);
  193. overflow-y: auto;
  194. .body_item {
  195. position: relative;
  196. margin-bottom: 10rpx;
  197. padding-bottom: 10rpx;
  198. width: 690rpx;
  199. border-radius: 15rpx;
  200. background-color: #fff;
  201. img {
  202. width: 100rpx;
  203. height: 36rpx;
  204. }
  205. .item_type {
  206. position: absolute;
  207. top: 0;
  208. left: 14rpx;
  209. font-size: 24rpx;
  210. font-weight: bold;
  211. color: #fff;
  212. }
  213. .item_box {
  214. padding: 0 25rpx;
  215. display: flex;
  216. .box_left {
  217. flex: 6;
  218. overflow: hidden;
  219. .left_title {
  220. margin: 12rpx 0;
  221. font-size: 36rpx;
  222. font-weight: bold;
  223. overflow: hidden;
  224. text-overflow: ellipsis;
  225. white-space: nowrap;
  226. }
  227. .left_tags {
  228. display: flex;
  229. flex-wrap: wrap;
  230. color: #808080;
  231. font-size: 24rpx;
  232. .tag {
  233. display: flex;
  234. align-items: center;
  235. margin-right: 32rpx;
  236. margin-bottom: 15rpx;
  237. img {
  238. margin-top: 4rpx;
  239. margin-left: 4rpx;
  240. width: 28rpx;
  241. height: 28rpx;
  242. }
  243. }
  244. }
  245. }
  246. .box_right {
  247. flex: 2;
  248. display: flex;
  249. .right_info {
  250. flex: 1;
  251. display: flex;
  252. flex-direction: column;
  253. width: 100rpx;
  254. color: #ff5733;
  255. .info_top {
  256. margin-top: 10rpx;
  257. font-size: 36rpx;
  258. }
  259. .info_bottom {
  260. margin-top: 10rpx;
  261. font-size: 20rpx;
  262. }
  263. .color {
  264. color: #a6a6a6;
  265. }
  266. }
  267. .right_radio {
  268. display: flex;
  269. justify-content: center;
  270. align-items: center;
  271. width: 40rpx;
  272. }
  273. }
  274. }
  275. }
  276. }
  277. .foot_btn {
  278. display: flex;
  279. justify-content: center;
  280. align-items: center;
  281. margin: 32rpx 0 17rpx;
  282. width: 690rpx;
  283. height: 96rpx;
  284. color: #fff;
  285. font-size: 32rpx;
  286. font-weight: bold;
  287. border-radius: 64rpx;
  288. background-color: #096562;
  289. }
  290. .popup_body {
  291. display: flex;
  292. flex-direction: column;
  293. align-items: center;
  294. width: 481rpx;
  295. // height: 404rpx;
  296. border-radius: 22.5rpx;
  297. background-color: #fff;
  298. .popup_header {
  299. display: flex;
  300. justify-content: center;
  301. align-items: center;
  302. height: 123rpx;
  303. font-size: 34rpx;
  304. font-weight: bold;
  305. color: #0f194d;
  306. img {
  307. width: 16rpx;
  308. height: 16rpx;
  309. }
  310. .header_title {
  311. margin: 0 10rpx;
  312. }
  313. }
  314. .popup_center {
  315. box-sizing: border-box;
  316. padding: 0 20rpx 20rpx;
  317. max-height: 400rpx;
  318. // height: 135rpx;
  319. line-height: 42rpx;
  320. color: rgba(15, 25, 77, 0.6);
  321. font-size: 28rpx;
  322. font-weight: bold;
  323. overflow-y: auto;
  324. }
  325. .popup_btn {
  326. display: flex;
  327. justify-content: center;
  328. align-items: center;
  329. margin-bottom: 20rpx;
  330. width: 396rpx;
  331. height: 76rpx;
  332. color: #fff;
  333. font-size: 26rpx;
  334. border-radius: 43rpx;
  335. background: linear-gradient(90deg, #0bc196 0%, #096562 100%);
  336. }
  337. }
  338. }
  339. </style>