import 'package:flutter/material.dart';
import 'package:flutter_alibc/alibc_model.dart';
import 'package:flutter_alibc/flutter_alibc.dart';
import 'package:zhiying_comm/util/taobao/taobao_auth_alert.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class TaobaoAuth {
  // 淘宝授权
  static auth(BuildContext context) async {
    bool isConfirm = await showDialog(
        context: context,
        builder: (BuildContext context) {
          return TaobaoAuthAlert();
        });
    if (isConfirm != null && isConfirm == true) {
      Map<String, dynamic> data = Map<String, dynamic>.from(
          await NetUtil.post('/api/v1/taobao/auth', method: NetMethod.GET));
      Logger.debug(data);
      String url = data['data']['redirect_url'];
      TradeResult result = await FlutterAlibc.openByUrl(url: url);
      // TradeResult result = await FlutterAlibc.openByUrl(url: '');
      Logger.debug('${result.errorCode}   ${result.errorMessage} ');
    }
  }

  // 返回是否授权
  static Future<bool> isAuth() {
    return Future.delayed(Duration.zero, () => false);
  }
}
