ApplicationItem.vue 6.5 KB

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