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

@Component({
  selector: 'app-pay-merchant-channel',
  templateUrl: './pay-merchant-channel.component.html',
  styleUrls: ['./pay-merchant-channel.component.scss']
})
export class PayMerchantChannelComponent extends FrameDetailComponent implements OnInit {
  currentChannel: any;
  channelMode = 'add';

  constructor(bsModalRef: BsModalRef, fb: FormBuilder) {
    super(bsModalRef);
    this.detailForm = fb.group({
      'merchant_id': [null],
      'channel_id': [null, Validators.compose([Validators.required])],
      'mc_status': [null, Validators.compose([Validators.required])],
      'channel_goods_name': [null, Validators.compose([Validators.required])],
      'small_image': [null],
      'normal_image': [null],
      'large__image': [null],
      'bank_merchant_id': [null],
      'bank_merchant_name': [null],
      'bank_merchant_pass': [null],
      'public_key_path': [null],
      'private_key_path': [null],
      'bank_merchant_key': [null],
      'notice_url': [null, Validators.compose([Validators.required])],
      'page_url': [null]

    });
  }

  ngOnInit() {

  }

  saveChannel(mode) {
    AjaxService.ajaxRequest(`pay/merchant/channel/${mode}.htm`, this.currentChannel, {
      callback: function () {
        MsgService.successToastr('操作成功！');
        console.log(this);
        this.ajax.request();
        this.currentChannel = undefined;
      }.bind(this)
    }, {RequestWithLoading: true})
  }


}

