import{C as e,E as t,M as n,O as r,T as i,_ as a,a as o,b as s,f as c,g as l,j as u,m as d,o as f,u as p,w as m,y as h}from"./index-vhvNh9F8.js";var g={class:`page`},_={style:{padding:`12px`,background:`#f5f6fa`,"min-height":`calc(100vh - 110px)`}},v={key:0,style:{"text-align":`center`,padding:`40px 0`,color:`#999`}},y={style:{position:`fixed`,bottom:`56px`,left:`0`,right:`0`,padding:`8px 12px`,background:`#fff`,"border-top":`1px solid #eee`,display:`flex`,gap:`8px`,"z-index":`100`}},b={__name:`Chat`,setup(b){let x=r(localStorage.getItem(`token`)||``),S=r([]),C=r(``),w=r(!1),T=r(null);async function E(){let e=C.value.trim();if(!(!e||w.value)){C.value=``,S.value.push({role:`user`,content:e}),w.value=!0;try{if(!T.value){let e=await o.post(`/ai/conversation`,{},{headers:{Authorization:`Bearer `+x.value}});e.code===0&&(T.value=e.data.id)}let t=await o.post(`/ai/message`,{conversation_id:T.value,content:e},{headers:{Authorization:`Bearer `+x.value}});t.code===0&&t.data.reply&&S.value.push({role:`assistant`,content:t.data.reply})}catch{S.value.push({role:`assistant`,content:`抱歉，我暂时无法回复，请稍后再试。`})}w.value=!1}}return(r,o)=>{let b=i(`van-field`),x=i(`van-button`);return e(),a(`div`,g,[s(f,{title:`在线客服`,onBack:o[0]||=e=>r.router.push(`/user`)}),d(`div`,_,[S.value.length===0?(e(),a(`div`,v,`开始咨询吧 👋`)):l(``,!0),(e(!0),a(c,null,m(S.value,(t,r)=>(e(),a(`div`,{key:r,style:u([{display:`flex`,"margin-bottom":`10px`},{justifyContent:t.role===`user`?`flex-end`:`flex-start`}])},[d(`div`,{style:u([{"max-width":`75%`,padding:`8px 12px`,"border-radius":`8px`,"font-size":`14px`,"line-height":`1.5`},{background:t.role===`user`?`var(--primary)`:`#fff`,color:t.role===`user`?`#fff`:`#333`}])},n(t.content),5)],4))),128))]),d(`div`,y,[s(b,{modelValue:C.value,"onUpdate:modelValue":o[1]||=e=>C.value=e,placeholder:`输入问题...`,style:{flex:`1`},onKeyup:p(E,[`enter`])},null,8,[`modelValue`]),s(x,{round:``,size:`small`,class:`primary-btn`,style:{height:`36px`,padding:`0 16px`},onClick:E,loading:w.value},{default:t(()=>[...o[2]||=[h(`发送`,-1)]]),_:1},8,[`loading`])])])}}};export{b as default};