YY 2 سال پیش
والد
کامیت
b3a7eae25e
4فایلهای تغییر یافته به همراه86 افزوده شده و 14 حذف شده
  1. 29 4
      pages/scoach/add.js
  2. 1 1
      pages/scoach/add.wxml
  3. 55 8
      pages/scoach/list.js
  4. 1 1
      pages/scoach/list.wxml

+ 29 - 4
pages/scoach/add.js

@@ -9,12 +9,13 @@ Page({
      */
     data: {
         frameStyle: { useTop: true, name: '教练信息', leftArrow: true, useBar: false },
+        id: '',
         form: { icon: [] },
         // 性别
         genderList: gender,
     },
     initValidate() {
-        const rules = { icon: { required: true }, name: { required: true }, card: { required: true }, gender: { required: true }, phone: { required: true, tel: true } }
+        const rules = { icon: { required: false }, name: { required: true }, card: { required: true }, gender: { required: true }, phone: { required: true, tel: true } }
         // 验证字段的提示信息,若不传则调用默认的信息
         const messages = { icon: { required: '请选择头像', }, name: { required: '请输入用户姓名', }, card: { required: '请输入身份证号', }, gender: { required: '请选择性别', }, phone: { required: '请输入手机号', } };
         this.WxValidate = new WxValidate(rules, messages)
@@ -46,7 +47,6 @@ Page({
     toCard: function (e) {
         var IDCard = e.detail.value;
         var birth = IDCard.substring(6, 10) + "-" + IDCard.substring(10, 12) + "-" + IDCard.substring(12, 14);
-        console.log('出生日期', birth);
         var sex = "";
         if (parseInt(IDCard.substr(16, 1)) % 2 == 1) {
             sex = "男";
@@ -74,7 +74,12 @@ Page({
             wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
             return false
         } else {
-            console.log('提交');
+            let arr;
+            console.log(params);
+            if (form._id) { arr = await app.$post(`/coach/${form._id}`, params); }
+            else { arr = await app.$post(`/coach`, params) }
+            if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
+            else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
         }
     },
     /**
@@ -82,9 +87,29 @@ Page({
      */
     onLoad: function (options) {
         const that = this;
+        that.setData({ id: options.id || '' })
         //验证规则函数
         that.initValidate();
-
+        // 监听用户是否登录
+        that.watchLogin();
+    },
+    // 监听用户是否登录
+    watchLogin: async function () {
+        const that = this;
+        wx.getStorage({
+            key: 'user',
+            success: async res => {
+                if (that.data.id) {
+                    const arr = await app.$get(`/coach/${that.data.id}`);
+                    if (arr.errcode == '0') {
+                        that.setData({ form: arr.data });
+                    }
+                }
+            },
+            fail: res => {
+                wx.redirectTo({ url: '/pages/index/index', })
+            }
+        })
     },
     /**
      * 生命周期函数--监听页面初次渲染完成

+ 1 - 1
pages/scoach/add.wxml

@@ -40,7 +40,7 @@
             <view class="content">
                 <view class="label">专业技能:</view>
                 <view class="value">
-                    <input name="phone" value="{{form.skill}}" placeholder="请输入专业技能" />
+                    <input name="skill" value="{{form.skill}}" placeholder="请输入专业技能" />
                 </view>
             </view>
             <view class="btn">

+ 55 - 8
pages/scoach/list.js

@@ -6,12 +6,11 @@ Page({
      */
     data: {
         frameStyle: { useTop: true, name: '教练信息', leftArrow: true, useBar: false },
-        list: [
-            { _id: '001', icon: [{ url: '/image/club.png' }], name: '教练1', gender: '女', age: '33', phone: '12345678901', skill: '羽毛球', card: '220220222202022222' },
-            { _id: '002', icon: [{ url: '/image/club.png' }], name: '教练1', gender: '女', age: '33', phone: '12345678901', skill: '羽毛球', card: '220220222202022222' },
-            { _id: '001', icon: [{ url: '/image/club.png' }], name: '教练1', gender: '女', age: '33', phone: '12345678901', skill: '羽毛球', card: '220220222202022222' },
-            { _id: '002', icon: [{ url: '/image/club.png' }], name: '教练1', gender: '女', age: '33', phone: '12345678901', skill: '羽毛球', card: '220220222202022222' },
-        ],
+        list: [],
+        total: 0,
+        page: 0,
+        skip: 0,
+        limit: 5,
     },
     // 返回
     back: function () {
@@ -19,10 +18,14 @@ Page({
     },
     // 添加
     toAdd() {
+        const that = this;
+        that.setData({ skip: 0, page: 0, list: [] })
         wx.navigateTo({ url: '/pages/scoach/add' })
     },
     // 修改
     toEdit: function (e) {
+        const that = this;
+        that.setData({ skip: 0, page: 0, list: [] })
         let { id } = e.currentTarget.dataset;
         wx.navigateTo({ url: `/pages/scoach/add?id=${id}` })
     },
@@ -34,10 +37,33 @@ Page({
             title: '提示',
             content: '是否确认删除该条数据?',
             async success(res) {
-                console.log('删除');
+                if (res.confirm) {
+                    const arr = await app.$delete(`/coach/${id}`);
+                    if (arr.errcode == '0') {
+                        wx.showToast({ title: `删除信息成功`, icon: 'success', duration: 2000 })
+                        that.watchLogin()
+                    } else {
+                        wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
+                    }
+                }
             }
         })
     },
+    // 分页
+    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 }) }
+    },
     /**
      * 生命周期函数--监听页面加载
      */
@@ -56,7 +82,28 @@ Page({
      * 生命周期函数--监听页面显示
      */
     onShow: function () {
-
+        const that = this;
+        // 监听用户是否登录
+        that.watchLogin();
+    },
+    // 监听用户是否登录
+    watchLogin: async function () {
+        const that = this;
+        wx.getStorage({
+            key: 'user',
+            success: async res => {
+                let info = { skip: that.data.skip, limit: that.data.limit };
+                const arr = await app.$get(`/coach`, { ...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' })
+            }
+        })
     },
 
     /**

+ 1 - 1
pages/scoach/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">