ChatingActionBar.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <template>
  2. <view class="chat_action_bar">
  3. <scroll-view :scroll-y="true" :show-scrollbar="false" class="action_scroll_view">
  4. <view class="action_row">
  5. <view v-for="item in actionList" :key="item.idx" @click="actionClick(item)" class="action_col">
  6. <view class="action_item">
  7. <image :src="item.icon" class="action_icon" mode="aspectFit" />
  8. <text class="action_item_title">{{ item.title }}</text>
  9. </view>
  10. </view>
  11. </view>
  12. </scroll-view>
  13. </view>
  14. </template>
  15. <script>
  16. import { mapGetters, mapActions } from 'vuex';
  17. import { ChatingFooterActionTypes, ContactChooseTypes, PageEvents } from '../../../../../constant';
  18. import { AmapWebKey } from '../../../../../common/config';
  19. import IMSDK, { IMMethods } from 'openim-uniapp-polyfill';
  20. // import { getPurePath } from '../../../../../util/common';
  21. import { callingModule } from '../../../../../util/imCommon';
  22. import { premissionCheck } from "@/js_sdk/wa-permission/permission.js"
  23. export default {
  24. components: {},
  25. data() {
  26. return {
  27. userID: '',
  28. isUser: false,
  29. readFilePermission:false,
  30. actionList: [
  31. {
  32. idx: 0,
  33. type: ChatingFooterActionTypes.takePhoto,
  34. title: '拍照',
  35. icon: '/pages_im/static/images/new/take_pictures_icon.png'
  36. },
  37. {
  38. idx: 1,
  39. type: ChatingFooterActionTypes.Album,
  40. title: '相册',
  41. icon: '/pages_im/static/images/new/album_icon.png'
  42. },
  43. {
  44. idx: 2,
  45. type: ChatingFooterActionTypes.Camera,
  46. title: '视频',
  47. icon: '/pages_im/static/images/new/video_icon.png'
  48. },
  49. {
  50. idx: 3,
  51. type: ChatingFooterActionTypes.pickCamera,
  52. title: '录像',
  53. icon: '/pages_im/static/images/new/picture_recording_icon.png'
  54. }
  55. ,{
  56. idx: 4,
  57. type: ChatingFooterActionTypes.Call,
  58. title: "语音通话",
  59. icon: "/pages_im/static/images/new/voice_call_icon.png",
  60. },
  61. {
  62. idx: 5,
  63. type: ChatingFooterActionTypes.VideoCall,
  64. title: "视频通话",
  65. icon: "/pages_im/static/images/new/video_call_icon.png",
  66. }
  67. //{
  68. // idx: 6,
  69. // type: ChatingFooterActionTypes.File,
  70. // title: "问诊订单",
  71. // icon: require("../../../../../static/images/news/consultation_order_icon.png"),
  72. // },
  73. // {
  74. // idx: 4,
  75. // type: ChatingFooterActionTypes.Card,
  76. // title: "名片",
  77. // icon: require("../../../../../static/images/chating_action_card.png"),
  78. // },
  79. // {
  80. // idx: 12,
  81. // type: ChatingFooterActionTypes.Location,
  82. // title: "位置",
  83. // icon: require("../../../../../static/images/chating_action_location.png"),
  84. // }
  85. ]
  86. };
  87. },
  88. computed: {
  89. ...mapGetters(['timStore']),
  90. imType() {
  91. return this.timStore?.imType ?? '';
  92. },
  93. orderId() {
  94. return this.timStore?.orderId ?? '';
  95. },
  96. orderType() {
  97. return this.timStore?.orderType ?? '';
  98. }
  99. },
  100. mounted() {
  101. let conversation = this.$store.getters.storeCurrentConversation;
  102. let userID = (conversation && conversation.userID) ? conversation.userID : '';
  103. if (userID) {
  104. this.userID = userID.substring(1);
  105. this.isUser = userID.indexOf('U') != -1;
  106. }
  107. if (this.$companyUserIsLogin() && this.isUser) {
  108. // this.actionList.push({
  109. // idx: 4,
  110. // type: ChatingFooterActionTypes.Call,
  111. // title: '语音通话',
  112. // icon: require('../../../../../static/images/audio-calling.svg')
  113. // });
  114. // this.actionList.push({
  115. // idx: 5,
  116. // type: ChatingFooterActionTypes.VideoCall,
  117. // title: '视频通话',
  118. // icon: require('../../../../../static/images/chating_action_call.png')
  119. // });
  120. this.actionList.push({
  121. idx: 6,
  122. type: ChatingFooterActionTypes.Order,
  123. title: '问诊订单',
  124. icon: '/pages_im/static/images/new/consultation_order_icon.png'
  125. });
  126. this.actionList.push({
  127. idx: 8,
  128. type: ChatingFooterActionTypes.StoreOrder,
  129. title: '药品订单',
  130. icon: '/pages_im/static/images/new/drug_orders_icon.png'
  131. });
  132. this.actionList.push({
  133. idx: 9,
  134. type: ChatingFooterActionTypes.Package,
  135. title: '疗法',
  136. icon: '/pages_im/static/images/new/therapy_icon.png'
  137. });
  138. this.actionList.push({
  139. idx: 10,
  140. type: ChatingFooterActionTypes.CouponPackage,
  141. title: '私域疗法券',
  142. icon: '/pages_im/static/images/new/therapy_voucher_icon.png'
  143. });
  144. this.actionList.push({
  145. idx: 11,
  146. type: ChatingFooterActionTypes.InquirySelect,
  147. title: '会诊',
  148. icon: '/pages_im/static/images/new/consultation_doctors_icon.png'
  149. });
  150. return;
  151. }
  152. //if((this.imType==1&&this.orderType==2)||this.imType==2){ //语音通话
  153. // this.actionList.push({
  154. // idx: 4,
  155. // type: ChatingFooterActionTypes.Call,
  156. // title: '语音通话',
  157. // icon: require('../../../../../static/images/audio-calling.svg')
  158. // });
  159. //}
  160. //if((this.imType==1&&this.orderType==2)||this.imType==2){ //视频通话
  161. // this.actionList.push({
  162. // idx: 5,
  163. // type: ChatingFooterActionTypes.VideoCall,
  164. // title: '视频通话',
  165. // icon: require('../../../../../static/images/chating_action_call.png')
  166. // });
  167. //}
  168. if (this.imType == 1) {
  169. //问诊订单
  170. this.actionList.push({
  171. idx: 6,
  172. type: ChatingFooterActionTypes.Order,
  173. title: '问诊订单',
  174. icon: '/pages_im/static/images/new/consultation_order_icon.png'
  175. });
  176. }
  177. if (this.imType == 2) {
  178. //视频通话
  179. this.actionList.push({
  180. idx: 7,
  181. type: ChatingFooterActionTypes.Follow,
  182. title: '随访单',
  183. icon: '/pages_im/static/images/chating_action_file.png'
  184. });
  185. this.actionList.push({
  186. idx: 8,
  187. type: ChatingFooterActionTypes.StoreOrder,
  188. title: '药品订单',
  189. icon: '/pages_im/static/image/new/drug_orders_icon.png'
  190. });
  191. }
  192. },
  193. methods: {
  194. async actionClick(action) {
  195. switch (action.type) {
  196. case ChatingFooterActionTypes.takePhoto:
  197. if (uni.$u.os() != 'ios') {
  198. this.requestPressmition();
  199. if(!this.readFilePermission){
  200. return;
  201. }
  202. }
  203. this.$emit('prepareMediaMessage', { type: ChatingFooterActionTypes.Camera, index: 0 });
  204. break;
  205. case ChatingFooterActionTypes.Album:
  206. if (uni.$u.os() != 'ios') {
  207. this.requestPressmition();
  208. if(!this.readFilePermission){
  209. return;
  210. }
  211. }
  212. this.$emit('prepareMediaMessage', { type: ChatingFooterActionTypes.Album, index: 0 });
  213. break;
  214. case ChatingFooterActionTypes.Camera:
  215. if (uni.$u.os() != 'ios') {
  216. this.requestPressmition();
  217. if(!this.readFilePermission){
  218. return;
  219. }
  220. }
  221. this.$emit('prepareMediaMessage', { type: ChatingFooterActionTypes.Album, index: 1 });
  222. break;
  223. case ChatingFooterActionTypes.pickCamera:
  224. if (uni.$u.os() != 'ios') {
  225. this.requestPressmition();
  226. if(!this.readFilePermission){
  227. return;
  228. }
  229. }
  230. this.$emit('prepareMediaMessage', { type: ChatingFooterActionTypes.Camera, index: 1 });
  231. break;
  232. case ChatingFooterActionTypes.Call:
  233. if (!this.$store.getters.storeCurrentConversation.groupID) {
  234. uni.$emit(PageEvents.RtcCall, 'audio');
  235. return;
  236. }
  237. IMSDK.asyncApi('signalingGetRoomByGroupID', IMSDK.uuid(), this.$store.getters.storeCurrentConversation.groupID).then(({ data }) => {
  238. if (data.invitation) {
  239. uni.showModal({
  240. title: '提示',
  241. content: '群通话进行中,是否直接加入?',
  242. confirmText: '确认',
  243. cancelText: '取消',
  244. success: (res) => {
  245. if (res.confirm) {
  246. callingModule.joinRoomLiveChat(data);
  247. }
  248. }
  249. });
  250. } else {
  251. uni.$emit(PageEvents.RtcCall, 'audio');
  252. }
  253. });
  254. break;
  255. case ChatingFooterActionTypes.VideoCall:
  256. if (!this.$store.getters.storeCurrentConversation.groupID) {
  257. uni.$emit(PageEvents.RtcCall, 'video');
  258. return;
  259. }
  260. IMSDK.asyncApi('signalingGetRoomByGroupID', IMSDK.uuid(), this.$store.getters.storeCurrentConversation.groupID).then(({ data }) => {
  261. if (data.invitation) {
  262. uni.showModal({
  263. title: '提示',
  264. content: '群通话进行中,是否直接加入?',
  265. confirmText: '确认',
  266. cancelText: '取消',
  267. success: (res) => {
  268. if (res.confirm) {
  269. callingModule.joinRoomLiveChat(data);
  270. }
  271. }
  272. });
  273. } else {
  274. uni.$emit(PageEvents.RtcCall, 'video');
  275. }
  276. });
  277. break;
  278. case ChatingFooterActionTypes.Order:
  279. this.$emit('enterSubPage');
  280. {
  281. if (this.$companyUserIsLogin()) {
  282. uni.navigateTo({
  283. url: '/pages/company/inquiryOrderIMList?userId=' + this.userID
  284. });
  285. } else {
  286. uni.navigateTo({
  287. url: '/pages/store/inquiryOrderDetails?orderId=' + this.timStore.orderId
  288. });
  289. }
  290. }
  291. break;
  292. case ChatingFooterActionTypes.Follow:
  293. this.$emit('enterSubPage');
  294. uni.navigateTo({
  295. url: '/pages/user/followDetails?followId=' + this.timStore.followId
  296. });
  297. break;
  298. case ChatingFooterActionTypes.StoreOrder:
  299. {
  300. if (this.$companyUserIsLogin()) {
  301. uni.navigateTo({
  302. url: '/pages/company/storeOrderList?userId=' + this.userID
  303. });
  304. } else {
  305. uni.navigateTo({
  306. url: '/pages/store/storeOrderDetail?orderId=' + this.timStore.orderId
  307. });
  308. }
  309. }
  310. break;
  311. case ChatingFooterActionTypes.Package: //疗法
  312. {
  313. if (this.$companyUserIsLogin()) {
  314. uni.navigateTo({
  315. url: '/pages/company/packageList?isIM=1'
  316. });
  317. }
  318. }
  319. break;
  320. case ChatingFooterActionTypes.CouponPackage:
  321. {
  322. if (this.$companyUserIsLogin()) {
  323. uni.navigateTo({
  324. url: '/pages/company/couponList?couponType=5&isIM=1'
  325. });
  326. }
  327. }
  328. break;
  329. case ChatingFooterActionTypes.InquirySelect:
  330. {
  331. if (this.$companyUserIsLogin()) {
  332. let companyId=uni.getStorageSync('companyId');
  333. let companyUserId=uni.getStorageSync('companyUserId');
  334. uni.navigateTo({
  335. url: '/pages/store/inquirySelectType?companyId='+companyId+'&companyUserId='+companyUserId+'&isIM=1'
  336. });
  337. }
  338. }
  339. break;
  340. case ChatingFooterActionTypes.Card:
  341. uni.navigateTo({
  342. url: `/pages_im/pages/common/contactChoose/index?type=${ContactChooseTypes.Card}`
  343. });
  344. break;
  345. case ChatingFooterActionTypes.File:
  346. if (uni.$u.os() != 'ios') {
  347. this.requestPressmition();
  348. if(!this.readFilePermission){
  349. return;
  350. }
  351. }
  352. IMSDK.pickFile().then(async (path) => {
  353. console.log(path);
  354. const idx = path.lastIndexOf('/');
  355. const fileName = path.slice(idx + 1);
  356. const message = await IMSDK.asyncApi(IMMethods.CreateFileMessageFromFullPath, IMSDK.uuid(), {
  357. filePath: this.getPurePath(path),
  358. fileName
  359. });
  360. this.$emit('sendMessage', message);
  361. });
  362. break;
  363. case ChatingFooterActionTypes.Location:
  364. this.$emit('enterSubPage');
  365. uni.chooseLocation({
  366. success: async (res) => {
  367. if (res) {
  368. const options = {
  369. name: res.name,
  370. latng: `${res.latitude},${res.longitude}`,
  371. addr: res.address,
  372. city: res.address,
  373. module: 'locationPicker',
  374. latitude: res.latitude,
  375. longitude: res.longitude,
  376. url: `https://restapi.amap.com/v3/staticmap?size=600*300&markers=-1,https://cache.amap.com/lbs/static/cuntom_marker1.png,0:${res.longitude},${res.latitude}&key=${AmapWebKey}`
  377. };
  378. const message = await IMSDK.asyncApi(IMMethods.CreateLocationMessage, IMSDK.uuid(), {
  379. description: JSON.stringify(options),
  380. longitude: res.longitude,
  381. latitude: res.latitude
  382. });
  383. this.$emit('sendMessage', message);
  384. } else {
  385. uni.$u.toast('获取位置失败');
  386. }
  387. },
  388. fail: ({ errMsg }) => {
  389. if (!errMsg.includes('cancel')) {
  390. uni.$u.toast('获取位置失败');
  391. }
  392. }
  393. });
  394. break;
  395. default:
  396. break;
  397. }
  398. },
  399. async requestPressmition(){
  400. let result = await premissionCheck("EXTERNAL_STORAGE");
  401. console.log("premission result:"+result);
  402. if(result == 1) {
  403. this.readFilePermission=true;
  404. }
  405. },
  406. getPurePath(path){
  407. const prefix = "file://";
  408. const relativeRrefix = "_doc/";
  409. if (path.includes(prefix)) {
  410. path = path.replace(prefix, "");
  411. }
  412. if (path.includes(relativeRrefix)) {
  413. path = plus.io.convertLocalFileSystemURL(path);
  414. }
  415. return path;
  416. }
  417. }
  418. };
  419. </script>
  420. <style scoped>
  421. .chat_action_bar {
  422. width: 750rpx;
  423. height: 550rpx;
  424. background-color: #F5F7FA;
  425. border-top-width: 1px;
  426. border-top-color: #EAEBED;
  427. }
  428. .action_scroll_view {
  429. width: 750rpx;
  430. flex-direction: column;
  431. padding: 24rpx 0;
  432. }
  433. .action_row {
  434. flex-direction: row;
  435. flex-wrap: wrap;
  436. width: 750rpx;
  437. }
  438. .action_col {
  439. width: 187rpx;
  440. align-items: center;
  441. justify-content: center;
  442. margin-bottom: 24rpx;
  443. }
  444. .action_item {
  445. align-items: center;
  446. justify-content: center;
  447. background: #fff;
  448. border-radius: 10px;
  449. width: 130rpx;
  450. padding:8px 0;
  451. margin:5px 0;
  452. }
  453. .action_icon {
  454. width: 50rpx;
  455. height: 50rpx;
  456. margin-bottom: 10rpx;
  457. }
  458. .action_item_title {
  459. font-size: 24rpx;
  460. color: #666666;
  461. }
  462. </style>