Browse Source

no message

seamwang 1 year ago
parent
commit
30ce329d05
1 changed files with 130 additions and 51 deletions
  1. 130 51
      src/pages/myStudents/myStudents.vue

+ 130 - 51
src/pages/myStudents/myStudents.vue

@@ -18,29 +18,36 @@
18 18
             <view class="text-lg">学生列表</view>
19 19
             <view class="text-xs text-grey">
20 20
               <text class="text-red">点击选择,左滑删除,右侧添加</text>
21
-              <text class="cuIcon-roundaddfill text-cyan margin-left-xl add-icon" @tap="showModal"
22
-                data-target="ChooseModal"></text>
21
+              <text class="cuIcon-roundaddfill text-cyan margin-left-xl add-icon" @tap="showModal" data-target="ChooseModal"></text>
23 22
             </view>
24 23
           </view>
25 24
           <view class="padding-lr text-right" v-if="!phone">
26 25
             <text class="text-red text-xs">右侧点击绑定手机号,直接获取绑定学生列表</text>
27 26
             <text class="cuIcon-mobile text-cyan add-icon margin-left-xl" @tap="globalNavigateTo('bindPhone')"></text>
28 27
           </view>
29
-          <scroll-view scroll-y :style="[{height:'calc(100vh - 230px - '+ topHeader+'px)'}]">
28
+          <scroll-view scroll-y :style="[{ height: 'calc(100vh - 230px - ' + topHeader + 'px)' }]">
30 29
             <view class="cu-list menu-avatar">
31
-              <view class="cu-item" :class="moveModel=='move-box-'+ index?'move-cur':''"
32
-                v-for="(item,index) in result.student_data" :key="index" @touchstart="ListTouchStart"
33
-                @touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + index"
34
-                @tap="chooseKid(item.id)">
30
+              <view
31
+                class="cu-item"
32
+                :class="moveModel == 'move-box-' + index ? 'move-cur' : ''"
33
+                v-for="(item, index) in result.student_data"
34
+                :key="index"
35
+                @touchstart="ListTouchStart"
36
+                @touchmove="ListTouchMove"
37
+                @touchend="ListTouchEnd"
38
+                :data-target="'move-box-' + index"
39
+                @tap="chooseKid(item.id)"
40
+              >
35 41
                 <image mode="scaleToFill" :src="defaultAvatar" class="avatar md left"></image>
36 42
                 <view class="content">
37
-                  <view>{{item.name}}</view>
38
-                  <view class="text-gray">{{item.school_name}}-{{item.grade_name}}-{{item.class_name}}</view>
43
+                  <view>{{ item.name }}</view>
44
+                  <view class="text-gray">{{ item.school_name }}-{{ item.grade_name }}-{{ item.class_name }}</view>
39 45
                 </view>
40 46
                 <view class="action">
41
-                  <text class="cuIcon-check text-student font-check" v-if="item.id===kid"></text>
47
+                  <text class="cuIcon-check text-student font-check" v-if="item.id === kid"></text>
42 48
                 </view>
43 49
                 <view class="move student-move">
50
+                  <view class="bg-cyan" @tap.stop="fixStudent(item.id)">修改</view>
44 51
                   <view class="bg-red" @tap.stop="unbind(item.id)">删除</view>
45 52
                 </view>
46 53
               </view>
@@ -50,16 +57,16 @@
50 57
       </view>
51 58
     </view>
52 59
     <!-- 选择学生列表 -->
53
-    <view class="cu-modal" :class="modalName=='showStudents'?'show':''" @tap="hideModal">
54
-      <view class="cu-dialog bg-student" @tap.stop=''>
60
+    <view class="cu-modal" :class="modalName == 'showStudents' ? 'show' : ''" @tap="hideModal">
61
+      <view class="cu-dialog bg-student" @tap.stop="">
55 62
         <view class="padding text-left modal-body radius-student">
56 63
           <view class="cu-list menu-avatar">
57
-            <view class="cu-item" v-for="(item,index) in chooseList" :key="index" @tap="save(item.id)">
58
-              <view class="cu-inner" :class="{'checked':item.id===selectKid}">
64
+            <view class="cu-item" v-for="(item, index) in chooseList" :key="index" @tap="save(item.id)">
65
+              <view class="cu-inner" :class="{ checked: item.id === selectKid }">
59 66
                 <image mode="scaleToFill" :src="defaultAvatar" class="avatar md left"></image>
60 67
                 <view class="content">
61
-                  <view>{{item.name}}</view>
62
-                  <view class="text-gray">{{item.school_name}}-{{item.grade_name}}-{{item.class_name}}</view>
68
+                  <view>{{ item.name }}</view>
69
+                  <view class="text-gray">{{ item.school_name }}-{{ item.grade_name }}-{{ item.class_name }}</view>
63 70
                 </view>
64 71
               </view>
65 72
             </view>
@@ -68,19 +75,17 @@
68 75
       </view>
69 76
     </view>
70 77
     <!--添加学生-->
