<template>
    <div>
        <FullPage 
        title='查看详情' 
        :showTopSearch='false' 
        :logList='logList'
        @selectTable='selectTable'
        @changePage='changePage'
        @changeSize='changeSize'
        :tableColums='tableColums'
        :tableData='tableData'
        :pageIndex='pageIndex'
        :pageSize='pageSize'
        :total='total'
        >   
            <div slot='titleButton'>
                <Button @click="back" style="margin-right:10px;">返回</Button>
                <Button @click="batchPrint" type="primary" style="margin-right:10px;" ghost>打印派工单</Button>
                <Button @click="finish(selectIds,2)" type="error" style="margin-right:10px;" ghost>批量驳回</Button>
                <Button @click="finish(selectIds,1)" type="success"  ghost>批量完成</Button>
            </div>

            <template slot='set' slot-scope='{row}'>
                <div>
                   <a v-if="row.sub_state<3" class="map-margin" style="color:#32C800" @click="finish(row,1)">完成</a>
                   <a v-if="row.sub_state<3" class="map-margin" style="color:#ed4014" @click="finish(row,2)">驳回</a>
                </div>
            </template>
        </FullPage>
    </div>
</template>

<script>
export default {
    data(){
        return {
            type:1,
            logList:[{title:'系统单号',value:'10998765'}],
            tableColums:[
                {type:'selection',fixed:'left',width:'90',align:'center'},
                {title:'房间号',align:'center',key:'number_detail',minWidth:150,
                    render:(h,params)=>{
                        const {row} = params
                        return h('span',`${row.house}-${row.unit}-${row.layer}-${row.number_detail}`)
                    }
                },
                {title:'产品',align:'center',minWidth:150,key:'product_title'},
                {title:'位置',align:'center',minWidth:150,key:'position'},
                {title:'部件',align:'center',minWidth:150,key:'part_title'},
                {title:'零部件',align:'center',minWidth:150,key:'part_detail_title'},
                {title:'部件是否贴标签',align:'center',minWidth:150,
                    render:(h,params)=>h('span',{},params.row.label == '1' ? '是' : '否')
                },
                {title:'贴标签零部件',align:'center',minWidth:150,key:'sub_part'},
                {title:'工序分类',align:'center',minWidth:150,key:'basic_title'},
                {title:'工序',align:'center',minWidth:150,key:'procedure_title'},
                {title:'班组',align:'center',minWidth:150,key:'nickname'},
                {title:'测量尺寸',align:'center',minWidth:150,key:'measure'},
                {title:'单位',align:'center',minWidth:100,key:'company'},
                {title:'芯片编号',align:'center',minWidth:150,key:'chip'},
                {title:'完工状态',align:'center',minWidth:100,
                    render:(h,params)=>h('span',{},params.row.sub_state == 3 ? '已完工' : '未完工')
                },
                {title:'操作',align:'center',slot:'set',fixed:'right',width:'150'},
            ],
            tableData:[],
            pageIndex:1,
            pageSize:10,
            total:0,
            selectIds:[],
            proxyObj:{...this.$route.query},
        }
    },
    mounted(){
        this.getData(this.$route.query)
    },
    methods:{
        back(){
            this.$router.go(-1)
        },
        getData(row){
            row.page_size = this.pageSize
            row.page_index = this.pageIndex
            this.axios('/api/orders_dispatch_detail',{params:row}).then(res=>{
                if(res.code == 200){
                    this.tableData = res.data.list;
                    this.logList = res.data.detail;
                    this.total = res.data.total
                }
            })
        },
        postData(data,type){
            let url = type == 1 ? '/api/orders_dispatch_confirm' : '/api/orders_plan_cancer'
            this.axios.post(url,data).then(res=>{
                if(res.code == 200){
                    this.$Message.success(res.msg);
                    this.getData(this.$route.query)
                }
            })
        },
        finish(row,type){
            if(!row||row.length<1){return this.$Message.warning('请至少选择一项')}
            let str = Array.isArray(row) ? row.join(',') : row.id
            this.confirmDelete({
                content:type == 1 ? '是否手动操作此订单生产完成' : '确认驳回？',
                title:type == 1 ? '生产完成' : '驳回',
                type:type == 1 ? 'primary' : 'error',
                then:()=>{
                    this.postData({id:str},type)
                },
                cancel:()=>{}
            })
        },
        selectTable(e){
            let result = [];
            e.map(v=>result.push(v.id));
            this.selectIds = result;
        },
        changePage(e){
            this.pageIndex = e;
            this.proxyObj.page_index = this.pageIndex;
            this.getData(this.proxyObj)
        },
        changeSize(e){
            this.pageSize = e;
            this.proxyObj.page_size = this.page_size;
            this.getData(this.proxyObj)
        },
        batchPrint(){
            this.confirmForm({
            title:'批量打印派工单',
            forms:[
                {name:'Select',title:'模板',value:'',serverName:'template_id',placeholder:'请选择模板',
                    option:[
                        {label:'木工',value:1},
                        {label:'开料',value:2},
                        {label:'贴皮',value:3},
                        {label:'油漆',value:4},
                        {label:'接、拼板',value:6}
                    ]
                },
            ],
            then:(result)=>{
                this.axios('/api/produce_export',{params:{...result,...this.$route.query}}).then(res=>{
                        if(res.code == 200){
                        let url = `${this.$store.state.ip}/api/storage/${res.data.file}`
                        location.href = url
                    }
                })
            }
        })
        }
    }
}
</script>

<style lang="scss" scoped>
.log-list{display: flex;flex-wrap:wrap;padding:10px 0;}
</style>