<template>
  <section class="AppOpenChat">
    <AiLoading tips="正在处理..."/>
  </section>
</template>

<script>
import {mapActions, mapState} from "vuex"

export default {
  name: "AppOpenChat",
  appName: "创建群聊",
  computed: {
    ...mapState(['user'])
  },
  data() {
    return {
      users: {}
    }
  },
  methods: {
    ...mapActions(['injectJWeixin']),
    getUsers() {
      return Promise.all([
        this.$http.post("/app/wxcp/wxuser/list", null, {params: {listType: 0}}).then(res => {
          if (res?.data) {
            return this.users.userIds = res.data.records?.map(e => e.id)
          }
        }),
        this.$http.post("/app/wxcp/wxcustomer/list", null, {
          params: {
            wxUserId: this.user.wxUserId
          }
        }).then(res => {
          if (res?.data) {
            return this.users.externalUserIds = res.data.records?.map(e => e.id)
          }
        }),
      ])

    }
  },
  created() {
    this.injectJWeixin("openEnterpriseChat").then(() => this.$confirm("确定创建省志愿者活动专用群聊?"))
    .then(this.getUsers).then(() => {
      wx.openEnterpriseChat({
        userIds: "18507227517;AiXianLing",
        externalUserIds: "wmGBFVDgAAj_krfwaThRm-RRAq9rBeaQ",
        groupName: "省志愿者活动专用群",
        ...this.users,
      })
    }).catch(() => 0)
  }
}
</script>

<style lang="scss" scoped>
.AppOpenChat {
}
</style>
