info.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <!-- 聊天内容 -->
  6. <scroll-view class="scroll-view" scroll-y="true" scroll-with-animation="true"
  7. :scroll-into-view="scrollToView" refresher-enabled="true" :refresher-triggered="triggered"
  8. @refresherrefresh="getFresh">
  9. <view class="list-scroll-view">
  10. <view class="chat-ls" v-for="(item,index) in msgList" :key="index" :id="'msg'+ item._id">
  11. <view class="chat-time" v-if="item.time != ''">
  12. {{item.time}}
  13. </view>
  14. <view class="msg-m msg-left" v-if="item.speaker !=  user._id">
  15. <image @tap="toShop()" class="user-img"
  16. :src="shop.logo&&shop.logo.length>0?shop.logo[0].url:''">
  17. </image>
  18. <!-- 文字 -->
  19. <view class="message" v-if="item.msg_type =='0'">                           
  20. <view class="msg-text">{{item.content}}</view>
  21. </view>
  22. <!-- 图像 -->
  23. <view class="message img" v-else-if="item.msg_type =='1'"
  24. @tap="previewImg(item.content)">
  25. <image :src="item.content" class="msg-img" mode="widthFix"></image>
  26. </view>
  27. <!-- 商品 -->
  28. <view class="message img" v-else-if="item.msg_type =='2'" @tap="toView(item)">
  29. <view class="msg-goods">
  30. <image :src="item.goodsInfo&&item.goodsInfo.file" class="image"
  31. mode="scaleToFill">
  32. </image>
  33. <view class="goods_1">
  34. <view class="name textOver">{{item.goodsInfo&&item.goodsInfo.name}}</view>
  35. <view class="money">
  36. <text class="money_1"
  37. v-if="item.goodsInfo&&item.goodsInfo.spec&&item.goodsInfo.spec.leader_price"><text>会员价¥</text>{{item.goodsInfo.spec.leader_price||0}}</text>
  38. <text class="money_2"
  39. v-else-if="item.goodsInfo&&item.goodsInfo.spec&&item.goodsInfo.spec.price"><text>特价¥</text>{{item.goodsInfo.spec.price||0}}</text>
  40. <text class="money_2"
  41. v-else><text>¥</text>{{item.goodsInfo.spec.sell_money||0}}</text>
  42. <text
  43. class="money_2"><text>¥</text>{{item.goodsInfo.spec.flow_money||0}}</text>
  44. </view>
  45. <view class="act" v-if="item.goodsInfo&&item.goodsInfo.act">
  46. <text class="label" v-for="(tag,index) in item.goodsInfo.act"
  47. :key="index">{{tag}}</text>
  48. </view>
  49. <view class="button" @tap.stop="toSend(item)" v-if="item.is_send=='0'">
  50. <text>发送连接</text>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 订单 -->
  56. <view class="message img" v-else-if="item.msg_type =='3'" @tap="toView(item)">
  57. <view class="msg-order">
  58. <view class="order_1">
  59. <view class="image" v-for="(tago,index) in item.ordernfo.goods"
  60. :key="index">
  61. <image v-if="tago.file.length>0" :src="tago.file&&tago.file[0].url"
  62. class="image" mode="scaleToFill">
  63. </image>
  64. <image v-else :src="tago.goods&&tago.goods.file[0].url" class="image"
  65. mode="scaleToFill">
  66. </image>
  67. </view>
  68. </view>
  69. <view class="order_2">
  70. <view class="no">订单号:{{item.ordernfo.no}}</view>
  71. <view class="status">
  72. <text>{{item.ordernfo.status}}</text>
  73. <view class="button" @tap.stop="toSend(item)" v-if="item.is_send=='0'">
  74. <text>发送连接</text>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. <view class="msg-m msg-right" v-else-if="item.speaker == user._id">
  82. <image class="user-img" :src="user.icon&&user.icon.length>0?user.icon[0].url:''">
  83. </image>
  84. <!-- 文字 -->
  85. <view class="message" v-if="item.msg_type =='0'">
  86. <view class="msg-text">{{item.content}}</view>
  87. </view>
  88. <!-- 图像 -->
  89. <view class="message img" v-else-if="item.msg_type =='1'"
  90. @tap="previewImg(item.content)">
  91. <image :src="item.content" class="msg-img" mode="widthFix"></image>
  92. </view>
  93. <!-- 商品 -->
  94. <view class="message img" v-else-if="item.msg_type =='2'" @tap="toView(item)">
  95. <view class="msg-goods">
  96. <image :src="item.goodsInfo&&item.goodsInfo.file" class="image"
  97. mode="scaleToFill">
  98. </image>
  99. <view class="goods_1">
  100. <view class="name textOver">{{item.goodsInfo&&item.goodsInfo.name}}</view>
  101. <view class="money">
  102. <text class="money_1"
  103. v-if="item.goodsInfo&&item.goodsInfo.spec&&item.goodsInfo.spec.leader_price"><text>会员价¥</text>{{item.goodsInfo.spec.leader_price||0}}</text>
  104. <text class="money_2"
  105. v-else-if="item.goodsInfo&&item.goodsInfo.spec&&item.goodsInfo.spec.price"><text>特价¥</text>{{item.goodsInfo.spec.price||0}}</text>
  106. <text class="money_2"
  107. v-else><text>¥</text>{{item.goodsInfo.spec.sell_money||0}}</text>
  108. <text
  109. class="money_2"><text>¥</text>{{item.goodsInfo.spec.flow_money||0}}</text>
  110. </view>
  111. <view class="act" v-if="item.goodsInfo&&item.goodsInfo.act">
  112. <text class="label" v-for="(tag,index) in item.goodsInfo.act"
  113. :key="index">{{tag}}</text>
  114. </view>
  115. <view class="button" @tap.stop="toSend(item)" v-if="item.is_send=='0'">
  116. <text>发送连接</text>
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. <!-- 订单 -->
  122. <view class="message img" v-else-if="item.msg_type =='3'" @tap="toView(item)">
  123. <view class="msg-order">
  124. <view class="order_1">
  125. <view class="images" v-for="(tago,index) in item.ordernfo.goods"
  126. :key="index">
  127. <image v-if="tago.file.length>0" :src="tago.file&&tago.file[0].url"
  128. class="image" mode="scaleToFill">
  129. </image>
  130. <image v-else :src="tago.goods&&tago.goods.file[0].url" class="image"
  131. mode="scaleToFill">
  132. </image>
  133. </view>
  134. </view>
  135. <view class="order_2">
  136. <view class="no">订单号:{{item.ordernfo.no}}</view>
  137. <view class="status">
  138. <text>{{item.ordernfo.status}}</text>
  139. <view class="button" @tap.stop="toSend(item)" v-if="item.is_send=='0'">
  140. <text>发送连接</text>
  141. </view>
  142. </view>
  143. </view>
  144. </view>
  145. </view>
  146. </view>
  147. </view>
  148. </view>
  149. </scroll-view>
  150. </view>
  151. <view class="two">
  152. <submit_1 @choseImg="choseImg" @inputs="inputs" @heights="heights" @sendGoods="sendGoods"
  153. @sendOrder="sendOrder"></submit_1>
  154. </view>
  155. </view>
  156. <!-- 规格 -->
  157. <uni-popup ref="specShow" background-color="#fff" type="bottom" :is-mask-click="false">
  158. <view class="popup">
  159. <view class="close">
  160. <text @click="toClose" class="iconfont icon-shanchu"></text>
  161. </view>
  162. <view class="info_1" v-if="popupShow=='1'">
  163. <goods_1 :marketList="list" @toPage="toPage" @toSend="toGoods"></goods_1>
  164. </view>
  165. <view class="info_1" v-else-if="popupShow=='2'">
  166. <order_1 :tabs="tabs" :status="status" :orderList="list" @toPage="toPage" @toSend="toOrder"
  167. @tabsChange="tabsChange">
  168. </order_1>
  169. </view>
  170. </view>
  171. </uni-popup>
  172. </mobile-frame>
  173. </template>
  174. <script>
  175. import moment from 'moment';
  176. import submit_1 from './components/submit_1.vue';
  177. import goods_1 from './components/goods_1.vue';
  178. import order_1 from './components/order_1.vue';
  179. export default {
  180. components: {
  181. submit_1,
  182. goods_1,
  183. order_1,
  184. },
  185. data() {
  186. return {
  187. // 用户信息
  188. user: {},
  189. // 房间号id
  190. id: '',
  191. // 店铺信息
  192. shop: {},
  193. shop_id: "",
  194. // 商品或订单信息条件
  195. goods: {},
  196. // 订单状态
  197. statusList: [],
  198. // 历史记录
  199. msgList: [],
  200. // 订单列表
  201. list: [],
  202. status: '0',
  203. tabs: {
  204. active: '0',
  205. menu: []
  206. },
  207. // 聊天记录
  208. total: 0,
  209. skip: 0,
  210. limit: 6,
  211. page: 0,
  212. // 判断是否跳到最后一条
  213. is_bottom: true,
  214. // 判断是否下拉刷新复位
  215. triggered: false,
  216. scrollToView: '', //滑动最后一条信息
  217. // 规格弹框
  218. popupShow: '1',
  219. // 判断是否是选择图片刷新
  220. is_img: false
  221. };
  222. },
  223. onShow: async function() {
  224. const that = this;
  225. // 判断是否是选择图片刷新
  226. if (!that.is_img) {
  227. if (that.id) {
  228. await that.clearPage();
  229. await that.search()
  230. }
  231. await that.searchOther();
  232. }
  233. },
  234. onLoad: async function(e) {
  235. const that = this;
  236. that.$set(that, `goods`, e);
  237. that.$set(that, `id`, e.id);
  238. that.$set(that, `shop_id`, e.shop);
  239. that.watchlogin();
  240. },
  241. computed: {
  242. listenWebsocket() {
  243. return this.$store.state.websocketData;
  244. }
  245. },
  246. watch: {
  247. listenWebsocket: async function(newstr) {
  248. const that = this;
  249. if (newstr && newstr.type == 'chat' && newstr.room == that.id) {
  250. if (newstr.msg_type == '2') {
  251. // 商品
  252. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  253. id: newstr.content
  254. });
  255. if (res.errcode == '0') {
  256. let indexSpecs;
  257. // 显示最低价格的规格信息,不考虑库存问题
  258. if (res.data.specs && res.data.specs.length > 0) {
  259. // 规格排序
  260. indexSpecs = res.data.specs.sort(function(a, b) {
  261. let i, j;
  262. if (a.price) i = 'price'
  263. else i = 'sell_money'
  264. if (b.price) j = 'price'
  265. else j = 'sell_money'
  266. return a[i] - b[j];
  267. })
  268. }
  269. let act = res.data.act.map(i => {
  270. return i.tag
  271. })
  272. let goodsInfo = {
  273. "file": res.data && res.data.goods && res.data.goods.file && res.data.goods
  274. .file[0]
  275. .url,
  276. "name": res.data && res.data.goods && res.data.goods.name,
  277. "spec": indexSpecs[0],
  278. "act": act,
  279. }
  280. newstr.goodsInfo = goodsInfo
  281. newstr.is_send = '1'
  282. }
  283. } else if (newstr.msg_type == '3') {
  284. // 订单
  285. res = await that.$api(`/viewOrder/getOrder/${newstr.content}`)
  286. if (res.errcode == '0') {
  287. let status = that.statusList.find(i => i.value == res.data.status)
  288. // 过滤店铺订单
  289. let shop_goods;
  290. if (res.data.status != '0') {
  291. // 已支付订单
  292. shop_goods = res.data.goods
  293. } else {
  294. // 未支付订单
  295. if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
  296. else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
  297. if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
  298. }
  299. let ordernfo = {
  300. "no": res.data && res.data.no,
  301. "goods": shop_goods,
  302. "status": status.label || '暂无',
  303. "is_status": res.data.status
  304. }
  305. newstr.ordernfo = ordernfo
  306. newstr.is_send = '1'
  307. }
  308. }
  309. that.msgList.push(newstr);
  310. that.goBottom();
  311. }
  312. }
  313. },
  314. methods: {
  315. // 监听用户是否登录
  316. watchlogin() {
  317. const that = this;
  318. uni.getStorage({
  319. key: 'token',
  320. success: async function(res) {
  321. let user = that.$jwt(res.data);
  322. if (user) {
  323. // 查询状态
  324. let arr = await that.$api(`/dictData`, 'GET', {
  325. code: 'order_process'
  326. })
  327. if (arr.errcode == '0') that.$set(that, `statusList`, arr.data);
  328. that.$set(that, `user`, user)
  329. }
  330. }
  331. })
  332. },
  333. // 查询商品或订单信息
  334. async searchOther() {
  335. const that = this;
  336. let res;
  337. let statusList = that.statusList.filter((i) => {
  338. return i.value != '-2' && i.value != '-3';
  339. });
  340. var menu = statusList.map((item) => {
  341. return {
  342. title: item.label,
  343. active: item.value
  344. }
  345. })
  346. that.$set(that.tabs, `menu`, menu)
  347. // 发送商品信息
  348. if (that.goods && that.goods.goods) {
  349. // 商品
  350. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  351. id: that.goods.goods
  352. });
  353. if (res.errcode == '0') {
  354. let indexSpecs;
  355. // 显示最低价格的规格信息,不考虑库存问题
  356. if (res.data.specs && res.data.specs.length > 0) {
  357. // 规格排序
  358. indexSpecs = res.data.specs.sort(function(a, b) {
  359. let i, j;
  360. if (a.price) i = 'price'
  361. else i = 'sell_money'
  362. if (b.price) j = 'price'
  363. else j = 'sell_money'
  364. return a[i] - b[j];
  365. })
  366. }
  367. let act = res.data.act.map(i => {
  368. return i.tag
  369. })
  370. let goodsInfo = {
  371. "file": res.data && res.data.goods && res.data.goods.file && res.data.goods.file[0]
  372. .url,
  373. "name": res.data && res.data.goods && res.data.goods.name,
  374. "spec": indexSpecs[0],
  375. "act": act
  376. }
  377. let data = {
  378. "_id": 'goods' + moment(new Date()).valueOf(),
  379. "speaker": that.user._id,
  380. "content": that.goods.goods,
  381. "goodsInfo": goodsInfo,
  382. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  383. "msg_type": '2',
  384. "is_send": '0'
  385. }
  386. if (!that.id) data.shop = that.shop_id
  387. else data.room = that.id
  388. that.msgList.push(data);
  389. }
  390. } else if (that.goods && that.goods.order) {
  391. // 订单
  392. if (that.goods.status == '0') res = await that.$api(`/order/${that.goods.order}`)
  393. else res = await that.$api(`/orderDetail/${that.goods.order}`);
  394. if (res.errcode == '0') {
  395. let status = that.statusList.find(i => i.value == res.data.status)
  396. // 过滤店铺订单
  397. let shop_goods;
  398. if (that.goods.status != '0') {
  399. // 已支付订单
  400. shop_goods = res.data.goods
  401. } else {
  402. // 未支付订单
  403. if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
  404. else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
  405. if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
  406. }
  407. let ordernfo = {
  408. "no": res.data && res.data.no,
  409. "goods": shop_goods,
  410. "status": status.label || '暂无',
  411. "is_status": res.data.status
  412. }
  413. let data = {
  414. "_id": 'order' + moment(new Date()).valueOf(),
  415. "speaker": that.user._id,
  416. "content": that.goods.order,
  417. "ordernfo": ordernfo,
  418. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  419. "msg_type": '3',
  420. "is_send": '0'
  421. }
  422. if (!that.id) data.shop = that.shop_id
  423. else data.room = that.id
  424. that.msgList.push(data);
  425. }
  426. }
  427. // 跳转到最后一条数据 与前面的:id进行对照
  428. // 如果是下拉刷新聊天记录不跳到最后一条
  429. if (that.is_bottom == true) that.goBottom();
  430. },
  431. // 查询历史记录
  432. async search() {
  433. const that = this;
  434. // 查询房间信息
  435. // 如果是下拉刷新聊天记录不请求房间信息
  436. if (that.is_bottom == true) {
  437. res = await that.$api(`/room/${that.id}`, `GET`, {}, 'chat')
  438. if (res.errcode == '0') {
  439. that.$set(that, `shop`, res.data && res.data.shop);
  440. if (res.data && res.data.shop && res.data.shop.name) {
  441. uni.setNavigationBarTitle({
  442. title: res.data.shop.name
  443. });
  444. }
  445. } else {
  446. uni.showToast({
  447. title: res.errmsg,
  448. icon: 'none'
  449. })
  450. }
  451. }
  452. let info = {
  453. skip: that.skip,
  454. limit: that.limit,
  455. room: that.id
  456. }
  457. let res;
  458. res = await that.$api(`/chatRecord`, `GET`, {
  459. ...info,
  460. }, 'chat');
  461. if (res.errcode == '0') {
  462. let msgList = [...res.data, ...that.msgList];
  463. msgList.sort(function(a, b) {
  464. return a.time > b.time ? 1 : -1;
  465. });
  466. that.$set(that, `total`, res.total)
  467. for (let val of msgList) {
  468. if (val.msg_type == '2') {
  469. // 商品
  470. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  471. id: val.content
  472. });
  473. if (res.errcode == '0') {
  474. let indexSpecs;
  475. // 显示最低价格的规格信息,不考虑库存问题
  476. if (res.data.specs && res.data.specs.length > 0) {
  477. // 规格排序
  478. indexSpecs = res.data.specs.sort(function(a, b) {
  479. let i, j;
  480. if (a.price) i = 'price'
  481. else i = 'sell_money'
  482. if (b.price) j = 'price'
  483. else j = 'sell_money'
  484. return a[i] - b[j];
  485. })
  486. }
  487. let act = res.data.act.map(i => {
  488. return i.tag
  489. })
  490. let goodsInfo = {
  491. "file": res.data && res.data.goods && res.data.goods.file && res.data.goods
  492. .file[0]
  493. .url,
  494. "name": res.data && res.data.goods && res.data.goods.name,
  495. "spec": indexSpecs[0],
  496. "act": act,
  497. }
  498. val.goodsInfo = goodsInfo
  499. val.is_send = '1'
  500. }
  501. } else if (val.msg_type == '3') {
  502. // 订单
  503. res = await that.$api(`/viewOrder/getOrder/${val.content}`)
  504. if (res.errcode == '0') {
  505. let status = that.statusList.find(i => i.value == res.data.status)
  506. // 过滤店铺订单
  507. let shop_goods;
  508. if (res.data.status != '0') {
  509. // 已支付订单
  510. shop_goods = res.data.goods
  511. } else {
  512. // 未支付订单
  513. if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
  514. else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
  515. if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
  516. }
  517. let ordernfo = {
  518. "no": res.data && res.data.no,
  519. "goods": shop_goods,
  520. "status": status.label || '暂无',
  521. "is_status": res.data.status
  522. }
  523. val.ordernfo = ordernfo
  524. val.is_send = '1'
  525. }
  526. }
  527. }
  528. that.$set(that, `msgList`, msgList);
  529. } else {
  530. uni.showToast({
  531. title: res.errmsg,
  532. icon: 'none'
  533. })
  534. }
  535. let id = that.msgList.filter(i => {
  536. if (i.speaker != that.user._id) return i.is_read = '0';
  537. })
  538. let ids = id.map(i => {
  539. return i._id
  540. })
  541. if (ids.length > 0) {
  542. // 信息已读
  543. res = await that.$api(`/chatRecord/read`, `POST`, {
  544. ids
  545. }, 'chat')
  546. if (res.errcode == '0') {} else {
  547. uni.showToast({
  548. title: res.errmsg,
  549. icon: 'none'
  550. })
  551. }
  552. }
  553. },
  554. // 进行图片的预览
  555. previewImg(e) {
  556. const that = this;
  557. // 预览图片
  558. uni.previewImage({
  559. current: 0,
  560. urls: [e],
  561. longPressActions: {
  562. itemList: ['发送给朋友', '保存图片', '收藏'],
  563. success: function(data) {
  564. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) +
  565. '张图片');
  566. },
  567. fail: function(err) {
  568. console.log(err.errMsg);
  569. }
  570. }
  571. });
  572. },
  573. // 判断是否是选择图片刷新
  574. choseImg(e) {
  575. const that = this;
  576. that.$set(that, `is_img`, e)
  577. },
  578. //接受输入内容
  579. async inputs(e) {
  580. const that = this;
  581. let user = that.user
  582. if (user._id) {
  583. //时间间隔处理
  584. let data = {
  585. "speaker": user._id,
  586. "content": e.message,
  587. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  588. "msg_type": e.type
  589. };
  590. // 发送给服务器消息
  591. if (!that.id) data.shop = that.shop_id
  592. else data.room = that.id
  593. let res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
  594. if (res.errcode == '0') {
  595. that.msgList.push(res.data);
  596. } else {
  597. uni.showToast({
  598. title: res.errmsg,
  599. icon: 'none'
  600. })
  601. }
  602. // 跳转到最后一条数据 与前面的:id进行对照
  603. that.goBottom();
  604. } else {
  605. uni.showToast({
  606. title: '未登录账号无法发送消息 ,请及时登录!',
  607. icon: 'none'
  608. })
  609. }
  610. },
  611. // 发送连接
  612. async toSend(e) {
  613. const that = this;
  614. //时间间隔处理
  615. let data = {
  616. "speaker": e.speaker,
  617. "content": e.content,
  618. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  619. "msg_type": e.msg_type
  620. };
  621. if (!that.id) data.shop = that.shop_id
  622. else data.room = that.id
  623. let res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
  624. if (res.errcode == '0') {
  625. e.is_send = '1'
  626. that.msgList = that.msgList.map(t => {
  627. return t.time === e.time ? e : t;
  628. });
  629. } else {
  630. uni.showToast({
  631. title: res.errmsg,
  632. icon: 'none'
  633. })
  634. }
  635. },
  636. // 发送商品
  637. async sendGoods() {
  638. const that = this;
  639. let res;
  640. let info = {
  641. skip: that.skip,
  642. limit: that.limit,
  643. shop: that.shop._id || that.shop_id
  644. };
  645. // 首页产品列表
  646. res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  647. ...info
  648. });
  649. if (res.errcode == '0') {
  650. let list = [...that.list, ...res.data];
  651. that.$set(that, `list`, list);
  652. that.$set(that, `total`, res.total)
  653. that.$set(that, `popupShow`, '1')
  654. that.$refs.specShow.open();
  655. }
  656. },
  657. // 发送商品
  658. async toGoods(e) {
  659. const that = this;
  660. let user = that.user
  661. if (user._id) {
  662. let res;
  663. // 商品
  664. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  665. id: e._id
  666. });
  667. if (res.errcode == '0') {
  668. let indexSpecs;
  669. // 显示最低价格的规格信息,不考虑库存问题
  670. if (res.data.specs && res.data.specs.length > 0) {
  671. // 规格排序
  672. indexSpecs = res.data.specs.sort(function(a, b) {
  673. let i, j;
  674. if (a.price) i = 'price'
  675. else i = 'sell_money'
  676. if (b.price) j = 'price'
  677. else j = 'sell_money'
  678. return a[i] - b[j];
  679. })
  680. }
  681. let act = res.data.act.map(i => {
  682. return i.tag
  683. })
  684. let goodsInfo = {
  685. "file": res.data && res.data.goods && res.data.goods.file && res.data.goods
  686. .file[0]
  687. .url,
  688. "name": res.data && res.data.goods && res.data.goods.name,
  689. "spec": indexSpecs[0],
  690. "act": act,
  691. }
  692. //时间间隔处理
  693. let data = {
  694. "speaker": user._id,
  695. "content": e._id,
  696. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  697. "msg_type": '2',
  698. };
  699. if (!that.id) data.shop = that.shop_id
  700. else data.room = that.id
  701. res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
  702. if (res.errcode == '0') {
  703. res.data.goodsInfo = goodsInfo
  704. res.data.is_send = '1'
  705. that.msgList.push(res.data);
  706. } else {
  707. uni.showToast({
  708. title: res.errmsg,
  709. icon: 'none'
  710. })
  711. }
  712. }
  713. // 跳转到最后一条数据 与前面的:id进行对照
  714. that.goBottom();
  715. that.toClose();
  716. } else {
  717. uni.showToast({
  718. title: '未登录账号无法发送消息 ,请及时登录!',
  719. icon: 'none'
  720. })
  721. }
  722. },
  723. // 分页
  724. toPage(e) {
  725. const that = this;
  726. let list = that.list;
  727. let limit = that.limit;
  728. if (that.total > list.length) {
  729. uni.showLoading({
  730. title: '加载中',
  731. mask: true
  732. })
  733. let page = that.page + 1;
  734. that.$set(that, `page`, page)
  735. let skip = page * limit;
  736. that.$set(that, `skip`, skip)
  737. if (that.popupShow == '1') that.sendGoods();
  738. else that.sendOrder();
  739. uni.hideLoading();
  740. }
  741. },
  742. // 发送订单
  743. async sendOrder() {
  744. const that = this;
  745. let user = that.user;
  746. let status = that.status;
  747. let info = {
  748. skip: that.skip,
  749. limit: that.limit,
  750. customer: user._id,
  751. shop: that.shop._id || that.shop_id,
  752. status: status
  753. }
  754. let res;
  755. if (status == '0') {
  756. res = await that.$api(`/order`, 'GET', {
  757. ...info,
  758. });
  759. } else {
  760. res = await that.$api(`/orderDetail`, 'GET', {
  761. ...info,
  762. });
  763. }
  764. if (res.errcode == '0') {
  765. let list = [...that.list, ...res.data];
  766. for (let val of list) {
  767. val.zhStatus = that.searchStatus(val.status)
  768. }
  769. that.$set(that, `list`, list);
  770. that.$set(that, `total`, res.total)
  771. that.$set(that, `popupShow`, '2')
  772. that.$refs.specShow.open();
  773. } else {
  774. uni.showToast({
  775. title: res.errmsg,
  776. icon: 'none'
  777. })
  778. }
  779. },
  780. // 发送订单
  781. async toOrder(e) {
  782. const that = this;
  783. let user = that.user
  784. if (user._id) {
  785. let res;
  786. // 订单
  787. if (e.status == '0') res = await that.$api(`/order/${e._id}`)
  788. else res = await that.$api(`/orderDetail/${e._id}`);
  789. if (res.errcode == '0') {
  790. let status = that.statusList.find(i => i.value == res.data.status)
  791. // 过滤店铺订单
  792. let shop_goods;
  793. if (e.status != '0') {
  794. // 已支付订单
  795. shop_goods = res.data.goods
  796. } else {
  797. // 未支付订单
  798. if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
  799. else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
  800. if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
  801. }
  802. let ordernfo = {
  803. "no": res.data && res.data.no,
  804. "goods": shop_goods,
  805. "status": status.label || '暂无',
  806. "is_status": res.data.status
  807. }
  808. //时间间隔处理
  809. let data = {
  810. "speaker": user._id,
  811. "content": e._id,
  812. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  813. "msg_type": '3',
  814. };
  815. if (!that.id) data.shop = that.shop_id
  816. else data.room = that.id
  817. res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
  818. if (res.errcode == '0') {
  819. res.data.ordernfo = ordernfo
  820. res.data.is_send = '1'
  821. that.msgList.push(res.data);
  822. } else {
  823. uni.showToast({
  824. title: res.errmsg,
  825. icon: 'none'
  826. })
  827. }
  828. }
  829. // 跳转到最后一条数据 与前面的:id进行对照
  830. that.goBottom();
  831. that.toClose();
  832. } else {
  833. uni.showToast({
  834. title: '未登录账号无法发送消息 ,请及时登录!',
  835. icon: 'none'
  836. })
  837. }
  838. },
  839. // 查询状态
  840. searchStatus(e) {
  841. const that = this;
  842. let data = that.statusList.find((i) => i.value == e);
  843. if (data) return data.label
  844. else return '暂无'
  845. },
  846. // 选择选项卡
  847. tabsChange(e) {
  848. const that = this;
  849. that.$set(that.tabs, `active`, e.active)
  850. that.$set(that, `status`, e.active);
  851. that.$set(that, `list`, [])
  852. that.$set(that, `skip`, 0)
  853. that.$set(that, `limit`, 6)
  854. that.$set(that, `page`, 0)
  855. that.sendOrder()
  856. },
  857. // 关闭弹框
  858. toClose() {
  859. const that = this;
  860. that.$refs.specShow.close();
  861. that.$set(that, `list`, [])
  862. that.$set(that, `skip`, 0)
  863. that.$set(that, `limit`, 6)
  864. that.$set(that, `page`, 0)
  865. },
  866. // 店铺
  867. toShop() {
  868. const that = this;
  869. let id = that.shop._id
  870. uni.navigateTo({
  871. url: `/pagesHome/shop/index?id=${id}`
  872. })
  873. },
  874. // 查看详情
  875. toView(e) {
  876. const that = this;
  877. if (e.msg_type == '2') {
  878. let id = e.content;
  879. uni.navigateTo({
  880. url: `/pagesHome/order/detail?id=${id}`
  881. })
  882. } else {
  883. let status = e.ordernfo.is_status;
  884. uni.navigateTo({
  885. url: `/pagesMy/order/info?id=${e.content}&status=${status}`
  886. })
  887. }
  888. },
  889. //输入框高度
  890. heights(e) {
  891. const that = this;
  892. that.goBottom();
  893. },
  894. // 滚动到底部
  895. async goBottom() {
  896. const that = this;
  897. that.scrollToView = '';
  898. let lastItem = that.msgList.at(-1);
  899. that.$nextTick(function() {
  900. that.scrollToView = 'msg' + (lastItem._id)
  901. })
  902. },
  903. // 下拉刷新分页
  904. getFresh(e) {
  905. const that = this;
  906. that.$set(that, `triggered`, true)
  907. that.$set(that, `is_img`, false)
  908. let msgList = that.msgList;
  909. let limit = that.limit;
  910. setTimeout(() => {
  911. if (that.total > msgList.length) {
  912. uni.showLoading({
  913. title: '加载中',
  914. mask: true
  915. })
  916. let page = that.page + 1;
  917. that.$set(that, `page`, page)
  918. let skip = page * limit;
  919. that.$set(that, `skip`, skip)
  920. that.$set(that, `is_bottom`, false)
  921. that.search();
  922. uni.hideLoading();
  923. } else {
  924. uni.showToast({
  925. title: `没有更多聊天记录了`,
  926. icon: 'none'
  927. })
  928. }
  929. that.triggered = false;
  930. }, 1000)
  931. },
  932. clearPage() {
  933. const that = this;
  934. that.$set(that, `msgList`, [])
  935. that.$set(that, `skip`, 0)
  936. that.$set(that, `limit`, 6)
  937. that.$set(that, `page`, 0)
  938. },
  939. }
  940. }
  941. </script>
  942. <style lang="scss">
  943. .main {
  944. display: flex;
  945. flex-direction: column;
  946. width: 100vw;
  947. height: 100vh;
  948. overflow: hidden;
  949. .one {
  950. position: relative;
  951. flex-grow: 1;
  952. .scroll-view {
  953. .chat-ls {
  954. padding: 2vw 2vw 0 2vw;
  955. .chat-time {
  956. font-size: 24rpx;
  957. color: rgba(39, 40, 50, 0.3);
  958. line-height: 34rpx;
  959. padding: 10rpx 0rpx;
  960. text-align: center;
  961. }
  962. .msg-m {
  963. display: flex;
  964. padding: 20rpx 0;
  965. .user-img {
  966. flex: none;
  967. width: 80rpx;
  968. height: 80rpx;
  969. border-radius: 40rpx;
  970. border: 1px solid #c0c0c0;
  971. }
  972. .message {
  973. flex: none;
  974. max-width: 480rpx;
  975. }
  976. .img {
  977. margin: 0 20rpx;
  978. }
  979. .msg-text {
  980. font-size: 32rpx;
  981. color: rgba(39, 40, 50, 1);
  982. line-height: 44rpx;
  983. padding: 18rpx 24rpx;
  984. word-break: break-all;
  985. }
  986. .msg-img {
  987. max-width: 400rpx;
  988. border-radius: 20rpx;
  989. }
  990. .msg-goods {
  991. .image {
  992. width: 100rpx;
  993. height: 100rpx;
  994. border-radius: 10rpx;
  995. }
  996. .goods_1 {
  997. width: 350rpx;
  998. margin: 0 0 0 10rpx;
  999. .name {
  1000. font-size: 14px;
  1001. }
  1002. .money {
  1003. .money_1 {
  1004. color: #23B67A;
  1005. font-size: 16px;
  1006. padding: 0 1vw 0 0;
  1007. font-weight: bold;
  1008. text {
  1009. font-size: 12px;
  1010. }
  1011. }
  1012. .money_2 {
  1013. font-size: 16px;
  1014. padding: 0 1vw 0 0;
  1015. color: var(--fFB1Color);
  1016. font-weight: bold;
  1017. text {
  1018. font-size: 12px;
  1019. }
  1020. }
  1021. .money_2:last-child {
  1022. font-size: 14px;
  1023. color: #858585;
  1024. text-decoration: line-through;
  1025. }
  1026. }
  1027. .act {
  1028. .label {
  1029. font-size: 12px;
  1030. color: #FFA500;
  1031. border: 1px solid #FFA500;
  1032. border-radius: 5px;
  1033. padding: 0 1vw;
  1034. margin: 0 1vw 0 0;
  1035. }
  1036. }
  1037. .button {
  1038. text-align: right;
  1039. margin: 5rpx 0 10rpx 0;
  1040. text {
  1041. font-size: 12px;
  1042. padding: 10rpx;
  1043. border-radius: 10rpx;
  1044. color: #FF4500;
  1045. background-color: #FFF8DC;
  1046. }
  1047. }
  1048. }
  1049. }
  1050. .msg-order {
  1051. .order_1 {
  1052. display: flex;
  1053. flex-wrap: wrap;
  1054. .image {
  1055. width: 100rpx;
  1056. height: 100rpx;
  1057. border-radius: 10rpx;
  1058. margin: 0 5rpx 0 0;
  1059. border: 1rpx solid #858585;
  1060. }
  1061. }
  1062. .order_2 {
  1063. .no {
  1064. font-size: 12px;
  1065. }
  1066. .status {
  1067. display: flex;
  1068. justify-content: space-between;
  1069. margin: 5rpx 0;
  1070. text {
  1071. padding: 1rpx 2rpx;
  1072. border-radius: 5px;
  1073. font-size: 12px;
  1074. color: var(--fFB1Color);
  1075. }
  1076. .button {
  1077. text-align: right;
  1078. text {
  1079. font-size: 12px;
  1080. padding: 10rpx;
  1081. border-radius: 10rpx;
  1082. color: #FF4500;
  1083. background-color: #FFF8DC;
  1084. }
  1085. }
  1086. }
  1087. }
  1088. }
  1089. }
  1090. .msg-left {
  1091. flex-direction: row;
  1092. .msg-text {
  1093. word-break: break-all;
  1094. margin-left: 16rpx;
  1095. background-color: #f1f1f1;
  1096. border-radius: 0rpx 20rpx 20rpx 20rpx;
  1097. }
  1098. .msg-goods {
  1099. display: flex;
  1100. padding: 10rpx;
  1101. background-color: #f0f0f0;
  1102. border-radius: 0rpx 20rpx 20rpx 20rpx;
  1103. }
  1104. .msg-order {
  1105. width: 460rpx;
  1106. padding: 10rpx;
  1107. background-color: #f0f0f0;
  1108. border-radius: 0rpx 20rpx 20rpx 20rpx;
  1109. }
  1110. .ms-img {
  1111. margin-left: 16rpx;
  1112. }
  1113. }
  1114. .msg-right {
  1115. flex-direction: row-reverse;
  1116. .msg-text {
  1117. margin-right: 16rpx;
  1118. background-color: rgba(255, 228, 49, 0.8);
  1119. border-radius: 20rpx 0rpx 20rpx 20rpx;
  1120. }
  1121. .msg-goods {
  1122. display: flex;
  1123. padding: 10rpx;
  1124. background-color: #f0f0f0;
  1125. border-radius: 20rpx 0rpx 20rpx 20rpx;
  1126. }
  1127. .msg-order {
  1128. width: 460rpx;
  1129. padding: 10rpx;
  1130. background-color: #f0f0f0;
  1131. border-radius: 20rpx 0rpx 20rpx 20rpx;
  1132. }
  1133. .ms-img {
  1134. margin-right: 16rpx;
  1135. }
  1136. }
  1137. }
  1138. }
  1139. }
  1140. .two {
  1141. background-color: #f0f0f0;
  1142. border-top: 1px solid rgba(39, 40, 50, 0.1);
  1143. }
  1144. }
  1145. .uni-popup {
  1146. z-index: 9999 !important;
  1147. }
  1148. .popup {
  1149. display: flex;
  1150. flex-direction: column;
  1151. width: 100vw;
  1152. height: 80vh;
  1153. .close {
  1154. text-align: right;
  1155. padding: 2vw;
  1156. }
  1157. .info_1 {
  1158. position: relative;
  1159. display: flex;
  1160. flex-direction: column;
  1161. height: 74vh;
  1162. }
  1163. }
  1164. .scroll-view {
  1165. position: absolute;
  1166. top: 0;
  1167. left: 0;
  1168. right: 0;
  1169. bottom: 0;
  1170. .list-scroll-view {
  1171. display: flex;
  1172. flex-direction: column;
  1173. }
  1174. }
  1175. </style>