这是一个商品展示并能进行评论和答复的功能页面,

遇到的问题有:

  1. 分享功能没有办法将json数据写在地址中,只能传id来进行获取
  2. 这里必须新加一个状态用来判断是否显示x回复@x,因为我以前的判断这个依据是如果回复的人是楼主则不显示,后来发现如果楼主回复了你,你再想回复楼主的话就无法显示x回复@x,所以这里要加一个参数,所有回复的都是false,评论都是true,加上这个条件就能判断出你是单纯的评论还是回复了

<!--pages/wantDetail/wantDetail.wxml-->
<view class='qiu' bindtouchstart="touchstar">
  <view class='qiu_titleAndUser'>
    <text class='title'>{{title}}</text>
    <view class='user'>
      <image class='userImg' src='{{userImg}}'></image>
      <text class='userName' style='position: absolute; margin-left:20rpx;'>{{userName}}</text>
    </view>
    <view class='text_detail'>{{content}}</view>
    <image wx:if="{{imgUrl !==''}}" class='img' src='https://qhds.drefore.cn{{imgUrl}}'></image>
    <view class='three_but'>
      <view class='three_view'>
        <button class='share' open-type='share'>
          <image class='countImg' src="../../resources/images/share.png" />
        </button>
      </view>
      <view class='three_view'>
        <image bindtap='addWantImg' class='countImg' src='../../resources/images/anscount.png'></image>
        <text class='count'>{{count}}</text>
      </view>
      <view class='three_view'>
        <text class='time'>{{time}}</text>
      </view>
    </view>
  </view>
</view>
<view class='reply'>
  <view class='replyUser' wx:for="{{wantReplay}}" wx:key="{{index}}" bindtouchstart="touchstar">
    <block wx:if="{{item.replyName === userName && item.state === true}}">
      <image class='userImg' src='{{item.userImg}}'></image>
      <text class='userName' style='position: absolute; margin-left:20rpx;'>{{item.userName}}</text>
      <view class='reply_content' data-replyuserid='{{item.userID}}' data-replyname='{{item.userName}}' bindtap='getReplyUserID'>{{item.content}}</view>
      <view class='reply_time'>{{item.time}}</view>
    </block>
    <block wx:else>
      <image class='userImg' src='{{item.userImg}}'></image>
      <view class='huifu'>
        <text class='userName'>{{item.userName}}</text>
        <text class='huifu_text'>回复@</text>
        <text class='userName'>{{item.replyName}}</text>
      </view>
      <view class='reply_content' data-replyuserid='{{item.userID}}' data-replyname='{{item.userName}}' bindtap='getReplyUserID'>{{item.content}}</view>
      <view class='reply_time'>{{item.time}}</view>
    </block>
  </view>
</view>
<view class='ask'>
  <block wx:if="{{check}}">
    <input class='input' type='text' placeholder='我来评论' bindinput='contentInp' value='{{contentInp}}' focus='{{focus}}'></input>
    <button class='button' bindtap='addWant'>评论</button>
  </block>
  <block wx:else>
    <input class='input' type='text' placeholder='回复@{{replyName}}' bindinput='replyInp' value='{{replyInp}}' focus='{{focus}}'></input>
    <button class='button' bindtap='addWant'>评论</button>
  </block>
</view>

WXML

