import { Component, OnInit } from '@angular/core';
import {FormBuilder} 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-msg',
  templateUrl: './weixin-user-msg.component.html',
  styleUrls: ['./weixin-user-msg.component.scss']
})

export class WeixinUserMsgComponent extends FrameDetailComponent implements OnInit {

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

  ngOnInit() {
  }

  sendMsg() {
    if (this.currentEntity.msg_content === undefined || this.currentEntity.msg_content.trim().length === 0) {
      return;
    }
    MsgService.confirmAlert('确定要推送消息给用户吗？',  () => {
      AjaxService.request('weixin/custom/send/text.htm', {
        open_id: this.currentEntity.open_id,
        wx_id: this.currentEntity.wx_id,
        content: this.currentEntity.msg_content
      }, () => {
        MsgService.successToastr('消息推送成功！');
        this.closeWindow();
      }, {RequestWithLoading: true});
    });


  }
}
