index.vue 14 KB

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