<template>

  <div class="container-fluid mt-1">
    <div class="card">
      <div class="row">
        <div class="col-1">选择服务器</div>
        <div class="col-2">
          <el-select v-model="serverselected" placeholder="选择服务器">
            <el-option v-for="item in servers" :key="item.value" :label="item.value" :value="item.value">
            </el-option>
          </el-select>
        </div>
        <div class="col-1">玩家唯一ID</div>
        <div class="col-2">
          <el-input v-model="puid" placeholder="玩家唯一ID"></el-input>
        </div>
      </div>
    </div>
  </div>

  <div class="container-fluid mt-1">
    <div class="card">
      <div class="row">
        <div class="col-3">
          <div class="card">
            <el-form ref="form" :model="formAddMoney" label-width="80px">
              <el-form-item label="货币类型">
                <el-select v-model="formAddMoney.tp" placeholder="请选择货币类型">
                  <el-option label="金币" value="2"></el-option>
                  <el-option label="钻石" value="3"></el-option>
                  <el-option label="体力" value="4"></el-option>
                  <el-option label="经验值" value="1"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="添加值">
                <el-input v-model="formAddMoney.count"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onAddMoney">货币添加</el-button>
              </el-form-item>
            </el-form>
          </div>
        </div>
        <div class="col-3">
        </div>
        <div class="col-3"></div>
        <div class="col-3">
        </div>
      </div>
    </div>
  </div>


  <div id="output">
    <el-button round type="primary" class="btn-block" v-on:click="ontest">测试</el-button>
    选择的网站是: {{ serverselected }} puid: {{ puid }}
  </div>
</template>

<script>
import axios from 'axios';
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data() {
    return {
      servers: [{
        value: '本机',
      }, {
        value: '内网测试服',
      }, {
        value: '审核服',
      }],
      serversDict: {
        '本机': 'http://localhost:9002/api/gm/action',
        '内网测试服': 'http://172.10.10.18:9002/api/gm/action',
        '审核服': 'http://152.136.44.171:40002/api/gm/action',
      },
      serverselected: '本机',
      input1: '',
      puid: '',

      formAddMoney: {
        tp: '',
        count: 0,
      }
    }
  },
  methods: {
    onGmPost: function (data) {
      data.Uid = this.puid
      axios.post(this.serversDict[this.serverselected], data)
        .then(function (response) {
          console.log(response);
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    ontest: function (event) {
      axios.post(this.serverselected, {
        Action: '服务器操作',
        Args: ["服务器信息"]
      })
        .then(function (response) {
          console.log(response);
        })
        .catch(function (error) {
          console.log(error);
        });
    },
    onAddMoney() {
      this.onGmPost({
        Action: '玩家数据修改',
        Args: ["货币添加",this.formAddMoney.tp,this.formAddMoney.count]
      })
    },
  }
}
</script>
