index.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import { useState } from "react";
  2. import { View } from "@tarojs/components";
  3. import Taro, { useRouter } from "@tarojs/taro";
  4. import PageCustom from "@/components/page-custom/index";
  5. import NavBarNormal from "@/components/NavBarNormal/index";
  6. import ButtonCardAdd from "@/components/button-card-add";
  7. import ContactCard from "@/components/AgentCard/index";
  8. import style from './index.module.less'
  9. import Popup from "@/components/popup/popup";
  10. import WemetaTabs from "@/components/wemeta-tabs/index";
  11. import BottomBar from "@/components/BottomBar";
  12. import { TContactItem } from "@/types/contact";
  13. import AgentScrollList from './components/MyContactsScrollList'
  14. import MyAgentsScrollList from './components/MyAgentsScrollList'
  15. import MyEntAgentsScrollList from './components/MyEntAgentsScrollList'
  16. import { TAgent } from "@/types/agent";
  17. import IconMoreBlack from "@/components/icon/IconMoreBlack";
  18. import PopupSheets from "@/components/popup/popup-sheets";
  19. import { EComponentType } from "@/consts/enum";
  20. import { useComponentStore } from "@/store/componentStore";
  21. import { useAgentStore } from "@/store/agentStore";
  22. export default function Index() {
  23. const { saveComponent } = useComponentStore();
  24. let currentComponent = useComponentStore((state) => state.currentComponent);
  25. const loading = useComponentStore((state) => state.loading);
  26. const prevData = currentComponent?.data.values ?? []
  27. const [picked, setPicked] = useState<(TContactItem|TAgent)[]>(prevData);
  28. const [agents, setAgents] = useState<(TContactItem|TAgent)[]>(prevData);
  29. const [current, setCurrent] = useState<(TContactItem|TAgent)|null>(null);
  30. const agent = useAgentStore((state)=> state.agent)
  31. // 是否显示选择器
  32. const [show, setShow] = useState(false);
  33. const [showPopupSheets, setShowPopupSheets] = useState(false);
  34. const handleSubmit = async () => {
  35. if(!currentComponent?.data?.id){
  36. return
  37. }
  38. if (loading) {
  39. return;
  40. }
  41. // 过虑掉 email, mobile, qrCodeUrl
  42. const newPicked = picked.map(item=> {
  43. return {
  44. ...item,
  45. email: undefined,
  46. mobile: undefined,
  47. qrCodeUrl: undefined,
  48. }
  49. })
  50. const c = {
  51. data: {
  52. values: newPicked,
  53. layout: currentComponent.data.layout ?? 'mini',
  54. id: currentComponent.data.id,
  55. index: currentComponent.data.index,
  56. },
  57. enabled: currentComponent?.enabled ?? true,
  58. type: EComponentType.bluebook,
  59. };
  60. await saveComponent(c);
  61. Taro.navigateBack();
  62. };
  63. const handleClickMore = (item: TAgent|TContactItem) => {
  64. setCurrent(item)
  65. setShowPopupSheets(true)
  66. };
  67. const handleClick = () => {
  68. setShow(true)
  69. }
  70. const handlePicked = () => {
  71. setShow(false)
  72. setPicked(agents)
  73. }
  74. const visitorCurrent = ()=> {
  75. if(!current){
  76. return;
  77. }
  78. setShowPopupSheets(false)
  79. Taro.navigateTo({
  80. url: "/pages/profile/index?agentId=" + current?.agentId,
  81. });
  82. setCurrent(null)
  83. }
  84. const removePicked = ()=> {
  85. if(!current){
  86. return;
  87. }
  88. setShowPopupSheets(false)
  89. const restAgent = picked.filter(item => item.agentId !== current.agentId);
  90. setPicked(restAgent)
  91. setAgents(restAgent)
  92. setCurrent(null)
  93. }
  94. const renderContactList = () => {
  95. if (!picked.length) {
  96. return (
  97. <></>
  98. );
  99. }
  100. return (
  101. <View className="flex flex-col gap-8 w-full">
  102. {picked.map((item) => {
  103. return (
  104. <ContactCard
  105. className="p-16"
  106. key={item.agentId}
  107. data={item}
  108. renderRight={() => {
  109. return (
  110. <View className="flex self-center" onClick={() => handleClickMore(item)}>
  111. <IconMoreBlack />
  112. </View>
  113. );
  114. }}
  115. ></ContactCard>
  116. );
  117. })}
  118. </View>
  119. );
  120. };
  121. const colleagues = {
  122. key: "3",
  123. label: "企业同事",
  124. children: (
  125. <View className={style.tabContainer}>
  126. <MyEntAgentsScrollList selected={agents} setSelected={setAgents}></MyEntAgentsScrollList>
  127. </View>
  128. ),
  129. }
  130. const tabsBaseList = [
  131. {
  132. key: "1",
  133. label: "我创建的",
  134. children: (
  135. <View className={style.tabContainer}>
  136. <MyAgentsScrollList selected={agents} setSelected={setAgents}></MyAgentsScrollList>
  137. </View>
  138. ),
  139. },
  140. {
  141. key: "2",
  142. label: "我的联系⼈",
  143. children: (
  144. <View className={style.tabContainer}>
  145. <AgentScrollList selected={agents} setSelected={setAgents}></AgentScrollList>
  146. </View>
  147. ),
  148. },
  149. ]
  150. const tabList = agent?.isEnt ? [...tabsBaseList, colleagues] : tabsBaseList;
  151. return (
  152. <PageCustom>
  153. <NavBarNormal>智能体</NavBarNormal>
  154. <View>
  155. </View>
  156. <View className="w-full">
  157. <View className='flex flex-col items-center w-full'>
  158. <ButtonCardAdd
  159. text={`添加展示的智能体`}
  160. onClick={handleClick}
  161. ></ButtonCardAdd>
  162. <View className="pt-16 pb-162 px-16 w-full">
  163. {renderContactList()}
  164. </View>
  165. </View>
  166. </View>
  167. <BottomBar>
  168. <View className="button-rounded button-primary flex-1" onClick={handleSubmit}>保存</View>
  169. </BottomBar>
  170. <Popup setShow={setShow} show={show} title="智能体">
  171. <WemetaTabs current="1" list={tabList}></WemetaTabs>
  172. <BottomBar>
  173. <View
  174. className="button-rounded button-primary flex-1"
  175. onClick={handlePicked}
  176. >
  177. 引用
  178. </View>
  179. </BottomBar>
  180. </Popup>
  181. <PopupSheets
  182. setShow={setShowPopupSheets}
  183. show={showPopupSheets}
  184. content={[
  185. {item: '访问TA的主页', type: 'primary', onClick: visitorCurrent},
  186. {item:'删除', type: 'warn', onClick: removePicked},
  187. ]}
  188. >
  189. </PopupSheets>
  190. </PageCustom>
  191. );
  192. }