<template>
  <div class="main_root">
    <div class="header">
      <div class="comm">开机自动强制启动某个APP</div>
      <div class="comm">仅支持选择一个APP</div>
    </div>
    <div class="content">
      <Form ref="addForm" :model="adminInfo" :label-width="140" inline>
        <FormItem label="开机启动应用包名" style="width: 100%">
          <Input
            v-model="adminInfo.appPackage"
            placeholder="请输入开机启动应用包名"
          ></Input>
        </FormItem>
        <FormItem label="页面地址" style="width: 100%">
          <Input
            v-model="adminInfo.authUrl"
            placeholder="请输入页面地址"
          ></Input>
        </FormItem>
        <FormItem label="约定标识" style="width: 100%">
          <RadioGroup v-model="adminInfo.singleType">
            <Radio :label="1">账号</Radio>
            <Radio :label="2">手机号码</Radio>
            <Radio :label="3">身份证号码</Radio>
          </RadioGroup>
        </FormItem>
      </Form>
    </div>
    <div class="footer">
      <Button style="margin-right: 20px" @click="Refresh()">取消</Button>
      <Button @click="saveInfo()" class="primary_btn" type="primary"
        >保存</Button
      >
    </div>
    <Spin fix v-if="showLoading" style="background-color: transparent">
      <Icon type="ios-loading" size="18" class="demo-spin-icon-load"></Icon>
      <div>加载中</div>
    </Spin>
  </div>
</template>

<script>
import {
  autoapp_detail,
  autoapp_edit
} from "@/api/setting";

export default {
  data() {
    return {
      adminInfo: {
        regionid: "",
        appPackage: "",
        authUrl: "",
        singleType: 1
      },
      userInfo: {},
      showLoading: false
    };
  },
  created() {
    this.userInfo = JSON.parse(
      localStorage.getItem("xh_control_userInfo")
    ).content;
    this.init();
  },
  methods: {
    init() {
      autoapp_detail({ regionid: this.userInfo.regionid }).then((res) => {
        this.showLoading = false;
        if (res.code === 0) {
          if (res.obj) {
            console.log(res.obj);
            this.adminInfo = {
              appPackage: res.obj.appPackage,
              authUrl: res.obj.authUrl,
              singleType: res.obj.singleType
            };
          }
        } else {
          this.$Message.error(res.msg);
        }
      });
    },
    //刷新页面
    Refresh() {
      location.reload();
    },
    saveInfo() {
      if (!this.adminInfo.password) {
        this.$Message.error("请输入管理密码！");
        return;
      }
      let form = {
        regionid: this.userInfo.regionid,
        appPackage: this.adminInfo.appPackage,
        authUrl: this.adminInfo.authUrl,
        singleType: this.adminInfo.singleType
      };
      console.log(form);
      this.showLoading = true;
      autoapp_edit(form).then((res) => {
        this.showLoading = false;
        if (res.code === 0) {
          console.log(res.obj);
          this.$Message.success(res.msg);
        } else {
          this.$Message.error(res.msg);
        }
      });
    }
  }
};
</script>

<style lang="less" scoped>
.main_root {
  position: relative;
  padding: 40px 100px;
  .header {
    margin-top: 10px;
    width: 100%;
    height: 92px;
    border-radius: 8px;
    border: 1px dashed #ced9f2;
    background-color: #f1f6fc;
    padding: 6px 0;
    .comm {
      padding-left: 20px;
      height: 40px;
      line-height: 40px;
      &::before {
        content: "*" !important;
        display: inline-block;
        margin-right: 4px;
        line-height: 1;
        font-family: SimSun;
        font-size: 14px;
        color: #ed4014;
      }
    }
  }
  .content {
    width: 500px;
    margin: 100px auto 40px;
  }
  .footer {
    text-align: center;
  }
}
</style>
