<template>
  <div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="200px">
      <!--小程序登录设置-->
      <div class="common-form">小程序登录设置</div>

      <el-form-item label="是否开启验证码登录">
        <div>
          <el-radio v-model="form.is_open" :label="1">开启</el-radio>
          <el-radio v-model="form.is_open" :label="0">关闭</el-radio>
        </div>
      </el-form-item>
      <!--提交-->
      <div class="common-button-wrapper">
        <el-button type="primary" @click="onSubmit" :loading="loading">提交</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
  import SettingApi from '@/api/setting.js';

  export default {
    data() {
      return {
        /*切换菜单*/
        // activeIndex: '1',
        /*form表单数据*/
        form: {
          is_open: '',
        },
        checked: false,
        printerList: [],
        loading: false,
      };
    },
    created() {
      this.getData()
    },

    methods: {
      getData() {
        let self = this;
        SettingApi.loginDetail({}, true)
          .then(response => {
            self.form.is_open = parseInt(response.data.vars.values.is_open);
          })
          .catch(() => {});
      },
      //提交表单
      onSubmit() {
        let self = this;
        let params = this.form;
        self.loading = true;
        SettingApi.editLogin(params, true)
          .then(() => {
            self.loading = false;
            self.$message({
              message: '恭喜你，设置成功',
              type: 'success'
            });
          })
          .catch(() => {
            self.loading = false;
          });
      },
    }
  };
</script>

<style>
  .tips {
    color: #ccc;
  }
</style>
