微信小程序实现列表及tab标签

一、效果图

二、代码部分

   代码复制就可以使用,但需要注意的是xml文件部分,相关的图片资源引用需要自行替换,发话不多说直接看代码。

a、json文件代码

{
  "usingComponents": {},
  "navigationBarBackgroundColor": "#F2F2F2",
  "navigationBarTextStyle": "black",
  "navigationBarTitleText": " 家属订单",
  "backgroundColor": "#eeeeee",
  "backgroundTextStyle": "light",
  "navigationStyle": "custom"
}

b、tabchange.wxml文件代码

<!--pages/personal/persontranction/myoppoint/oppointment.wxml-->
<!-- 头部标题 -->
<view class="title_search">
  <view class="seeck_md">
    <!-- 返回 -->
    <view class="logout" bindtap="logout">
      <image class="logout_ic" src="/images/return_back.png">
      </image>
      <text class="logout_txt">返回</text>
    </view>
    <!--消息-->
    <view class="msg_title_center">
      <view class="msg" bindtap="open_msg">
        <text class="msg_txt">家属订单</text>
      </view>
    </view>
  </view>
  <view class="logout">
    <image class="logout_ic">
    </image>
    <text class="logout_txt"></text>
  </view>
</view>
<view>
  <!-- Tab布局 -->
  <!-- 家属成员 -->
  <scroll-view class="scroll-view_H" scroll-x="true" bindscroll="scroll" style="width: 100%">
    <view class="head_list">
      <!-- 李XX -->
      <block wx:for="{{listItem}}" wx:key="id" wx:for-item="itemName" wx:for-index="id">
        <view class="{{itemCheck[id].isChecked?'head_list_item_one_ed':'head_list_item_one'}}" catchtap="family_tap" id="{{id}}">
          <view class="head_list_item_one_im_parent" catchtap="family_tap" id="{{id}}">
            <image class="head_list_item_one_im" catchtap="family_tap" src="/images/lemon.png" id="{{id}}"></image>
          </view>
          <text class="{{itemCheck[id].isChecked?'head_list_item_one_txt_ed':'head_list_item_one_txt'}}"  catchtap="family_tap" id="{{id}}">{{itemName.realName}}
          </text>
        </view>
      </block>
    </view>
  </scroll-view>
  <!-- 导航栏navigationbar -->
  <view class='navBox'>
    <view class='titleBox' id="allaid" bindtap='titleClick' data-idx='0'>
      <text class="{{0 == currentIndex ? 'fontColorBox' : ''}}">待接收</text>
      <hr class="{{0 == currentIndex ? 'lineBox' : 'notLineBox'}}" />
    </view>
    <view class='titleBox' id="aiding" bindtap='titleClick' data-idx='1'>
      <text class="{{1 == currentIndex ? 'fontColorBox1' : ''}}">待处理</text>
      <hr class="{{1 == currentIndex ? 'lineBox' : 'notLineBox'}} " />
    </view>
    <view class='titleBox' id="aidfinish" bindtap='titleClick' data-idx='2'>
      <text class="{{2 == currentIndex ? 'fontColorBox2' : ''}}">已完成</text>
      <hr class="{{2== currentIndex ? 'lineBox' : 'notLineBox'}} " />
    </view>
  </view>
  <!-- 内容布局 -->
  <swiper class='swiperTtemBox' bindchange='pagechange' current='{{currentIndex}}'>
    <!--待接收 -->
    <swiper-item class='swiperTtemBox' catchtouchmove='onTouchMove'>
      <scroll-view class='scbg' scroll-y='true'>
        <block wx:for="{{receivedList}}" wx:key="id" wx:for-item="itemName" wx:for-index="id">
          <view class='box'>
            <view class='firstblock'>
              <!-- 日期 -->
              <view class="item_State">
                <view class="state_bg">
                  <!-- 可添加背景状态图片 -->
                  <image class="img_state_bg" src=""> </image>
                  <text class='txt_state_bg'>待接收</text>
                </view>
                <view class='item_first_title'>
                  <text class='showdataone'>{{itemName.serviceTime==null?'':itemName.serviceTime}}</text>
                  <text class='dataunit'>{{itemName.workTime==null?'':itemName.workTime}}</text>
                </view>
              </view>
              <view class='tel'>
                <!-- 可添加背景状态图片 -->
                <image class="imge_appoint_tag" src=""></image>
                <text class='showdata_conn'>{{itemName.brandName}}</text>
              </view>
            </view>
          </view>
        </block>
      </scroll-view>
    </swiper-item>
    <!-- 待处理 -->
    <swiper-item class='swiperTtemBox' catchtouchmove='onTouchMove'>
      <scroll-view class='scbg' scroll-y='true'>
        <block wx:for="{{dealedList}}" wx:key="id" wx:for-item="itemName" wx:for-index="id">
          <view class='box'>
            <view class='firstblock'>
              <!-- 日期 -->
              <view class="item_State">
                <view class="state_bg">
                  <image class="img_state_bg" src=""> </image>
                  <text class='txt_state_bg'>待处理</text>
                </view>
                <view class='item_first_title'>
                  <text class='showdataone'>{{itemName.serviceTime}}</text>
                  <text class='dataunit'>{{itemName.workTime}}</text>
                </view>
              </view>
              <view class='tel'>
                <!-- 可添加背景状态图片 -->
                <image class="imge_appoint_tag" src=""></image>
                <text class='showdata_conn'>{{itemName.brandName}}</text>
              </view>
            </view>
          </view>
        </block>
      </scroll-view>
    </swiper-item>
    <!-- 已完成 -->
    <swiper-item class='swiperTtemBox' catchtouchmove='onTouchMove'>
      <scroll-view class='scbg' scroll-y='true'>
        <block wx:for="{{finishedList}}" wx:key="id" wx:for-item="itemName" wx:for-index="id">
          <view class='box'>
            <view class='firstblock'>
              <!-- 日期 -->
              <view class="item_State">
                <view class="state_bg">
                  <!-- 可添加背景状态图片 -->
                  <image class="img_state_bg" src=""> </image>
                  <text class='txt_state_bg'>已完成</text>
                </view>
                <view class='item_first_title'>
                  <text class='showdataone'>{{itemName.serviceTime}}</text>
                  <text class='dataunit'>{{itemName.workTime}}</text>
                </view>
              </view>
              <view class='tel'>
                <!-- 可添加背景状态图片 -->
                <image class="imge_appoint_tag" src=""></image>
                <text class='showdata_conn'>{{itemName.brandName}}</text>
              </view>
            </view>
          </view>
        </block>
      </scroll-view>
    </swiper-item>
  </swiper>
