<template>
    <div>
        <div class="divborder newSearchDiv">
            <div class="filter">
                <label>{{$t(8218)}}：</label>
                <Input v-model="tool_name" class="searchInput" />
            </div>
            <div class="filter">
                <label>{{$t(8217)}}：</label>
                <Input v-model="tool_number" class="searchInput" />
            </div>
            <div class="filter">
                <label>{{$t(8219)}}：</label>
                <Input v-model="tool_type" class="searchInput" />
            </div>
            <div class="filter">
                <label>退货环节：</label>
                <Select v-model="checkState" clearable class="searchSelect">
                    <Option value="998">检测</Option>
                    <Option value="999">测试</Option>
                </Select>
            </div>
            <div class="searchBtn">
                <Button type="primary" class="twoWord"  icon="ios-search"  @click="search(1,10)">{{$t('1001')}}</Button>
            </div>
        </div>
        <div class="divborder newTableDiv">
            <Table
                 class="tableClass"
                :data="tableData1"
                :columns="columns1"
            ></Table>
            <div class="pageDiv">
                <div class="pageDirection">
                    <Page
                        :total="total"
                        :current="page"
                        @on-change="changePage"
                        show-elevator
                        show-sizer
                        show-total
                        @on-page-size-change="handlePageSize"
                        :page-size-opts="[10,20,30,40,100]"
                    ></Page>

                </div>
            </div>
        </div>
    </div>
</template>

<script>
import axios from '@/libs/api.request';

export default {
    data () {
        return {
            action:
                axios.publicPath +
                'ims/Upload/Submit?templateName=TechToolList',
            headers: {
                token: localStorage.getItem('token'),
                timestamp: localStorage.getItem('timestamp'),
                nonce: localStorage.getItem('nonce'),
                sign: localStorage.getItem('sign')
            },
            tool_name: '',
            tool_number: '',
            tool_type: '',
            checkState: '998,999',
            columns1: [
                {
                    type: 'index2',
                    title: this.$t('1008'),
                    key: 'xuhao',
                    render: (h, params) => {
                        return h(
                            'span',
                            params.index + (this.page - 1) * this.pagesize + 1
                        );
                    },
                    width: '70px'
                },
                {
                    title: '类别',
                    key: 'category_name',
                    width: 100
                },
                {
                    title: this.$t(8218),
                    key: 'material_name'
                },
                {
                    title: this.$t(900933),
                    key: 'part_no'
                },
                {
                    title: this.$t(600011),
                    key: 'supplier_name'
                },
                {
                    title: '退货环节',
                    key: 'state',
                    align: 'center',
                    render: (h, params) => {
                        let str = '';
                        if (params.row.state == 998 || params.row.state == 2) {
                            str = '检测';
                        }
                        if (params.row.state == 999 || params.row.state == 4) {
                            str = '测试';
                        }
                        return h('span', str);
                    }
                },
                {
                    title: '退货原因',
                    key: 'reason'
                }
            ],
            tableData1: [],
            total: 0,
            page: 1,
            pagesize: 10,
            detailobj: {}
        };
    },
    created () {
        this.search(1, 10);
        // 格式化表格样式
        this.columns1 = this.$time.initTableTitle(this.columns1)
    },
    methods: {
        search (page, pagesize) {
            let data = {
                Page: page,
                PageSize: pagesize,
                ProjectId: 0,
                state: 0,
                states: this.checkState,
                tool_number: this.tool_number,
                tool_name: this.tool_name,
                tool_type: this.tool_type
            };
            this.request('/ims/ToolTest/GetTestData', data, 'post').then(
                res => {
                    // console.log(res.data.data);
                    if (res.data.ret == 1) {
                        this.total = res.data.total;
                        this.tableData1 = res.data.data;
                    }
                }
            );
        },
        getDefendList () {
            let data = {
                Page: 0,
                PageSize: 0,
                Id: this.detailobj.tool_id,
                ProjectId: 0,
                ToolType: 1
            };
            this.request('/ims/ToolTest/GetDetection', data, 'post').then(
                res => {
                    if (res.data.ret == 1) {
                        this.defendList = res.data.data;
                        this.defendList.forEach(ele => {
                            ele.orderNumber = this.detailobj.orderNumber;
                        });
                    }
                }
            );
        },
        check () {
            if (!this.detailobj.tool_id) {
                this.$Message.error(this.$t(1043));
                return false;
            }
            this.modal = true;
        },
        submitList () {
            let data = [];
            var bool = false;
            this.defendList.forEach(ele => {
                if (
                    ele.ActualValue == '' ||
                    ele.ActualValue == undefined ||
                    ele.ActualValue == null
                ) {
                    bool = true;
                }
            });
            if (bool) {
                this.$Message.error(this.$t(8115));
                return false;
            }
            this.request(
                '/ims/ToolTest/SetTestData',
                this.defendList,
                'post'
            ).then(res => {
                console.log(res.data);
                if (res.data.ret == 1) {
                    this.$Message.success(this.$t(900345));
                    this.modal = false;
                } else {
                    this.$Message.error(this.$t(res.data.msg));
                }
            });
        },

        handlePageSize (value) {
            this.pagesize = value;
            this.tableData1 = this.search(this.page, this.pagesize);
        },
        changePage (value) {
            this.page = value;
            this.tableData1 = this.search(this.page, this.pagesize);
        },
        request (url, data, type) {
            if (type == 'get') {
                return this.axios
                    .request({
                        url: url,
                        params: data,
                        method: type
                    })
                    .then(res => {
                        return res;
                    })
                    .catch(error => error);
            } else {
                return this.axios
                    .request({
                        url: url,
                        data,
                        method: type
                    })
                    .then(res => {
                        return res;
                    })
                    .catch(error => error);
            }
        }
    }
};
</script>

<style>
</style>
