<template>
    <ifrm ref="ifrm">
        <!-- 安全点检 -->
        <uni-forms ref="form" err-show-type="toast">
            <uni-forms-item name="allegation"><input type="text" :focus="oneInputFcous" v-model="oneInput"
                    @input="oneInputBlur" class="uni-input-border" placeholder="设备" /></uni-forms-item>
        </uni-forms>
        <uni-card title="设备信息">
            <t-table>
                <t-tr>
                    <t-td>编号</t-td>
                    <t-td>{{ facilityObj.deviceCode }}</t-td>
                </t-tr>
                <t-tr>
                    <t-td>名称</t-td>
                    <t-td>{{ facilityObj.deviceName }}</t-td>
                </t-tr>
                <t-tr>
                    <t-td>状态</t-td>
                    <t-td>{{ facilityObj.usedText }}</t-td>
                </t-tr>
            </t-table>
        </uni-card>
        <uni-forms ref="form" err-show-type="toast">
            <uni-forms-item><uni-easyinput type="textarea" autoHeight v-model="memo"
                    placeholder="请输入内容"></uni-easyinput></uni-forms-item>
        </uni-forms>
        <view class="buttonBox"><button class="button" type="primary" :disabled="!(Object.keys(facilityObj).length > 0)"
                @click="submitClick">提交</button></view>
    </ifrm>
</template>

<script>
    import ifrm from '@/pages/index/ifrm';
    import tTable from '@/components/t-table/t-table.vue';
    import tTh from '@/components/t-table/t-th.vue';
    import tTr from '@/components/t-table/t-tr.vue';
    import tTd from '@/components/t-table/t-td.vue';
    import inputBlur from '@/mixin/inputBlur.js';
    export default {
        mixins: [inputBlur],
        components: {
            ifrm,
            tTable,
            tTh,
            tTr,
            tTd
        },
        data() {
            return {
                facilityObj: {},
                memo: '',
            };
        },
        methods: {

            oneInputData(code) {
                uni.hideKeyboard()
                if (!code) return;
                this.oneInput = code;
                this.$ajax.request({
                    url: 'pdaLoad/getEcByDeviceCode',
                    method: 'POST',
                    data: {
                        deviceCode: code
                    },
                    success: data => {
                        this.clearOneInput()
                        this.facilityObj = data;
                        uni.showToast({
                            title: '数据获取成功'
                        });
                    }
                })
            },
            submitClick() {
                let deEquipmentRepair = {
                    equipmentCard: this.facilityObj,
                    memo: this.memo,
                }
                this.$ajax.request({
                    url: 'pdaSave/saveEqRepair',
                    method: 'POST',
                    data: deEquipmentRepair,
                    success: data => {
                        this.clearOneInput()
                        this.memo = ''
                        this.facilityObj = {}
                        uni.showToast({
                            title: '报修成功'
                        });
                    }
                });
            }
        },
        onNavigationBarButtonTap(btn) {
            this.$refs.ifrm.topMenuClick(btn);
        },
        onShow() {}
    };
</script>

<style scoped>
    .uni-forms-item {
        margin-bottom: 6px !important;
    }
</style>