</view>

c、tabchange.wxss代码

/* pages/personal/persontranction/myoppoint/oppointment.wxss */
Page {
  background: #f0f0f0;
  height: 100%;
  position: fixed;
}

.fontColorBox,
.fontColorBox1,
.fontColorBox2{
  /* 文字默认颜色 */
  color: #00c6ac;
}

.navBox {
  /* 顶部tab盒子样式 */
  width: 100%;
  height: 90rpx;
  background: white;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

#aiding,
#aidfinish{
   margin-left: 0rpx;
}

.titleBox {
  /* 未选中文字的样式 */
  color: rgb(168, 170, 175);
  font-size: 30rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: 250rpx;
  height: 100%;
}
.lineBox,.notLineBox{
  /* 选中及未选中底线共同样式 */
  width: 60rpx;
  height: 4rpx;
  margin-top: 16rpx;
  border-radius: 4rpx;
}

.lineBox {
  /* 选中底线样式 */
  background: #00c6ac;
  width: 250rpx;
  height: 4rpx;
  margin-top: 16rpx;
  border-radius: 4rpx;
}

.notLineBox {
  /* 未选中底线样式 */
  background: transparent;
    width: 250rpx;
  height: 4rpx;
}

.swiperTtemBox {
  /* 底部内容样式 */
  height: 100vh;
  overflow: scroll;
  margin: 0rpx 0rpx;
  background: #f0f0f0;
  font-size: 28rpx;
}

