<template>
    <div class="layout-default flex h-screen w-full">
        <div class="app-aside">
            <layout-sidebar />
        </div>

        <div class="flex-1 flex flex-col min-w-0">
            <div class="app-header">
                <layout-header />
            </div>
            <div class="app-main flex-1 min-h-0">
                <layout-main />
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import LayoutMain from './components/main.vue'
import LayoutSidebar from './components/sidebar/index.vue'
import LayoutHeader from './components/header/index.vue'
import { Push } from "@/common/push.js";
import { print } from "@/utils/print";

const connection = new Push({
  url: import.meta.env.VITE_PUSH_URL, // websocket地址
  app_key: '2ce3ce22329517213caa7dad261f5695',
});

// 浏览器监听user-1
const user_channel = connection.subscribe(`platform_1`);
// const user_channel = connection.subscribe(`store_merchant_${1}`);

// setTimeout(()=>{
  
//   print(
//     {
//     id: 405,
//     merchant: 501,
//     real_name: '阿哈',
//     user_phone: '19330904744',
//     user_address: '里海三楼',
//     uid: '9',
//     number: 'PF171617436315965155',
//     total: '0.02',
//     actual: '0.02',
//     create_time: '2024-05-20 11:06:03',
//     mer_name: '莲花农贸市场',
//     mer_phone: '15566669999',
//     mer_nickname: '小明',
//     mer_user_mobile: '',
//     nickname: '用户1532345',
//     user_moblie: '19330904747',
//     info: [
//       {
//         goods: 317,
//         nums: '1.00',
//         price: '0.02',
//         total: '0.02',
//         unit_name: '斤',
//         goods_name: '西瓜'
//       },
//       {
//         goods: 317,
//         nums: '1.56',
//         price: '1.98',
//         total: '3.09',
//         unit_name: '斤',
//         goods_name: '苹果'
//       },
//       {
//         goods: 317,
//         nums: '2.58',
//         price: '3.68',
//         total: '9.49',
//         unit_name: '斤',
//         goods_name: '香蕉'
//       }
//     ]
//   }
// )
// }, 1000)

// 当user-2频道有message事件的消息时
user_channel.on('message', function (data: any) {
  console.log("收到消息--",data);
  if(data.content?.type=='platform_print'){
    console.log('收到打印消息');
    if(typeof data?.content?.data != 'object' || !data?.content?.data?.info?.length) return ElMessage.error('收到订单，但打印数据不合法，请联系管理员');
    else print(data?.content?.data);
  }
});
// 断线事件
user_channel.on('close', function () {
  
});
</script>
