usable.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="usable">
  3. <view class="top"></view>
  4. <view class="head">
  5. <view class="head_left">
  6. <span class="cuIcon-back" @click="back"></span>
  7. </view>
  8. <view class="case">
  9. 可用时间
  10. </view>
  11. </view>
  12. <view class="content">
  13. <u-radio-group v-model="value" @change="radioGroupChange"
  14. style="width: 100%;background-color: #ffffff;padding: 16rpx;border-radius: 16rpx;">
  15. <view class="title">
  16. 可使用日期
  17. </view>
  18. <u-radio @change="radioChange" name="now"
  19. style="width: 100%;height:65rpx; flex;align-items: center;border-bottom: 1px solid #eeeeee;">
  20. <view class="title now">
  21. 购买后立即生效,有效时间
  22. <input type="number" style="background-color:#F7F8FC ;" v-model="expirationDays" /> 天
  23. </view>
  24. </u-radio>
  25. <u-radio @change="radioChange" name="date" style="width: 100%;margin-top: 16rpx;">
  26. <view class="title now">
  27. 指定消费日期
  28. <view class="picker">
  29. <u-input placeholder="去设置" v-model="showDate" @click="selectDate" />
  30. <u-icon name="arrow-right" style="margin-left: 17rpx;"></u-icon>
  31. </view>
  32. </view>
  33. </u-radio>
  34. </u-radio-group>
  35. </view>
  36. <view class="foot">
  37. <view class="btn" @click="save">
  38. 保存
  39. </view>
  40. </view>
  41. <rangTime ref="rangTime" :mode="mode" @onSubmit="onEndTimeChange" />
  42. </view>
  43. </template>
  44. <script>
  45. import rangTime from '../../components/dengrq-datetime-picker/dateSelector/index.vue'
  46. export default {
  47. components: {
  48. rangTime
  49. },
  50. data() {
  51. return {
  52. expirationDays: '',
  53. isSelectDate: false,
  54. selectedTime: {},
  55. value: 'now',
  56. mode: 1,
  57. availableStartDate: '',
  58. availableEndDate: '',
  59. showDate: ''
  60. }
  61. },
  62. methods: {
  63. //返回
  64. back() {
  65. console.log('1111')
  66. uni.navigateBack({
  67. delta: 1
  68. });
  69. },
  70. // 选中某个单选框时,由radio时触发
  71. radioChange(e) {
  72. // console.log(e);
  73. },
  74. // 选中任一radio时,由radio-group触发
  75. radioGroupChange(e) {
  76. console.log(e);
  77. if (e == 'date') {
  78. this.valid = ''
  79. }
  80. },
  81. onEndTimeChange(val) {
  82. this.availableStartDate = val.startDate
  83. this.availableEndDate = val.endDate
  84. this.showDate = val.startDate + '-' + val.endDate
  85. this.$forceUpdate(); // 强制刷新视图
  86. },
  87. selectDate() {
  88. // this.isSelectDate = true
  89. if (this.value == 'date') {
  90. this.$refs.rangTime.open()
  91. }
  92. },
  93. save() {
  94. if (this.availableStartDate !== '' && this.availableEndDate !== '') {
  95. uni.setStorage({
  96. key: 'smdate',
  97. data: {
  98. availableStartDate: this.availableStartDate,
  99. availableEndDate: this.availableEndDate
  100. }
  101. })
  102. this.back()
  103. } else if (this.expirationDays !== '') {
  104. uni.setStorage({
  105. key: 'smdate',
  106. data: {
  107. expirationDays: this.expirationDays
  108. }
  109. })
  110. this.back()
  111. } else {
  112. uni.showToast({
  113. title: '选择售卖时间',
  114. icon: 'none'
  115. });
  116. }
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .usable {
  123. width: 100vw;
  124. height: 100vh;
  125. display: flex;
  126. flex-direction: column;
  127. justify-content: space-between;
  128. background: #F7F8FC;
  129. /*#ifdef APP-PLUS*/
  130. .top {
  131. width: 100%;
  132. height: var(--status-bar-height);
  133. background-color: #fff;
  134. }
  135. /*#endif*/
  136. .head {
  137. width: 100%;
  138. padding: 20rpx;
  139. background-color: #fff;
  140. display: flex;
  141. justify-content: space-between;
  142. align-items: center;
  143. position: relative;
  144. .head_left {
  145. font-size: 40rpx;
  146. }
  147. .case {
  148. position: absolute;
  149. left: 50%;
  150. top: 50%;
  151. transform: translate(-50%, -50%);
  152. font-size: 36rpx;
  153. font-weight: 600;
  154. }
  155. }
  156. .content {
  157. flex: 1;
  158. padding: 24rpx;
  159. }
  160. .title {
  161. width: 100%;
  162. font-weight: 600;
  163. font-size: 30rpx;
  164. margin-bottom: 16rpx;
  165. }
  166. .now {
  167. font-weight: normal;
  168. display: flex;
  169. align-items: center;
  170. justify-content: space-between;
  171. box-sizing: border-box;
  172. margin: 0;
  173. .picker {
  174. flex: 1;
  175. display: flex;
  176. align-items: center;
  177. justify-content: flex-end;
  178. font-size: 28rpx;
  179. color: #999999;
  180. /deep/.u-input {
  181. text-align: right !important;
  182. }
  183. }
  184. input {
  185. width: 100rpx;
  186. }
  187. }
  188. .foot {
  189. width: 100%;
  190. height: 112rpx;
  191. background-color: #fff;
  192. display: flex;
  193. align-items: center;
  194. justify-content: center;
  195. padding: 24rpx;
  196. .btn {
  197. width: 100%;
  198. height: 100%;
  199. background: linear-gradient(90deg, #77B6FF 0%, #449AFF 100%);
  200. border-radius: 75rpx;
  201. font-size: 28rpx;
  202. color: #FFFFFF;
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. }
  207. }
  208. }
  209. .btn {
  210. width: 80%;
  211. height: 80rpx;
  212. background-color: #ccc;
  213. margin: 0 auto;
  214. text-align: center;
  215. line-height: 80rpx;
  216. }
  217. /deep/ .u-radio__label {
  218. width: 100%;
  219. }
  220. </style>