info.vue 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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: function(newstr) {
  248. if (newstr && newstr.type == 'chat' && newstr.room == this.id) {
  249. this.msgList.push(newstr);
  250. this.goBottom();
  251. }
  252. }
  253. },
  254. methods: {
  255. // 监听用户是否登录
  256. watchlogin() {
  257. const that = this;
  258. uni.getStorage({
  259. key: 'token',
  260. success: async function(res) {
  261. let user = that.$jwt(res.data);
  262. if (user) {
  263. // 查询状态
  264. let arr = await that.$api(`/dictData`, 'GET', {
  265. code: 'order_process'
  266. })
  267. if (arr.errcode == '0') that.$set(that, `statusList`, arr.data);
  268. that.$set(that, `user`, user)
  269. }
  270. }
  271. })
  272. },
  273. // 查询商品或订单信息
  274. async searchOther() {
  275. const that = this;
  276. let res;
  277. let statusList = that.statusList.filter((i) => {
  278. return i.value != '-2' && i.value != '-3';
  279. });
  280. var menu = statusList.map((item) => {
  281. return {
  282. title: item.label,
  283. active: item.value
  284. }
  285. })
  286. that.$set(that.tabs, `menu`, menu)
  287. // 发送商品信息
  288. if (that.goods && that.goods.goods) {
  289. // 商品
  290. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  291. id: that.goods.goods
  292. });
  293. if (res.errcode == '0') {
  294. let indexSpecs;
  295. // 显示最低价格的规格信息,不考虑库存问题
  296. if (res.data.specs && res.data.specs.length > 0) {
  297. // 规格排序
  298. indexSpecs = res.data.specs.sort(function(a, b) {
  299. let i, j;
  300. if (a.price) i = 'price'
  301. else i = 'sell_money'
  302. if (b.price) j = 'price'
  303. else j = 'sell_money'
  304. return a[i] - b[j];
  305. })
  306. }
  307. let act = res.data.act.map(i => {
  308. return i.tag
  309. })
  310. let goodsInfo = {
  311. "file": res.data && res.data.goods && res.data.goods.file && res.data.goods.file[0]
  312. .url,
  313. "name": res.data && res.data.goods && res.data.goods.name,
  314. "spec": indexSpecs[0],
  315. "act": act
  316. }
  317. let data = {
  318. "_id": 'goods' + moment(new Date()).valueOf(),
  319. "speaker": that.user._id,
  320. "content": that.goods.goods,
  321. "goodsInfo": goodsInfo,
  322. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  323. "msg_type": '2',
  324. "is_send": '0'
  325. }
  326. if (!that.id) data.shop = that.shop_id
  327. else data.room = that.id
  328. that.msgList.push(data);
  329. }
  330. } else if (that.goods && that.goods.order) {
  331. // 订单
  332. if (that.goods.status == '0') res = await that.$api(`/order/${that.goods.order}`)
  333. else res = await that.$api(`/orderDetail/${that.goods.order}`);
  334. if (res.errcode == '0') {
  335. let status = that.statusList.find(i => i.value == res.data.status)
  336. // 过滤店铺订单
  337. let shop_goods;
  338. if (that.goods.status != '0') {
  339. // 已支付订单
  340. shop_goods = res.data.goods
  341. } else {
  342. // 未支付订单
  343. if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
  344. else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
  345. if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
  346. }
  347. let ordernfo = {
  348. "no": res.data && res.data.no,
  349. "goods": shop_goods,
  350. "status": status.label || '暂无',
  351. "is_status": res.data.status
  352. }
  353. let data = {
  354. "_id": 'order' + moment(new Date()).valueOf(),
  355. "speaker": that.user._id,
  356. "content": that.goods.order,
  357. "ordernfo": ordernfo,
  358. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  359. "msg_type": '3',
  360. "is_send": '0'
  361. }
  362. if (!that.id) data.shop = that.shop_id
  363. else data.room = that.id
  364. that.msgList.push(data);
  365. }
  366. }
  367. // 跳转到最后一条数据 与前面的:id进行对照
  368. // 如果是下拉刷新聊天记录不跳到最后一条
  369. if (that.is_bottom == true) that.goBottom();
  370. },
  371. // 查询历史记录
  372. async search() {
  373. const that = this;
  374. // 查询房间信息
  375. // 如果是下拉刷新聊天记录不请求房间信息
  376. if (that.is_bottom == true) {
  377. res = await that.$api(`/room/${that.id}`, `GET`, {}, 'chat')
  378. if (res.errcode == '0') {
  379. that.$set(that, `shop`, res.data && res.data.shop);
  380. if (res.data && res.data.shop && res.data.shop.name) {
  381. uni.setNavigationBarTitle({
  382. title: res.data.shop.name
  383. });
  384. }
  385. } else {
  386. uni.showToast({
  387. title: res.errmsg,
  388. icon: 'none'
  389. })
  390. }
  391. }
  392. let info = {
  393. skip: that.skip,
  394. limit: that.limit,
  395. room: that.id
  396. }
  397. let res;
  398. res = await that.$api(`/chatRecord`, `GET`, {
  399. ...info,
  400. }, 'chat');
  401. if (res.errcode == '0') {
  402. let msgList = [...res.data, ...that.msgList];
  403. msgList.sort(function(a, b) {
  404. return a.time > b.time ? 1 : -1;
  405. });
  406. that.$set(that, `total`, res.total)
  407. for (let val of msgList) {
  408. if (val.msg_type == '2') {
  409. // 商品
  410. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  411. id: val.content
  412. });
  413. if (res.errcode == '0') {
  414. let indexSpecs;
  415. // 显示最低价格的规格信息,不考虑库存问题
  416. if (res.data.specs && res.data.specs.length > 0) {
  417. // 规格排序
  418. indexSpecs = res.data.specs.sort(function(a, b) {
  419. let i, j;
  420. if (a.price) i = 'price'
  421. else i = 'sell_money'
  422. if (b.price) j = 'price'
  423. else j = 'sell_money'
  424. return a[i] - b[j];
  425. })
  426. }
  427. let act = res.data.act.map(i => {
  428. return i.tag
  429. })
  430. let goodsInfo = {
  431. "file": res.data && res.data.goods && res.data.goods.file && res.data.goods
  432. .file[0]
  433. .url,
  434. "name": res.data && res.data.goods && res.data.goods.name,
  435. "spec": indexSpecs[0],
  436. "act": act,
  437. }
  438. val.goodsInfo = goodsInfo
  439. val.is_send = '1'
  440. }
  441. } else if (val.msg_type == '3') {
  442. // 订单
  443. res = await that.$api(`/viewOrder/getOrder/${val.content}`)
  444. if (res.errcode == '0') {
  445. let status = that.statusList.find(i => i.value == res.data.status)
  446. // 过滤店铺订单
  447. let shop_goods;
  448. if (res.data.status != '0') {
  449. // 已支付订单
  450. shop_goods = res.data.goods
  451. } else {
  452. // 未支付订单
  453. if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
  454. else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
  455. if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
  456. }
  457. let ordernfo = {
  458. "no": res.data && res.data.no,
  459. "goods": shop_goods,
  460. "status": status.label || '暂无',
  461. "is_status": res.data.status
  462. }
  463. val.ordernfo = ordernfo
  464. val.is_send = '1'
  465. }
  466. }
  467. }
  468. that.$set(that, `msgList`, msgList);
  469. } else {
  470. uni.showToast({
  471. title: res.errmsg,
  472. icon: 'none'
  473. })
  474. }
  475. let id = that.msgList.filter(i => {
  476. if (i.speaker != that.user._id) return i.is_read = '0';
  477. })
  478. let ids = id.map(i => {
  479. return i._id
  480. })
  481. if (ids.length > 0) {
  482. // 信息已读
  483. res = await that.$api(`/chatRecord/read`, `POST`, {
  484. ids
  485. }, 'chat')
  486. if (res.errcode == '0') {} else {
  487. uni.showToast({
  488. title: res.errmsg,
  489. icon: 'none'
  490. })
  491. }
  492. }
  493. },
  494. // 进行图片的预览
  495. previewImg(e) {
  496. const that = this;
  497. // 预览图片
  498. uni.previewImage({
  499. current: 0,
  500. urls: [e],
  501. longPressActions: {
  502. itemList: ['发送给朋友', '保存图片', '收藏'],
  503. success: function(data) {
  504. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) +
  505. '张图片');
  506. },
  507. fail: function(err) {
  508. console.log(err.errMsg);
  509. }
  510. }
  511. });
  512. },
  513. // 判断是否是选择图片刷新
  514. choseImg(e) {
  515. const that = this;
  516. that.$set(that, `is_img`, e)
  517. },
  518. //接受输入内容
  519. async inputs(e) {
  520. const that = this;
  521. let user = that.user
  522. if (user._id) {
  523. //时间间隔处理
  524. let data = {
  525. "speaker": user._id,
  526. "content": e.message,
  527. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  528. "msg_type": e.type
  529. };
  530. // 发送给服务器消息
  531. if (!that.id) data.shop = that.shop_id
  532. else data.room = that.id
  533. let res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
  534. if (res.errcode == '0') {
  535. that.msgList.push(res.data);
  536. } else {
  537. uni.showToast({
  538. title: res.errmsg,
  539. icon: 'none'
  540. })
  541. }
  542. // 跳转到最后一条数据 与前面的:id进行对照
  543. that.goBottom();
  544. } else {
  545. uni.showToast({
  546. title: '未登录账号无法发送消息 ,请及时登录!',
  547. icon: 'none'
  548. })
  549. }
  550. },
  551. // 发送连接
  552. async toSend(e) {
  553. const that = this;
  554. //时间间隔处理
  555. let data = {
  556. "speaker": e.speaker,
  557. "content": e.content,
  558. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  559. "msg_type": e.msg_type
  560. };
  561. if (!that.id) data.shop = that.shop_id
  562. else data.room = that.id
  563. let res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
  564. if (res.errcode == '0') {
  565. e.is_send = '1'
  566. that.msgList = that.msgList.map(t => {
  567. return t.time === e.time ? e : t;
  568. });
  569. } else {
  570. uni.showToast({
  571. title: res.errmsg,
  572. icon: 'none'
  573. })
  574. }
  575. },
  576. // 发送商品
  577. async sendGoods() {
  578. const that = this;
  579. let res;
  580. let info = {
  581. skip: that.skip,
  582. limit: that.limit,
  583. shop: that.shop._id || that.shop_id
  584. };
  585. // 首页产品列表
  586. res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  587. ...info
  588. });
  589. if (res.errcode == '0') {
  590. let list = [...that.list, ...res.data];
  591. that.$set(that, `list`, list);
  592. that.$set(that, `total`, res.total)
  593. that.$set(that, `popupShow`, '1')
  594. that.$refs.specShow.open();
  595. }
  596. },
  597. // 发送商品
  598. async toGoods(e) {
  599. const that = this;
  600. let user = that.user
  601. if (user._id) {
  602. let res;
  603. // 商品
  604. res = await that.$api(`/viewGoods/goodsDetail`, `POST`, {
  605. id: e._id
  606. });
  607. if (res.errcode == '0') {
  608. let indexSpecs;
  609. // 显示最低价格的规格信息,不考虑库存问题
  610. if (res.data.specs && res.data.specs.length > 0) {
  611. // 规格排序
  612. indexSpecs = res.data.specs.sort(function(a, b) {
  613. let i, j;
  614. if (a.price) i = 'price'
  615. else i = 'sell_money'
  616. if (b.price) j = 'price'
  617. else j = 'sell_money'
  618. return a[i] - b[j];
  619. })
  620. }
  621. let act = res.data.act.map(i => {
  622. return i.tag
  623. })
  624. let goodsInfo = {
  625. "file": res.data && res.data.goods && res.data.goods.file && res.data.goods
  626. .file[0]
  627. .url,
  628. "name": res.data && res.data.goods && res.data.goods.name,
  629. "spec": indexSpecs[0],
  630. "act": act,
  631. }
  632. //时间间隔处理
  633. let data = {
  634. "speaker": user._id,
  635. "content": e._id,
  636. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  637. "msg_type": '2',
  638. };
  639. if (!that.id) data.shop = that.shop_id
  640. else data.room = that.id
  641. res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
  642. if (res.errcode == '0') {
  643. res.data.goodsInfo = goodsInfo
  644. res.data.is_send = '1'
  645. that.msgList.push(res.data);
  646. } else {
  647. uni.showToast({
  648. title: res.errmsg,
  649. icon: 'none'
  650. })
  651. }
  652. }
  653. // 跳转到最后一条数据 与前面的:id进行对照
  654. that.goBottom();
  655. that.toClose();
  656. } else {
  657. uni.showToast({
  658. title: '未登录账号无法发送消息 ,请及时登录!',
  659. icon: 'none'
  660. })
  661. }
  662. },
  663. // 分页
  664. toPage(e) {
  665. const that = this;
  666. let list = that.list;
  667. let limit = that.limit;
  668. if (that.total > list.length) {
  669. uni.showLoading({
  670. title: '加载中',
  671. mask: true
  672. })
  673. let page = that.page + 1;
  674. that.$set(that, `page`, page)
  675. let skip = page * limit;
  676. that.$set(that, `skip`, skip)
  677. if (that.popupShow == '1') that.sendGoods();
  678. else that.sendOrder();
  679. uni.hideLoading();
  680. }
  681. },
  682. // 发送订单
  683. async sendOrder() {
  684. const that = this;
  685. let user = that.user;
  686. let status = that.status;
  687. let info = {
  688. skip: that.skip,
  689. limit: that.limit,
  690. customer: user._id,
  691. shop: that.shop._id || that.shop_id,
  692. status: status
  693. }
  694. let res;
  695. if (status == '0') {
  696. res = await that.$api(`/order`, 'GET', {
  697. ...info,
  698. });
  699. } else {
  700. res = await that.$api(`/orderDetail`, 'GET', {
  701. ...info,
  702. });
  703. }
  704. if (res.errcode == '0') {
  705. let list = [...that.list, ...res.data];
  706. for (let val of list) {
  707. val.zhStatus = that.searchStatus(val.status)
  708. }
  709. that.$set(that, `list`, list);
  710. that.$set(that, `total`, res.total)
  711. that.$set(that, `popupShow`, '2')
  712. that.$refs.specShow.open();
  713. } else {
  714. uni.showToast({
  715. title: res.errmsg,
  716. icon: 'none'
  717. })
  718. }
  719. },
  720. // 发送订单
  721. async toOrder(e) {
  722. const that = this;
  723. let user = that.user
  724. if (user._id) {
  725. let res;
  726. // 订单
  727. if (e.status == '0') res = await that.$api(`/order/${e._id}`)
  728. else res = await that.$api(`/orderDetail/${e._id}`);
  729. if (res.errcode == '0') {
  730. let status = that.statusList.find(i => i.value == res.data.status)
  731. // 过滤店铺订单
  732. let shop_goods;
  733. if (e.status != '0') {
  734. // 已支付订单
  735. shop_goods = res.data.goods
  736. } else {
  737. // 未支付订单
  738. if (!that.id) shop_goods = res.data.goods.filter(i => i.shop == that.shop_id)
  739. else shop_goods = res.data.goods.filter(i => i.shop == that.shop._id)
  740. if (shop_goods.length > 0) shop_goods = shop_goods[0].goods
  741. }
  742. let ordernfo = {
  743. "no": res.data && res.data.no,
  744. "goods": shop_goods,
  745. "status": status.label || '暂无',
  746. "is_status": res.data.status
  747. }
  748. //时间间隔处理
  749. let data = {
  750. "speaker": user._id,
  751. "content": e._id,
  752. "time": moment().format('YYYY-MM-DD HH:mm:ss'),
  753. "msg_type": '3',
  754. };
  755. if (!that.id) data.shop = that.shop_id
  756. else data.room = that.id
  757. res = await that.$api(`/chatRecord`, `POST`, data, 'chat');
  758. if (res.errcode == '0') {
  759. res.data.ordernfo = ordernfo
  760. res.data.is_send = '1'
  761. that.msgList.push(res.data);
  762. } else {
  763. uni.showToast({
  764. title: res.errmsg,
  765. icon: 'none'
  766. })
  767. }
  768. }
  769. // 跳转到最后一条数据 与前面的:id进行对照
  770. that.goBottom();
  771. that.toClose();
  772. } else {
  773. uni.showToast({
  774. title: '未登录账号无法发送消息 ,请及时登录!',
  775. icon: 'none'
  776. })
  777. }
  778. },
  779. // 查询状态
  780. searchStatus(e) {
  781. const that = this;
  782. let data = that.statusList.find((i) => i.value == e);
  783. if (data) return data.label
  784. else return '暂无'
  785. },
  786. // 选择选项卡
  787. tabsChange(e) {
  788. const that = this;
  789. that.$set(that.tabs, `active`, e.active)
  790. that.$set(that, `status`, e.active);
  791. that.$set(that, `list`, [])
  792. that.$set(that, `skip`, 0)
  793. that.$set(that, `limit`, 6)
  794. that.$set(that, `page`, 0)
  795. that.sendOrder()
  796. },
  797. // 关闭弹框
  798. toClose() {
  799. const that = this;
  800. that.$refs.specShow.close();
  801. that.$set(that, `list`, [])
  802. that.$set(that, `skip`, 0)
  803. that.$set(that, `limit`, 6)
  804. that.$set(that, `page`, 0)
  805. },
  806. // 店铺
  807. toShop() {
  808. const that = this;
  809. let id = that.shop._id
  810. uni.navigateTo({
  811. url: `/pagesHome/shop/index?id=${id}`
  812. })
  813. },
  814. // 查看详情
  815. toView(e) {
  816. const that = this;
  817. if (e.msg_type == '2') {
  818. let id = e.content;
  819. uni.navigateTo({
  820. url: `/pagesHome/order/detail?id=${id}`
  821. })
  822. } else {
  823. let status = e.ordernfo.is_status;
  824. uni.navigateTo({
  825. url: `/pagesMy/order/index?status=${status}`
  826. })
  827. }
  828. },
  829. //输入框高度
  830. heights(e) {
  831. const that = this;
  832. that.goBottom();
  833. },
  834. // 滚动到底部
  835. async goBottom() {
  836. const that = this;
  837. that.scrollToView = '';
  838. let lastItem = that.msgList.at(-1);
  839. that.$nextTick(function() {
  840. that.scrollToView = 'msg' + (lastItem._id)
  841. })
  842. },
  843. // 下拉刷新分页
  844. getFresh(e) {
  845. const that = this;
  846. that.$set(that, `triggered`, true)
  847. that.$set(that, `is_img`, false)
  848. let msgList = that.msgList;
  849. let limit = that.limit;
  850. setTimeout(() => {
  851. if (that.total > msgList.length) {
  852. uni.showLoading({
  853. title: '加载中',
  854. mask: true
  855. })
  856. let page = that.page + 1;
  857. that.$set(that, `page`, page)
  858. let skip = page * limit;
  859. that.$set(that, `skip`, skip)
  860. that.$set(that, `is_bottom`, false)
  861. that.search();
  862. uni.hideLoading();
  863. } else {
  864. uni.showToast({
  865. title: `没有更多聊天记录了`,
  866. icon: 'none'
  867. })
  868. }
  869. that.triggered = false;
  870. }, 1000)
  871. },
  872. clearPage() {
  873. const that = this;
  874. that.$set(that, `msgList`, [])
  875. that.$set(that, `skip`, 0)
  876. that.$set(that, `limit`, 6)
  877. that.$set(that, `page`, 0)
  878. },
  879. }
  880. }
  881. </script>
  882. <style lang="scss">
  883. .main {
  884. display: flex;
  885. flex-direction: column;
  886. width: 100vw;
  887. height: 100vh;
  888. overflow: hidden;
  889. .one {
  890. position: relative;
  891. flex-grow: 1;
  892. .scroll-view {
  893. .chat-ls {
  894. padding: 2vw 2vw 0 2vw;
  895. .chat-time {
  896. font-size: 24rpx;
  897. color: rgba(39, 40, 50, 0.3);
  898. line-height: 34rpx;
  899. padding: 10rpx 0rpx;
  900. text-align: center;
  901. }
  902. .msg-m {
  903. display: flex;
  904. padding: 20rpx 0;
  905. .user-img {
  906. flex: none;
  907. width: 80rpx;
  908. height: 80rpx;
  909. border-radius: 40rpx;
  910. border: 1px solid #c0c0c0;
  911. }
  912. .message {
  913. flex: none;
  914. max-width: 480rpx;
  915. }
  916. .img {
  917. margin: 0 20rpx;
  918. }
  919. .msg-text {
  920. font-size: 32rpx;
  921. color: rgba(39, 40, 50, 1);
  922. line-height: 44rpx;
  923. padding: 18rpx 24rpx;
  924. word-break: break-all;
  925. }
  926. .msg-img {
  927. max-width: 400rpx;
  928. border-radius: 20rpx;
  929. }
  930. .msg-goods {
  931. display: flex;
  932. padding: 20rpx 10rpx;
  933. background-color: #f0f0f0;
  934. border-radius: 10rpx;
  935. .image {
  936. width: 100rpx;
  937. height: 100rpx;
  938. border-radius: 10rpx;
  939. }
  940. .goods_1 {
  941. width: 350rpx;
  942. margin: 0 0 0 10rpx;
  943. .name {
  944. font-size: 14px;
  945. }
  946. .money {
  947. .money_1 {
  948. color: #23B67A;
  949. font-size: 16px;
  950. padding: 0 1vw 0 0;
  951. font-weight: bold;
  952. text {
  953. font-size: 12px;
  954. }
  955. }
  956. .money_2 {
  957. font-size: 16px;
  958. padding: 0 1vw 0 0;
  959. color: #ff0000;
  960. font-weight: bold;
  961. text {
  962. font-size: 12px;
  963. }
  964. }
  965. .money_2:last-child {
  966. font-size: 14px;
  967. color: #858585;
  968. text-decoration: line-through;
  969. }
  970. }
  971. .act {
  972. .label {
  973. font-size: 12px;
  974. color: #FFA500;
  975. border: 1px solid #FFA500;
  976. border-radius: 5px;
  977. padding: 0 1vw;
  978. margin: 0 1vw 0 0;
  979. }
  980. }
  981. .button {
  982. text-align: right;
  983. margin: 1rpx 0;
  984. text {
  985. font-size: 12px;
  986. padding: 10rpx;
  987. border-radius: 10rpx;
  988. color: #FF4500;
  989. background-color: #FFF8DC;
  990. }
  991. }
  992. }
  993. }
  994. .msg-order {
  995. width: 460rpx;
  996. padding: 20rpx 10rpx;
  997. background-color: #f0f0f0;
  998. border-radius: 10rpx;
  999. .order_1 {
  1000. display: flex;
  1001. flex-wrap: wrap;
  1002. margin: 10rpx 0;
  1003. .image {
  1004. width: 100rpx;
  1005. height: 100rpx;
  1006. border-radius: 10rpx;
  1007. margin: 0 5rpx 0 0;
  1008. border: 1rpx solid #858585;
  1009. }
  1010. }
  1011. .order_2 {
  1012. margin: 10rpx 0;
  1013. .no {
  1014. font-size: 12px;
  1015. }
  1016. .status {
  1017. display: flex;
  1018. justify-content: space-between;
  1019. margin: 5rpx 0;
  1020. text {
  1021. padding: 1rpx 2rpx;
  1022. border-radius: 5px;
  1023. font-size: 12px;
  1024. color: #ff0000;
  1025. }
  1026. .button {
  1027. text-align: right;
  1028. text {
  1029. font-size: 12px;
  1030. padding: 10rpx;
  1031. border-radius: 10rpx;
  1032. color: #FF4500;
  1033. background-color: #FFF8DC;
  1034. }
  1035. }
  1036. }
  1037. }
  1038. }
  1039. }
  1040. .msg-left {
  1041. flex-direction: row;
  1042. .msg-text {
  1043. word-break: break-all;
  1044. margin-left: 16rpx;
  1045. background-color: #f1f1f1;
  1046. border-radius: 0rpx 20rpx 20rpx 20rpx;
  1047. }
  1048. .ms-img {
  1049. margin-left: 16rpx;
  1050. }
  1051. }
  1052. .msg-right {
  1053. flex-direction: row-reverse;
  1054. .msg-text {
  1055. margin-right: 16rpx;
  1056. background-color: rgba(255, 228, 49, 0.8);
  1057. border-radius: 20rpx 0rpx 20rpx 20rpx;
  1058. }
  1059. .ms-img {
  1060. margin-right: 16rpx;
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }
  1066. .two {
  1067. background-color: #f0f0f0;
  1068. border-top: 1px solid rgba(39, 40, 50, 0.1);
  1069. }
  1070. }
  1071. .uni-popup {
  1072. z-index: 9999 !important;
  1073. }
  1074. .popup {
  1075. display: flex;
  1076. flex-direction: column;
  1077. width: 100vw;
  1078. height: 80vh;
  1079. .close {
  1080. text-align: right;
  1081. padding: 2vw;
  1082. }
  1083. .info_1 {
  1084. position: relative;
  1085. display: flex;
  1086. flex-direction: column;
  1087. height: 74vh;
  1088. }
  1089. }
  1090. .scroll-view {
  1091. position: absolute;
  1092. top: 0;
  1093. left: 0;
  1094. right: 0;
  1095. bottom: 0;
  1096. .list-scroll-view {
  1097. display: flex;
  1098. flex-direction: column;
  1099. }
  1100. }
  1101. </style>