info.vue 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  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.triggered = true;
  847. let msgList = that.msgList;
  848. let limit = that.limit;
  849. setTimeout(() => {
  850. if (that.total > msgList.length) {
  851. uni.showLoading({
  852. title: '加载中',
  853. mask: true
  854. })
  855. let page = that.page + 1;
  856. that.$set(that, `page`, page)
  857. let skip = page * limit;
  858. that.$set(that, `skip`, skip)
  859. that.$set(that, `is_bottom`, false)
  860. that.search();
  861. uni.hideLoading();
  862. } else {
  863. uni.showToast({
  864. title: `没有更多聊天记录了`,
  865. icon: 'none'
  866. })
  867. }
  868. that.triggered = false;
  869. }, 1000)
  870. },
  871. clearPage() {
  872. const that = this;
  873. that.$set(that, `msgList`, [])
  874. that.$set(that, `skip`, 0)
  875. that.$set(that, `limit`, 6)
  876. that.$set(that, `page`, 0)
  877. },
  878. }
  879. }
  880. </script>
  881. <style lang="scss">
  882. .main {
  883. display: flex;
  884. flex-direction: column;
  885. width: 100vw;
  886. height: 100vh;
  887. overflow: hidden;
  888. .one {
  889. position: relative;
  890. flex-grow: 1;
  891. .scroll-view {
  892. .chat-ls {
  893. padding: 2vw 2vw 0 2vw;
  894. .chat-time {
  895. font-size: 24rpx;
  896. color: rgba(39, 40, 50, 0.3);
  897. line-height: 34rpx;
  898. padding: 10rpx 0rpx;
  899. text-align: center;
  900. }
  901. .msg-m {
  902. display: flex;
  903. padding: 20rpx 0;
  904. .user-img {
  905. flex: none;
  906. width: 80rpx;
  907. height: 80rpx;
  908. border-radius: 40rpx;
  909. border: 1px solid #c0c0c0;
  910. }
  911. .message {
  912. flex: none;
  913. max-width: 480rpx;
  914. }
  915. .img {
  916. margin: 0 20rpx;
  917. }
  918. .msg-text {
  919. font-size: 32rpx;
  920. color: rgba(39, 40, 50, 1);
  921. line-height: 44rpx;
  922. padding: 18rpx 24rpx;
  923. word-break: break-all;
  924. }
  925. .msg-img {
  926. max-width: 400rpx;
  927. border-radius: 20rpx;
  928. }
  929. .msg-goods {
  930. display: flex;
  931. padding: 20rpx 10rpx;
  932. background-color: #f0f0f0;
  933. border-radius: 10rpx;
  934. .image {
  935. width: 100rpx;
  936. height: 100rpx;
  937. border-radius: 10rpx;
  938. }
  939. .goods_1 {
  940. width: 350rpx;
  941. margin: 0 0 0 10rpx;
  942. .name {
  943. font-size: 14px;
  944. }
  945. .money {
  946. .money_1 {
  947. color: #23B67A;
  948. font-size: 16px;
  949. padding: 0 1vw 0 0;
  950. font-weight: bold;
  951. text {
  952. font-size: 12px;
  953. }
  954. }
  955. .money_2 {
  956. font-size: 16px;
  957. padding: 0 1vw 0 0;
  958. color: #ff0000;
  959. font-weight: bold;
  960. text {
  961. font-size: 12px;
  962. }
  963. }
  964. .money_2:last-child {
  965. font-size: 14px;
  966. color: #858585;
  967. text-decoration: line-through;
  968. }
  969. }
  970. .act {
  971. .label {
  972. font-size: 12px;
  973. color: #FFA500;
  974. border: 1px solid #FFA500;
  975. border-radius: 5px;
  976. padding: 0 1vw;
  977. margin: 0 1vw 0 0;
  978. }
  979. }
  980. .button {
  981. text-align: right;
  982. margin: 1rpx 0;
  983. text {
  984. font-size: 12px;
  985. padding: 10rpx;
  986. border-radius: 10rpx;
  987. color: #FF4500;
  988. background-color: #FFF8DC;
  989. }
  990. }
  991. }
  992. }
  993. .msg-order {
  994. width: 460rpx;
  995. padding: 20rpx 10rpx;
  996. background-color: #f0f0f0;
  997. border-radius: 10rpx;
  998. .order_1 {
  999. display: flex;
  1000. flex-wrap: wrap;
  1001. margin: 10rpx 0;
  1002. .image {
  1003. width: 100rpx;
  1004. height: 100rpx;
  1005. border-radius: 10rpx;
  1006. margin: 0 5rpx 0 0;
  1007. border: 1rpx solid #858585;
  1008. }
  1009. }
  1010. .order_2 {
  1011. margin: 10rpx 0;
  1012. .no {
  1013. font-size: 12px;
  1014. }
  1015. .status {
  1016. display: flex;
  1017. justify-content: space-between;
  1018. margin: 5rpx 0;
  1019. text {
  1020. padding: 1rpx 2rpx;
  1021. border-radius: 5px;
  1022. font-size: 12px;
  1023. color: #ff0000;
  1024. }
  1025. .button {
  1026. text-align: right;
  1027. text {
  1028. font-size: 12px;
  1029. padding: 10rpx;
  1030. border-radius: 10rpx;
  1031. color: #FF4500;
  1032. background-color: #FFF8DC;
  1033. }
  1034. }
  1035. }
  1036. }
  1037. }
  1038. }
  1039. .msg-left {
  1040. flex-direction: row;
  1041. .msg-text {
  1042. word-break: break-all;
  1043. margin-left: 16rpx;
  1044. background-color: #f1f1f1;
  1045. border-radius: 0rpx 20rpx 20rpx 20rpx;
  1046. }
  1047. .ms-img {
  1048. margin-left: 16rpx;
  1049. }
  1050. }
  1051. .msg-right {
  1052. flex-direction: row-reverse;
  1053. .msg-text {
  1054. margin-right: 16rpx;
  1055. background-color: rgba(255, 228, 49, 0.8);
  1056. border-radius: 20rpx 0rpx 20rpx 20rpx;
  1057. }
  1058. .ms-img {
  1059. margin-right: 16rpx;
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. .two {
  1066. background-color: #f0f0f0;
  1067. border-top: 1px solid rgba(39, 40, 50, 0.1);
  1068. }
  1069. }
  1070. .uni-popup {
  1071. z-index: 9999 !important;
  1072. }
  1073. .popup {
  1074. display: flex;
  1075. flex-direction: column;
  1076. width: 100vw;
  1077. height: 80vh;
  1078. .close {
  1079. text-align: right;
  1080. padding: 2vw;
  1081. }
  1082. .info_1 {
  1083. position: relative;
  1084. display: flex;
  1085. flex-direction: column;
  1086. height: 74vh;
  1087. }
  1088. }
  1089. .scroll-view {
  1090. position: absolute;
  1091. top: 0;
  1092. left: 0;
  1093. right: 0;
  1094. bottom: 0;
  1095. .list-scroll-view {
  1096. display: flex;
  1097. flex-direction: column;
  1098. }
  1099. }
  1100. </style>