zxl
3 小时以前 172933f098017bc4c4f57dcda0d490ea12bb13bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import SocketInstance from "@/im-server/socket-instance";
import { ServeGetUserSetting,ServeGetStoreSetting } from "@/api/user";
import store from "@/store";
import { ServeGetTalkList,ServeGetStoreTalkList } from "@/api/chat";
import { formatTalkItem } from "@/utils/talk";
export default {
  
  created() {
    // 判断用户是否登录
    
  },
  methods: {
    // 页面初始化设置
    initialize() {
      SocketInstance.connect();
    },
 
    // 加载用户相关设置信息,更新本地缓存
    loadUserSetting() {
      //标识没有值,获取用户信息
 
      if(this.$route.query.id){
        ServeGetUserSetting().then(async ({ code, result }) => {
          // 如果result有值说明用户创建成功
          if (result) {
            store.commit("UPDATE_USER_INFO", {
              id: result.id,
              face: result.face,
              name: result.nickName,
            });
            console.log(result.nickName)
            /**
             * 用户像商家进行聊天,商家进行刷新好友列表
             */
            // 判断如果是有id说明是 用户像商家进行聊天。
            if (this.$route.query.id) {
              await this.createTalk(this.$route.query.id);
            }
            if(this.$route.query.goodsId && this.$route.query.skuId){
              this.goodsParams.goodsId = this.$route.query.goodsId
              this.goodsParams.skuId = this.$route.query.skuId
            }
          } else if (code === 200 && !result) {
            setTimeout(() => {
              this.loadUserSetting();
            }, 2000);
          }
        });
      }else{
        //标识有值代表是店铺
        ServeGetStoreSetting().then(async ({ code, result }) => {
          if (result) {
            store.commit("UPDATE_USER_INFO", {
              id: result.id,
              face: result.storeLogo,
              name: result.storeName,
            });
            //获取店铺聊天列表
            await this.loadStoreChatList()
          }else if (code === 200 && !result) {
            setTimeout(() => {
              this.loadUserSetting();
            }, 2000);
          }
        })
      }
    },
 
 
     // 获取用户对话列表
     loadChatListInJs() {
    
      ServeGetTalkList()
        .then(({ code, result }) => {
          if (code !== 200) return false;
          store.commit("SET_UNREAD_NUM", 0);
          store.commit("SET_TALK_ITEMS", {
            items: result.map((item) => formatTalkItem(item)),
          });
          let index_name = sessionStorage.getItem("send_message_index_name");
          if (index_name) {
            sessionStorage.removeItem("send_message_index_name");
          }
        })
        .finally(() => {
         
        });
    },
 
    
    //获取商家聊天记录
    loadStoreChatList() {
      this.loadStatus = this.talkNum == 0 ? 0 : 1;
      ServeGetStoreTalkList().then(({ code, result }) => {
        if (code !== 200) return false;
        this.$store.commit("SET_UNREAD_NUM", 0);
        this.$store.commit("SET_TALK_ITEMS", {
          items: result.map((item) => formatTalkItem(item)),
        });
 
        // 判断
        if (this.$route.query.id) {
          let takeData, takeIndex;
          console.log(result)
          result.forEach((take, index) => {
            if (take.id == this.$route.query.id) {
              takeData = take;
              takeIndex = index;
            }
          });
          this.$nextTick(() =>
            this.clickTab(this.$route.query.id, takeData, takeIndex)
          );
        }
      }).finally(() => {
        this.loadStatus = 1;
      });
    },
 
 
    reload() {
      this.$root.$children[0].refreshView();
    },
  },
};