import { Component, OnInit } from '@angular/core';
import {FormBuilder, Validators} from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { AjaxService } from '../../../../core/service/ajax.service';
import { MsgService } from '../../../../core/service/msg.service';
import { FrameDetailComponent } from '../../../frame/core/detail/frame.detail';

@Component({
  selector: 'app-weixin-user-detail',
  templateUrl: './weixin-user-detail.component.html',
  styleUrls: ['./weixin-user-detail.component.scss']
})
export class WeixinUserDetailComponent extends FrameDetailComponent implements OnInit {

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
  }

  ngOnInit() {
  }

  initDefautEntity() {
    if (this.currentEntity.user_tags_ids !== undefined) {
      this.currentEntity.tag_ids = [];
      for (const s of this.currentEntity.user_tags_ids.split(',')) {
        this.currentEntity.tag_ids.push(parseInt(s, 10));
      }
    }
  }


  saveUserTag() {
    MsgService.confirmAlert('确定要保存用户标签吗？', () => {
      AjaxService.request('weixin/user/tags/save.htm', {wx_id: this.currentEntity.wx_id, wuser_id : this.currentEntity.wuser_id, tag_ids: this.currentEntity.tag_ids}, () => {
        MsgService.successAlert('用户标签保存成功，且已经同步到微信服务器！');
      }, {RequestWithLoading: true});
    });
  }


  saveUserRemark() {
    MsgService.confirmAlert('确定要保存用户备注吗？', () => {
      AjaxService.request('weixin/user/remark/save.htm', {wx_id: this.currentEntity.wx_id, open_id : this.currentEntity.open_id, remark: this.currentEntity.remark}, () => {
        MsgService.successAlert('用户备注保存成功，且已经同步到微信服务器！');
      }, {RequestWithLoading: true});
    });
  }
}
