<template> 
 | 
    <div class="tl"> 
 | 
        <!--    工单详情信息    --> 
 | 
        <V-WorkOrderInfo :info="info"></V-WorkOrderInfo> 
 | 
        <div class="tl_title"> 
 | 
            <div class="tl_title_left"> 
 | 
                <div class="tl_title_left_x"></div> 
 | 
                <span>生产点检</span> 
 | 
            </div> 
 | 
            <div class="tl_title_right" @click="add"> 
 | 
                <img src="@/assets/icon/gongdan_ic_shoudong@2x.png" alt="" /> 
 | 
                <span>增加属性</span> 
 | 
            </div> 
 | 
        </div> 
 | 
        <van-swipe-cell v-for="(item, index) in formList" :key="index"> 
 | 
            <div class="tl_list"> 
 | 
                <div class="tl_list_item" @click="open(index)"> 
 | 
                    <div class="tl_list_item_label">生产属性</div> 
 | 
                    <div class="tl_list_item_go"> 
 | 
                        <span :style="item.attributeName ? 'color: #000;' : ''">{{ item.attributeName ? item.attributeName : '请选择'}}</span> 
 | 
                        <van-icon name="arrow" color="#999999" /> 
 | 
                    </div> 
 | 
                </div> 
 | 
                <div class="tl_list_item" v-if="item.type === ''"> 
 | 
                    <div class="tl_list_item_label">属性值</div> 
 | 
                    <div class="tl_list_item_go"> 
 | 
                        <input type="text" v-model="item.num" placeholder="请输入" /> 
 | 
                    </div> 
 | 
                </div> 
 | 
                <div class="tl_list_item" v-else-if="item.type === 0"> 
 | 
                    <div class="tl_list_item_label">属性值</div> 
 | 
                    <div class="tl_list_item_go"> 
 | 
                        <van-radio-group v-model="item.num" direction="horizontal"> 
 | 
                            <van-radio :name="item1" checked-color="#4275FC" v-for="(item1, i) in item.data" :key="i">{{item1}}</van-radio> 
 | 
                        </van-radio-group> 
 | 
                    </div> 
 | 
                </div> 
 | 
                <div class="tl_list_item" v-else-if="item.type === 1"> 
 | 
                    <div class="tl_list_item_label">属性值</div> 
 | 
                    <div class="tl_list_item_go"> 
 | 
                        <van-checkbox-group v-model="item.num" direction="horizontal"> 
 | 
                            <van-checkbox :name="item1" v-for="(item1, i) in item.data" :key="i">{{item1}}</van-checkbox> 
 | 
                        </van-checkbox-group> 
 | 
                    </div> 
 | 
                </div> 
 | 
                <div class="tl_list_item" v-else-if="item.type === 2"> 
 | 
                    <div class="tl_list_item_label">属性值</div> 
 | 
                    <div class="tl_list_item_go"> 
 | 
                        <input type="text" v-model="item.num" :placeholder="item.tips" /> 
 | 
                    </div> 
 | 
                </div> 
 | 
                <div class="tl_list_item" v-else-if="item.type === 3"> 
 | 
                    <div class="tl_list_item_label">属性值</div> 
 | 
                    <div class="tl_list_item_go"> 
 | 
                        <input type="text" v-model="item.num" :placeholder="item.tips" /> 
 | 
                    </div> 
 | 
                </div> 
 | 
                <div class="tl_list_item" @click="openTimer(index)" v-else-if="item.type === 4"> 
 | 
                    <div class="tl_list_item_label">属性值</div> 
 | 
                    <div class="tl_list_item_go"> 
 | 
                        <span :style="item.num ? 'color: #000;' : ''">{{item.num ? item.num : item.tips}}</span> 
 | 
                        <van-icon name="arrow" color="#999999" /> 
 | 
                    </div> 
 | 
                </div> 
 | 
            </div> 
 | 
            <template #right> 
 | 
                <van-button square style="height: 100%;" type="danger" text="删除" @click="dele(index)" /> 
 | 
            </template> 
 | 
        </van-swipe-cell> 
 | 
  
 | 
        <div class="tl_zw"></div> 
 | 
        <div class="tl_footer"> 
 | 
            <button class="tl_footer_submit" v-preventReClick @click="submit">提交</button> 
 | 
        </div> 
 | 
    </div> 
 | 
    <!--  选择生产属性  --> 
 | 
    <van-popup v-model:show="show" position="bottom" round :style="{ height: '50%' }"> 
 | 
        <van-picker 
 | 
            title="选择生产属性" 
 | 
            :columns="gzqjData" 
 | 
            @confirm="gzqjConfirm" 
 | 
            @cancel="onCancel" 
 | 
        /> 
 | 
    </van-popup> 
 | 
    <!--  日期  --> 
 | 
