企微助手 ,仓库名 短剧

userSopH5.vue 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <div class="user-sop-wrap">
  3. <div class="tips-1">{{ sopDetail.desc }}</div>
  4. <div class="title-1">推送详情</div>
  5. <div class="tips-2">企微助手提醒您给一下客户发送消息</div>
  6. <div class="title-2">
  7. <span>推送内容</span>
  8. <span v-if="sopDetail.msg_list && sopDetail.msg_list.length > 1" class="collapse-btn" @click="onClickCollapse">
  9. {{ isShowMore ? '收起' : '查看全部' }}
  10. </span>
  11. </div>
  12. <div class="msg-list-wrap">
  13. <!-- 默认只展示第一个消息 -->
  14. <template v-if="!isShowMore">
  15. <div v-if="sopDetail.msg_list && sopDetail.msg_list[0]" class="msg-item-wrap">
  16. <template v-if="sopDetail.msg_list[0].msg_type==1">
  17. {{ sopDetail.msg_list[0]?.content?.content || '-' }}
  18. </template>
  19. <template v-else-if="sopDetail.msg_list[0].msg_type==2">
  20. <div class="flex">
  21. <img :src="sopDetail.msg_list[0]?.content?.oss_url" class="coverImg flex-shrink">
  22. <div class="title">{{ sopDetail.msg_list[0]?.content?.name || '-' }}</div>
  23. </div>
  24. </template>
  25. <template v-else-if="sopDetail.msg_list[0].msg_type==3">
  26. <div class="flex">
  27. <video class="video-wrap flex-shrink" controls :src="sopDetail.msg_list[0]?.content?.oss_url" />
  28. <div class="title">{{ sopDetail.msg_list[0]?.content?.name || '-' }}</div>
  29. </div>
  30. </template>
  31. <template v-else-if="sopDetail.msg_list[0].msg_type==4">
  32. <div class="flex">
  33. <div class="flex-shrink">【文件】:</div>
  34. <div class="title">{{ sopDetail.msg_list[0]?.content?.name || '-' }}</div>
  35. </div>
  36. </template>
  37. <template v-else-if="sopDetail.msg_list[0].msg_type==5">
  38. <div class="flex">
  39. <img :src="sopDetail.msg_list[0]?.content?.imgUrl" class="coverImg flex-shrink">
  40. <div>
  41. <div class="title">{{ sopDetail.msg_list[0]?.content?.title || '-' }}</div>
  42. <div class="desc">{{ sopDetail.msg_list[0]?.content?.desc || '-' }}</div>
  43. </div>
  44. </div>
  45. </template>
  46. <template v-else-if="sopDetail.msg_list[0].msg_type==6">
  47. <div class="flex">
  48. <div class="flex-shrink">【小程序】:</div>
  49. <div class="title">{{ sopDetail.msg_list[0]?.content?.title || '-' }}</div>
  50. </div>
  51. </template>
  52. </div>
  53. </template>
  54. <!-- 展示全部消息 -->
  55. <template v-else>
  56. <div class="msg-item-wrap" v-for="(item, idx) in sopDetail.msg_list" :key="idx">
  57. <template v-if="item.msg_type==1">
  58. {{ item?.content?.content || '-' }}
  59. </template>
  60. <template v-else-if="item.msg_type==2">
  61. <div class="flex">
  62. <img :src="item?.content?.oss_url" class="coverImg flex-shrink">
  63. <div class="title">{{ item?.content?.name || '-' }}</div>
  64. </div>
  65. </template>
  66. <template v-else-if="item.msg_type==3">
  67. <div class="flex">
  68. <video class="video-wrap flex-shrink" controls :src="item?.content?.oss_url" />
  69. <div class="title">{{ item?.content?.name || '-' }}</div>
  70. </div>
  71. </template>
  72. <template v-else-if="item.msg_type==4">
  73. <div class="flex">
  74. <div class="flex-shrink">【文件】:</div>
  75. <div class="title">{{ item?.content?.name || '-' }}</div>
  76. </div>
  77. </template>
  78. <template v-else-if="item.msg_type==5">
  79. <div class="flex">
  80. <img :src="item?.content?.imgUrl" class="coverImg flex-shrink">
  81. <div>
  82. <div class="title">{{ item?.content?.title || '-' }}</div>
  83. <div class="desc">{{ item?.content?.desc || '-' }}</div>
  84. </div>
  85. </div>
  86. </template>
  87. <template v-else-if="item.msg_type==6">
  88. <div class="flex">
  89. <div class="flex-shrink">【小程序】:</div>
  90. <div class="title">{{ item?.content?.title || '-' }}</div>
  91. </div>
  92. </template>
  93. </div>
  94. </template>
  95. </div>
  96. <div class="title-2">选择客户跟进</div>
  97. <van-list
  98. v-model:loading="customer.loading"
  99. :finished="customer.finished"
  100. finished-text="没有更多了"
  101. @load="handleGetCustomer"
  102. >
  103. <div class="customer-wrap" v-for="(item, idx) in customer.list" :key="idx">
  104. <div class="lt-wrap">
  105. <div>
  106. <img class="avatar" :src="item.avatar" />
  107. </div>
  108. <div class="info">
  109. <div class="name">
  110. <span>{{ item.name }}</span>
  111. <span class="source">@{{ item.source }}</span>
  112. </div>
  113. <div class="time">
  114. <span>添加时间:</span>
  115. <span>{{ item.createtime }}</span>
  116. </div>
  117. </div>
  118. </div>
  119. <div class="rt-wrap">
  120. <div class="btn" @click="onClickCustomer(item)">跟进</div>
  121. </div>
  122. </div>
  123. </van-list>
  124. </div>
  125. </template>
  126. <script lang="ts" setup>
  127. import { ref, reactive, onMounted, onBeforeMount } from 'vue'
  128. import { Toast } from 'vant';
  129. import { getQueryString, isJSON } from '@/utils/common'
  130. import $axios from '@/utils/axios'
  131. import getWxConfig from '@/utils/getWxConfig';
  132. import { initQYConfig } from '@/utils/getWxConfig';
  133. interface IRes<T = any> {
  134. errno: string | number
  135. rst: T
  136. [index: string]: any
  137. }
  138. // 请求参数
  139. const params = reactive({
  140. corpid: getQueryString('corpid'),
  141. rule_id: getQueryString('rule_id'),
  142. user_id: getQueryString('user_id'),
  143. })
  144. const sopDetail = ref<any>({
  145. msg_list: []
  146. })
  147. const isShowMore = ref(false)
  148. const onClickCollapse = () => {
  149. isShowMore.value = !isShowMore.value
  150. }
  151. onBeforeMount(() => {//组件挂载之前
  152. if (getQueryString('againJump')) {
  153. params.corpid = getQueryString('corpid')
  154. params.rule_id = getQueryString('rule_id')
  155. params.user_id = getQueryString('user_id')
  156. getWxConfig(() => {
  157. // handleGetSopDetail()
  158. });
  159. } else {//获取用户信息
  160. getWxConfig('', (authInfo) => {
  161. let redirect_uri = encodeURIComponent(window.location.href + '&againJump=true')
  162. let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${authInfo.corpid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=1&agentid=${authInfo.agent_id}#wechat_redirect`;
  163. let link = document.createElement("a");
  164. link.href = url;
  165. document.body.appendChild(link);
  166. link.click();
  167. document.body.removeChild(link);
  168. });
  169. }
  170. });
  171. onMounted(() => {
  172. handleGetSopDetail()
  173. localStorage.removeItem('USER_SOP')
  174. })
  175. // 获取SOP规则详情
  176. const handleGetSopDetail = async () => {
  177. try {
  178. Toast.loading({
  179. message: '加载中...',
  180. duration: 0,
  181. forbidClick: true,
  182. })
  183. const { errno, rst } = await $axios.get('/api/h5/userSop/detail', {
  184. corpid: params.corpid,
  185. rule_id: params.rule_id,
  186. }) as IRes
  187. if (errno == 0) {
  188. console.log('rst => ', rst)
  189. if (rst?.data?.msg_list && Array.isArray(rst.data.msg_list) ) { // 解析JSON类型消息体
  190. rst.data.msg_list.forEach(msg => {
  191. if (isJSON(msg.content)) {
  192. msg.content = JSON.parse(msg.content)
  193. }
  194. })
  195. }
  196. sopDetail.value = rst.data
  197. }
  198. } catch (error) {
  199. console.log('error =>', error)
  200. } finally {
  201. Toast.clear();
  202. }
  203. }
  204. const customer = reactive({
  205. list: [],
  206. loading: false,
  207. finished: false,
  208. page: 1,
  209. page_size: 10,
  210. })
  211. // 获取待跟进客户列表
  212. const handleGetCustomer = async () => {
  213. try {
  214. Toast.loading({
  215. message: '加载中...',
  216. duration: 0,
  217. forbidClick: true,
  218. })
  219. const { errno, rst } = await $axios.get('/api/h5/userSop/customer', {
  220. corpid: params.corpid,
  221. rule_id: params.rule_id,
  222. user_id: params.user_id,
  223. page: customer.page,
  224. page_size: customer.page_size,
  225. }) as IRes
  226. if (errno == 0) {
  227. console.log('rst => ', rst)
  228. if (Array.isArray(rst?.data)) {
  229. customer.list = [...customer.list, ...rst.data]
  230. if (customer.page < rst?.pageInfo?.pages) {
  231. customer.page = customer.page + 1
  232. } else {
  233. customer.finished = true
  234. }
  235. }
  236. }
  237. } catch (error) {
  238. console.log('error =>', error)
  239. } finally {
  240. Toast.clear();
  241. customer.loading = false
  242. }
  243. }
  244. // 监听点击"跟进"客户
  245. const onClickCustomer = (customer) => {
  246. console.log('onClickCustomer => ', customer)
  247. handleSetSop(customer) // 存储当前sop到本地
  248. console.log('wx => ', wx)
  249. const res = wx.invoke('openUserProfile', {
  250. "type": 2, //1表示该userid是企业成员,2表示该userid是外部联系人
  251. "userid": customer.external_userid //可以是企业成员,也可以是外部联系人
  252. }, function(res) {
  253. console.log('res => ', res)
  254. if(res.err_msg != "openUserProfile:ok") {
  255. //错误处理
  256. }
  257. });
  258. console.log('res => ', res)
  259. }
  260. // 存储当前sop到本地
  261. const handleSetSop = (customer) => {
  262. localStorage.removeItem('USER_SOP')
  263. const list = JSON.parse(JSON.stringify(sopDetail.value.msg_list))
  264. list.forEach(item => {
  265. item.content.rule_id = params.rule_id
  266. })
  267. // const USER_SOP = {
  268. // [customer.external_userid]: list,
  269. // }
  270. const USER_SOP = list
  271. console.log('USER_SOP => ', USER_SOP)
  272. localStorage.setItem('USER_SOP', JSON.stringify(USER_SOP))
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. .user-sop-wrap {
  277. box-sizing: border-box;
  278. min-height: 100vh;
  279. background-color: #FFF;
  280. padding: 20px;
  281. .tips-1 {
  282. font-weight: 600;
  283. font-size: 14px;
  284. color: #F59A22;
  285. }
  286. .title-1 {
  287. margin-top: 20px;
  288. font-size: 16px;
  289. font-weight: 600;
  290. color: #333;
  291. }
  292. .tips-2 {
  293. margin-top: 10px;
  294. font-size: 14px;
  295. color: #333;
  296. }
  297. .title-2 {
  298. margin-top: 20px;
  299. font-size: 14px;
  300. color: #333;
  301. font-weight: 600;
  302. display: flex;
  303. justify-content: space-between;
  304. .collapse-btn {
  305. color: #32B38C;
  306. font-size: 12px;
  307. font-weight: 400;
  308. }
  309. }
  310. .msg-list-wrap {
  311. margin-top: 10px;
  312. .msg-item-wrap {
  313. background-color: #f8f8f8;
  314. padding: 13px 14px;
  315. margin-top: 4px;
  316. color: #333;
  317. word-wrap: break-word;
  318. font-size: 14px;
  319. .flex{
  320. display:flex;
  321. align-items:center;
  322. .flex-shrink {
  323. flex-shrink: 0;
  324. }
  325. }
  326. .coverImg{
  327. width:100px;
  328. margin-right:10px;
  329. }
  330. .title{
  331. color: #444;
  332. font-size: 14px;
  333. word-wrap:break-word;
  334. }
  335. .video-wrap {
  336. width: 100px;
  337. height: 150px;
  338. margin-right: 10px;
  339. background-color: #666;
  340. }
  341. .desc{
  342. color: #999;
  343. margin-top: 4px;
  344. font-size: 12px;
  345. word-wrap:break-word;
  346. }
  347. }
  348. }
  349. .customer-wrap {
  350. display: flex;
  351. align-items: center;
  352. justify-content: space-between;
  353. padding: 10px;
  354. margin-top: 10px;
  355. background-color: #F8F8F8;
  356. .lt-wrap {
  357. flex: 1;
  358. flex-shrink: 0;
  359. display: flex;
  360. align-items: center;
  361. .avatar {
  362. width: 50px;
  363. height: 50px;
  364. }
  365. .info {
  366. margin-left: 4px;
  367. font-size: 14px;
  368. color: #333;
  369. .name {
  370. .source {
  371. margin-left: 3px;
  372. color: #00b38a;
  373. }
  374. }
  375. .time {
  376. margin-top: 10px;
  377. font-size: 12px;
  378. color: #666;
  379. }
  380. }
  381. }
  382. .rt-wrap {
  383. flex-shrink: 0;
  384. .btn {
  385. box-sizing: border-box;
  386. border: 1px solid #00b38a;
  387. width: 56px;
  388. height: 24px;
  389. font-size: 14px;
  390. color: #00b38a;
  391. display: flex;
  392. align-items: center;
  393. justify-content: center;
  394. background-color: #fff;
  395. }
  396. }
  397. }
  398. }
  399. </style>