Files
sales-trainer/frontend/dist/assets/Chat-CpZrRyQZ.js
Macky cb2642a659 fix(ui): no raw JSON on Training list, pain no longer [object Object], add Chat button on GroupEdit, drop facebook/line from persona
- list_groups returns lightweight summaries (id/title/status/persona_count + product) —
  never the full personas array, so Training no longer shows a long JSON blob.
- PersonaForm toLines extracts .description/.text from pain/objection objects (fixes
  '[object Object]'); save re-wraps pains as {description}.
- GroupEdit persona cards get a 'แชท' (MessageSquare) button so you can start chatting
  right where you land after creating (chat was only on Personas page before).
- channel: default neutral 'social', removed facebook/line validation + removed from
  revealable_view (scenario now sets the tone, not fb/line).
All 9 backend suites pass. Rebuilt dist.
2026-08-09 11:15:13 +07:00

7 lines
7.5 KiB
JavaScript

import{c as P,_ as R,p as G,y as j,a as o,l as k,q as D,u as a,b as s,t,i as n,F as S,x as T,m as g,g as p,C as L,w as K,v as $,d as q,k as H,r as u,B as J,E as O,z as U,o as l}from"./index-Dyfiqyex.js";import{T as Y}from"./target-D9jhWfH4.js";import{A as Q}from"./arrow-left-C95UZZnG.js";/**
* @license lucide-vue-next v1.0.0 - ISC
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const W=P("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),X={key:0,class:"card"},Z={style:{"margin-top":"0"}},ee=["onClick"],se={class:"row",style:{"align-items":"center"}},te={key:0,class:"badge line"},ae={key:1,class:"badge facebook"},oe={class:"muted",style:{"margin-top":"6px"}},le=["disabled"],ne={key:1},ie={class:"card guide"},re={style:{margin:"6px 0 0","line-height":"1.7"}},ce={class:"row",style:{"align-items":"center","margin-bottom":"12px"}},ue={style:{margin:"0"}},de={key:0,class:"muted"},ve={key:0,class:"bubble msg-customer muted"},me={key:0,class:"composer"},pe=["disabled","placeholder"],he=["disabled"],_e={key:1,class:"card debrief"},ge={key:0},ye={key:0,class:"reveal-grid"},fe={class:"rk"},be={class:"rv"},ke={class:"primary",style:{"margin-top":"12px"}},we={__name:"Chat",setup(xe){const A=H(),y=A.params.gid,w=A.params.pid,h=u(null),c=u("pick"),d=u([]),_=u(""),f=u(!1),i=u(null),B=u(null),b=u("social"),N=J(()=>{const e=n.locale==="en";return[{id:"social",emoji:"💬",init:"customer",label:e?"Social Media (chat)":"Social Media (แชท)",desc:e?"The customer messages you first — short, chat-style replies":"ลูกค้าทักมาหาคุณก่อน — โทนสั้น ทักๆ ตามสไตล์แชท"},{id:"f2f_call",emoji:"📞",init:"seller",label:e?"Face-to-face / Phone":"พบหน้า / โทรศัพท์",desc:e?"You must proactively open the conversation (seller starts)":"คุณต้องเป็นฝ่ายเปิดการสนทนาเชิงรุกกับลีด (ผู้ฝึกทักก่อน)"},{id:"recontact",emoji:"⏳",init:"customer",label:e?"Re-contact (1-3 months)":"ลูกค้ากลับมาติดต่อ (1-3 เดือน)",desc:e?"Customer contacted you before, now returns more ready to decide":"เคยได้รับข้อมูลไปแล้ว ตอนนี้กลับมาติดต่อ พร้อมตัดสินใจมากขึ้น"}]});function z(){O(()=>{x.value&&(x.value.scrollTop=x.value.scrollHeight)})}const x=u(null);async function E(){c.value="chat";const e=await j.chatStart(y,w,b.value,n.locale);B.value=e.session.id,d.value=e.session.messages||[],d.value.length&&z()}G(async()=>{h.value=(await j.getPersona(y,w)).persona;try{const e=await j.chatResume(y,w);B.value=e.session.id,d.value=e.session.messages||[],d.value.length&&!e.session.debrief?(c.value="chat",N.find(C=>C.id===e.scenario)&&(b.value=e.scenario)):e.session.debrief&&(i.value=e.session.debrief,d.value=e.session.messages||[],c.value="done"),d.value.length&&z()}catch{c.value="pick"}});async function V(){if(_.value.trim()){f.value=!0;try{const e=await j.chatSend(y,w,_.value.trim());d.value=e.messages,_.value="",e.finished&&(i.value=e.debrief||null,c.value="done"),z()}catch(e){alert(e.message)}finally{f.value=!1}}}const F={name:"ชื่อ",tier:"ระดับ",difficulty:"ความยาก",profession:"อาชีพ",age_group:"ช่วงอายุ",location:"พื้นที่",income:"รายได้",budget:"งบประมาณ",lifestyle:"ไลฟ์สไตล์",background:"ภูมิหลัง",personality:"บุคลิก",communication_style:"สไตล์การสื่อสาร",goal:"เป้าหมาย",decision_timeline:"กรอบตัดสินใจ",pains:"ปัญหา (Pain)",objections:"ข้อโต้แย้ง",negotiation_levers:"สิ่งที่ใช้ต่อรอง",opener:"บทเปิดบทสนทนา",channel:"ช่องทาง",initiation_mode:"ใครเริ่มก่อน",product_context:"บริบทสินค้า"};function I(e){return F[e]||e}function M(e){return Array.isArray(e)?e.join(", "):e&&typeof e=="object"?JSON.stringify(e):String(e??"—")}return(e,v)=>{const C=U("router-link");return l(),o("div",null,[k(C,{to:`/groups/${a(y)}/personas`,class:"btn-back"},{default:D(()=>[k(a(Q),{size:16,"stroke-width":2}),g(" "+t(a(n).t("personas")),1)]),_:1},8,["to"]),c.value==="pick"?(l(),o("div",X,[s("h3",Z,"🎬 "+t(a(n).t("chooseScenario")),1),v[1]||(v[1]=s("p",{class:"muted",style:{"margin-top":"0"}},"เลือกสถานการณ์ที่อยากฝึกการขาย — แต่ละแบบกำหนดว่าใครทักก่อน และโทนการสนทนา",-1)),(l(!0),o(S,null,T(N.value,r=>(l(),o("div",{key:r.id,class:L(["scenario",{sel:b.value===r.id}]),onClick:m=>b.value=r.id},[s("div",se,[s("strong",null,t(r.emoji)+" "+t(r.label),1),r.init==="customer"?(l(),o("span",te,"ลูกค้าทักก่อน")):(l(),o("span",ae,"คุณต้องทักก่อน (เชิงรุก)"))]),s("div",oe,t(r.desc),1)],10,ee))),128)),s("button",{class:"primary",style:{"margin-top":"16px",width:"100%"},disabled:!b.value,onClick:E}," ▶ "+t(a(n).t("start")),9,le)])):(l(),o("div",ne,[s("div",ie,[s("strong",null,[k(a(Y),{size:17,"stroke-width":1.8,style:{"vertical-align":"-3px"}}),g(" "+t(a(n).t("chatGuideTitle")),1)]),s("p",re,t(a(n).t("chatGuideText")),1)]),s("div",ce,[s("h2",ue,t(h.value?h.value.name:"..."),1),h.value?(l(),o("span",de,t(h.value.profession)+" · "+t(h.value.age_group),1)):p("",!0),c.value==="done"?(l(),o("span",{key:1,class:L(["badge",i.value&&i.value.outcome])},t(i.value&&i.value.outcome==="won"?a(n).t("won"):a(n).t("lost")),3)):p("",!0)]),s("div",{class:"thread",ref_key:"thread",ref:x},[(l(!0),o(S,null,T(d.value,(r,m)=>(l(),o("div",{key:m,class:L(["bubble",r.role==="seller"?"msg-seller":r.role==="system"?"msg-system":"msg-customer"])},t(r.text),3))),128)),f.value?(l(),o("div",ve,"...")):p("",!0)],512),c.value==="chat"?(l(),o("div",me,[K(s("input",{"onUpdate:modelValue":v[0]||(v[0]=r=>_.value=r),onKeyup:q(V,["enter"]),disabled:f.value,placeholder:a(n).t("send")},null,40,pe),[[$,_.value]]),s("button",{class:"primary",onClick:V,disabled:f.value||!_.value.trim()},t(a(n).t("send")),9,he)])):p("",!0),c.value==="done"&&i.value?(l(),o("div",_e,[s("h3",null,t(a(n).t("debrief")),1),s("p",null,[s("span",{class:L(["badge",i.value.outcome])},t(i.value.outcome==="won"?a(n).t("won"):a(n).t("lost")),3),g(" — "+t(a(n).t("score"))+": ",1),s("strong",null,t(i.value.score),1)]),s("p",null,[s("strong",null,t(a(n).t("pain"))+":",1),g(" "+t(i.value.pain||"—"),1)]),s("p",null,[s("strong",null,t(a(n).t("why"))+":",1),g(" "+t(i.value.why),1)]),i.value.coaching&&i.value.coaching.length?(l(),o("div",ge,[v[2]||(v[2]=s("strong",null,"Coaching:",-1)),s("ul",null,[(l(!0),o(S,null,T(i.value.coaching,(r,m)=>(l(),o("li",{key:m},t(r),1))),128))])])):p("",!0),s("details",null,[s("summary",null,[k(a(W),{size:15,"stroke-width":1.8,style:{"vertical-align":"-2px"}}),g(" "+t(a(n).t("reveal")),1)]),i.value.revealed_persona?(l(),o("div",ye,[(l(!0),o(S,null,T(i.value.revealed_persona,(r,m)=>(l(),o("div",{key:m,class:"rev"},[s("span",fe,t(I(m)),1),s("span",be,t(M(r)),1)]))),128))])):p("",!0)]),k(C,{to:"/"},{default:D(()=>[s("button",ke,t(a(n).t("dashboard")),1)]),_:1})])):p("",!0)]))])}}},Te=R(we,[["__scopeId","data-v-dd1df48f"]]);export{Te as default};