<!--    <van-calendar v-model:show="timer" :min-date="minDate" :max-date="maxDate" color="#4275FC" @confirm="onConfirm" />--> 
 | 
    <!--  日期  --> 
 | 
    <van-popup v-model:show="timer" position="bottom" :style="{ height: '50%' }"> 
 | 
        <van-datetime-picker 
 | 
            type="datetime" 
 | 
            title="请选择时间" 
 | 
            :min-date="minDate" 
 | 
            :max-date="maxDate" 
 | 
            @confirm="onConfirm" 
 | 
            @cancel="cancelData" 
 | 
        /> 
 | 
    </van-popup> 
 | 
</template> 
 | 
  
 | 
<script setup lang="ts"> 
 | 
    import { ref, onMounted } from 'vue' 
 | 
    import { useRoute, useRouter } from "vue-router" 
 | 
    import { queryById, getJdList, createDJ } from '@/apis/WorkOrderAPI' 
 | 
    import { Toast } from 'vant' 
 | 
    import { setTimeO } from '@/utils/utils' 
 | 
    import VWorkOrderInfo from '@/components/common/WorkOrderInfo.vue' 
 | 
  
 | 
    const route = useRoute() 
 | 
  
 | 
    const router = useRouter() 
 | 
  
 | 
    // 控制日期显示隐藏 
 | 
    let timer = ref<boolean>(false) 
 | 
  
 | 
    const minDate: Date = new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 1, new Date().getHours(), new Date().getMinutes()) 
 | 
  
 | 
    const maxDate: Date = new Date(new Date().getFullYear() + 1, 12, 30) 
 | 
  
 | 
    // 属性索引 
 | 
    let indexs: any = ref<number>() 
 | 
  
 | 
    let info: any = ref({}) 
 | 
  
 | 
    // 属性信息数组 
 | 
    let formList: any = ref([ 
 | 
        { 
 | 
            id: Date.now(), 
 | 
            attribute: '',       // 属性值 
 | 
            attributeName: '',   // 属性值名称 
 | 
            data: '',            // 数据 
 | 
            type: '',            // 类型 
 | 
            tips: '',            // 提示子 
 | 
            num: ''              // 数量 
 | 
        } 
 | 
    ]) 
 | 
  
 | 
    // 属性数据 
 | 
    const gzqjData: any = ref([]); 
 | 
  
 | 
    const show = ref<boolean>(false) 
 | 
  
 | 
    // 打开日期插件 
 | 
    const openTimer = (i: number) => { 
 | 
        indexs.value = i 
 | 
        timer.value = true 
 | 
    } 
 | 
  
 | 
    // 关闭时间弹框 
 | 
    const cancelData = () => { 
 | 
        timer.value = false 
 | 
    } 
 | 
  
 | 
    // 日期确认 
 | 
    const onConfirm = (value: any) => { 
 | 
        formList.value.forEach((item: any, index: number) => { 
 | 
            if (indexs.value === index) { 
 | 
                item.num = setTimeO(value, '-') 
 | 
            } 
 | 
        }) 
 | 
        timer.value = false; 
 | 
    } 
 | 
  
 | 
    // 打开属性弹框 
 | 
    const open = (index: number): void => { 
 | 
        indexs.value = index 
 | 
        show.value = true 
 | 
    } 
 | 
  
 | 
    // 属性确认 
 | 
    const gzqjConfirm = (value: any): void => { 
 | 
        formList.value.forEach((item: any, index: number) => { 
 | 
            if (indexs.value === index) { 
 | 
                item.attribute = value.id 
 | 
                item.attributeName = value.text 
 | 
                item.type = value.type 
 | 
                item.data = value.data 
 | 
                item.tips = value.tips 
 | 
                console.log(value) 
 | 
                item.num = '' 
 | 
                if (item.type === 1) { 
 | 
                    item.num = [] 
 | 
                } else if (item.type === 0) { 
 | 
                    item.num = item.data[0] 
 | 
                } 
 | 
                if (value.type === 4) { 
 | 
                    formList.value[indexs.value].num = setTimeO(new Date(), '-') 
 | 
                } 
 | 
            } 
 | 
        }) 
 | 
        show.value = false 
 | 
    } 
 | 
  
 | 
    // 关闭弹框 
 | 
    const onCancel = (): void => { 
 | 
        show.value = false 
 | 
    } 
 | 
  
 | 
    // 添加点检信息 
 | 
    const add = (): void => { 
 | 
        formList.value.push({ id: Date.now(), attribute: '', attributeName: '', num: '', type: '', data: '', tips: '' }) 
 | 
    } 
 | 
  
 | 
    // 删除点检信息 
 | 
    const dele = (index: number): void => { 
 | 
        if (formList.value.length === 1) { 
 | 
            Toast('至少保留一条点检信息') 
 | 
            return 
 | 
        } 
 | 
        formList.value.splice(index, 1) 
 | 
    } 
 | 
  
 | 
    // 提交点检 
 | 
    const submit = (): void => { 
 | 
        let isOpen: any = true 
 | 
  
 | 
        formList.value.forEach((item: any) => { 
 | 
            if (item.type === 1) { 
 | 
                if (item.attribute === '' || item.num.length === 0) { 
 | 
                    isOpen = false 
 | 
                } 
 | 
            } else { 
 | 
                if (item.attribute === '' || item.num === '') { 
 | 
                    isOpen = false 
 | 
                } 
 | 
            } 
 | 
        }) 
 | 
  
 | 
        if (isOpen) { 
 | 
            let attrList: any = [] 
 | 
            formList.value.forEach((item: any) => { 
 | 
                if (item.type === 1) { 
 | 
                    attrList.push({ val: item.num.join(' '), attrId: item.attribute }) 
 | 
                } else { 
 | 
                    attrList.push({ val: item.num, attrId: item.attribute }) 
 | 
                } 
 | 
            }) 
 | 
            createDJ({ 
 | 
                attrList: attrList, 
 | 
                id: route.query.id 
 | 
            }).then(res => { 
 | 
                if (res.code === 200) { 
 | 
                    Toast.success({ 
 | 
                        message: '创建成功', 
 | 
                        duration: 2000, 
 | 
                        forbidClick: true 
 | 
                    }) 
 | 
                    setTimeout(() => { 
 | 
                        router.go(-1) 
 | 
                    }, 2000) 
 | 
                } 
 | 
            }) 
 | 
        } else { 
 | 
            Toast({ 
 | 
                message: '请将信息填写完整', 
 | 
                duration: 2000 
 | 
            }) 
 | 
        } 
 | 
    } 
 | 
  
 | 
    // 获取详情数据 
 | 
    const queryByIds = (): void => { 
 | 
        queryById(route.query.id).then(res => { 
 | 
            if (res.code === 200) { 
 | 
                info.value = res.data 
 | 
            } 
 | 
        }) 
 | 
    } 
 | 
  
 | 
    // 属性值数据 
 | 
    const getJdLists = () => { 
 | 
        getJdList({ workOrderID: route.query.id }) 
 | 
            .then(res => { 
 | 
                if (res.code === 200 && res.data && res.data.length !== 0) { 
 | 
                    res.data.forEach((item: any) => { 
 | 
                        gzqjData.value.push({ text: item.name, id: item.id, type: item.type, data: item.remark ? item.remark.split(' ') : '', tips: item.tips }) 
 | 
                    }) 
 | 
                } 
 | 
            }) 
 | 
    } 
 | 
  
 | 
    onMounted(() => { 
 | 
        queryByIds() 
 | 
        getJdLists() 
 | 
    }) 
 | 
