<template>
  <div class="testdiv">
    <div class="divborder newSearchDiv" style="margin:0px;">
      <div class="filter">
        <label>{{$t('101066')}}：</label>
        <Select
          v-model="project"
          label-in-value
          @on-change="projectChange"
          clearable
          class="searchSelect"
        >
          <Option v-for="item in projects" :value="item.id" :key="item.id">{{ item.title }}</Option>
        </Select>
      </div>
      <div>
        <div class="filter" style="height:165px;">
          <label>{{$t('920020')}}：</label>
          <Input
            v-model="txt"
            type="textarea"
            :autosize="{minRows: 5,maxRows: 5}"
            placeholder="Enter License..."
            class="searchInput MaxWidth"
          />
        </div>
      <div class="searchBtn" style="margin-left:105px;">
          <Button type="primary" class="twoWord" icon="ios-build" @click="save(0)">{{$t('900306')}}</Button>
      </div>
      </div>
      <div>
        <div class="filter" style="height:165px">
          <label>MySql配置：</label>
          <Input
            v-model="txt1"
            type="textarea" :autosize="{minRows: 5,maxRows: 5}"
            placeholder="Enter script..."
            class="searchInput MaxWidth"
          />
        </div>
        <div class="searchBtn" style="margin-left:105px;">
          <Button type="primary" class="twoWord" icon="ios-build" @click="save(1)">{{$t('900306')}}</Button>
        </div>
      </div>
      <!-- <div>
        <div class="filter" style="height:120px">
          <label>HBase配置:</label>
          <Input
            v-model="txt2"
            type="textarea" :autosize="{minRows: 5,maxRows: 5}"
            placeholder="Enter License..."
            style="width: 600px;"
          /><Button type="primary" icon="ios-build" @click="save(2)">{{$t('900306')}}</Button>
        </div>
      </div> -->
      <div class="filter"></div>
    </div>
  </div>
</template>
<script>
import axios from '@/libs/api.request'
export default {
    name: 'Businessmanagement', // 组件不刷新
    data () {
        return {
            txt: '',
            txt1: '',
            txt2: '',
            project: '',
            projects: []
        }
    },
    created () {
        this.init()
    },
    methods: {
        init () {
            axios
                .request({
                    url: '/config/Project/getProjectLists',
                    method: 'get'
                })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.projects = res.data.data
                    }
                })
        },
        projectChange () {
            var params = {
                projectId: this.project
            }
            axios
                .request({
                    url: '/config/License/GetLicense',
                    params,
                    method: 'get'
                })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.txt = res.data.data
                    }
                })
        },
        save (type) {
            if (this.project === '') {
                this.$Message.error(this.$t(100102))
                return
            }
            if (this.txt === '') {
                this.$Message.error(this.$t(90000088))
                return
            }
            if (type == 0) {
                var data = {
                    projectId: this.project,
                    license: this.txt
                }
                axios
                    .request({
                        url: '/config/License/SetLicense',
                        data,
                        method: 'post'
                    })
                    .then(res => {
                        if (res.data.ret === 1) {
                            this.$Message.success(this.$t(1055))
                        } else {
                            this.$Message.error(this.$t(res.data.msg))
                        }
                    })
            } else if (type == 1) {
                var data = {
                    projectId: this.project,
                    sql: this.txt1
                }
                axios
                    .request({
                        url: '/config/License/CreateTable',
                        data,
                        method: 'post'
                    })
                    .then(res => {
                        if (res.data.ret === 1) {
                            this.$Message.success(this.$t(1055))
                        } else {
                            this.$Message.error(this.$t(res.data.msg))
                        }
                    })
            }
        }
    }
}
</script>
