index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  1. <template>
  2. <view class="content">
  3. <!-- <navigation-custom :config="config" :scrollTop="scrollTopNav" @customConduct="customConduct" :scrollMaxHeight="scrollMaxHeight" /> -->
  4. <scroll-view id="scrollview" class='chat-box' :style="{height: style.contentViewHeight + 'px'}" scroll-y="true"
  5. :scroll-with-animation="false" :scroll-top="scrollTop" @scrolltoupper="lower()">
  6. <!-- <view class="tips-box">
  7. {{nowTime}}
  8. </view> -->
  9. <!-- <view class="tips-box tips-title">
  10. 您好,智能投顾很高兴为您服务!
  11. </view> -->
  12. <!--
  13. <view class="talk-box">
  14. <view class="talk-head-box">
  15. <image src="../../static/rabotHead.png" mode="" class="talk-head"></image>
  16. </view>
  17. <view class="talk-content">您好,智能顾投很高兴为您服务!</view>
  18. </view> -->
  19. <view v-for="chat in talkList" :key="chat.talkType" class="m-item">
  20. <view class="talk-box talk-box-end" v-show="chat.content">
  21. <view class="talk-reply">{{chat.content}}</view>
  22. <view class="talk-head-box">
  23. <image :src='userHeadUrl' mode="" class="talk-head"></image>
  24. </view>
  25. </view>
  26. <view class="talk-box">
  27. <view class="talk-head-box">
  28. <image :src='rabotHeadImg' mode="" class="talk-head"></image>
  29. </view>
  30. <view class="talk-content">{{chat.reply}}</view>
  31. </view>
  32. </view>
  33. </scroll-view>
  34. <view class="send-box" :style="{ 'padding-bottom' : isShowKeyBoard + 'px'}">
  35. <input type="text" class="enter-box" v-model="inputInfo" :adjust-position="true" @input='isInputing'
  36. @confirm='sendInputInfo' :style="{'width':inputWidth}" />
  37. <button type="primary" class="submit-message" @click="sendInputInfo()" v-if='isShowSend'>发送</button>
  38. <image src="/static/setIcon.png" @click.stop='openModal()' v-if='isShowSetCenter'></image>
  39. </view>
  40. <!-- <drag-button :isDock="true" :existTabBar="true" @btnClick="goUserSelf" /> -->
  41. <uni-popup ref="popup" type="bottom">
  42. <view class="uni-share">
  43. <view class="uni-share-content">
  44. <view class="uni-share-content-box" @click.stop='goUserSelf' >
  45. <view class="uni-share-content-image">
  46. <image src="/static/icon/userSetIcon.png" class="image" />
  47. </view>
  48. <view class="uni-share-content-text">个人中心</view>
  49. </view>
  50. <view class="uni-share-content-box" @click.stop='goRecharge' >
  51. <view class="uni-share-content-image">
  52. <image src="/static/icon/recharge.png" class="image" />
  53. </view>
  54. <view class="uni-share-content-text">去充值</view>
  55. </view>
  56. </view>
  57. <view class="uni-share-btn" @click="cancelModal()">取消</view>
  58. </view>
  59. </uni-popup>
  60. </view>
  61. </template>
  62. <script>
  63. import uniPopup from "@/components/uni-popup/uni-popup.vue"
  64. var md5 = require("../../common/md5.js");
  65. var page = 1;
  66. export default {
  67. data() {
  68. return {
  69. isShowSend:false,
  70. isShowSetModal:false,
  71. isShowSetCenter:true,
  72. inputWidth:'80%',
  73. title: 'RABOT',
  74. nowTime: '',
  75. nowHeight: '622px',
  76. inputInfo: '',
  77. isShowKeyBoard:0,
  78. rabotHeadImg: "../../static/rabotHead.png",
  79. userHeadUrl: getApp().globalData.user_headUrl || '../../static/userDefault.png',
  80. talkList: [],
  81. scrollTopNav: 0, // 当linear为true的时候需要通过onpagescroll传递参数
  82. scrollMaxHeight: 200 ,//滑动的高度限制,超过这个高度即背景全部显示
  83. scrollTop:0,
  84. scrollRequestEnable: true,
  85. pageSize:10,
  86. style: {
  87. pageHeight: 0,
  88. contentViewHeight: 0,
  89. footViewHeight: 90,
  90. mitemHeight: 0
  91. },
  92. }
  93. },
  94. components: {
  95. uniPopup
  96. },
  97. onPageScroll(e) {
  98. this.scrollTopNav = e.scrollTop;
  99. },
  100. onLoad() {
  101. this.userLogin();
  102. this.getEquipmentHeight();
  103. },
  104. onShow() {
  105. this.getNowTime();
  106. },
  107. methods: {
  108. userLogin(){
  109. uni.login({
  110. success: (res) => {
  111. this.getCodeRabot(res)
  112. }
  113. });
  114. },
  115. getCodeRabot(res){
  116. let that = this;
  117. uni.request({
  118. url:getApp().globalData.shareUrl, //需要设置为全局
  119. method: 'POST',
  120. header: {
  121. 'content-type': 'application/x-www-form-urlencoded'
  122. },
  123. data: {
  124. method: 'login',
  125. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  126. code: res.code,
  127. sign: md5('login' + getApp().globalData.globalTimestamp),
  128. // invited:'invited'
  129. },
  130. success: res => {
  131. // 通过openid发起会员登录
  132. getApp().globalData.user_id = res.data.msg.id;
  133. getApp().globalData.open_id = res.data.msg.openid;
  134. getApp().globalData.isAuth = res.data.msg.isauth === '0';
  135. getApp().globalData.user_name = res.data.msg.name;
  136. getApp().globalData.user_headUrl = res.data.msg.headimg;
  137. getApp().globalData.times = res.data.msg.times;
  138. getApp().globalData.total_times = res.data.msg.total_times;
  139. that.getHistory();
  140. }
  141. });
  142. },
  143. getNowTime() {
  144. let time = new Date();
  145. let y = time.getFullYear();
  146. let m = time.getMonth() + 1;
  147. let d = time.getDate();
  148. let h = time.getHours();
  149. let i = time.getMinutes();
  150. i = i > 10 ? i : '0' + i;
  151. this.nowTime = y + "年" + m + "月" + d + "日" + " " + h + ":" + i
  152. },
  153. getEquipmentHeight() {
  154. const height = uni.getSystemInfoSync().windowHeight;
  155. this.nowHeight = height + 'px';
  156. getApp().globalData.glbalHeight = this.nowHeight;
  157. this.style.pageHeight = height;
  158. this.style.contentViewHeight = height - uni.getSystemInfoSync().screenWidth / 750 * (100) -7; //像素 因为给出的是像素高度 然后我们用的是upx 所以换算一下
  159. },
  160. scrollToBottom() {
  161. let that = this;
  162. let query = uni.createSelectorQuery();
  163. query.selectAll('.m-item').boundingClientRect();
  164. query.select('#scrollview').boundingClientRect();
  165. query.exec((res) => {
  166. that.style.mitemHeight = 0;
  167. res[0].forEach((rect) => that.style.mitemHeight = that.style.mitemHeight + rect.height + 40) //获取所有内部子元素的高度
  168. // 因为vue的虚拟DOM 每次生成的新消息都是之前的,所以采用异步setTimeout 主要就是添加了这红字
  169. that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight
  170. // setTimeout(() => {
  171. // if (that.style.mitemHeight > (that.style.contentViewHeight - 100)) { //判断子元素高度是否大于显示高度
  172. // that.scrollTop = that.style.mitemHeight - that.style.contentViewHeight //用子元素的高度减去显示的高度就获益获得序言滚动的高度
  173. // }
  174. // }, 100)
  175. })
  176. },
  177. getHistory() {
  178. let that = this;
  179. uni.request({
  180. url: getApp().globalData.shareUrl, //需要设置为全局
  181. method: 'POST',
  182. header: {
  183. 'content-type': 'application/x-www-form-urlencoded'
  184. },
  185. data: {
  186. method: 'question_list',
  187. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  188. uid: getApp().globalData.user_id,
  189. sign: md5('question_list' + getApp().globalData.globalTimestamp),
  190. page: page || 1,
  191. pageSize: 10,
  192. },
  193. success: res => {
  194. that.userHeadUrl = getApp().globalData.user_headUrl;
  195. if(page === 1){
  196. that.scrollRequestEnable = true;
  197. that.talkList = ((res.data.msg).reverse());
  198. console.log(1,that.talkList)
  199. setTimeout(()=>{
  200. that.scrollToBottom()
  201. },100)
  202. }else if (page > 1 && res.data.msg.length === that.pageSize) {
  203. that.scrollRequestEnable = true;
  204. that.talkList.unshift(...((res.data.msg).reverse()));
  205. }else if (page > 1 && (res.data.msg.length > 0) && (res.data.msg.length < that.pageSize)){
  206. that.scrollRequestEnable = true;
  207. that.talkList.unshift(...((res.data.msg).reverse()));
  208. }else if (page > 1 && res.data.msg.length == 0){
  209. that.scrollRequestEnable = false;
  210. }
  211. }
  212. });
  213. },
  214. goUserSelf() {
  215. this.$refs.popup.close()
  216. uni.navigateTo({
  217. url: '../selfInfo/selfInfo'
  218. })
  219. },
  220. goRecharge() {
  221. this.$refs.popup.close()
  222. uni.navigateTo({
  223. url: '../selfInfo/payList/payList'
  224. })
  225. },
  226. sendMsgRequest(msg) {
  227. let that = this;
  228. uni.request({
  229. url: getApp().globalData.shareUrl, //需要设置为全局
  230. method: 'POST',
  231. header: {
  232. 'content-type': 'application/x-www-form-urlencoded'
  233. },
  234. data: {
  235. method: 'question',
  236. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  237. uid: getApp().globalData.user_id,
  238. sign: md5('question' + getApp().globalData.globalTimestamp),
  239. content: msg
  240. },
  241. success: res => {
  242. this.inputInfo = '';
  243. that.getHistory();
  244. }
  245. });
  246. },
  247. sendInputInfo() {
  248. this.inputWidth = '80%';
  249. this.isShowSend = false;
  250. this.isShowSetCenter = true;
  251. if (!this.inputInfo) {
  252. uni.showToast({
  253. title: '请输入股票代码',
  254. icon: 'none'
  255. });
  256. } else {
  257. page = 1;
  258. this.sendMsgRequest(this.inputInfo)
  259. }
  260. },
  261. isInputing(){
  262. if (this.inputInfo) {
  263. this.inputWidth = '72%';
  264. this.isShowSend = true;
  265. this.isShowSetCenter = false;
  266. } else {
  267. this.inputWidth = '80%';
  268. this.isShowSend = false;
  269. this.isShowSetCenter = true;
  270. }
  271. },
  272. // 滚动至底部触发的事件
  273. lower() {
  274. if (this.scrollRequestEnable) {
  275. // 允许滚动时,触底page加一,重新请求数据
  276. page++;
  277. this.getHistory();
  278. } else {
  279. // 不允许滚动时,只显示"到底了"提示
  280. // this.showBottem = true
  281. console.log('noData')
  282. }
  283. },
  284. getInputFocus(e){
  285. //this.isShowKeyBoard = e.detail.height
  286. },
  287. getInputBlur(){
  288. //this.isShowKeyBoard = 0
  289. },
  290. openModal(){
  291. // 需要在 popup 组件,指定 ref 为 popup
  292. this.$refs.popup.open();
  293. },
  294. cancelModal(){
  295. // 需要在 popup 组件,指定 ref 为 popup
  296. this.$refs.popup.close();
  297. }
  298. },
  299. }
  300. </script>
  301. <style>
  302. .content {
  303. text-align: center;
  304. }
  305. .chat-box {
  306. background: #f4f5f7;
  307. padding-top: 3%;
  308. /* padding-bottom: 100upx; */
  309. }
  310. .tips-box {
  311. background: #D5D5DA;
  312. font-size: 28upx;
  313. color: #fff;
  314. border-radius: 30upx;
  315. width: 50%;
  316. margin: 0 auto;
  317. height: 50rpx;
  318. line-height: 50rpx
  319. }
  320. .tips-title {
  321. width: 70%;
  322. margin-top: 5%;
  323. font-size: 30rpx;
  324. height: 70rpx;
  325. line-height: 70rpx
  326. }
  327. .send-box {
  328. width: 100%;
  329. height: 90rpx;
  330. position: fixed;
  331. bottom: 0;
  332. background: #F4F0ED;
  333. display: flex;
  334. align-items: center;
  335. padding: 2upx;
  336. }
  337. .talk-box {
  338. display: flex;
  339. justify-content: flex-start;
  340. align-items: center;
  341. margin-top: 3%;
  342. }
  343. .talk-box-end {
  344. justify-content: flex-end;
  345. }
  346. .talk-head-box {
  347. width: 80rpx;
  348. height: 80rpx;
  349. border-radius: 30rpx;
  350. margin-left: 2%;
  351. margin-right: 2%;
  352. }
  353. .talk-head {
  354. width: 100%;
  355. height: 100%;
  356. border-radius: 50%;
  357. }
  358. .talk-content {
  359. padding: 2%;
  360. background: #fff;
  361. font-size: 28rpx;
  362. border-top-right-radius: 20rpx;
  363. border-bottom-left-radius: 20rpx;
  364. border-bottom-right-radius: 20rpx;
  365. text-align: left;
  366. max-width: 70%;
  367. }
  368. .talk-reply{
  369. padding: 2%;
  370. background: #fff;
  371. font-size: 28rpx;
  372. border-top-left-radius: 20rpx;
  373. border-bottom-left-radius: 20rpx;
  374. border-bottom-right-radius: 20rpx;
  375. text-align: left;
  376. max-width: 70%;
  377. }
  378. .enter-box {
  379. height: 70rpx;
  380. background: #fff;
  381. border-radius: 1%;
  382. text-align: left;
  383. margin: 8px;
  384. margin-bottom: 10px;
  385. padding-left:8px;
  386. }
  387. .send-box image {
  388. width: 60rpx;
  389. height: 60rpx;
  390. margin-right: 10upx;
  391. margin-left: 10upx;
  392. }
  393. .submit-message {
  394. width: 18%;
  395. margin-right: 20upx;
  396. height: 70rpx;
  397. font-size: 28rpx;
  398. line-height: 70rpx;
  399. color: #fff;
  400. background-color: #0A98D5 !important;
  401. }
  402. .logo {
  403. height: 200upx;
  404. width: 200upx;
  405. margin-top: 200upx;
  406. margin-left: auto;
  407. margin-right: auto;
  408. margin-bottom: 50upx;
  409. }
  410. .text-area {
  411. display: flex;
  412. justify-content: center;
  413. }
  414. .title {
  415. font-size: 36upx;
  416. color: #8f8f94;
  417. }
  418. .uniFab{
  419. width:98px;
  420. height:36px;
  421. background:rgba(231,247,236,1);
  422. box-shadow:-6px 5px 74px 0px rgba(60,188,99,0.08);
  423. border-radius:100px 0px 0px 100px;
  424. right: 0upx;
  425. position: fixed;
  426. z-index: 9999;
  427. top: 50%;
  428. display: flex;
  429. justify-content: center;
  430. align-items: center;
  431. }
  432. .uniFab text{
  433. width:64px;
  434. font-size:16px;
  435. font-family:PingFangSC;
  436. font-weight:600;
  437. color:rgba(60,188,99,1);
  438. text-shadow:0px 1px 2px rgba(12,39,20,0.2);
  439. }
  440. .uni-share-content {
  441. display: flex;
  442. flex-wrap: wrap;
  443. padding: 15px;
  444. /* justify-content: center */
  445. }
  446. .uni-share-content-box {
  447. display: flex;
  448. flex-direction: column;
  449. align-items: center;
  450. width: 25%;
  451. box-sizing: border-box;
  452. }
  453. .uni-share-content-image {
  454. display: flex;
  455. justify-content: center;
  456. align-items: center;
  457. width: 60upx;
  458. height: 60upx;
  459. overflow: hidden;
  460. border-radius: 10upx;
  461. }
  462. .uni-share-content-image .image {
  463. width: 100%;
  464. height: 100%;
  465. }
  466. .uni-share-content-text {
  467. font-size: 26upx;
  468. color: #333;
  469. padding-top: 5px;
  470. padding-bottom: 10px;
  471. }
  472. .uni-share-btn {
  473. height: 90upx;
  474. line-height: 90upx;
  475. border-top: 1px #f5f5f5 solid;
  476. text-align: center;
  477. color: #666;
  478. font-size: 30rpx;
  479. }
  480. /* .placeHolder {
  481. padding:2px
  482. } */
  483. </style>