<template>
  <div>
    <el-form>
      <el-form-item label="账号">
        <el-input v-model="account"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="password"></el-input>
      </el-form-item>
      <el-form-item label="token">{{ token }}</el-form-item>
      <el-button @click="login">登录</el-button>
    </el-form>
    <MMCFlightControlCenter v-if="token" :token="token" :devMode="true"></MMCFlightControlCenter>
  </div>
</template>

<script>
import { Base64 } from "js-base64"

export default {
  name: "fkzx1",
  data() {
    return {
      account: "mmctest@admin",
      password: "test@Admin001",
      token: "",
    };
  },
  computed: {},
  async mounted() {},
  methods: {
    async login() {
      let formData = new FormData();
      formData.append("userAccount", this.account);
      formData.append("password", Base64.encode(this.password));
      let res1 = await fetch("/crm/login", {
        method: "post",
        headers: {
          // "Content-Type": "multipart/form-data",
        },
        body: formData,
      });
      let data1 = await res1.json();

      if (data1.code == 200) {
        await fetch("/crm/user/platformPermission", {
          method: "get",
          headers: {
            "Token": data1.data.token
          },
        })
        this.token = data1.data.token;
      }
    },
  },
};
</script>