71
-    <view class="cu-modal" :class="modalName=='ChooseModal'?'show':''" @tap="hideModal">
72
-      <view class="cu-dialog bg-student" @tap.stop=''>
78
+    <view class="cu-modal" :class="modalName == 'ChooseModal' ? 'show' : ''" @tap="hideModal">
79
+      <view class="cu-dialog bg-student" @tap.stop="">
73 80
         <view class="cu-bar justify-around">
74 81
           <view class="content modal-title">添加学生</view>
75 82
         </view>
76 83
         <view class="padding-xl text-left modal-body">
77 84
           <view>
78
-            <input type="text" v-model.trim="student.student_name" placeholder="请输入学生名字"
79
-              class="student-input text-black text-lg">
85
+            <input type="text" v-model.trim="student.student_name" placeholder="请输入学生名字" class="student-input text-black text-lg" />
80 86
           </view>
81 87
           <view class="margin-top" v-if="student.student_name">
82
-            <input type="text" v-model.trim="student.school_name" placeholder="请输入学校名称"
83
-              class="student-input text-black text-lg">
88
+            <input type="text" v-model.trim="student.school_name" placeholder="请输入学校名称" class="student-input text-black text-lg" />
84 89
           </view>
85 90
           <view class="margin-top">
86 91
             <button class="student-input text-student text-left" @tap="get_students">获取学生</button>
@@ -91,6 +96,38 @@
91 96
         </view>
92 97
       </view>
93 98
     </view>
99
+    <!-- 修改学生 -->
100
+    <view class="cu-modal" :class="modalName == 'FixModal' ? 'show' : ''" @tap="hideModal">
101
+      <view class="cu-dialog bg-student" @tap.stop="">
102
+        <view class="cu-bar justify-around">
103
+          <view class="content modal-title">修改学生</view>
104
+        </view>
105
+        <view class="padding-xl text-left modal-body">
106
+          <view>{{ info.name }}</view>
107
+          <view class="margin-top">
108
+            <picker class="student-input" @change="gradeChange" :value="gradeIndex" :range="grades" range-key="name">
109
+              <view class="picker text-lg text-black">
110
+                {{ gradeIndex > -1 ? grades[gradeIndex].name : '请选择年级' }}
111
+              </view>
112
+            </picker>
113
+          </view>
114
+          <view class="margin-top">
115
+            <picker class="student-input" @change="classChange" :value="classIndex" :range="classes" range-key="name">
116
+              <view class="picker text-lg text-black">
117
+                {{ classIndex > -1 ? classes[classIndex].name : '请选择班级' }}
118
+              </view>
119
+            </picker>
120
+            <!-- <input type="text" v-model.trim="info.class_name" placeholder="修改班级" class="student-input text-black text-lg" /> -->
121
+          </view>
122
+        </view>
123
+        <view class="cu-bar modal-footer justify-center">
124
+          <view class="action">
125
+            <button class="cu-btn btn-lg round bg-cyan margin-right-sm" @tap="confirmFix">确定</button>
126
+            <button class="cu-btn btn-lg round bg-grey" @tap="hideModal">取消</button>
127
+          </view>
128
+        </view>
129
+      </view>
130
+    </view>
94 131
   </view>
95 132
 </template>
96 133
 
@@ -99,7 +136,7 @@ import { _getStudents, _bindStudent, _unbindStudent } from '@/api/auth'
99 136
 import { _shopList } from '@/api/course'
100 137
 import { mapGetters } from 'vuex'
