VoucherUse.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view>
  3. <view class="line-pane" @click="drawerVisible = true">
  4. <view style="font-size: 28upx;" class="title">代金券</view>
  5. <view style="display: flex;align-items: center;">
  6. <view class="desc" style="color: #999999">{{ voucherName }}</view>
  7. <tui-icon name="arrowright" size="22" color="#979797" style="padding: 2upx 0 2upx 8upx;"></tui-icon>
  8. </view>
  9. </view>
  10. <tui-drawer mode="bottom" :visible="drawerVisible" @close="drawerVisible = false">
  11. <view style="height: 55vh;padding: 20upx;overflow-y: auto;">
  12. <view v-if="voucherList && voucherList.length">
  13. <view style="text-align: right;">
  14. <tui-radio-group :value="String(voucherSelected)" style="" @change="handleRadioChange">
  15. <tui-label>
  16. <tui-list-cell padding="16upx">
  17. <view>
  18. <text style="padding-right: 10upx;">不使用</text>
  19. <tui-radio value="0" color="#e25531" border-color="#999"></tui-radio>
  20. </view>
  21. </tui-list-cell>
  22. </tui-label>
  23. </tui-radio-group>
  24. <!-- <text>不使用</text>
  25. <tui-radio :checked="false" :value="part.value" color="#07c160" border-color="#999">
  26. </tui-radio> -->
  27. </view>
  28. <view>
  29. <view v-for="item in voucherList" :key="item.id" class="item">
  30. <view style="display: flex;justify-content: space-between;align-items: center;padding: 20upx;margin: 20upx;border: 1upx solid #b1b0b0;border-radius: 12upx;">
  31. <view style="flex: 1;">
  32. <view style="display: flex;justify-content: space-between;">
  33. <text>{{ item.voucherName }}</text>
  34. <text style="padding-right: 50upx;color: #b1b0b0;">{{ item.ratio }} : 1</text>
  35. </view>
  36. <view>{{ item.desc }}</view>
  37. </view>
  38. <tui-button
  39. type="warning" width="120rpx" height="50rpx" shape="circle"
  40. :disabled="item.id === voucherSelected" @click="handleChooseVoucher(item)"
  41. >
  42. 选择
  43. </tui-button>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. <view v-else>
  49. <tui-no-data>暂无代金券</tui-no-data>
  50. </view>
  51. </view>
  52. </tui-drawer>
  53. </view>
  54. </template>
  55. <script>
  56. export default {
  57. name: 'CouponUse',
  58. props: {
  59. voucherList: {
  60. type: Array,
  61. default: () => []
  62. }
  63. },
  64. data() {
  65. return {
  66. drawerVisible: false,
  67. voucherName: '暂无代金券可用',
  68. voucherSelected: 0
  69. }
  70. },
  71. watch: {
  72. voucherList: {
  73. handler(newVal) {
  74. if (newVal && newVal.length && !this.voucherSelected) {
  75. this.voucherName = '不使用'
  76. this.voucherSelected = 0
  77. } else if (!newVal.length) {
  78. this.voucherName = '暂无代金券可用'
  79. this.voucherSelected = 0
  80. }
  81. },
  82. immediate: true,
  83. deep: true
  84. }
  85. },
  86. methods: {
  87. handleReset() {
  88. this.voucherName = '不使用'
  89. this.voucherSelected = 0
  90. this.drawerVisible = false
  91. },
  92. handleRadioChange(e) {
  93. console.log(e)
  94. this.voucherName = '不使用'
  95. if (this.voucherSelected !== Number(e.detail.value)) {
  96. this.voucherSelected = Number(e.detail.value)
  97. this.$emit('choose', { id: this.voucherSelected })
  98. }
  99. this.drawerVisible = false
  100. },
  101. handleChooseVoucher(item) {
  102. console.log(item)
  103. this.voucherName = item.voucherName
  104. this.voucherSelected = item.id
  105. this.$emit('choose', { id: this.voucherSelected })
  106. this.drawerVisible = false
  107. }
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .line-pane {
  113. box-sizing: border-box;
  114. display: flex;
  115. justify-content: space-between;
  116. align-items: center;
  117. height: 100upx;
  118. margin: 20upx 0;
  119. padding: 20upx 18upx;
  120. background-color: #fff;
  121. }
  122. </style>