my.component.ts 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import { Component, OnInit } from '@angular/core';
  2. import { LoadingController, ToastController } from '@ionic/angular';
  3. import * as Parse from 'parse';
  4. import { AgreementComponent } from '../../login/agreement/agreement.component';
  5. import { AlertController, ModalController } from '@ionic/angular';
  6. import { ActivatedRoute, Router } from '@angular/router';
  7. import { AuthService } from '../../../services/auth.service';
  8. import { AiChatService } from '../../../services/aichart.service';
  9. import { AccountService } from '../../../services/account.service';
  10. import { ionicStandaloneModules } from '../../ionic-standalone.modules';
  11. import { DatePipe, CommonModule } from '@angular/common';
  12. import { AvatarComponent } from '../../../app/components/avatar/avatar.component';
  13. import { HttpService } from '../../../services/http.service';
  14. import { DeviceService } from '../../../services/device.service';
  15. @Component({
  16. selector: 'app-my',
  17. templateUrl: './my.component.html',
  18. styleUrls: ['./my.component.scss'],
  19. standalone: true,
  20. imports: [...ionicStandaloneModules, CommonModule,AvatarComponent],
  21. providers: [DatePipe],
  22. })
  23. export class MyComponent implements OnInit {
  24. profile?: Parse.Object; //身份信息
  25. user: Parse.Object = Parse.User.current()!;
  26. constructor(
  27. private loadingCtrl: LoadingController,
  28. private modalController: ModalController,
  29. private alertController: AlertController,
  30. private authServ: AuthService,
  31. private toastController: ToastController,
  32. private activateRoute: ActivatedRoute,
  33. private router: Router,
  34. public aiServ: AiChatService,
  35. private accServ: AccountService,
  36. private http: HttpService,
  37. public deviceSer:DeviceService
  38. ) {}
  39. tools: Array<{ icon: string; title: string; path: string }> = [
  40. {
  41. icon: 'img/钱包.png',
  42. title: '钱包',
  43. path: 'account/wattle',
  44. },
  45. {
  46. icon: 'img/相册.png',
  47. title: '相册',
  48. path: 'user/album',
  49. },
  50. {
  51. icon: 'img/邀请.png',
  52. title: '邀请',
  53. path: 'user/share',
  54. },
  55. {
  56. icon: 'img/访客.png',
  57. title: '访客记录',
  58. path: 'user/browse',
  59. },
  60. {
  61. icon: 'img/设置.png',
  62. title: '设置',
  63. path: 'user/setting',
  64. },
  65. ];
  66. registerAgreement: any; //用户协议
  67. liveAgreement: any; //直播协议
  68. company: string | null = localStorage?.getItem('company');
  69. userObj: any = {
  70. fans: 0,
  71. follow: 0,
  72. friendly_degree: 0,
  73. vip: null,
  74. };
  75. orderList: Array<any> = [];
  76. loading: boolean = true;
  77. ngOnInit() {
  78. this.activateRoute.paramMap.subscribe(async (params) => {
  79. this.refresh();
  80. });
  81. }
  82. async refresh() {
  83. const loading = await this.loadingCtrl.create({
  84. message: '加载中',
  85. });
  86. loading.present();
  87. this.user = Parse.User.current()!;
  88. await this.getProfile();
  89. this.getAgreement();
  90. const data = await this.aiServ.getFansAndFollow(this.user.id);
  91. // console.log(data);
  92. this.orderList = await this.aiServ.getOrderAnchor(null,10);
  93. console.log(this.orderList);
  94. const { fans, follow } = data.data[0];
  95. this.userObj = { fans, follow, friendly_degree: 0 };
  96. this.userObj.vip = this.accServ.userVip;
  97. if (!this.userObj.vip) {
  98. this.userObj.vip = await this.accServ.getVip();
  99. }
  100. console.log(this.userObj);
  101. await this.updateLevel()
  102. loading.dismiss();
  103. this.loading = false;
  104. }
  105. // 获取用户信息
  106. async getProfile() {
  107. let user = Parse.User.current();
  108. let query = new Parse.Query('Profile');
  109. query.equalTo('user', user?.id);
  110. query.notEqualTo('isDeleted', true);
  111. query.select('isCheck', 'isCross','birthdate','identyType','degreeNumber');
  112. this.profile = await query.first();
  113. }
  114. getAgreement() {
  115. let Agreement = new Parse.Query('ContractAgreement');
  116. Agreement.equalTo('company', this.company);
  117. Agreement.equalTo('type', 'register');
  118. Agreement.first().then((res) => {
  119. console.log(res);
  120. this.registerAgreement = res;
  121. });
  122. let Agreement2 = new Parse.Query('ContractAgreement');
  123. Agreement2.equalTo('company', this.company);
  124. Agreement2.equalTo('type', 'live');
  125. Agreement2.first().then((res) => {
  126. console.log(res);
  127. this.liveAgreement = res;
  128. });
  129. }
  130. async onChange(e: any) {
  131. const loading = await this.loadingCtrl.create({
  132. message: '正在修改',
  133. });
  134. loading.present();
  135. let checked = e.detail.checked;
  136. console.log(checked);
  137. if (!this.profile?.id) {
  138. let obj = Parse.Object.extend('Profile');
  139. this.profile = new obj();
  140. this.profile?.set('mobile', Parse.User.current()?.get('mobile'));
  141. this.profile?.set('user', Parse.User.current()?.toPointer());
  142. this.profile?.set('company', {
  143. __type: 'Pointer',
  144. className: 'Company',
  145. objectId: this.authServ.company,
  146. });
  147. }
  148. this.profile?.set('isCheck', checked);
  149. await this.profile?.save();
  150. loading.dismiss();
  151. const toast = await this.toastController.create({
  152. message: `已${checked ? '开启' : '关闭'}`,
  153. color: 'success',
  154. duration: 1000,
  155. });
  156. toast.present();
  157. }
  158. toUrl(url: string, params?: Object) {
  159. console.log(url);
  160. if (params) {
  161. this.router.navigate([url, Object]);
  162. } else {
  163. this.router.navigate([url]);
  164. }
  165. }
  166. async showAgreement(type: string) {
  167. if (type == 'liveAgreement' || type == 'registerAgreement') {
  168. const modal = await this.modalController.create({
  169. component: AgreementComponent,
  170. cssClass: 'my-custom-class',
  171. componentProps: {
  172. agreement: this[type],
  173. },
  174. });
  175. return await modal.present();
  176. }
  177. }
  178. /* 进入直播间 */
  179. async goRoom() {
  180. if (
  181. !this.profile?.get('isCross') ||
  182. this.profile?.get('identyType') !== 'anchor'
  183. ) {
  184. const alert = await this.alertController.create({
  185. header: '提示',
  186. message: '你还未认证主播身份,请认证后再进入直播间',
  187. buttons: [
  188. {
  189. text: '取消',
  190. role: 'cancel',
  191. cssClass: 'secondary',
  192. handler: (blah) => {},
  193. },
  194. {
  195. text: '去认证',
  196. handler: () => {
  197. console.log('Confirm Cancel: blah');
  198. this.toUrl('/user/anchor');
  199. },
  200. },
  201. ],
  202. });
  203. await alert.present();
  204. } else {
  205. this.toUrl('/live/room-manage');
  206. }
  207. }
  208. /* 退出登录 */
  209. async onLogout() {
  210. const alert = await this.alertController.create({
  211. cssClass: 'my-custom-class',
  212. header: '',
  213. message: '你确定退出登录吗?',
  214. backdropDismiss:false,
  215. buttons: [
  216. {
  217. text: '确定',
  218. role: 'cancel',
  219. cssClass: 'secondary',
  220. handler: (blah) => {
  221. console.log('Confirm Cancel: blah');
  222. this.authServ.logout();
  223. },
  224. },
  225. {
  226. text: '取消',
  227. handler: () => {},
  228. },
  229. ],
  230. });
  231. await alert.present();
  232. }
  233. toService(){
  234. location.href = 'tel:4000-000-000';
  235. console.log('拨号');
  236. }
  237. async updateLevel(){
  238. let url = 'https://server.fmode.cn/api/ailiao/update/level'
  239. let data = await this.http.httpRequst(url,{pid: this.profile?.id},'POST')
  240. console.log(data);
  241. }
  242. async toUrlService(url: string){
  243. if(!this.accServ.userVip?.rights?.['vip-service']){
  244. const toast = await this.toastController.create({
  245. message: '高级会员专享服务',
  246. color: 'warning',
  247. duration: 1500,
  248. });
  249. toast.present();
  250. return
  251. }
  252. this.router.navigate([url]);
  253. }
  254. async changeTop(e:any, type?:string){
  255. e.cancelBubble = true;
  256. this.orderList = await this.aiServ.getOrderAnchor(null,10,type);
  257. }
  258. }