index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <uni-forms ref="form" v-model="form" :rules="rules" label-width="auto">
  6. <uni-forms-item label="人数限制" name="person_limit">
  7. <uni-easyinput type="number" v-model="form.person_limit" placeholder="请输入人数限制" />
  8. </uni-forms-item>
  9. <uni-forms-item label="开始时间" name="start_time">
  10. <uni-datetime-picker type="datetime" v-model="form.start_time" @change="startChange" />
  11. </uni-forms-item>
  12. <uni-forms-item label="结束时间" name="end_time">
  13. <uni-datetime-picker type="datetime" v-model="form.end_time" @change="endChange" />
  14. </uni-forms-item>
  15. </uni-forms>
  16. <view class="btn">
  17. <button type="primary" size="mini" @click="onSubmit('form')">确认开团</button>
  18. </view>
  19. </view>
  20. </view>
  21. </mobile-frame>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. user: {},
  28. id: '',
  29. form: {},
  30. rules: {
  31. person_limit: {
  32. rules: [{
  33. required: true,
  34. errorMessage: '请输入人数限制',
  35. }]
  36. },
  37. start_time: {
  38. rules: [{
  39. required: true,
  40. errorMessage: '请选择开始时间'
  41. }]
  42. },
  43. end_time: {
  44. rules: [{
  45. required: true,
  46. errorMessage: '请选择结束时间'
  47. }]
  48. }
  49. },
  50. };
  51. },
  52. onLoad: function(e) {
  53. const that = this;
  54. that.$set(that, `form`, e || {});
  55. },
  56. onShow: function(e) {
  57. const that = this;
  58. that.watchLogin();
  59. },
  60. methods: {
  61. // 监听用户是否登录
  62. watchLogin() {
  63. const that = this;
  64. uni.getStorage({
  65. key: 'token',
  66. success: async function(res) {
  67. let user = that.$jwt(res.data);
  68. if (user) {
  69. that.$set(that, `user`, user);
  70. let res = await that.$api(`/goodsConfig`, `GET`, that.form, 'group');
  71. if (res.errcode == '0') that.$set(that.form, `group_config`, res.data);
  72. }
  73. },
  74. fail: function(err) {
  75. uni.navigateTo({
  76. url: '/pages/login/index'
  77. })
  78. }
  79. })
  80. },
  81. // 开始时间选择
  82. startChange(e) {
  83. const that = this;
  84. that.$set(that.form, `start_time`, e);
  85. },
  86. // 结束时间选择
  87. endChange(e) {
  88. const that = this;
  89. that.$set(that.form, `end_time`, e);
  90. },
  91. // 提交保存
  92. onSubmit(ref) {
  93. const that = this;
  94. uni.showModal({
  95. title: '提示',
  96. content: '确定是否开团吗?',
  97. success: async function(res) {
  98. that.$set(that.form, `leader`, that.user.id || '');
  99. that.$refs[ref].validate().then(async params => {
  100. // 创建团数据
  101. let res = await that.$api(`/group`, 'POST', that.form, 'group');
  102. if (res.errcode == '0') {
  103. uni.reLaunch({
  104. url: `/pagesHome/group/share?id=${res.data.goods}&group=${res.data._id}`
  105. })
  106. } else {
  107. uni.showToast({
  108. title: res.errmsg,
  109. icon: 'none'
  110. })
  111. }
  112. })
  113. }
  114. });
  115. },
  116. }
  117. }
  118. </script>
  119. <style lang="scss">
  120. .main {
  121. display: flex;
  122. flex-direction: column;
  123. width: 100vw;
  124. height: 100vh;
  125. .one {
  126. padding: 2vw;
  127. .toLoacl {
  128. margin: 1vw 0 0 0;
  129. }
  130. .picker {
  131. border: 1px solid #3333;
  132. border-radius: 5px;
  133. padding: 2vw;
  134. }
  135. .btn {
  136. text-align: center;
  137. button {
  138. width: 30%;
  139. font-size: 14px;
  140. background-color: var(--f35BColor);
  141. }
  142. }
  143. }
  144. }
  145. </style>