usable.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <view class="usable">
  3. <view class="head">
  4. <span class="cuIcon-back" @click="back"></span>
  5. <view class="case">
  6. 可用时间
  7. </view>
  8. </view>
  9. <view class="content">
  10. <u-radio-group v-model="value" @change="radioGroupChange" style="width: 100%;">
  11. <view class="title">
  12. 可使用日期
  13. </view>
  14. <u-radio @change="radioChange" name="now" style="width: 100%;">
  15. <view class="title now">
  16. 购买后立即生效,有效时间
  17. <input type="number" v-model="valid" /> 天
  18. </view>
  19. </u-radio>
  20. <u-radio @change="radioChange" name="date" style="width: 100%;">
  21. <view class="title now">
  22. 指定消费日期
  23. <view class="" @click="isSelectDate = true">
  24. {{ Object.keys(selectedTime).length === 0 ?'去选择':selectedTime.startTime+'--'+selectedTime.endTime}}
  25. </view>
  26. </view>
  27. </u-radio>
  28. </u-radio-group>
  29. </view>
  30. <view class="btn">
  31. 保存
  32. </view>
  33. <selectDate @confirm="handleConfirm" @close="closeSelectDate" v-if="isSelectDate" />
  34. </view>
  35. </template>
  36. <script>
  37. import selectDate from '@/components/product/select_date.vue'
  38. export default {
  39. components: {
  40. selectDate
  41. },
  42. data() {
  43. return {
  44. valid: '',
  45. isSelectDate: false,
  46. selectedTime: {},
  47. value: 'now'
  48. }
  49. },
  50. methods: {
  51. //返回
  52. back() {
  53. uni.navigateBack({
  54. delta: 1
  55. });
  56. },
  57. // 处理 confirm 事件,接收子组件传递的时间段数据
  58. handleConfirm(time) {
  59. this.selectedTime = time; // 保存时间段数据
  60. this.isSelectDate = false
  61. console.log(this.selectedTime)
  62. },
  63. //隐藏弹窗
  64. closeSelectDate() {
  65. this.isSelectDate = false
  66. },
  67. // 选中某个单选框时,由radio时触发
  68. radioChange(e) {
  69. // console.log(e);
  70. },
  71. // 选中任一radio时,由radio-group触发
  72. radioGroupChange(e) {
  73. console.log(e);
  74. if(e=='date'){
  75. this.valid = ''
  76. }
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss" scoped>
  82. .usable {
  83. width: 100vw;
  84. height: 100vh;
  85. display: flex;
  86. flex-direction: column;
  87. justify-content: space-between;
  88. padding-bottom: 20rpx;
  89. .head {
  90. width: 100%;
  91. height: auto;
  92. padding: 20rpx;
  93. display: flex;
  94. align-items: center;
  95. background-color: #fff;
  96. position: relative;
  97. .cuIcon-back {
  98. font-size: 40rpx;
  99. margin-right: 40rpx;
  100. }
  101. }
  102. .content{
  103. flex: 1;
  104. }
  105. .title {
  106. width: 100%;
  107. height: 80rpx;
  108. font-weight: 600;
  109. line-height: 80rpx;
  110. border-bottom: 1px solid #ccc;
  111. padding: 0rpx 20rpx;
  112. }
  113. .now {
  114. font-weight: normal;
  115. display: flex;
  116. align-items: center;
  117. justify-content: space-between;
  118. box-sizing: border-box;
  119. input {
  120. width: 100rpx;
  121. }
  122. }
  123. }
  124. .btn {
  125. width: 80%;
  126. height: 80rpx;
  127. background-color: #ccc;
  128. margin: 0 auto;
  129. text-align: center;
  130. line-height: 80rpx;
  131. }
  132. /deep/ .u-radio__label {
  133. width: 100%;
  134. }
  135. </style>