<template>
  <div class="testdiv">
    <div class="divborder newSearchDiv" style="margin:0px;">
      <div class="title">{{$t(9900063)}}</div>
      <div class="filter">
        <label>{{$t(5000047)}}：</label>
          <Select
                v-model="daynum"
                label-in-value
                clearable
                class="searchSelect MaxWidth">
                <Option v-for="item in kpilist1" :value="item.id" :key="item.id">{{ item.name }}</Option>
              </Select>
      </div>
      <div class="filter">
        <label>{{$t(5000045)}}：</label>
        <Select
                v-model="deliveryRate"
                label-in-value
                clearable
                class="searchSelect MaxWidth">
                <Option v-for="item in kpilist2" :value="item.id" :key="item.id">{{ item.name }}</Option>
              </Select>
      </div>
      <div class="filter">
        <label>{{$t(5000046)}}：</label>
        <Select
                v-model="guestComplaint"
                label-in-value
                clearable
                class="searchSelect MaxWidth">
                <Option v-for="item in kpilist3" :value="item.id" :key="item.id">{{ item.name }}</Option>
              </Select>
      </div>
    </div>

    <div class="divborder newSearchDiv" style="margin-top:10px;">
      <div class="title">{{$t(9900064)}}</div>
      <div class="filter">
        <label>{{$t(5500011)}}：</label>
          <Input class="searchInput MaxWidth" type="number" min="0" v-model="fac_ok"/>
          <span>{{$t(5500013)}}</span>
      </div>
      <div class="filter">
        <label>{{$t(5500012)}}：</label>
          <Input class="searchInput MaxWidth" type="number" min="0" v-model="fac_oee"/>
          <span>{{$t(5500013)}}</span>
      </div>
    </div>

    <div class="divborder newSearchDiv" style="margin-top:10px;">
      <div class="title">{{$t(9900065)}}</div>
      <div class="filter">
        <label>{{$t(5500011)}}：</label>
          <Input class="searchInput MaxWidth" type="number" min="0" v-model="pass_ok"/>
          <span>{{$t(5500013)}}</span>
      </div>
      <div class="filter">
        <label>{{$t(5500012)}}：</label>
          <Input class="searchInput MaxWidth" type="number" min="0" v-model="pass_oee"/>
          <span>{{$t(5500013)}}</span>
      </div>

    </div>
     <div class="divborder newSearchDiv" style="margin-top:10px;">
       <div class="searchBtn">
        <Button type="primary" class="twoWord" icon="ivu-icon ivu-icon-md-add-circle" @click="addp()">{{$t('900306')}}</Button>
        </div>
      </div>
  </div>
</template>
<script>
import axios from '@/libs/api.request'
import moment from 'moment'
export default {
    name: 'Businessmanagement', // 组件不刷新
    data () {
        return {
            kpilist1: [],
            kpilist2: [],
            kpilist3: [],
            daynum: '',
            deliveryRate: '',
            guestComplaint: '',
            fac_ok: '',
            fac_oee: '',
            pass_ok: '',
            pass_oee: ''
        }
    },
    created () {
        this.getkpilist()
        this.search()
    },
    methods: {
        getkpilist () {
            axios
                .request({
                    url: '/kpi/Item/GetAllItems',
                    method: 'get'
                })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.kpilist1 = res.data.data
                        this.kpilist2 = res.data.data
                        this.kpilist3 = res.data.data
                    }
                })
        },
        search () {
            axios
                .request({
                    url: '/dashboard/DashboardCnConfig/GetTotalSet',
                    method: 'get'
                })
                .then(res => {
                    if (res.data.ret === 1) {
                        var item = res.data.data
                        this.daynum = item.safe_day === '' ? 0 : parseInt(item.safe_day)
                        this.deliveryRate = item.delivery_rate === '' ? 0 : parseInt(item.delivery_rate)
                        this.guestComplaint = item.complaint_count === '' ? 0 : parseInt(item.complaint_count)
                        this.fac_ok = item.factory_ftq
                        this.fac_oee = item.factory_oee
                        this.pass_ok = item.passway_ftq
                        this.pass_oee = item.passway_oee
                    }
                })
        },
        addp () {
            var data = {
                safe_day: this.daynum,
                delivery_rate: this.deliveryRate,
                complaint_count: this.guestComplaint,
                factory_ftq: this.fac_ok,
                factory_oee: this.fac_oee,
                passway_ftq: this.pass_ok,
                passway_oee: this.pass_oee
            }
            axios
                .request({
                    url: '/dashboard/DashboardCnConfig/SetTotalSet',
                    data,
                    method: 'post'
                })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.$Message.success(this.$t('1064'));
                        this.search();
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                    }
                })
        }
    }
}
</script>
<style lang="less" scoped>
.title{
    display: block;
    height: 40px;
    background-color: #ddd;
    padding-left: 10px;
    line-height: 40px;
    font-size: 14px;
    margin-bottom: 10px;
    font-weight: bold;
}

.filter{
  display:block;
  margin-left:100px;
}
label {
  width: 120px!important;
  display: inline-block;
  text-align: right;
}
input{
  margin-right:10px;
}
</style>
