<template>
  <div class="test">
    <WlChat
      @addRecordChat="getCheckedList"
      :showAdd="true"
      title="从聊天记录中选择"
      @close="close"
      external_userid="woK9-UBwAAGPU5vOIkIfrovOv8h2WIsA"
      chat_id=""
      :filterFunction="filterFunction"
    />
  </div>
</template>

<script>
export default {
  name: "zcyTestPage",
  data() {
    return {};
  },
  methods: {
    getCheckedList(obj) {
      console.log(obj);
    },
    close() {
      console.log("close");
    },
    filterFunction(data) {
      return data.filter((res) => {
        //如果是外部联系人的话是问，需要禁掉图片
        const { msg_type = "", msg_detail = {} } = res;
        const { image = "", emotion = {} } = msg_detail;
        if (!res.is_self_chat) {
          if (!["emotion", "image"].includes(msg_type)) {
            return res;
          }
          //如果是员工的话是答，需要禁掉图片格式为非JPG，PNG和JPEG的
        } else {
          if (["emotion", "image"].includes(msg_type)) {
            const { url = "" } = image || emotion;
            const picType = url.slice(url.lastIndexOf(".") + 1, url.length);
            if (["jpg", "jpeg", "png"].includes(picType.toLowerCase())) {
              return res;
            }
          } else {
            return res;
          }
        }
      });
    },
  },
};
</script>

<style lang="scss" scope>
.test {
}
</style>
