coupon.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template name="coupon">
  2. <view class="coupon-template">
  3. <view class="coupon-title" @tap.stop="showPopup">
  4. <text class="text">优惠券:</text> <text class="text-coupon">-¥{{ coupon.couponAmount | NumFormat }}</text>
  5. <text class="iconfont icon-xiayibu"></text>
  6. </view>
  7. <!-- 优惠券 -->
  8. <tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup">
  9. <view class="tui-popup-box clearfix">
  10. <view class="title">
  11. <view class="title-l">优惠券</view>
  12. <view class="title-r" @click="showExchangePopup">兑换优惠券</view>
  13. </view>
  14. <div class="tui-popup-main coupon">
  15. <scroll-view class="tui-popup-scroll" scroll-y="true">
  16. <view
  17. v-for="(coupon, index) in dataList"
  18. :key="index"
  19. class="coupon-list"
  20. @click.stop="checkedCoupon(index)"
  21. >
  22. <view class="list-cell-le">
  23. <view class="coupon-maxMoney">
  24. <text class="small">¥</text> {{ coupon.couponAmount }}
  25. </view>
  26. <view class="coupon-minMoney"> 满{{ coupon.touchPrice }}可用 </view>
  27. </view>
  28. <view class="list-cell-ri">
  29. <view class="list-cell-top">
  30. <view class="list-cell-type">
  31. <view class="list-cell-tags">
  32. <text class="tags">{{ coupon.couponType | TypeFormat }}</text>
  33. </view>
  34. <view class="list-cell-texts">
  35. <text v-if="coupon.couponType == 0">
  36. {{
  37. coupon.productType && coupon.productType == 1
  38. ? '全商城商品通用'
  39. : '仅可购买指定商品'
  40. }}
  41. </text>
  42. <text v-if="coupon.couponType == 1">
  43. {{
  44. coupon.categoryType == 1
  45. ? '仅限购买产品类商品'
  46. : '仅限购买仪器类商品'
  47. }}
  48. </text>
  49. <text v-if="coupon.couponType == 3"
  50. >仅限购买店铺【{{ coupon.shopName }}】的商品</text
  51. >
  52. <text v-if="coupon.couponType == 4 || coupon.couponType == 2"
  53. >全商城商品通用</text
  54. >
  55. </view>
  56. </view>
  57. <view class="list-cell-btn">
  58. <view class="list-cell-checkbox">
  59. <view
  60. class="checkbox iconfont"
  61. :class="[coupon.ischecked ? 'icon-yixuanze' : 'icon-weixuanze']"
  62. >
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="list-cell-time">{{ coupon.startDate }} - {{ coupon.endDate }}</view>
  68. </view>
  69. </view>
  70. </scroll-view>
  71. </div>
  72. <view class="tui-right-flex tui-popup-btn" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
  73. <view class="tui-flex-1"> <view class="tui-button" @click="hidePopup">确定</view> </view>
  74. </view>
  75. </view>
  76. </tui-bottom-popup>
  77. </view>
  78. </template>
  79. <script>
  80. export default {
  81. name: 'coupon',
  82. props: {
  83. couponList: {
  84. type: Array
  85. }
  86. },
  87. data() {
  88. return {
  89. popupShow: false,
  90. isIphoneX: this.$store.state.isIphoneX,
  91. checkedIndex: 0,
  92. dataList: [],
  93. coupon: {
  94. couponAmount: 0,
  95. clubCouponId: 0
  96. }
  97. }
  98. },
  99. filters: {
  100. NumFormat(value) {
  101. //处理金额
  102. return Number(value).toFixed(2)
  103. },
  104. TypeFormat(value) {
  105. switch (value) {
  106. case 0:
  107. return '活动券'
  108. break
  109. case 1:
  110. return '品类券'
  111. break
  112. case 2:
  113. return '用户专享券'
  114. break
  115. case 3:
  116. return '店铺券'
  117. break
  118. case 4:
  119. return '新用户券'
  120. break
  121. }
  122. }
  123. },
  124. created() {
  125. this.initData(this.couponList)
  126. },
  127. watch: {
  128. couponList: {
  129. handler: function(el) {
  130. //监听对象的变换使用 function,箭头函数容易出现this指向不正确
  131. console.log(el)
  132. this.couponList = el
  133. },
  134. deep: true
  135. }
  136. },
  137. methods: {
  138. initData(data) {
  139. if (data.length > 0) {
  140. data.forEach((el, index) => {
  141. this.dataList.push(Object.assign({}, el, { ischecked: false }))
  142. })
  143. this.coupon.couponAmount = data[0].couponAmount
  144. this.dataList[0].ischecked = true
  145. }
  146. },
  147. checkedCoupon(idx) {
  148. // 选择优惠券
  149. this.checkedIndex = idx
  150. this.dataList.forEach((el, index) => {
  151. if (this.checkedIndex == index) {
  152. el.ischecked = !el.ischecked
  153. } else {
  154. el.ischecked = false
  155. }
  156. })
  157. },
  158. showExchangePopup() {
  159. this.popupShow = false
  160. this.$parent.isExchangePopup = true
  161. },
  162. showPopup() {
  163. this.popupShow = true
  164. },
  165. hidePopup() {
  166. this.popupShow = false
  167. let coupon = {
  168. couponAmount: 0,
  169. clubCouponId: 0
  170. }
  171. this.dataList.forEach((el, index) => {
  172. if (el.ischecked) {
  173. coupon.couponAmount = el.couponAmount
  174. coupon.clubCouponId = el.clubCouponId
  175. }
  176. })
  177. this.coupon = coupon
  178. this.$emit('handleChoiceaCoupon', this.coupon)
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. .coupon-template {
  185. width: 100%;
  186. height: auto;
  187. background: #ffffff;
  188. float: left;
  189. margin-top: 24rpx;
  190. .coupon-title {
  191. width: 702rpx;
  192. padding: 0 24rpx;
  193. height: 88rpx;
  194. line-height: 88rpx;
  195. position: relative;
  196. .text {
  197. font-size: $font-size-28;
  198. color: $text-color;
  199. }
  200. .text-coupon {
  201. display: inline-block;
  202. float: right;
  203. padding-right: 30rpx;
  204. line-height: 88rpx;
  205. font-size: 28rpx;
  206. color: #f94b4b;
  207. }
  208. .iconfont {
  209. width: 50rpx;
  210. height: 88rpx;
  211. line-height: 88rpx;
  212. color: #999999;
  213. display: block;
  214. position: absolute;
  215. right: 0;
  216. top: 0;
  217. }
  218. }
  219. }
  220. .tui-popup-box {
  221. position: relative;
  222. box-sizing: border-box;
  223. min-height: 220rpx;
  224. padding: 24rpx 24rpx 0 24rpx;
  225. .title {
  226. font-size: $font-size-34;
  227. color: $text-color;
  228. line-height: 88rpx;
  229. text-align: center;
  230. float: left;
  231. width: 100%;
  232. height: 88rpx;
  233. display: flex;
  234. box-sizing: border-box;
  235. padding: 0 24rpx;
  236. .title-l {
  237. flex: 1;
  238. text-align: left;
  239. }
  240. .title-r {
  241. flex: 1;
  242. text-align: right;
  243. color: #f94b4b;
  244. }
  245. }
  246. .tui-popup-main {
  247. width: 100%;
  248. float: left;
  249. padding-top: 10rpx;
  250. .tui-popup-scroll {
  251. width: 100%;
  252. height: 600rpx;
  253. .coupon-list {
  254. width: 100%;
  255. height: 200rpx;
  256. margin-bottom: 24rpx;
  257. box-sizing: border-box;
  258. background: url(https://static.caimei365.com/app/img/icon/icon-coupon-uesb@2x.png);
  259. background-size: cover;
  260. .list-cell-le {
  261. width: 224rpx;
  262. height: 100%;
  263. box-sizing: border-box;
  264. padding: 37rpx 0;
  265. float: left;
  266. .coupon-maxMoney {
  267. width: 100%;
  268. height: 78rpx;
  269. line-height: 78rpx;
  270. font-size: 56rpx;
  271. color: #ffffff;
  272. text-align: center;
  273. .small {
  274. font-size: $font-size-24;
  275. }
  276. }
  277. .coupon-minMoney {
  278. width: 100%;
  279. height: 33rpx;
  280. line-height: 33rpx;
  281. font-size: $font-size-24;
  282. color: #ffffff;
  283. text-align: center;
  284. }
  285. }
  286. .list-cell-ri {
  287. width: 478rpx;
  288. height: 100%;
  289. box-sizing: border-box;
  290. padding: 20rpx 24rpx 0 24rpx;
  291. float: right;
  292. .list-cell-top {
  293. width: 100%;
  294. height: 121rpx;
  295. float: left;
  296. border-bottom: 1px solid #e1e1e1;
  297. .list-cell-type {
  298. width: 286rpx;
  299. height: 100%;
  300. float: left;
  301. .list-cell-tags {
  302. width: 100%;
  303. height: 32rpx;
  304. margin-bottom: 7rpx;
  305. .tags {
  306. display: inline-block;
  307. padding: 0 10rpx;
  308. height: 32rpx;
  309. line-height: 32rpx;
  310. background-color: #ffdcce;
  311. color: #f94b4b;
  312. font-size: $font-size-20;
  313. border-radius: 8rpx;
  314. text-align: center;
  315. float: left;
  316. }
  317. }
  318. .list-cell-texts {
  319. width: 100%;
  320. height: auto;
  321. line-height: 35rpx;
  322. text-overflow: ellipsis;
  323. display: -webkit-box;
  324. word-break: break-all;
  325. -webkit-box-orient: vertical;
  326. -webkit-line-clamp: 2;
  327. overflow: hidden;
  328. font-size: 26rpx;
  329. color: #333333;
  330. }
  331. }
  332. .list-cell-btn {
  333. width: 128rpx;
  334. height: 100%;
  335. float: right;
  336. .list-cell-checkbox {
  337. width: 100%;
  338. height: 50%;
  339. .checkbox {
  340. width: 40rpx;
  341. line-height: 60rpx;
  342. float: right;
  343. box-sizing: border-box;
  344. text-align: center;
  345. text-decoration: none;
  346. -webkit-tap-highlight-color: transparent;
  347. overflow: hidden;
  348. color: #f94b4b;
  349. }
  350. }
  351. }
  352. }
  353. .list-cell-time {
  354. width: 100%;
  355. height: 58rpx;
  356. line-height: 58rpx;
  357. text-align: left;
  358. font-size: $font-size-20;
  359. color: #999999;
  360. }
  361. }
  362. }
  363. }
  364. .tui-popup-coupon {
  365. width: 100%;
  366. height: 500rpx;
  367. box-sizing: border-box;
  368. padding: 30rpx 20rpx;
  369. .tui-popup-h1 {
  370. width: 100%;
  371. height: 66rpx;
  372. display: flex;
  373. align-items: center;
  374. .tui-popup-text {
  375. flex: 1;
  376. height: 66rpx;
  377. line-height: 66rpx;
  378. font-size: $font-size-30;
  379. color: #333333;
  380. &.red {
  381. color: #f94b4b;
  382. }
  383. &.bold {
  384. font-weight: bold;
  385. }
  386. &.left {
  387. text-align: left;
  388. }
  389. &.right {
  390. text-align: right;
  391. }
  392. }
  393. }
  394. }
  395. }
  396. .tui-popup-btn {
  397. width: 100%;
  398. height: auto;
  399. float: left;
  400. margin-top: 24rpx;
  401. .tui-button {
  402. width: 100%;
  403. height: 88rpx;
  404. background: $btn-confirm;
  405. line-height: 88rpx;
  406. text-align: center;
  407. color: #ffffff;
  408. font-size: $font-size-28;
  409. border-radius: 44rpx;
  410. }
  411. }
  412. }
  413. </style>