小程序实现近三天时间导航栏,并根据对应不同信息

页面实现效果展示:

代码:

 wxml

<!--导航条-->
<view class="navbar">
  <text wx:for="{{dayList}}" data-idx="{{index}}" class="item {{currentTab==index ? 'active' : ''}}" wx:key="unique" bindtap="navbarTap">
    {{item.year}}-{{item.month}}-{{item.day}}
  </text>
</view>
<!-- 主体内容 -->
<view class="show-date">
  <text>当前时间:{{nowDate}}</text>
    <!-- 表格 -->
      <view style="padding:15px;">
        <view class="table">
          <view class="table-tr">
            <view class="table-th1">跟进</view>
            <view class="table-th2">客户简称</view>
            <view class="table-th3">取消</view>
            <view class="table-th4">延后</view>
          </view>
         <!-- 根据循环,展示表格数据 -->
          <view class="table-tr" wx:for="{{schedule_item}}" wx:key="unique">
            <view class="table-td1">跟进</view>
            <view class="table-td2">{{item.customer_code}}</view>
            <view class="table-td3">取消</view>
            <view class="table-td4">延后</view>
          </view>
        </view>
      </view>
</view>

wxss

/* 顶部导航栏 */
page {
  display: flex;
  flex-direction: column;
  height: 100%;
}
/* 导航栏横向排列 */
.navbar {
  flex: none;
  display: flex;
  background: #fff;
}
/* 导航栏总样式 */
.navbar .item {
  position: relative;
  flex: auto;
  text-align: center;
  height:60px;
}
/* 选中时字体的颜色改变 */
.navbar .item.active {
  color: #7acfa6;
}
/* 选中时增加横线样式 */
.navbar .item.active:after {
  content: "";
  display: block;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4rpx;
  background: #7acfa6;
}

