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

@Component({
  selector: 'app-weixin-user-msg',
  templateUrl: './weixin-user-msg.component.html',
  styleUrls: ['./weixin-user-msg.component.scss']
})

export class WeixinUserMsgComponent extends FrameEditComponent 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.confirm('确定要推送消息给用户吗？',  () => {
      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.successToaster('消息推送成功！');
        this.closeWindow();
      }, {RequestWithLoading: true});
    });


  }
}
