VoucherUse.vue 4.2 KB

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