import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { STColumn, STComponent, STData, STRequestOptions } from '@delon/abc/st';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { processSingleSort } from '@shared';
import { NzModalService } from 'ng-zorro-antd/modal';
import { ChannelSalesService } from '../../services/channel-sales.service';
import { ParterChannelSalesEditComponent } from '../edit/edit.component';

@Component({
  selector: 'app-parter-channel-sales-list',
  templateUrl: './list.component.html'
})
export class ParterChannelSalesListComponent implements OnInit {
  schema: SFSchema = {};
  columns!: STColumn[];
  ui!: SFUISchema;
  @ViewChild('st', { static: false })
  st!: STComponent;
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  spuStatus = '1';

  data=[{name1:1111}]
  constructor(
    public router: Router,
    public ar: ActivatedRoute,
    public service: ChannelSalesService,
    private modalService: NzModalService
  ) {}

  /**
   * 查询参数
   */
  get reqParams() {
    return { ...this.sf?.value };
  }
  ngOnInit() {
    this.initSF();
    this.initST();
  }

  initSF() {
    this.schema = {
      properties: {
        name: {
          type: 'string',
          title: '销售渠道姓名'
        },
        telephone: {
          type: 'string',
          title: '手机号'
        },
      }
    };
    this.ui = {
      '*': {
        grid: { span: 8, gutter: 4 }
      }
    };
  }

  initST() {
    this.columns = [
      {
        title: '销售渠道姓名',
        index: 'name'
      },
      {
        title: '手机号',
        index: 'telephone'
      },
      {
        title: '所属组织',
        index: 'organLable'
      },
      {
        title: '职级',
        index: 'station'
      },
      {
        title: '等级',
        index: 'postLevel'
      },
      {
        title: '省市',
        index: 'residencePlace'
      },
      {
        title: '邀请码',
        index: 'inviteCode'
      },
      {
        title: '操作',
        className: 'text-center',
        buttons: [
          {
            text: '编辑',
            click: (_record, _modal, _instance) => this.edit(_record),
          },
          {
            text: '冻结',
            click: (_record, _modal, _instance) => this.stop(_record.id),
          }
        ]
      }
    ];
  }

  add() {
    const modalRef = this.modalService.create({
      nzWidth:600,
      nzTitle: '新增',
      nzContent: ParterChannelSalesEditComponent,
    });
    modalRef.afterClose.subscribe(res => {
      if (res) {
        this.st.reload();
      }
    });
  }

  // 编辑
  edit(record: STData) {
    const modalRef = this.modalService.create({
      nzWidth:600,
      nzTitle: '编辑',
      nzContent: ParterChannelSalesEditComponent,
      nzComponentParams: { i: record }
    });
    modalRef.afterClose.subscribe(res => {
      if (res) {
        this.st.reload();
      }
    });
  }

   

  stop(id: any) {
    this.modalService.confirm({
      nzTitle: '<i>冻结确认</i>',
      nzContent: `<b>确定冻结该账号吗？</br>`,
      // nzOnOk: () =>
      //   this.service.request('', '').subscribe(res => {
      //     if (res) {
      //       this.service.msgSrv.success('冻结成功！');
      //       this.st.reload();
      //     }
      //   })
    });
  }

  /**
   * 重置表单
   */
  resetSF() {
    this.sf.reset();
    this.st.load(1);
  }


}