.box {
  background-color: white;
  margin-top: 20rpx;
  border-radius: 20rpx;
  margin-left: 30rpx;
  margin-right: 30rpx;
}

.firstblock {
  height: 150rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 20rpx;
  flex-direction: row;
  padding-right: 30rpx;
}

.showtime {
  font-size: 24rpx;
  color: #e3e3e3;
  font-family: PingFangSC-regular;
}

/* 左侧标记 */
.item_first_title{
  margin-top: 0rpx;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  margin-left: 30rpx;
}
.state_bg{
  width: 200rpx;
  display: flex;
  align-items: center;
}
.img_state_bg{
  width: 160rpx;
  height: 60rpx;
}

.txt_state_bg{
  position: absolute;
  margin-left: 30rpx;
}

.dataunit{
  margin-left: 10rpx;
  color: #e3e3e3;
}

/* item右侧标记 */
.tel{
  margin-top: 0rpx;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
 .showdata_conn{
  font-size: 28rpx;
  color: #000000;
  font-family: PingFangSC-regular;
  margin-top: 10rpx;
 }

.imge_appoint_tag{
  width: 40rpx;
  height: 40rpx;
}

.showdataone {
  font-size: 28rpx;
  color: #e3e3e3;
  margin-top: 10rpx;
}
/* item右侧标记 */

.showdatatwo {
  font-size: 32rpx;
  color: #000000;
  font-weight: bold;
  font-family: PingFangSC-regular;
}

/* scroolview布局 */
.scbg {
  background-color: #EFEFEF;
  width: 100%;
  height: calc(100vh - 420rpx);
  left: 0rpx;
  right: 0rpx;
  top: 0rpx;
  padding-bottom: 10rpx;
}


/* 头部搜索 */
/* 搜索标题 */
.title_search{
  background: linear-gradient(to right, #0455a7, #62c8ec);
  height: 170rpx;
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  justify-content: flex-start;
}
.seeck_md{
  display: flex;
  flex-direction: row;
  width: 100%;
  justify-content: flex-start;
  align-items: flex-end;
}

/* 消息 */
.msg{
  width: 180rpx;
  height: 90rpx; 
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-right: 0rpx;
  margin-left: 30rpx;

}

.msg_title_center{
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.msg_txt{
  font-size: 36rpx;
  height: 80rpx;
  width: 160rpx;
  margin-bottom: 20rpx;
  align-items: center;
  color: #fff;
  display: flex;
  justify-content: center;
}

/* 返回 */
.logout{
  width: 100rpx;
  height: 90rpx; 
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-right: 20rpx; 
  margin-left: 30rpx;
}
.logout_ic{
  height: 44rpx;
  width: 48rpx;
  margin-right: 2rpx;
}
.logout_txt{
  font-size: 24rpx;
  height: 40rpx;
  width: 60rpx;
  margin-bottom: 10rpx;
  align-items: flex-start;
  color: #fff;
  display: flex;
  justify-content: flex-start;
}
/* 搜索标题 */
/* 头部搜索  */

/* 家属横向列表 */
.scroll-view_H {
  overflow: scroll;
  white-space: nowrap;
  background-color: white;
  margin-right: 30rpx;
}

.head_list {
  display: flex;
  /* display: inline-block; */
  flex-direction: row;
  background-color: white;
  height: 160rpx;
  width: 100%;
  justify-content: flex-start;
  align-items: center;
}

/* 家属选择背景 */
.head_list_item_one {
  flex-shrink: 0;
  flex-grow: 0;
  display: flex;
  flex-direction: column;
  background-color: #f0f0f0;
  width: 140rpx;
  height: 140rpx;
  align-items: center;
  justify-content: center;
  margin-left: 30rpx;
  border-radius: 10rpx;
}

/* 家属选背景 */
.head_list_item_one_ed {
  display: flex;
  flex-direction: column;
  background-color: #06c7ae;
  flex-shrink: 0;
  flex-grow: 0;
  width: 140rpx;
  height: 140rpx;
  align-items: center;
  justify-content: center;
  margin-left: 30rpx;
  border-radius: 10rpx;
}

.head_list_item_one_im_parent {
  background-color: white;
  width: 80rpx;
  height: 80rpx;
  border-radius: 40rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.head_list_item_one_im {
  width: 72rpx;
  height: 72rpx;
  border-radius: 36rpx;
  background-color: white;
}

.head_list_item_one_txt {
  margin-top: 6rpx;
  font-size: 26rpx;
  color: #252525;
}

.head_list_item_one_txt_ed {
  margin-top: 6rpx;
  font-size: 26rpx;
  color: #ffffff;
}

/* 家属选背景 */

d、tabchange.ts代码

// pages/personal/persontranction/myoppoint/oppointment.ts
const appointid = getApp()
Page({
  data: {
    currentIndex: 0, //默认是活动项
    list: [],
    receivedList:[{serviceTime:"2021-10-01",workTime:"10:12",brandName:"hash"},
    {serviceTime:"2021-11-01",workTime:"10:12",brandName:"sdcvav"}],//待接收
    dealedList:[{serviceTime:"2021-10-01",workTime:"10:12",brandName:"hash"},
    {serviceTime:"2021-11-01",workTime:"10:12",brandName:"sdcvav"}],//待处理
    finishedList:[{serviceTime:"2021-10-01",workTime:"10:12",brandName:"hash"},
    {serviceTime:"2021-11-01",workTime:"10:12",brandName:"sdcvav"},{serviceTime:"2021-10-01",workTime:"10:12",brandName:"hash"},
    {serviceTime:"2021-11-01",workTime:"10:12",brandName:"sdcvav"}],//已完成
    itemCheck: [{ "id": 0, "isChecked": true, }, { "id": 1, "isChecked": false, }, { "id": 2, "isChecked": false, }, { "id": 3, "isChecked": false, }, { "id": 4, "isChecked": false, }, { "id": 5, "isChecked": false, }, { "id": 6, "isChecked": false, }, { "id": 7, "isChecked": false, }, { "id": 8, "isChecked": false, }, { "id": 9, "isChecked": false, }, { "id": 10, "isChecked": false, }, { "id": 12, "isChecked": false, }],//状态标记
    listItem: [{realName:"大明"},{realName:"大宝"},{realName:"mogu"}],//数据列表数据
    patintIdS: '',
    stateDataId:''
  },
  //返回上一级页面
  logout: function () {
    wx.navigateBack({})
  },
  //点击tab时触发
  titleClick: function (e: any) {
    var that=this;
    this.setData({
      //拿到当前索引并动态改变
      currentIndex: e.currentTarget.dataset.idx
    })

    // if(e.currentTarget.dataset.idx==0){
    //   that.data.stateDataId=1+"";
     
    // }else if(e.currentTarget.dataset.idx==1){
    //   that.data.stateDataId=2+"";
   
    // }else if(e.currentTarget.dataset.idx==2){
    //   that.data.stateDataId=0+"";

    // }
    // console.log("======拿到当前索引并动态改变=dddd======"+e.currentTarget.dataset.idx)
  },

  onLoad(){
    var that = this;
    that.data.stateDataId=1+"";

  },

  //选中那个家庭成员
  family_tap: function (e: any) {
    var that = this;
    var ids = e.target.id;//点击当前位置

    for (var i = 0; i < that.data.itemCheck.length; i++) {
      that.data.itemCheck[i].isChecked = false;
    }
    that.data.itemCheck[ids].isChecked = true;
    that.data.patintIdS = that.data.listItem[ids].patientId + "";

    that.setData({
      itemCheck: that.data.itemCheck
    })

  },


})

最后总结,代码逻辑有多种实现方式,以上只是其中一种,仅供交流使用。

  • 0
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值