<template>
    <div class="testdiv">
        <div  class="divborder" style="margin:0px">
            <Row>
                <Col span="24"  class="font_place tolerance_title" v-text="$t(8000021)">计划维护容差</Col>
            </Row>
             <br>
            <Row type="flex" justify="space-around" align="middle" class="font_place code-row-bg">
                <Col span="2"></Col>
                <Col span="2" v-text="$t('1101')">天</Col>
                <Col span="2" v-text="$t('1136')">周</Col>
                <Col span="2" v-text="$t('1137')">两周</Col>
                <Col span="2" v-text="$t('1138')">月</Col>
                <Col span="2" v-text="$t('1139')">两月</Col>
                <Col span="2" v-text="$t('1140')">季度</Col>
                <Col span="2" v-text="$t('1141')">半年</Col>
                <Col span="2" v-text="$t('1142')">年</Col>
            </Row>
            <br>
            <Row type="flex" justify="space-around" align="middle" class="font_place">
                <Col span="2">±</Col>
                <Col span="2" >
                  <InputNumber  :min="0" :max="1" style="text-align:center " v-model="date_data[0].space_time" disabled></InputNumber>
                </Col>
                <Col span="2">
                  <InputNumber  :min="0" :max="7" style="text-align:center " v-model="date_data[1].space_time" ></InputNumber>
                </Col>
                <Col span="2" >
                  <InputNumber  :min="0" :max="14" style="text-align:center " v-model="date_data[2].space_time" ></InputNumber>
                </Col>
                <Col span="2">
                  <InputNumber  :min="0" :max="30" style="text-align:center " v-model="date_data[3].space_time"></InputNumber>
                </Col>
                <Col span="2" >
                  <InputNumber  :min="0" :max="60" style="text-align:center " v-model="date_data[4].space_time" ></InputNumber>
                </Col>
                <Col span="2" >
                  <InputNumber  :min="0" :max="90" style="text-align:center " v-model="date_data[5].space_time" ></InputNumber>
                </Col>
                <Col span="2">
                  <InputNumber  :min="0" :max="180" style="text-align:center " v-model="date_data[6].space_time" ></InputNumber>
                </Col>
                <Col span="2">
                  <InputNumber  :min="0" :max="365" style="text-align:center " v-model="date_data[7].space_time" ></InputNumber>
                </Col>
            </Row>
            <br>
             <Row type="flex" justify="space-around" align="middle" class="font_place">
                <Col span="2"></Col>
                <Col span="2">≤1</Col>
                <Col span="2">≤7</Col>
                <Col span="2">≤14</Col>
                <Col span="2">≤30</Col>
                <Col span="2">≤60</Col>
                <Col span="2">≤90</Col>
                <Col span="2">≤180</Col>
                <Col span="2">≤365</Col>
            </Row>
            <Row  class="font_place" style="margin-top:15px;">
                <Col span="1" push="22">
                   <Button type="primary" @click="setSetting" v-text="$t(900306)">保存</Button>
                </Col>
            </Row>
        </div>
    </div>
</template>
<script>
export default {
    data () {
        return {
            date_data: [{
                type: 1,
                space_time: 0,
                mode: 0,
                able: true,
                max: 1
            }, {
                type: 2,
                space_time: 1,
                mode: 0,
                able: false,
                max: 7
            }, {
                type: 3,
                space_time: 1,
                mode: 0,
                able: false,
                max: 14
            }, {
                type: 4,
                space_time: 1,
                mode: 0,
                able: false,
                max: 30
            }, {
                type: 5,
                space_time: 1,
                mode: 0,
                able: false,
                max: 60
            }, {
                type: 6,
                space_time: 1,
                mode: 0,
                able: false,
                max: 90
            }, {
                type: 7,
                space_time: 1,
                mode: 0,
                able: false,
                max: 180
            }, {
                type: 8,
                space_time: 1,
                mode: 0,
                able: false,
                max: 365
            }]
        }
    },
    created () {
        this.getSetting()
    },
    methods: {
        getSetting () {
            var params = {
                mode: 0
            }
            this.axios.request({
                url: '/tpm/Plan/GetSelectedtolerance',
                params,
                method: 'get'
            })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.date_data = res.data.data
                    } else {
                    }
                })
        },
        setSetting () {
            var truevalue = false
            this.date_data.forEach((item) => {
                if (item.space_time === 0) {

                } else {
                    if (!item.space_time) {
                        truevalue = true
                        return false
                    }
                }
            })
            if (truevalue) {
                this.$Message.error(this.$t(930112))
                return false
            }
            var data = {
                data: this.date_data
            }
            this.axios.request({
                url: '/tpm/Plan/Edittolerance',
                data,
                method: 'post'
            })
                .then(res => {
                    if (res.data.ret === 1) {
                        this.getSetting()
                        this.$Message.success(this.$t(1060))
                    } else {
                        this.$Message.error(this.$t(res.data.msg))
                    }
                })
        }
    }
}
</script>
<style lang="less" scoped>
 .font_place{
     text-align: center
 }
 .tolerance_title{
     font-size: 20px;
     font-weight: 600;
 }
</style>
