Browse Source

学员管理

zs 2 years ago
parent
commit
54a86db33d
4 changed files with 54 additions and 27 deletions
  1. 16 14
      pages/sstudent/add.js
  2. 1 1
      pages/sstudent/add.wxml
  3. 36 11
      pages/sstudent/list.js
  4. 1 1
      pages/sstudent/list.wxml

+ 16 - 14
pages/sstudent/add.js

@@ -7,7 +7,9 @@ Page({
         form: { icon: [] },
         // 性别
         genderList: gender,
-        id: ''
+        id: '',
+        //用户id
+        user_id: ''
     },
     initValidate() {
         const rules = { icon: { required: true }, name: { required: true }, card: { required: true, idcard: true }, age: { required: true }, gender: { required: true }, phone: { required: true, tel: true } }
@@ -38,7 +40,7 @@ Page({
         const that = this;
         let card = e.detail.value;
         if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(card)) {
-            wx.showToast({ title: `请输入18位的有效身份证`, icon: 'error', duration: 2000 })
+            wx.showToast({ title: `请输入有效身份证号码`, icon: 'none', duration: 2000 })
         } else {
             //获取出生日期
             let birth = card.substring(6, 10) + "-" + card.substring(10, 12) + "-" + card.substring(12, 14);
@@ -51,7 +53,7 @@ Page({
             var day = myDate.getDate();
             var age = myDate.getFullYear() - card.substring(6, 10) - 1;
             if (card.substring(10, 12) < month || card.substring(10, 12) == month && card.substring(12, 14) <= day) age++;
-            that.setData({ 'form.age': age });
+            that.setData({ 'form.age': parseFloat(age) });
         }
     },
     // 选择性别
@@ -66,16 +68,17 @@ Page({
         const form = that.data.form;
         const params = e.detail.value;
         params.icon = form.icon;
+        params.user_id = that.data.user_id;
         if (!this.WxValidate.checkForm(params)) {
             const error = this.WxValidate.errorList[0];
             wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
             return false
         } else {
-            console.log(params);
-            // if (form._id) arr = await app.$post(`/newCourt/api/student/${form._id}`, params);
-            // else arr = await app.$post(`/newCourt/api/student`, params); 
-            // if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
-            // else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
+            let arr;
+            if (form._id) arr = await app.$post(`/student/${form._id}`, params);
+            else arr = await app.$post(`/student`, params)
+            if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
+            else wx.showToast({ title: `${errmsg}`, icon: 'error', duration: 2000 })
         }
     },
     /**
@@ -95,13 +98,12 @@ Page({
         wx.getStorage({
             key: 'user',
             success: async res => {
+                that.setData({ user_id: res.data._id });
                 if (that.data.id) {
-                    const form = { _id: '1', icon: [{ url: '/image/beijing.jpeg' }], name: "测试姓名", card: '220581200003302462', phone: '12345678901', age: '18', gender: '0' };
-                    that.setData({ form: form });
-                    // const arr = await app.$get(`/newCourt/api/student/${that.data.id}`);
-                    // if (arr.errcode == '0') {
-                    //     that.setData({ form: arr.data });
-                    // }
+                    const arr = await app.$get(`/student/${that.data.id}`);
+                    if (arr.errcode == '0') {
+                        that.setData({ form: arr.data });
+                    }
                 }
             },
             fail: async res => {

+ 1 - 1
pages/sstudent/add.wxml

@@ -23,7 +23,7 @@
                 <view class="content">
                     <view class="label">年龄:</view>
                     <view class="value">
-                        <input type="text" name="age" value="{{form.age}}" placeholder="请输入年龄" />
+                        <input type="number" name="age" value="{{form.age}}" placeholder="请输入年龄" />
                     </view>
                 </view>
                 <view class="content">

+ 36 - 11
pages/sstudent/list.js

@@ -6,12 +6,11 @@ Page({
      */
     data: {
         frameStyle: { useTop: true, name: '学员信息', leftArrow: true, useBar: false },
-        list: [
-            { _id: '1', icon: [{ url: '/image/beijing.jpeg' }], name: "测试姓名", card: '220581200003302462', phone: '12345678901', age: '18', gender: '0' },
-            { _id: '2', icon: [{ url: '/image/beijing.jpeg' }], name: "测试姓名", card: '220581200003302462', phone: '12345678901', age: '18', gender: '1' },
-            { _id: '1', icon: [{ url: '/image/beijing.jpeg' }], name: "测试姓名", card: '220581200003302462', phone: '12345678901', age: '18', gender: '0' },
-            { _id: '2', icon: [{ url: '/image/beijing.jpeg' }], name: "测试姓名", card: '220581200003302462', phone: '12345678901', age: '18', gender: '1' }
-        ],
+        list: [],
+        total: 0,
+        page: 0,
+        skip: 0,
+        limit: 5,
     },
     // 返回
     back: function () {
@@ -19,6 +18,8 @@ Page({
     },
     //添加或修改
     toCommon: function (e) {
+        const that = this;
+        that.setData({ skip: 0, page: 0, list: [] })
         const { route, id } = e.currentTarget.dataset;
         if (id) wx.navigateTo({ url: `/pages/sstudent/${route}?id=${id}` })
         else wx.navigateTo({ url: `/pages/sstudent/${route}` })
@@ -32,9 +33,10 @@ Page({
             content: '是否确认删除该条数据?',
             async success(res) {
                 if (res.confirm) {
-                    const arr = await app.$delete(`/newCourt/api/student/${id}`);
+                    const arr = await app.$delete(`/student/${id}`);
                     if (arr.errcode == '0') {
                         wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
+                        that.setData({ skip: 0, page: 0, list: [] })
                         that.watchLogin()
                     } else {
                         wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
@@ -43,19 +45,41 @@ Page({
             }
         })
     },
+    // 分页
+    toPage: function () {
+        const that = this;
+        let list = that.data.list;
+        let limit = that.data.limit;
+        if (that.data.total > list.length) {
+            wx.showLoading({ title: '加载中', mask: true })
+            let page = that.data.page + 1;
+            that.setData({ page: page })
+            let skip = page * limit;
+            that.setData({ skip: skip })
+            that.watchLogin();
+            wx.hideLoading()
+        } else { wx.showToast({ title: '没有更多数据了', icon: 'none', duration: 2000 }) }
+    },
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
-        const that = this;
-        that.watchLogin();
+      
     },
     // 监听用户是否登录
     watchLogin: async function () {
         const that = this;
         wx.getStorage({
             key: 'user',
-            success: async res => { },
+            success: async res => {
+                let info = { skip: that.data.skip, limit: that.data.limit };
+                let arr;
+                arr = await app.$get(`/student`, { ...info });
+                if (arr.errcode == '0') {
+                    that.setData({ list: [...that.data.list, ...arr.data] })
+                    that.setData({ total: arr.total })
+                } else { wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 }) }
+            },
             fail: async res => {
                 wx.redirectTo({ url: '/pages/index/index' })
             }
@@ -73,7 +97,8 @@ Page({
      * 生命周期函数--监听页面显示
      */
     onShow: function () {
-
+        const that = this;
+        that.watchLogin();
     },
 
     /**

+ 1 - 1
pages/sstudent/list.wxml

@@ -9,7 +9,7 @@
             </view>
         </view>
         <view class="two">
-            <scroll-view scroll-y="true" class="scroll-view">
+            <scroll-view scroll-y="true" class="scroll-view" bindscrolltolower="toPage">
                 <view class="list-scroll-view">
                     <view class="list" wx:for="{{list}}" wx:key="item">
                         <view class="list_1">