index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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. setTimeout(()=>{
  206. that.scrollToBottom()
  207. },100)
  208. }else if (page > 1 && res.data.msg.length === that.pageSize) {
  209. that.scrollRequestEnable = true;
  210. that.talkList.unshift(...((res.data.msg).reverse()));
  211. }else if (page > 1 && (res.data.msg.length > 0) && (res.data.msg.length < that.pageSize)){
  212. that.scrollRequestEnable = true;
  213. that.talkList.unshift(...((res.data.msg).reverse()));
  214. }else if (page > 1 && res.data.msg.length == 0){
  215. that.scrollRequestEnable = false;
  216. }
  217. }
  218. });
  219. },
  220. goUserSelf() {
  221. this.$refs.popup.close()
  222. uni.navigateTo({
  223. url: '../selfInfo/selfInfo'
  224. })
  225. },
  226. goRecharge() {
  227. this.$refs.popup.close()
  228. uni.navigateTo({
  229. url: '../selfInfo/payList/payList'
  230. })
  231. },
  232. sendMsgRequest(msg) {
  233. let that = this;
  234. uni.request({
  235. url: getApp().globalData.shareUrl, //需要设置为全局
  236. method: 'POST',
  237. header: {
  238. 'content-type': 'application/x-www-form-urlencoded'
  239. },
  240. data: {
  241. method: 'question',
  242. timestamp: getApp().globalData.globalTimestamp, //Date.now()
  243. uid: getApp().globalData.user_id,
  244. sign: md5('question' + getApp().globalData.globalTimestamp),
  245. content: msg
  246. },
  247. success: res => {
  248. if(res.data.code === 100){
  249. that.isShowRecharge = true;
  250. that.inputInfo = '';
  251. that.getHistory('show');
  252. }else {
  253. that.inputInfo = '';
  254. that.getHistory();
  255. that.isShowRecharge = false
  256. }
  257. }
  258. });
  259. },
  260. sendInputInfo() {
  261. // this.inputWidth = '80%';
  262. // this.isShowSend = false;
  263. // this.isShowSetCenter = true;
  264. if (!this.inputInfo) {
  265. uni.showToast({
  266. title: '请输入股票代码',
  267. icon: 'none'
  268. });
  269. } else {
  270. page = 1;
  271. this.sendMsgRequest(this.inputInfo)
  272. }
  273. },
  274. isInputing(){
  275. if (this.inputInfo) {
  276. this.inputWidth = '72%';
  277. this.isShowSend = true;
  278. this.isShowSetCenter = false;
  279. } else {
  280. this.inputWidth = '80%';
  281. this.isShowSend = false;
  282. this.isShowSetCenter = true;
  283. }
  284. },
  285. // 滚动至底部触发的事件
  286. lower() {
  287. if (this.scrollRequestEnable) {
  288. // 允许滚动时,触底page加一,重新请求数据
  289. page++;
  290. this.getHistory();
  291. } else {
  292. // 不允许滚动时,只显示"到底了"提示
  293. // this.showBottem = true
  294. console.log('noData')
  295. }
  296. },
  297. getInputFocus(e){
  298. //this.isShowKeyBoard = e.detail.height
  299. },
  300. getInputBlur(){
  301. //this.isShowKeyBoard = 0
  302. },
  303. openModal(){
  304. // 需要在 popup 组件,指定 ref 为 popup
  305. this.$refs.popup.open();
  306. },
  307. cancelModal(){
  308. // 需要在 popup 组件,指定 ref 为 popup
  309. this.$refs.popup.close();
  310. }
  311. },
  312. }
  313. </script>
  314. <style>
  315. .content {
  316. text-align: center;
  317. }
  318. .chat-box {
  319. background: #f4f5f7;
  320. padding-top: 3%;
  321. /* padding-bottom: 100upx; */
  322. }
  323. .tips-box {
  324. background: #D5D5DA;
  325. font-size: 28upx;
  326. color: #fff;
  327. border-radius: 30upx;
  328. width: 50%;
  329. margin: 0 auto;
  330. height: 50rpx;
  331. line-height: 50rpx
  332. }
  333. .tips-title {
  334. width: 70%;
  335. margin-top: 5%;
  336. font-size: 30rpx;
  337. height: 70rpx;
  338. line-height: 70rpx
  339. }
  340. .send-box {
  341. width: 100%;
  342. height: 90rpx;
  343. position: fixed;
  344. bottom: 0;
  345. background: #F4F0ED;
  346. display: flex;
  347. align-items: center;
  348. padding: 2upx;
  349. }
  350. .talk-box {
  351. display: flex;
  352. justify-content: flex-start;
  353. align-items: center;
  354. margin-top: 3%;
  355. }
  356. .talk-box-end {
  357. justify-content: flex-end;
  358. }
  359. .talk-head-box {
  360. width: 80rpx;
  361. height: 80rpx;
  362. border-radius: 30rpx;
  363. margin-left: 2%;
  364. margin-right: 2%;
  365. }
  366. .talk-head {
  367. width: 100%;
  368. height: 100%;
  369. border-radius: 50%;
  370. }
  371. .talk-content {
  372. padding: 2%;
  373. background: #fff;
  374. font-size: 28rpx;
  375. border-top-right-radius: 20rpx;
  376. border-bottom-left-radius: 20rpx;
  377. border-bottom-right-radius: 20rpx;
  378. text-align: left;
  379. max-width: 70%;
  380. }
  381. .talk-reply{
  382. padding: 2%;
  383. background: #9EEA6A;
  384. font-size: 28rpx;
  385. border-top-left-radius: 20rpx;
  386. border-bottom-left-radius: 20rpx;
  387. border-bottom-right-radius: 20rpx;
  388. text-align: left;
  389. max-width: 70%;
  390. }
  391. .goRechargeText {
  392. color:#0A98D5
  393. }
  394. .enter-box {
  395. height: 70rpx;
  396. background: #fff;
  397. border-radius: 1%;
  398. text-align: left;
  399. margin: 8px;
  400. margin-bottom: 10px;
  401. padding-left:8px;
  402. }
  403. .send-box image {
  404. width: 60rpx;
  405. height: 60rpx;
  406. margin-right: 10upx;
  407. margin-left: 10upx;
  408. }
  409. .submit-message {
  410. width: 18%;
  411. margin-right: 20upx;
  412. height: 70rpx;
  413. font-size: 28rpx;
  414. line-height: 70rpx;
  415. color: #fff;
  416. background-color: #0A98D5 !important;
  417. }
  418. .logo {
  419. height: 200upx;
  420. width: 200upx;
  421. margin-top: 200upx;
  422. margin-left: auto;
  423. margin-right: auto;
  424. margin-bottom: 50upx;
  425. }
  426. .text-area {
  427. display: flex;
  428. justify-content: center;
  429. }
  430. .title {
  431. font-size: 36upx;
  432. color: #8f8f94;
  433. }
  434. .uniFab{
  435. width:98px;
  436. height:36px;
  437. background:rgba(231,247,236,1);
  438. box-shadow:-6px 5px 74px 0px rgba(60,188,99,0.08);
  439. border-radius:100px 0px 0px 100px;
  440. right: 0upx;
  441. position: fixed;
  442. z-index: 9999;
  443. top: 50%;
  444. display: flex;
  445. justify-content: center;
  446. align-items: center;
  447. }
  448. .uniFab text{
  449. width:64px;
  450. font-size:16px;
  451. font-family:PingFangSC;
  452. font-weight:600;
  453. color:rgba(60,188,99,1);
  454. text-shadow:0px 1px 2px rgba(12,39,20,0.2);
  455. }
  456. .uni-share-content {
  457. display: flex;
  458. flex-wrap: wrap;
  459. padding: 15px;
  460. /* justify-content: center */
  461. }
  462. .uni-share-content-box {
  463. display: flex;
  464. flex-direction: column;
  465. align-items: center;
  466. width: 25%;
  467. box-sizing: border-box;
  468. }
  469. .uni-share-content-image {
  470. display: flex;
  471. justify-content: center;
  472. align-items: center;
  473. width: 60upx;
  474. height: 60upx;
  475. overflow: hidden;
  476. border-radius: 10upx;
  477. }
  478. .uni-share-content-image .image {
  479. width: 100%;
  480. height: 100%;
  481. }
  482. .uni-share-content-text {
  483. font-size: 26upx;
  484. color: #333;
  485. padding-top: 5px;
  486. padding-bottom: 10px;
  487. }
  488. .uni-share-btn {
  489. height: 90upx;
  490. line-height: 90upx;
  491. border-top: 1px #f5f5f5 solid;
  492. text-align: center;
  493. color: #666;
  494. font-size: 30rpx;
  495. }
  496. /* .placeHolder {
  497. padding:2px
  498. } */
  499. </style>