/* 表格样式 */
.table {
  display: table;
  width: 100%;
  border-collapse: collapse;
  box-sizing: border-box;
}
.table-tr {
  display: table-row;
}
.table-th1 {
  width:20%;
  display: table-cell;
  font-weight: bold;
  border: 1rpx solid gray;
  background-color:#8fcabd;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.table-th2 {
  width:40%;
  display: table-cell;
  font-weight: bold;
  border: 1rpx solid gray;
  background-color:#8fcabd;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.table-th3 {
  width:20%;
  display: table-cell;
  font-weight: bold;
  border: 1rpx solid gray;
  background-color:#8fcabd;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.table-th4 {
  width:20%;
  display: table-cell;
  font-weight: bold;
  border: 1rpx solid gray;
  background-color:#8fcabd;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.table-td1{
  width:20%;
  display: table-cell;
  border: 1rpx solid gray;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.table-td2 {
  width:40%;
  display: table-cell;
  border: 1rpx solid gray;
  text-align: center;
  vertical-align: middle;
  padding: 5px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.table-td3 {
  width:20%;
  display: table-cell;
  border: 1rpx solid gray;
  text-align: center;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}
.table-td4 {
  width:20%;
  display: table-cell;
  border: 1rpx solid gray;
  text-align: center;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-all;
}

js

const app= getApp()
Page({
  data: {
    dayList: [],
    currentTab: 0,
    nowDate:''
  },
  //顶部菜单
  navbarTap: function (e) {
    this.setData({
      currentTab: e.currentTarget.dataset.idx
    })
//点击顶部栏,出现的下标值作为数组的第几项
    this.setData({
      nowDate:this.data.dayList[e.currentTarget.dataset.idx].year+'-'+this.data.dayList[e.currentTarget.dataset.idx].month+'-'+this.data.dayList[e.currentTarget.dataset.idx].day
    })
//访问服务器,将时间传入后端,以时间作为判断条件去查询
    wx.request({
      url: app.globalData.position + 'Crm/schedule_selcet',
      data: {
        nowDate:this.data.dayList[e.currentTarget.dataset.idx].year+'-'+this.data.dayList[e.currentTarget.dataset.idx].month+'-'+this.data.dayList[e.currentTarget.dataset.idx].day
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      method: 'POST',
      dataType: 'json',
      success: res => {
//将后端获取的值存入data中
        this.setData({
          schedule_item:res.data
        })
      },
      fail(res) {
        console.log("查询失败")
      }
    })
  },
//页面加载出进行的操作
  onLoad: function () {
    var myDate = new Date(); 
    myDate.toLocaleDateString();//获取当前日期
    var total = 1; // 个数(月份需要+1)
    var dayList = [];
    dayList.push({//将数据插入数组
      'day': myDate.getDate(),
      'month': myDate.getMonth() + total,
      // 'week': toWeekDay(myDate.getDay()),//星期显示
      'year': myDate.getFullYear()
    });
    for (var i = 0; i <2; i++) { //选择显示的天数(i<6就是一周),这里只显示三天0,1,2,当天,第一条,第二天
      myDate.setDate(myDate.getDate() + total); //自动计算后面的日期
      dayList.push({//将数据插入数组
        'day': myDate.getDate(),
        'month': myDate.getMonth() + total,
        // 'week': toWeekDay(myDate.getDay()),//调用toWeekDay()函数,显示星期
        'year': myDate.getFullYear(),
      });    
    }
  //查询,这里的查询主要是为了默认值使用,0就表示当天的数据
      wx.request({
        url: app.globalData.position + 'Crm/schedule_selcet',
        data: {
          nowDate:dayList[0].year+'-'+dayList[0].month+'-'+dayList[0].day
        },
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        method: 'POST',
        dataType: 'json',
        success: res => {
          this.setData({
            schedule_item:res.data
          })
        },
        fail(res) {
          console.log("查询失败")
        }
      })

    this.setData({
      dayList: dayList,
      nowDate:dayList[0].year+'-'+dayList[0].month+'-'+dayList[0].day//设置默认值
    });
  }
})
//下面适用于星期的显示
// function toWeekDay(weekDay) { //根据Switch case去传入每周的数据
//   switch (weekDay) {
//     case 1:
//       return '星期一';
//       break;
//     case 2:
//       return '星期二';
//       break;
//     case 3:
//       return '星期三';
//       break;
//     case 4:
//       return '星期四';
//       break;
//     case 5:
//       return '星期五';
//       break;
//     case 6:
//       return '星期六';
//       break;
//     case 0:
//       return '星期日';
//       break;
//     default:
//       break;
//   }
//   return '传入未知参数';
// }
  //排程查询
  public function schedule_selcet()
  {
    $nowDate = input('post.nowDate');//前端得来时间参数
    $arr = date_parse_from_format('Y-m-d', $nowDate); //Y-m-d中-与$nowDate要一致
    $time = mktime(0, 0, 0, $arr['month'], $arr['day'], $arr['year']);//转时间戳
    //根据判断条件进行查询,distinct表示根据'customer_code'字段,让其不存在重复值
    $schedule=DB::table('schedule')->where(['creation_date'=>$time])->distinct('customer_code')->field("customer_code")->select();
    echo json_encode($schedule); //以json格式返回$schedule的值
  }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在微信小程序实现底部导航栏,需要按照以下步骤进行操作: 1. 在 app.json 文件中设置底部导航栏的样式和内容。具体来说,在 app.json 文件中的 tabBar 属性中设置导航栏的样式和包含的页面路径,例如: ``` "tabBar": { "color": "#999", "selectedColor": "#007aff", "backgroundColor": "#f7f7f7", "borderStyle": "black", "list": [{ "pagePath": "pages/index/index", "text": "首页", "iconPath": "images/tabbar/home.png", "selectedIconPath": "images/tabbar/home_selected.png" },{ "pagePath": "pages/order/order", "text": "订单", "iconPath": "images/tabbar/order.png", "selectedIconPath": "images/tabbar/order_selected.png" },{ "pagePath": "pages/mine/mine", "text": "我的", "iconPath": "images/tabbar/mine.png", "selectedIconPath": "images/tabbar/mine_selected.png" }] } ``` 2. 在 app.js 文件中添加监听函数,用于处理底部导航栏的点击事件。具体来说,在 app.js 文件中的 onTabItemTap 函数中添加相应的逻辑代码,例如: ``` App({ onLaunch: function () { // ... }, onTabItemTap: function(item) { console.log('tap tab item', item.index, item.pagePath) } }) ``` 3. 在需要使用底部导航栏的页面中添加相应的代码。具体来说,在需要使用底部导航栏的页面中,需要将页面的配置文件中的 navigationBarHidden 属性设置为 true,同时在页面的 WXML 文件中添加一个 tabbar 组件,例如: ``` <tabbar selected="{{selected}}" bindchange="tabbarChange"> <tabbar-item key="home" icon="{{homeIcon}}" selected-icon="{{homeSelectedIcon}}"> <view wx:slot="text">首页</view> </tabbar-item> <tabbar-item key="order" icon="{{orderIcon}}" selected-icon="{{orderSelectedIcon}}"> <view wx:slot="text">订单</view> </tabbar-item> <tabbar-item key="mine" icon="{{mineIcon}}" selected-icon="{{mineSelectedIcon}}"> <view wx:slot="text">我的</view> </tabbar-item> </tabbar> ``` 其中,selected 表示当前选中的 tabbar-item 的 key 值,bindchange 表示 tabbar-item 点击事件的处理函数。 以上就是在微信小程序实现底部导航栏的基本步骤,需要注意的是,开发者需要根据实际需求进行样式和逻辑的调整,以达到最佳的用户体验效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值