</script> 
 | 
  
 | 
<style lang="scss" scoped> 
 | 
    .tl { 
 | 
        width: 100%; 
 | 
        height: 100%; 
 | 
        position: absolute; 
 | 
        background: #F7F7F7; 
 | 
        .tl_title { 
 | 
            display: flex; 
 | 
            align-items: center; 
 | 
            justify-content: space-between; 
 | 
            padding: 30px; 
 | 
            .tl_title_left { 
 | 
                display: flex; 
 | 
                align-items: center; 
 | 
                .tl_title_left_x { 
 | 
                    width: 8px; 
 | 
                    height: 30px; 
 | 
                    background: $nav-color; 
 | 
                    border-radius: 2px; 
 | 
                    margin-right: 12px; 
 | 
                } 
 | 
                span { 
 | 
                    font-size: 32px; 
 | 
                    font-weight: 500; 
 | 
                    color: #222222; 
 | 
                } 
 | 
            } 
 | 
            .tl_title_right { 
 | 
                display: flex; 
 | 
                align-items: center; 
 | 
                img { 
 | 
                    width: 28px; 
 | 
                    height: 28px; 
 | 
                    margin-right: 12px; 
 | 
                } 
 | 
                span { 
 | 
                    font-size: 28px; 
 | 
                    font-weight: 400; 
 | 
                    color: $nav-color; 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
        .tl_list { 
 | 
            display: flex; 
 | 
            flex-direction: column; 
 | 
            background: white; 
 | 
            padding: 0 30px; 
 | 
            margin-bottom: 20px; 
 | 
            .tl_list_item { 
 | 
                min-height: 98px; 
 | 
                display: flex; 
 | 
                align-items: center; 
 | 
                justify-content: space-between; 
 | 
                border-bottom: 1px solid #E5E5E5; 
 | 
                &:last-child { 
 | 
                    border: none; 
 | 
                } 
 | 
                .tl_list_item_label { 
 | 
                    font-size: 30px; 
 | 
                    font-weight: 400; 
 | 
                    color: #222222; 
 | 
                } 
 | 
                .tl_list_item_go { 
 | 
                    display: flex; 
 | 
                    align-items: center; 
 | 
                    input { 
 | 
                        text-align: right; 
 | 
                        width: 450px; 
 | 
                        height: 60px; 
 | 
                        border-radius: 8px; 
 | 
                        border: 1PX solid #E5E5E5; 
 | 
                        padding: 0 30px; 
 | 
                        box-sizing: border-box; 
 | 
                        font-size: 28px; 
 | 
                        font-weight: 400; 
 | 
                        color: #333333; 
 | 
                    } 
 | 
                    span { 
 | 
                        font-size: 28px; 
 | 
                        font-weight: 400; 
 | 
                        color: #999999; 
 | 
                        margin-right: 10px; 
 | 
                    } 
 | 
                } 
 | 
            } 
 | 
        } 
 | 
        .tl_zw { 
 | 
            height: 160px; 
 | 
        } 
 | 
        .tl_footer { 
 | 
            width: 100%; 
 | 
            position: fixed; 
 | 
            bottom: 0; 
 | 
            left: 0; 
 | 
            padding: 0 30px 68px 30px; 
 | 
            box-sizing: border-box; 
 | 
            .tl_footer_submit { 
 | 
                width: 690px; 
 | 
                height: 88px; 
 | 
                border: none; 
 | 
                background: #4275FC; 
 | 
                box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.08); 
 | 
                border-radius: 8px; 
 | 
                font-size: 30px; 
 | 
                font-weight: 500; 
 | 
                color: #FFFFFF; 
 | 
                display: flex; 
 | 
                align-items: center; 
 | 
                justify-content: center; 
 | 
            } 
 | 
        } 
 | 
    } 
 | 
</style> 
 |