index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div id="goods">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="8" class="left" v-loading="loadings" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading">
  6. <left-1 :roomList="roomList" @toView="toView"></left-1>
  7. </el-col>
  8. <el-col :span="16" class="non" v-if="show == '0'">
  9. <el-col :span="24"> <i class="el-icon-chat-line-round"></i></el-col>
  10. </el-col>
  11. <el-col :span="16" class="right" v-else>
  12. <right-1
  13. :chatRecordList="chatRecordList"
  14. :customer="customer"
  15. :shop="shop"
  16. @toUp="toUp"
  17. @onSubmit="onSubmit"
  18. :form="form"
  19. :srcList="srcList"
  20. ></right-1>
  21. </el-col>
  22. </el-col>
  23. </el-row>
  24. <e-dialog :dialog="dialog" @toClose="toClose">
  25. <template v-slot:info>
  26. <el-col :span="24" class="dia_one">
  27. <c-upload :url="url" v-model="file" :limit="1"></c-upload>
  28. <p>一次最多发送一张图片</p>
  29. </el-col>
  30. <el-col :span="24" class="dia_one">
  31. <el-button type="success" size="mini" @click="onSubmit('file')">发送</el-button>
  32. </el-col>
  33. </template>
  34. </e-dialog>
  35. </div>
  36. </template>
  37. <script>
  38. const _ = require('lodash');
  39. const moment = require('moment');
  40. import { mapState, createNamespacedHelpers } from 'vuex';
  41. const { mapActions: room } = createNamespacedHelpers('room');
  42. const { mapActions: users } = createNamespacedHelpers('users');
  43. const { mapActions: address } = createNamespacedHelpers('address');
  44. const { mapActions: chatRecord } = createNamespacedHelpers('chatRecord');
  45. export default {
  46. name: 'index',
  47. props: {},
  48. components: {
  49. cUpload: () => import('@/components/usual/c-upload.vue'),
  50. left1: () => import('./parts/left-1.vue'),
  51. right1: () => import('./parts/right-1.vue'),
  52. },
  53. data: function () {
  54. return {
  55. loadings: false,
  56. searchName: '',
  57. searchInfo: {},
  58. // 聊天房间列表
  59. roomList: [],
  60. // 聊天记录
  61. chatRecordList: [],
  62. // 用户信息
  63. customer: {},
  64. // 店铺信息
  65. shop: {},
  66. // 收货地址
  67. address: {},
  68. // 弹框
  69. dialog: { title: '信息管理', show: false, type: '1' },
  70. url: '/files/point/message/upload',
  71. file: [],
  72. // 大图预览列表
  73. srcList: [],
  74. form: {},
  75. // 判断显示聊天记录
  76. show: '0',
  77. // 判断显示地址
  78. add: '0',
  79. };
  80. },
  81. created() {
  82. this.searchOthers();
  83. this.search();
  84. if (this.customer_id) this.searchDetail();
  85. },
  86. methods: {
  87. ...users({ userFetch: 'fetch' }),
  88. ...address({ addFetch: 'fetch' }),
  89. ...room({ roomQuery: 'query', roomFetch: 'fetch', roomDelete: 'delete' }),
  90. ...chatRecord(['query', 'delete', 'fetch', 'update', 'create', 'read']),
  91. // 查询
  92. async search() {
  93. const res = await this.roomQuery({ shop: this.user.shop._id });
  94. if (this.$checkRes(res)) this.$set(this, `roomList`, res.data);
  95. this.loadings = false;
  96. },
  97. // 订单和售后跳转页面,联系买家
  98. async searchDetail() {
  99. let res = await this.roomQuery({ customer: this.customer_id, shop: this.user.shop._id });
  100. if (this.$checkRes(res)) {
  101. if (res.total > 0) this.toView(res.data[0]);
  102. else {
  103. let aee = await this.userFetch(this.customer_id);
  104. if (this.$checkRes(aee)) {
  105. let data = { customer: aee.data, shop: this.user.shop };
  106. this.toView(data);
  107. }
  108. }
  109. }
  110. },
  111. // 查看
  112. async toView(data) {
  113. if (this.customer._id != data.customer._id) this.$set(this, `customer`, data.customer);
  114. if (data._id) {
  115. this.$set(this, `form`, { room: data._id });
  116. // 处理已读
  117. let list = [];
  118. let res = await this.query({ room: data._id });
  119. if (this.$checkRes(res)) {
  120. // 聊天记录列表
  121. let arr1 = res.data.reverse();
  122. this.$set(this, `chatRecordList`, arr1);
  123. // 处理已读
  124. for (const p1 of res.data) {
  125. if (p1.speaker != this.user.shop._id && p1.is_read == '0') list.push(p1._id);
  126. }
  127. // 处理聊天图片,大图预览
  128. let arr = [];
  129. for (const p1 of this.chatRecordList) {
  130. if (p1.msg_type == '1') arr.push(p1.content);
  131. }
  132. this.$set(this, `srcList`, arr);
  133. }
  134. // 处理已读
  135. if (list.length != 0) {
  136. let form = { ids: list };
  137. res = await this.read(form);
  138. if (this.$checkRes(res)) this.search();
  139. }
  140. }
  141. this.show = '1';
  142. },
  143. // 发送图片
  144. toUp() {
  145. this.dialog = { title: '信息管理', show: true, type: '1' };
  146. },
  147. // 提交
  148. async onSubmit(value) {
  149. var form = { speaker: this.user.shop._id, time: moment().format('YYYY-MM-DD HH:mm:ss') };
  150. if (this.form.room) form.room = this.form.room;
  151. else form.customer = this.customer_id;
  152. if (value == 'content') {
  153. // 文字消息
  154. form.msg_type = '0';
  155. if (this.form.content) form.content = this.form.content;
  156. else this.$message({ type: `warning`, message: `请输入要发送的消息` });
  157. } else {
  158. // 图片消息
  159. form.msg_type = '1';
  160. if (this.file.length == 0) this.$message({ type: `warning`, message: `请选择要发送的图片` });
  161. else form.content = this.file[0].url;
  162. }
  163. let res = await this.create(form);
  164. if (this.$checkRes(res, '操作成功', '操作失败')) {
  165. let data = { _id: res.data.room, customer: this.customer, shop: this.shop };
  166. this.toClose();
  167. this.search();
  168. if (this.customer_id) this.searchDetail();
  169. if (!this.customer_id) this.toView(data);
  170. }
  171. },
  172. // 关闭
  173. toClose() {
  174. this.file = [];
  175. this.dialog = { title: '信息管理', show: false, type: '1' };
  176. },
  177. // 查询其他信息
  178. async searchOthers() {
  179. this.$set(this, `shop`, this.user.shop);
  180. },
  181. },
  182. computed: {
  183. ...mapState(['user']),
  184. customer_id() {
  185. return this.$route.query.customer_id;
  186. },
  187. },
  188. };
  189. </script>
  190. <style lang="less" scoped>
  191. .main {
  192. height: 81vh;
  193. overflow-y: auto;
  194. .left {
  195. background: rgb(240, 240, 240);
  196. padding: 0 5px;
  197. height: 80vh;
  198. overflow-y: auto;
  199. }
  200. .non {
  201. text-align: center;
  202. font-size: 300px;
  203. color: #ccc;
  204. padding: 10% 0;
  205. height: 80vh;
  206. overflow-y: auto;
  207. }
  208. .right {
  209. height: 80vh;
  210. background: rgb(219, 240, 188);
  211. overflow-y: auto;
  212. }
  213. }
  214. .dia_one {
  215. text-align: center;
  216. margin: 10px 0 0 0;
  217. }
  218. </style>