// pages/wantDetail/wantDetail.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   * user开头的数据都是楼主的
   */
  data: {
    wantID: 0,
    userID: 0, //userID
    replyUserID: 0, //回复哪个人的userID 默认等于楼主id
    replyName: "",
    count: 0,
    content: "",
    imgUrl: "",
    time: "",
    title: "",
    userName: "",
    userImg: "",
    limit: 5,
    wantReplay: [],
    contentInp: "",
    replyInp: "",
    focus: false,
    check: true, //默认显示我来评论input
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      wantID: options.id
    })
    this.getWantDetail();
  },

  getWantDetail() {
    let params = {
      wantID: this.data.wantID,
      offset: 0,
      limit: this.data.limit
    }
    app.getWantDetail(params).then(res => {
      let wantDetail = [];
      for (var i = 0; i < res.data.wantDetail.length; i++) {
        if (res.data.wantDetail[i].pid === 0) {
          wantDetail = res.data.wantDetail[i]
          res.data.wantDetail.splice(i, 1)
        }
      }
      this.setData({
        wantReplay: res.data.wantDetail,
        count: wantDetail.count,
        content: wantDetail.content,
        imgUrl: wantDetail.imgUrl,
        time: wantDetail.time,
        title: wantDetail.title,
        userName: wantDetail.userName,
        userImg: wantDetail.userImg,
        userID: wantDetail.userID,
        replyUserID: wantDetail.userID,
      })
    })
  },

  onReachBottom: function() {
    this.data.limit = this.data.limit + 4
    this.getWantDetail();
  },
  //触摸事件切换到回复楼主
  touchstar: function() {
    this.setData({
      check: true,
      focus: false,
      contentInp: "",
      replyInp: "",
    })
  },
  /**评论输入框 */
  contentInp(e) {
    this.setData({
      contentInp: e.detail.value
    })
  },
  /**答复输入框 */
  replyInp(e) {
    this.setData({
      replyInp: e.detail.value
    })
  },

  /**消息图片点击 */
  addWantImg() {
    this.setData({
      focus: true,
    })
  },
  addWant() {
    if (this.data.contentInp.length > 100) {
      wx.showToast({
        title: '请将字数控制在100字以内哦',
        icon: "none",
        duration: 1000,
        mask: true,
      })
    } else {
      if (this.data.replyUserID === this.data.userID && this.data.check === true) {
        this.addComment();
      } else {
        this.addReply();
      }
    }
  },

  /**发表评论 */
  addComment() {
    let params = {
      pID: this.data.wantID,
      userID: app.globalData.userID,
      content: this.data.contentInp,
      replyUserID: this.data.userID,
      type: 1,
      state: true
    }
    app.addReply(params).then(res => {
      if (res.state === 1) {
        this.setData({
          contentInp: ""
        })
        wx.showToast({
          title: '评论成功',
          icon: "none",
          duration: 1000,
          mask: true,
        })
        this.getWantDetail();
      }
    })
  },
  /**点击评论获取要回复的人的id */
  getReplyUserID(e) {
    let replyID = e.currentTarget.dataset.replyuserid;
    if (replyID === app.globalData.userID) {
      wx.showToast({
        title: '请不要回复自己哦',
        icon: "none",
        duration: 1000,
        mask: true,
      })
    } else {
      this.setData({
        replyUserID: replyID,
        replyName: e.currentTarget.dataset.replyname,
        focus: true,
        check: false
      })
    }
  },
  /**回复 */
  addReply() {
    let params = {
      pID: this.data.wantID,
      userID: app.globalData.userID,
      content: this.data.replyInp,
      replyUserID: this.data.replyUserID,
      type: 1,
      state: false
    }
    app.addReply(params).then(res => {
      if (res.state === 1) {
        this.setData({
          replyInp: "",
          check: true
        })
        wx.showToast({
          title: '评论成功',
          icon: "none",
          duration: 1000,
          mask: true,
        })
        this.getWantDetail();
      }
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(ops) {
    wx.showShareMenu({
      withShareTicket: true
    })
    return {
      title: 'xxxx',
      path: 'pages/wantDetail/wantDetail?id=' + this.data.wantID,
      imageUrl: "https://qhds.drefore.cn" + this.data.imgUrl,
      success: function(res) {
        console.log("success" + res)
      },
      fail: function(res) {
        console.log("fail" + res)
      }
    }
  },
})

JS

/* pages/wantDetail/wantDetail.wxss */

page {
  background-color: #f1f5fc;
}

.qiu {
  width: 100%;
  background-color: white;
}

.qiu_titleAndUser {
  margin-left: 20rpx;
}

.title {
  display: flex;
  justify-content: center;
  align-items: center;
}

.user {
  width: 100%;
  margin-top: 20rpx;
  margin-bottom: 20rpx;
}

.userImg {
  width: 70rpx;
  height: 70rpx;
  border-radius: 50%;
}

.userName {
  font-size: 30rpx;
  color: #566f98;
}

.text_detail {
  font-size: 30rpx;
  margin-left: 20rpx;
  margin-bottom: 20rpx;
}

.img {
  width: 90%;
  height: 500rpx;
  margin: 20rpx 20rpx;
}

.countImg {
  width: 50rpx;
  height: 50rpx;
}

.count {
  font-size: 20rpx;
  margin-left: 5rpx;
}

.time {
  font-size: 25rpx;
  color: #757575;
  margin-left: 410rpx;
}

.reply {
  width: 100%;
  background-color: white;
  margin-top: 20rpx;
  margin-bottom: 100rpx;
}

.replyUser {
  padding-top: 10rpx;
  margin-left: 20rpx;
  margin-bottom: 20rpx;
  width: 100%;
}

.reply_content {
  width: 80%;
  font-size: 30rpx;
  margin-left: 90rpx;
  margin-top: -30rpx;
}

.reply_time {
  width: 260rpx;
  height: 50rpx;
  font-size: 25rpx;
  color: #757575;
  margin-left: 480rpx;
}

.huifu {
  position: absolute;
  margin-left: 90rpx;
  margin-top: -90rpx;
}

.huifu_text {
  font-size: 30rpx;
  margin-left: 5rpx;
  margin-right: 5rpx;
}

.ask {
  position: fixed;
  bottom:;
  width: 100%;
  height: 90rpx;
  background-color: white;
  display: flex;
  flex-direction: row;
}

.input {
  width: 600rpx;
  border: 1rpx solid #f1f1f1;
  margin: 12rpx 0rpx 12rpx 20rpx;
  border-radius: 30rpx;
  background: #f1f5fc;
  font-size: 25rpx;
  text-align: center;
}

.button {
  background: #6fb442;
  color: white;
  border-radius: 30rpx;
  font-size: 30rpx;
  width: 130rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12rpx 20rpx;
}

CSS

微信小程序商品详情 + 评论功能实现的更多相关文章

  1. 微信小程序仿朋友圈功能开发(发布、点赞、评论等功能)

    微信小程序仿朋友圈功能开发(发布.点赞.评论等功能) 1.项目分析 项目整体分为三个部分 发布 展示 详情页 graph LR 朋友圈发布 --内容发布--> 内容展示 内容展示 --点击展示卡 ...

  2. 微信小程序产品定位及功能介绍

    产品定位及功能介绍 微信小程序是一种全新的连接用户与服务的方式,它可以在微信内被便捷地获取和传播,同时具有出色的使用体验. 小程序注册 注册小程序帐号 在微信公众平台官网首页(mp.weixin.qq ...

  3. (三)微信小程序首页的分类功能和搜索功能的实现笔记

    就在昨天,微信宣布了微信小程序开发者工具新增“云开发”功能 下载最新的开发者工具,现在无需服务器即可实现小程序的快速迭代! 分类功能和搜索功能的效果图 1.首页分类功能的实现 boxtwo方法(.js ...

  4. 微信小程序开发平台新功能「云开发」快速上手体验

    微信小程序开发平台刚刚开放了一个全新的功能:云开发. 简单地说就是将开发人员搭建微信小程序后端的成本再次降低,此文刚好在此产品公测时,来快速上手看看都有哪些方便开发者的功能更新. 微信小程序一直保持一 ...

  5. 让你的微信小程序具有在线支付功能

    前言 最近需要在微信小程序中用到在线支付功能,于是看了一下官方的文档,发现要在小程序里实现微信支付还是很方便的,如果你以前开发过服务号下的微信支付,那么你会发现其实小程序里的微信支付和服务号里的开发过 ...

  6. 微信小程序注册60s倒计时功能 使用JS实现注册60s倒计时功能

    微信小程序+WEB使用JS实现注册[60s]倒计时功能开发步骤: 1.wxml页面代码: <text>绑定手机</text> <form bindsubmit=" ...

  7. 微信小程序又一爆炸功能上线-云开发

    云开发介绍 开发者可以使用云开发开发微信小程序.小游戏,无需搭建服务器,即可使用云端能力. 云开发为开发者提供完整的云端支持,弱化后端和运维概念,无需搭建服务器,使用平台提供的 API 进行核心业务开 ...

  8. 微信小程序中悬浮窗功能的实现(主要探讨和解决在原生组件上的拖动)

    问题场景 所谓悬浮窗就是图中微信图标的按钮,采用fixed定位,可拖动和点击. 这算是一个比较常见的实现场景了. 为什么要用cover-view做悬浮窗?原生组件出来背锅了~ 最初我做悬浮窗用的不是c ...

  9. 【微信小程序】:评论、回复和删除功能 -- 2017/7/14

    1.理论核心:传参->pid,评论父id需要在wxml页面传递:小程序端和WEB端不同核心:前者操纵数据,后者操纵DOM元素对象 2.不废话,直接代码:wxml <view class=& ...

随机推荐

  1. 自定义属性Attribute的运用

    有时候需要一个枚举类,能够承载更多的信息,于是可以利用attribute这个特性. 首先编写自己业务需求类 [AttributeUsage(AttributeTargets.Field)] publi ...

  2. python_ 学习笔记(运算符)

    python的运算符基本和C语言一致,以下说一些不一样的! 算术运算符 **:代表乘方,对应也有**=: //:代表商向下取整,对应也有//=: 逻辑运算符 and or not 位运算符 :& ...

  3. Python的/整除

    在python3和python2里,正整数的/结果是一样的,但是负数的整除却有区别 比如python3中,-1/2是等于0的,c/c++的结果也是这样, 但在python2中,-1/2确是-1,想要得 ...

  4. E - Cricket Field

    Description   Once upon a time there was a greedy King who ordered his chief Architect to build a fi ...

  5. [luoguP1631] 序列合并(堆 || 优先队列)

    传送门 首先,把A和B两个序列分别从小到大排序,变成两个有序队列.这样,从A和B中各任取一个数相加得到N2个和,可以把这些和看成形成了n个有序表/队列: A[1]+B[1] <= A[1]+B[ ...

  6. jquery ajax获取json并解析,获取的json是object对象格式

    首先我们使用的是ajax方式,推荐一个学习网址: http://blog.csdn.net/shiyaru1314/article/details/51065410 这个博主写的特别好.现在来看我们的 ...

  7. [bzoj1072][SCOI2007]排列(状态压缩DP)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1072 分析:看了题解才知道,状态的设计很巧妙,用余数表示,即f[i][j]表示二进制状 ...

  8. 美河LINUX 内核学习视频

    Linux内核从原理到代码详解 培训视频 Linux内核源码研读与实战演练 [7.10][美河资料发布小组@aipepsi][linux内核分析视频教程] 炼数成金Linux内核探秘 [11.23][ ...

  9. Android GIS开发系列-- 入门季(5) FeatureLayer加载本地shp文件与要素查询

    FeatureLayer是要素图层,也是Arcgis的主要图层.用这个图层可以加载本地的shp文件.下面我们看怎样加载shp文件到MapView中.查看ArcGis API可知FeatureLayer ...

  10. HDOJ 5402 Travelling Salesman Problem 模拟

    行数或列数为奇数就能够所有走完. 行数和列数都是偶数,能够选择空出一个(x+y)为奇数的点. 假设要空出一个(x+y)为偶数的点,则必须空出其它(x+y)为奇数的点 Travelling Salesm ...