101 138
 export default {
102
-  data () {
139
+  data() {
103 140
     return {
104 141
       showAdd: false,
105 142
       topHeader: this.globalCustomBarHeight,
@@ -109,6 +146,26 @@ export default {
109 146
         student_name: '',
110 147
         school_name: ''
111 148
       },
149
+      info: {
150
+        id: '',
151
+        name: '',
152
+        grade_id: '',
153
+        class_id: ''
154
+      },
155
+      gradeIndex: -1, //年级index
156
+      classIndex: -1, //班级index
157
+      grades: [
158
+        { name: '一年级', id: 1 },
159
+        { name: '二年级', id: 2 },
160
+        { name: '三年级', id: 3 },
161
+        { name: '四年级', id: 4 },
162
+        { name: '五年级', id: 5 }
163
+      ], //年级列表
164
+      classes: [
165
+        { name: '一班', id: 1 },
166
+        { name: '二班', id: 2 },
167
+        { name: '三班', id: 3 }
168
+      ], //班级列表
112 169
       result: null,
113 170
       chooseList: [],
114 171
       moveModel: null,
@@ -118,13 +175,10 @@ export default {
118 175
     }
119 176
   },
120 177
   computed: {
121
-    ...mapGetters([
122
-      'kid', 'phone'
123
-    ])
124
-  },
125
-  onLoad () {
178
+    ...mapGetters(['kid', 'phone'])
126 179
   },
127
-  onShow () {
180
+  onLoad(options) {},
181
+  onShow() {
128 182
     this.get_list()
129 183
     const kid = this.kid
130 184
     if (kid) {
@@ -134,25 +188,23 @@ export default {
134 188
         title: '请选择学生',
135 189
         content: '请先选择一个学生',
136 190
         showCancel: false,
137
-        success: res => {
138
-
139
-        }
191
+        success: res => {}
140 192
       })
141 193
     }
142 194
   },
143 195
   methods: {
144
-    showModal (e) {
196
+    showModal(e) {
145 197
       this.modalName = e.currentTarget.dataset.target
146 198
     },
147
-    hideModal (e) {
199
+    hideModal(e) {
148 200
       this.modalName = null
149 201
     },
150
-    get_list () {
202
+    get_list() {
151 203
       _getStudents().then(res => {
152 204
         this.result = res.data
153 205
       })
154 206
     },
155
-    get_students () {
207
+    get_students() {
156 208
       if (!this.student.student_name) return uni.showToast({ title: '请输入学生姓名', icon: 'none' })
157 209
       if (!this.student.school_name) return uni.showToast({ title: '请输入学校名称', icon: 'none' })
158 210
       _getStudents(this.student).then(res => {
@@ -165,7 +217,7 @@ export default {
165 217
         }
166 218
       })
167 219
     },
168
-    save (id) {
220
+    save(id) {
169 221
       this.selectKid = id
170 222
       uni.showModal({
171 223
         title: '确定绑定?',
@@ -182,7 +234,30 @@ export default {
182 234
         }
183 235
       })
184 236
     },
185
-    unbind (id) {
237
+    fixStudent(id) {
238
+      const item = this.result.student_data.find(item => item.id === id)
239
+      this.info.id = id
240
+      this.info.name = item.name
241
+      this.gradeIndex = this.grades.findIndex(e => e.name === item.grade_name)
242
+      this.info.grade_id = this.grades[this.gradeIndex]['id']
243
+      this.classIndex = this.classes.findIndex(e => e.name === item.class_name)
244
+      this.info.class_id = this.classes[this.classIndex]['id']
245
+      this.modalName = 'FixModal'
246
+    },
247
+    get_grades() {},
248
+    get_classes() {},
249
+    gradeChange(e) {
250
+      this.gradeIndex = e.detail.value
251
+      this.studentForm.grade_id = this.grades[this.gradeIndex].id
252
+      this.classIndex = -1
253
+      this.get_classes()
254
+    },
255
+    classChange(e) {
256
+      this.classIndex = e.detail.value
257
+      this.studentForm.class_id = this.classes[this.classIndex].id
258
+    },
259
+    confirmFix() {},
260
+    unbind(id) {
186 261
       const _self = this
187 262
       uni.showModal({
188 263
         title: '确定解绑?',
@@ -192,7 +267,9 @@ export default {
192 267
             _unbindStudent({ student: id }).then(res => {
193 268
               if (res.code === 1) {
194 269
                 uni.showToast({ title: '解绑成功!' })
195
-                if (_self.kid === id) { _self.$store.dispatch('setKid', 0) }// 解绑选中学生
270
+                if (_self.kid === id) {
271
+                  _self.$store.dispatch('setKid', 0)
272
+                } // 解绑选中学生
196 273
                 this.get_list()
197 274
               }
198 275
             })
@@ -200,7 +277,7 @@ export default {
200 277
         }
201 278
       })
202 279
     },
203
-    chooseKid (id) {
280
+    chooseKid(id) {
204 281
       uni.showModal({
205 282
         title: '确定选择学生',
206 283
         message: '确定选择该学生?',
@@ -214,19 +291,20 @@ export default {
214 291
         }
215 292
       })
216 293
     },
217
-    setCarts () { // 刷新购物车
294
+    setCarts() {
295
+      // 刷新购物车
218 296
       _shopList().then(res => {
219 297
         const carts = res.data.map(item => item.class_attend_id)
220 298
         this.$store.dispatch('setCarts', carts)
221 299
       })
222 300
     },
223
-    ListTouchStart (e) {
301
+    ListTouchStart(e) {
224 302
       this.listTouchStart = e.touches[0].pageX
225 303
     },
226
-    ListTouchMove (e) {
304
+    ListTouchMove(e) {
227 305
       this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left'
228 306
     },
229
-    ListTouchEnd (e) {
307
+    ListTouchEnd(e) {
230 308
       if (this.listTouchDirection === 'left') {
231 309
         this.moveModel = e.currentTarget.dataset.target
232 310
       } else {
@@ -265,6 +343,7 @@ export default {
265 343
   font-size: 22px;
266 344
 }
267 345
 .student-input {
346
+  padding-left: 20rpx;
268 347
   height: 40px;
269 348
   line-height: 40px;
270 349
   border-radius: 20px;
@@ -295,11 +374,11 @@ export default {
295 374
 .font-check {
296 375
   font-size: 22px;
297 376
 }
298
-.cu-list > .cu-item .move.student-move {
299
-  width: 130rpx;
300
-  text-align: center;
301
-}
302
-.cu-list > .cu-item.move-cur {
303
-  transform: translateX(-130rpx);
304
-}
377
+// .cu-list > .cu-item .move.student-move {
378
+//   width: 130rpx;
379
+//   text-align: center;
380
+// }
381
+// .cu-list > .cu-item.move-cur {
382
+//   transform: translateX(-130rpx);
383
+// }
305 384
 </style>