index.vue 14 KB

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