ApplicationItem.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view @click="clickItem" class="application_item">
  3. <my-avatar :src="getAvatarUrl" :isGroup="isGroupApplication" :desc="application[isRecv ? 'fromNickname' : 'toNickname']" size="42">
  4. <image v-if="getRole() == 1" class="taoj" src="/static/svg/doctor.svg"></image>
  5. <image v-if="getRole() == 2" class="taoj" src="/static/svg/guanjia.svg"></image>
  6. </my-avatar>
  7. <view class="application_item_details">
  8. <view class="content">
  9. <text class="user_name">{{ getShowName }}</text>
  10. <view v-if="isGroupApplication" class="title">
  11. 申请加入
  12. <text class="group_name">{{ application.groupName }}</text>
  13. </view>
  14. <text class="req_message">{{ application.reqMsg }}</text>
  15. </view>
  16. <view class="application_action">
  17. <text v-if="showStateStr" class="status_tip">{{ getStateStr }}</text>
  18. <text v-if="showGreet" @tap.stop="greetToUser" class="status_tip greet">已添加</text>
  19. <button :loading="accessLoading" v-if="showAccept" class="access_btn" @tap.stop="acceptApplication" :plain="true" size="mini">
  20. {{ isGroupApplication ? '同意' : '接受' }}
  21. </button>
  22. </view>
  23. <view class="bottom_line"></view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import { navigateToDesignatedConversation } from '../../../util/imCommon';
  29. import IMSDK, { SessionType } from 'openim-uniapp-polyfill';
  30. import MyAvatar from '../../../components/MyAvatar/index.vue';
  31. export default {
  32. name: 'ApplicationItem',
  33. components: {
  34. MyAvatar
  35. },
  36. props: {
  37. application: Object,
  38. isRecv: Boolean
  39. },
  40. data() {
  41. return {
  42. accessLoading: false
  43. };
  44. },
  45. computed: {
  46. isGroupApplication() {
  47. return this.application.groupID !== undefined;
  48. },
  49. getShowName() {
  50. if (this.isRecv) {
  51. return this.application[this.isGroupApplication ? 'nickname' : 'fromNickname'];
  52. }
  53. return this.application[this.isGroupApplication ? 'groupName' : 'toNickname'];
  54. },
  55. showGreet() {
  56. return !this.isGroupApplication && this.application.handleResult === 1;
  57. },
  58. showStateStr() {
  59. if ((this.isRecv && this.application.handleResult === 0) || this.showGreet) {
  60. return false;
  61. }
  62. return true;
  63. },
  64. showAccept() {
  65. return this.application.handleResult === 0 && this.isRecv;
  66. },
  67. getStateStr() {
  68. if (this.application.handleResult === -1) {
  69. return '已拒绝';
  70. }
  71. if (this.application.handleResult === 0) {
  72. return '等待验证';
  73. }
  74. return '已同意';
  75. },
  76. getAvatarUrl() {
  77. if (this.isGroupApplication) {
  78. return this.application.groupFaceURL;
  79. }
  80. return this.application[this.isRecv ? 'fromFaceURL' : 'toFaceURL'];
  81. }
  82. },
  83. methods: {
  84. clickItem() {
  85. if (this.showAccept) {
  86. uni.navigateTo({
  87. url: `/pages/contact/applicationDetails/index?application=${JSON.stringify(this.application)}`
  88. });
  89. } else {
  90. let sourceID = this.application.groupID ?? (this.isRecv ? this.application.fromUserID : this.application.toUserID);
  91. let cardType = this.isGroupApplication ? 'groupCard' : 'userCard';
  92. const url = `/pages/common/${cardType}/index?sourceID=${sourceID}`;
  93. uni.navigateTo({
  94. url
  95. });
  96. }
  97. },
  98. acceptApplication() {
  99. this.accessLoading = true;
  100. let func;
  101. if (this.isGroupApplication) {
  102. func = IMSDK.asyncApi(IMSDK.IMMethods.AcceptGroupApplication, IMSDK.uuid(), {
  103. groupID: this.application.groupID,
  104. fromUserID: this.application.userID,
  105. handleMsg: ''
  106. });
  107. } else {
  108. func = IMSDK.asyncApi(IMSDK.IMMethods.AcceptFriendApplication, IMSDK.uuid(), {
  109. toUserID: this.application.fromUserID,
  110. handleMsg: ''
  111. });
  112. }
  113. func.then(() => {
  114. uni.$u.toast('操作成功');
  115. this.$store.dispatch('contact/getRecvFriendApplications');
  116. this.$store.dispatch('contact/getRecvGroupApplications');
  117. })
  118. .catch(() => uni.$u.toast('操作失败'))
  119. .finally(() => (this.accessLoading = false));
  120. },
  121. greetToUser() {
  122. navigateToDesignatedConversation(this.application[this.isRecv ? 'fromUserID' : 'toUserID'], SessionType.Single).catch(() => uni.$u.toast('获取会话信息失败'));
  123. },
  124. getRole() {
  125. let userType = 0;
  126. let userId = this.application.fromUserID;
  127. if (userId != undefined && (userId != '' || userId.length > 0)) {
  128. if (userId.indexOf('U') !== -1) {
  129. userType = 0;
  130. }
  131. if (userId.indexOf('D') !== -1) {
  132. userType = 1;
  133. }
  134. if (userId.indexOf('C') !== -1) {
  135. userType = 2;
  136. }
  137. }
  138. return userType;
  139. }
  140. }
  141. };
  142. </script>
  143. <style lang="scss" scoped>
  144. .application_item {
  145. // @include vCenterBox();
  146. display: flex;
  147. justify-content: flex-start;
  148. padding: 24rpx 44rpx;
  149. color: $uni-text-color;
  150. background-color: #fff;
  151. &_details {
  152. @include vCenterBox();
  153. margin-left: 24rpx;
  154. width: 100%;
  155. position: relative;
  156. .content {
  157. @include colBox(false);
  158. font-size: 26rpx;
  159. width: 100%;
  160. .user_name {
  161. @include nomalEllipsis();
  162. max-width: 400rpx;
  163. font-size: 28rpx;
  164. color: $uni-text-color;
  165. margin-bottom: 10rpx;
  166. }
  167. .req_message {
  168. @include ellipsisWithLine(2);
  169. max-width: 80%;
  170. color: #999;
  171. }
  172. .title {
  173. margin-bottom: 20rpx;
  174. word-break: break-all;
  175. width: 75%;
  176. .group_name {
  177. margin-left: 12rpx;
  178. color: $uni-color-primary;
  179. }
  180. }
  181. }
  182. .application_action {
  183. position: absolute;
  184. right: 0;
  185. .status_tip {
  186. font-size: 28rpx;
  187. color: #666;
  188. }
  189. .access_btn {
  190. padding: 0rpx 12rpx;
  191. height: 70rpx;
  192. line-height: 70rpx;
  193. background: #ff5c03;
  194. border-radius: 10rpx;
  195. color: #fff;
  196. border-color: #fff;
  197. }
  198. .greet {
  199. color: #999999;
  200. }
  201. }
  202. .bottom_line {
  203. height: 1px;
  204. width: 100%;
  205. background-color: #f0f0f0;
  206. position: absolute;
  207. bottom: -24rpx;
  208. }
  209. }
  210. }
  211. .u-list-item:last-child {
  212. .bottom_line {
  213. height: 0;
  214. }
  215. }
  216. .taoj {
  217. position: absolute;
  218. left: 0px;
  219. top: 0px;
  220. width: 100%;
  221. height: 100%;
  222. }
  223. </style>