微信小程序-订单评价交互样式(WXML&WXSS&JS)

效果图:
好评

中评

差评
核心代码:

<view class="weui-flex order_comment_type">
            <view class="weui-flex__item">
              <view class="placeholder" bindtap="selectCommentType" data-index="{{index}}" data-type="GOOD">
                <image src="{{item.commentType=='GOOD'?'/images/icon_good_select.png':'/images/icon_good.png'}}" style="width:30rpx;height:30rpx;"></image>
                <text class="{{item.commentType=='GOOD'?'order_comment_type_selected':'order_comment_type_default'}}">好评</text>
              </view>
            </view>
            <view class="weui-flex__item" style="text-align:center;">
              <view class="placeholder" bindtap="selectCommentType" data-index="{{index}}" data-type="NOTBAD">
                <image src="{{item.commentType=='NOTBAD'?'/images/icon_middle_select.png':'/images/icon_middle.png'}}" style="width:30rpx;height:30rpx;"></image>
                <text class="{{item.commentType=='NOTBAD'?'order_comment_type_selected':'order_comment_type_default'}}">中评</text>
              </view>
            </view>
            <view class="weui-flex__item" style="text-align:right;">
              <view class="placeholder" bindtap="selectCommentType" data-index="{{index}}" data-type="BAD">
                <image src="{{item.commentType=='BAD'?'/images/icon_bad_select.png':'/images/icon_bad.png'}}" style="width:30rpx;height:30rpx;"></image>
                <text class="{{item.commentType=='BAD'?'order_comment_type_selected':'order_comment_type_default'}}">差评</text>
              </view>
            </view>
          </view>
selectCommentType: function (e) {
    console.log('选中的是第几条评论的哪一种类型', e.currentTarget.dataset);
    var commentList = this.data.commentList;
    var index = parseInt(e.currentTarget.dataset.index);
    commentList[index].commentType = e.currentTarget.dataset.type;
    this.setData({
      'commentList': commentList
    });
  }

完整代码:

wxml

 <form>
  <view class="order_comment_bg">
    <view wx:for="{{commentList}}" style="background:#fff;">
      <view class="order_comment_item">
        <view class="weui-flex order_comment_content bottom_border">
          <view>
            <view class="placeholder">
              <image src="{{item.commodityIcon}}" class="order_comment_img"></image>
            </view>
          </view>
          <view class="weui-flex__item order_comment_textarea_box">
            <view class="placeholder">
              <textarea class="weui-textarea order_comment_textarea" placeholder="写评论" bindblur="saveContent" data-index="{{index}}" value="{{item.content}}" auto-height />
            </view>
          </view>
        </view>
        <view>
          <view class="weui-flex order_comment_type">
            <view class="weui-flex__item">
              <view class="placeholder" bindtap="selectCommentType" data-index="{{index}}" data-type="GOOD">
                <image src="{{item.commentType=='GOOD'?'/images/icon_good_select.png':'/images/icon_good.png'}}" style="width:30rpx;height:30rpx;"></image>
                <text class="{{item.commentType=='GOOD'?'order_comment_type_selected':'order_comment_type_default'}}">好评</text>
              </view>
            </view>
            <view class="weui-flex__item" style="text-align:center;">
              <view class="placeholder" bindtap="selectCommentType" data-index="{{index}}" data-type="NOTBAD">
                <image src="{{item.commentType=='NOTBAD'?'/images/icon_middle_select.png':'/images/icon_middle.png'}}" style="width:30rpx;height:30rpx;"></image>
                <text class="{{item.commentType=='NOTBAD'?'order_comment_type_selected':'order_comment_type_default'}}">中评</text>
              </view>
            </view>
            <view class="weui-flex__item" style="text-align:right;">
              <view class="placeholder" bindtap="selectCommentType" data-index="{{index}}" data-type="BAD">
                <image src="{{item.commentType=='BAD'?'/images/icon_bad_select.png':'/images/icon_bad.png'}}" style="width:30rpx;height:30rpx;"></image>
                <text class="{{item.commentType=='BAD'?'order_comment_type_selected':'order_comment_type_default'}}">差评</text>
              </view>
            </view>
          </view>
        </view>
      </view>
      <view class="line"></view>
    </view>
    <view class="commnet_btn_box">
      <button class="weui-btn" style="background:#158447;font-size:30rpx;padding:10rpx 0;" type="primary" formType="submit">确定</button>
    </view>
  </view>
</form>

js

Page({
  data: {
    windowHeight: 'auto',
    commentList: [
      {
        url: 'http://share.30days-tech.com/daka/pictures/commodity_icon.png',
        id: 1
      },
      {
        url: 'http://share.30days-tech.com/daka/pictures/commodity_icon.png',
        id: 2
      },
      {
        url: 'http://share.30days-tech.com/daka/pictures/commodity_icon.png',
        id: 3
      }
    ]
  },
  onShow: function () {
    // 页面显示
    var vm = this
    // 初始化评论选项为好评
    for (var i = 0, len = commentList.length; i < len; i++) {
      commentList[i].commentType = 'GOOD';
    }
  },
  selectCommentType: function (e) {
    console.log('选中的是第几条评论的哪一种类型', e.currentTarget.dataset);
    var commentList = this.data.commentList;
    var index = parseInt(e.currentTarget.dataset.index);
    commentList[index].commentType = e.currentTarget.dataset.type;
    this.setData({
      'commentList': commentList
    });
  },
  saveContent: function (e) {
    console.log('保存评论到列表', e.detail.value, e.currentTarget.dataset.index);
    var vm = this;
    var commentList = vm.data.commentList;
    var index = e.currentTarget.dataset.index;
    commentList[index].content = e.detail.value;
    vm.setData({
      commentList: commentList
    });
  }
})

wxss

.order_comment_bg {
  overflow: scroll;
  background: #efeff4;
}

.order_comment_item {
  padding: 30rpx 0;
  margin: 0 0 0 30rpx;
}

.order_comment_img {
  width: 134rpx;
  height: 134rpx;
  border: 1px solid #e5e5e5;
}

.order_comment_content {
  padding-bottom: 16rpx;
}

.order_comment_textarea_box {
  margin-left: 20rpx;
}

.order_comment_textarea {
  font-size: 30rpx;
}

.order_comment_type {
  padding: 12rpx 30rpx 0 0;
}

.order_comment_type_default, .order_comment_type_selected {
    font-size:30rpx;
    margin-left:10rpx;
}
.order_comment_type_default{
    color: #888888;
}

.order_comment_type_selected{
    color: #000000;
}
.commnet_btn_box{
    width:90%;
    margin:20rpx 5%;
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值