usable.vue 5.3 KB

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