index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <view>
  3. <!-- index.wxml -->
  4. <scroll-view :scroll-y="true" :style="'height: ' + scrollH + 'px'" :scroll-into-view="toView" scroll-with-animation @scrolltoupper="bindUpper">
  5. <view class="wrap_nr">
  6. <view class="tips">您好,在线客服很高兴为您服务</view>
  7. <view class="section_w" :id="'item' + item.id" v-for="(item, index) in dataList" :key="index">
  8. <view class="sec_time" v-if="index == 0">{{ item.created_at }}</view>
  9. <view class="section from_user" v-if="item.type == 1">
  10. <view class="item">
  11. <view class="item_wenzi">{{ item.content }}</view>
  12. <image class="icon" :src="userThumb"></image>
  13. </view>
  14. </view>
  15. <view class="section from_plat" v-if="item.type == 2">
  16. <view class="item">
  17. <image class="icon" :src="kfThumb"></image>
  18. <view class="item_wenzi">{{ item.content }}</view>
  19. </view>
  20. </view>
  21. </view>
  22. </view>
  23. </scroll-view>
  24. <!-- <view class="tips">您好,在线客服很高兴为您服务</view>
  25. <view id="scrollView" style="height:{{ scrollH }}px;">
  26. <view class="section_w" wx:for="{{ dataList }}" wx:key="index">
  27. <view class="sec_time" wx:if="{{ index == 0 }}">{{ item.created_at }}</view>
  28. <view class="section from_user" wx:if="{{ item.type == 1 }}">
  29. <view class="item">
  30. <view class="item_wenzi">{{ item.content }}</view>
  31. <image class="icon" src="{{ userThumb }}"></image>
  32. </view>
  33. </view>
  34. <view class="section from_plat" wx:if="{{ item.type == 2 }}">
  35. <view class="item">
  36. <image class="icon" src="{{ kfThumb }}"></image>
  37. <view class="item_wenzi">{{ item.content }}</view>
  38. </view>
  39. </view>
  40. </view>
  41. </view> -->
  42. <view class="wrap_pub" :style="'bottom:' + keybordH + 'px'">
  43. <view class="pub_l">
  44. <van-field :value="content" placeholder="" @input="getContent" />
  45. <!-- bind:input="getContent" -->
  46. <!-- adjust-position="{{ false }}" -->
  47. <!-- bind:focus="bindFocus" -->
  48. <!-- bind:blur= "bindBlur" -->
  49. </view>
  50. <image class="icon_send" src="/static/statics/img/icon_send.png" @tap="bindSendContent"></image>
  51. </view>
  52. <!-- loading -->
  53. <!-- <van-overlay show="{{ loading }}" z-index="100">
  54. <van-loading custom-class="custom_loading" />
  55. </van-overlay> -->
  56. </view>
  57. </template>
  58. <script>
  59. // index.js
  60. let myPro = require('../../utils/wxRequest.js');
  61. let util = require('../../utils/util.js');
  62. export default {
  63. data() {
  64. return {
  65. page: 1,
  66. size: 10,
  67. dataList: [],
  68. loading: false,
  69. finished: false,
  70. content: '',
  71. userThumb: '',
  72. // 用户头像
  73. kfThumb: '',
  74. // 客服头像
  75. latestId: '',
  76. // 最新的一条
  77. openToView: true,
  78. toView: '',
  79. scrollH: '',
  80. initScrollH: '',
  81. init: false,
  82. keybordH: ''
  83. };
  84. },
  85. onLoad: function (options) {
  86. // Do some initialize when page load.
  87. let that = this;
  88. that.setData({
  89. userThumb: getApp().globalData.userInfo.thumb,
  90. kfThumb: getApp().globalData.logoTu
  91. }); // console.log("用户头像",getApp().globalData.userInfo.thumb)
  92. },
  93. onShow: function () {
  94. // Do something when page show.
  95. let that = this; // 滚动区域高度计算
  96. uni.getSystemInfo({
  97. success: function (res) {
  98. let height = res.windowHeight; // that.setData({
  99. // scrollH: height + 160,
  100. // });
  101. console.log('总height', height);
  102. const query = uni.createSelectorQuery(); // query.select('.tips').boundingClientRect();
  103. query.select('.wrap_pub').boundingClientRect();
  104. query.exec((res) => {
  105. // 分别取出节点的高度
  106. let tipsH = res[0].height; // 发布框的高度 px
  107. let pubH = res[0].height; // 发布框的高度 px
  108. let scrollH = height - pubH;
  109. that.setData({
  110. scrollH: scrollH,
  111. initScrollH: scrollH
  112. }); // wx.pageScrollTo({
  113. // scrollTop: scrollH,
  114. // duration: 100
  115. // })
  116. console.log('setBgHeight', getApp().globalData.setBgHeight); // console.log('pubH',pubH)
  117. console.log('scrollH', scrollH);
  118. });
  119. }
  120. }); // 验证登录
  121. getApp().globalData.verifyLogin(function (loginStatus) {
  122. if (loginStatus) {
  123. that.setData({
  124. page: 1,
  125. openToView: true,
  126. dataList: [],
  127. init: true,
  128. finished: false
  129. });
  130. that.getDataList();
  131. }
  132. });
  133. },
  134. onReady: function () {
  135. // Do something when page ready.
  136. },
  137. onHide: function () {
  138. // Do something when page hide.
  139. },
  140. onUnload: function () {
  141. // Do something when page close.
  142. },
  143. onPullDownRefresh: function () {
  144. // Do something when pull down.
  145. // let that = this;
  146. // that.getDataList();
  147. // //停止当前页面下拉刷新
  148. // wx.stopPullDownRefresh();
  149. },
  150. onReachBottom: function () {
  151. // Do something when page reach bottom.
  152. },
  153. onPageScroll: function () {
  154. // Do something when page scroll
  155. },
  156. onResize: function () {
  157. // Do something when page resize
  158. },
  159. methods: {
  160. // 获取数据列表
  161. getDataList() {
  162. let that = this;
  163. let params = {
  164. page: that.page,
  165. size: that.size
  166. };
  167. myPro
  168. .wxRequest('user/v2/suggestionList', 'GET', params)
  169. .then((res) => {
  170. let list = res.result;
  171. if (list.length != 0) {
  172. if (that.page == 1) {
  173. that.setData({
  174. dataList: list,
  175. page: that.page + 1,
  176. init: false
  177. });
  178. console.log('openToView', that.openToView);
  179. setTimeout(function () {
  180. if (that.openToView) {
  181. that.setData({
  182. toView: 'item' + list[list.length - 1].id
  183. });
  184. }
  185. }, 100);
  186. } else {
  187. list = list.concat(that.dataList);
  188. that.setData({
  189. dataList: list,
  190. page: that.page + 1,
  191. init: false
  192. });
  193. }
  194. } else {
  195. uni.showToast({
  196. title: '暂无更多数据',
  197. icon: 'none'
  198. });
  199. }
  200. })
  201. .catch((err) => {
  202. console.log('报错信息', err);
  203. uni.showToast({
  204. title: err,
  205. icon: 'none'
  206. });
  207. });
  208. },
  209. // 获取输入内容
  210. getContent(event) {
  211. let that = this;
  212. that.setData({
  213. content: event.detail
  214. });
  215. },
  216. // 实现得不好, 还是使用自带的
  217. // 聚焦
  218. bindFocus(event) {
  219. let that = this; // console.log('focus',event);
  220. that.setData({
  221. content: event.detail.value,
  222. keybordH: event.detail.height,
  223. // 键盘高度
  224. scrollH: that.scrollH - event.detail.height
  225. });
  226. },
  227. // 失去焦点
  228. bindBlur(event) {
  229. let that = this;
  230. that.setData({
  231. content: event.detail.value,
  232. keybordH: 0,
  233. // 键盘高度
  234. scrollH: that.initScrollH
  235. });
  236. },
  237. // 发布消息
  238. bindSendContent() {
  239. let that = this;
  240. if (!that.content) {
  241. uni.showToast({
  242. title: '请输入内容',
  243. icon: 'none'
  244. });
  245. return;
  246. }
  247. let params = {
  248. content: that.content
  249. };
  250. myPro
  251. .wxRequest('user/v2/suggestionApply', 'POST', params)
  252. .then((res) => {
  253. that.setData({
  254. content: '',
  255. init: true
  256. });
  257. uni.showToast({
  258. title: res.msg,
  259. icon: 'none'
  260. }); // 重新拉取
  261. that.setData({
  262. page: 1,
  263. dataList: [],
  264. openToView: true,
  265. finished: false
  266. });
  267. that.getDataList();
  268. })
  269. .catch((err) => {
  270. console.log('报错信息', err);
  271. uni.showToast({
  272. title: err,
  273. icon: 'none'
  274. });
  275. });
  276. },
  277. // 滚动到顶部
  278. bindUpper() {
  279. let that = this; // console.log('触发了吗=====')
  280. if (!that.init) {
  281. that.setData({
  282. openToView: false
  283. });
  284. that.getDataList();
  285. }
  286. }
  287. }
  288. };
  289. </script>
  290. <style>
  291. /**index.wxss**/
  292. .wrap_nr {
  293. padding-bottom: 48rpx;
  294. }
  295. .tips {
  296. width: 444rpx;
  297. height: 58rpx;
  298. margin: 20rpx auto 0;
  299. background: #f3f4f9;
  300. border-radius: 29rpx;
  301. font-size: 26rpx;
  302. color: rgba(0, 0, 0, 0.54);
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. }
  307. .sec_time {
  308. font-size: 26rpx;
  309. color: rgba(0, 0, 0, 0.54);
  310. text-align: center;
  311. margin-top: 40rpx;
  312. }
  313. .section {
  314. padding: 0 30rpx;
  315. }
  316. .section .item {
  317. display: flex;
  318. /* align-items: center; */
  319. margin-top: 48rpx;
  320. }
  321. /* .latest{
  322. margin-bottom: 48rpx;
  323. } */
  324. .section .item .icon {
  325. width: 90rpx;
  326. height: 90rpx;
  327. border-radius: 50%;
  328. }
  329. .section .item .item_wenzi {
  330. max-width: 427rpx;
  331. padding: 30rpx;
  332. font-size: 28rpx;
  333. color: rgba(255, 255, 255, 0.87);
  334. margin-left: 12rpx;
  335. background: #d54c43;
  336. border-radius: 0 15rpx 15rpx 15rpx;
  337. }
  338. .section.from_user .item {
  339. justify-content: flex-end;
  340. }
  341. .section.from_user .item .item_wenzi {
  342. background: #f3f4f9;
  343. border-radius: 15rpx 0rpx 15rpx 15rpx;
  344. margin-left: 0rpx;
  345. margin-right: 18rpx;
  346. color: rgba(0, 0, 0, 0.87);
  347. }
  348. .wrap_pub {
  349. width: 100%;
  350. padding: 0 30rpx 0;
  351. height: 160rpx;
  352. position: fixed;
  353. bottom: 0;
  354. left: 0;
  355. background: #f6f6f6;
  356. display: flex;
  357. align-items: center;
  358. justify-content: space-between;
  359. }
  360. .wrap_pub .pub_l {
  361. width: 617rpx;
  362. border-radius: 35rpx;
  363. }
  364. .wrap_pub .icon_send {
  365. width: 42rpx;
  366. height: 42rpx;
  367. }
  368. .wrap_pub .van-cell {
  369. border-radius: 35rpx;
  370. height: 70rpx;
  371. padding: 0 20rpx !important;
  372. }
  373. .wrap_pub .van-field__body {
  374. height: 100%;
  375. }
  376. </style>