usable.vue 5.1 KB

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