coupon.vue 8.0 KB

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