<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 class="filter">
          <label>Redis数据库：</label>
          <Input v-model="redisdb" type="number" min=0 class="searchInput"/>
        </div>

       <div class="filter" >
          <label>DNC Host：</label>
          <Input v-model="scservice" type="text"  class="searchInput"/>
        </div>

      <div class="filter">
          <label>DNC Port：</label>
          <Input v-model="scport" type="text"  class="searchInput"/>
        </div>
        <br/>
         <div class="searchBtn">
          <Button type="primary" class="twoWord" icon="ios-build" @click="save(1)">{{$t('900306')}}</Button>
      </div>
      </div>
    </div>
</template>
<script>
import axios from '@/libs/api.request'
export default {
    name: 'Businessmanagement', // 组件不刷新
    data () {
        return {
            redisdb: '',
            scservice: '',
            scport: '',
            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/DbNameConfig/GetConfig',
                    params,
                    method: 'get'
                })
                .then(res => {
                    if (res.data.ret === 1) {
                        var data = res.data.data;
                        this.redisdb = parseInt(data.redisDBName)
                        this.scservice = data.scService
                        this.scport = data.scPort
                    }
                })
        },
        save () {
            if (this.redisdb === '') {
                this.$Message.error('请输入Redis数据库地址')
                return
            }
            var data = {
                projectId: this.project,
                redisdb: this.redisdb,
                scservice: this.scservice,
                scport: this.scport
            }
            axios
                .request({
                    url: '/config/DbNameConfig/SetConfig',
                    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>
