index.vue 14 KB

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