<template>
  <div class="app-container">
    <el-form :model="form" :rules="rules"  ref="form" label-width="150px">
<!--      <el-row>
        <el-form-item label="站点标题" prop="homeTitle">
          <el-input v-model="form.homeTitle" placeholder="请输入站点标题" />
        </el-form-item>
      </el-row>-->
      <el-row>
        <el-form-item label="banner图" prop="bannerOne">
          <ImageUpload2 v-model="form.bannerOne"/>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="聊天配置" prop="chatUrl">
          <el-input v-model="form.chatUrl" placeholder="请输入聊天配置" />
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="默认语言" prop="defaultLocal">
          <el-select v-model="form.defaultLocal" placeholder="请选择默认语言" size="small">
            <el-option key="ch" label="简体中文" value="zh_CN" />
            <el-option key="en" label="英语" value="en_US" />
<!--            <el-option key="in" label="印度语" value="gu_IN" />-->
          </el-select>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="货币单位" prop="defaultCoinUnit">
          <el-input v-model="form.defaultCoinUnit" placeholder="请输入货币单位" />
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="开启提现码功能" prop="openWithdrawCode">
          <el-select v-model="form.openWithdrawCode" placeholder="开启提现码功能" size="small">
            <el-option key="1" label="关闭" :value="false" />
            <el-option key="2" label="开启" :value="true" />
          </el-select>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="提现码" prop="withdrawCode">
          <el-input v-model="form.withdrawCode" placeholder="请输入提现码" />
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="手机号码格式" prop="randomPhoneVersion">
          <el-select v-model="form.randomPhoneVersion" placeholder="请选择手机号码格式" size="small">
            <el-option key="ch" label="中国号码" value="china" />
            <el-option key="en" label="印度号码" value="yindu" />
          </el-select>
        </el-form-item>
      </el-row>


<!--      <el-row>
        <el-form-item label="公章" prop="commonSeal">
          <imageUpload  v-model="form.bannerUrl"/>
        </el-form-item>
      </el-row>-->
      <el-form-item>
        <el-button :loading="buttonLoading"  v-hasPermi="['dk:HomeSetting:edit']" type="primary" size="mini" @click="submitForm">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  getHomeSetting,
  updateHomeSetting
} from '@/api/dk/HomeSetting'
import ImageUpload from '@/components/ImageUpload/index'

export default {
  name: "HomeSetting",
  components: {
    ImageUpload
  },
  data() {
    return {
      //按钮loading
      buttonLoading: false,
      // 表单参数
      form: {
        homeTitle: undefined,
        bannerOne: undefined,
        commonSeal: undefined,
        chatUrl: undefined,
        defaultLocal: undefined,
        defaultCoinUnit: undefined,
        withdrawCode: undefined,
        randomPhoneVersion: undefined,
        openWithdrawCode: undefined,
      },
      // 表单校验
      rules: {
      },
      formDisable:true,
    };
  },
  created() {
    this.init();
  },
  methods: {
    init(){
      this.refreshData(this.form.appType);
    },
    refreshData(){
      getHomeSetting().then(response => {
        this.form = response.data;
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          updateHomeSetting({
            id:this.form.id,
            homeTitle: this.form.homeTitle,
            bannerOne:this.form.bannerOne,
            commonSeal:this.form.commonSeal,
            chatUrl: this.form.chatUrl,
            defaultLocal: this.form.defaultLocal,
            defaultCoinUnit: this.form.defaultCoinUnit,
            withdrawCode: this.form.withdrawCode,
            randomPhoneVersion: this.form.randomPhoneVersion,
            openWithdrawCode: this.form.openWithdrawCode
          }).then(response => {
            this.formDisable = true;
            this.buttonLoading = false;
            this.msgSuccess("修改成功");
          }).catch(() => {
            this.formDisable = true;
            this.buttonLoading = false;
          });
        }
      });
    }
  }
};
</script>
