<template>
    <view class="quick-task" style="padding-bottom: 150upx">
        <cu-custom class="home-custom" bgColor=".bg-sancolor"
                   bgImage="https://ahwgh.oss-cn-hangzhou.aliyuncs.com/enterprise/6525f808df760.png" :isBack="true">
            <block slot="content">定量检测</block>
        </cu-custom>
        <view class="cu-bar search bg-white">
            <view class="text-center text-xxl text-bold padding-left-sm" @tap="scanQrCode">
                <text class="cuIcon-scan text-orange lg"></text>
            </view>
            <view class="search-form">
                <text class="cuIcon-search"></text>
                <input type="text" placeholder="输入抽样单号查询新抽样单" v-model="sampleSheetNumber" style="padding-right: 0;">
                <text class="cuIcon cuIcon-close endClass text-xxl text-bold" @tap="sampleSheetNumber = ''"
                                                                                                v-show="sampleSheetNumber !== ''"></text>
            </view>
            <view class="action">
                <button class="cu-btn bg-green shadow-blur round" @tap="searchNewSample">查询</button>
            </view>
        </view>
        <view class="padding-sm quick-list" v-if="!searchSample.id">
            <view class="cu-list menu bg-white shadow" v-for="(item, index) in listData" :key="index">
                <view class="cu-item">
                    <view class="title text-black text-bold text-lg">
                        <text class="cuIcon-titles text-green"></text>
                        {{ item.ahSampleDetailList.map(v => v.name).join(",") }}
                    </view>
                    <view class="action">
                        <text class="text-orange text-bold text-lg"
                              v-if="item.sampleStatus==='WAIT_ENTERPRISES_SUBMIT'">待确认
                        </text>
                    </view>
                </view>
                <view class="content padding-sm detail solid-bottom">
                    <!--                    <view>抽检产品：{{  }}</view>-->
                    <view>抽样任务：{{ item.ahTasks.taskName }}</view>
                    <view>任务编号：{{ item.ahTasks.taskNumber }}</view>
                    <view>年度/季度：{{ item.ahTasks.taskYear.substr(0, 4) }}-{{
                            item.ahTasks.taskBatch
                        }}
                    </view>
                    <view>发布单位：{{ item.publishUnitName }}</view>
                    <view>抽样单位：{{ item.sampleUnitName }}</view>
                    <view class="text-gray">抽样人员：{{ item.samplingPeopleFirst }}、{{ item.samplingPeopleSecond }}</view>
                    <view>抽样时间：{{ item.ahSampleDetailList[0].createTime }}</view>
                </view>
                <view class="tools padding-sm">
                    <view>
                    </view>
                    <view style="display: flex;justify-content: space-between;gap:30upx">
                        <view class="tool" @tap="toSampleDetail(item)">
                            <view class="cu-btn bg-blue light text-df text-bold">
                                {{ item.sampleStatus === 'WAIT_ENTERPRISES_SUBMIT' ? '去确认' : '查看' }}
                                <text class="cuIcon-right lg"></text>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
            <view class="radius shadow-warp bg-white text-lg" v-if="listData.length === 0">
                <view class="cu-list menu-avatar">
                    <view class="cu-item">
                        <view class="content">
                            <view class="text-sm text-center" style="justify-content: center;">
                                <text class="text-cut text-lg">
                                    <text class="cuIcon-warn text-yellow margin-right-xs text-xl"></text>
                                    未查询到相关数据
                                </text>
                            </view>
                        </view>
                    </view>
                </view>
            </view>

        </view>
        <view class="padding-sm quick-list" v-if="searchSample.id">
            <view class="cu-list menu bg-white shadow">
                <view class="cu-item">
                    <view class="title text-black text-bold text-lg">
                        <text class="cuIcon-titles text-green"></text>
                        {{ searchSample.bySampleUnitName }}
                    </view>
                    <view class="action">
                        <!--                        <text class="text-orange text-bold text-lg"
                                                      v-if="item.sampleStatus==='WAIT_ENTERPRISES_SUBMIT'">待确认
                                                </text>-->
                    </view>
                </view>
                <view class="content padding-sm detail solid-bottom">
                    <view>抽样单编号：{{ searchSample.samplingNumber }}</view>
                    <view>抽样样品：{{ searchSample.mustProductName }}</view>
                    <view>抽样单位：{{ searchSample.sampleUnitName }}</view>
                    <view class="text-gray">抽样人员：{{ searchSample.samplingPeopleFirst }}、{{ searchSample.samplingPeopleSecond }}</view>
                    <view>抽样时间：{{ searchSample.updateTime }}</view>
                </view>
                <view class="tools padding-sm">
                    <view>
                    </view>
                    <view style="display: flex;justify-content: space-between;gap:30upx">
                        <view class="tool" @tap="toSampleDetail(searchSample.id)">
                            <view class="cu-btn bg-blue light text-df text-bold">
                                {{ searchSample.sampleStatus === 'WAIT_ENTERPRISES_SUBMIT' ? '去确认' : '查看' }}
                                <text class="cuIcon-right lg"></text>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </view>

    </view>
</template>

<script>
    import {
        _checkModel
    } from "./check-model";

    export default {
        data() {
            return {
                curIndex: 1,
                listData: [],
                modalName: null,
                pageNum: 1,
                pageSize: 10,
                pageTotal: 1,
                sampleSheetNumber:'',
                searchSample:{}
            };
        },
        onShow() {
            this.pageNum = 1;
            this.pageSize = 10
            this.getList();
        },
        methods: {
            search() {
                this.pageNum = 1;
                this.getList()
            },
            getList() {
                // this.inSearching = true
                _checkModel.getSampleListByNJB({
                    pageNum: this.pageNum,
                    pageSize: this.pageSize
                }, res => {
                    console.log(res);
                    const {records, total} = res.data
                    if (this.pageNum === 1) {
                        this.listData = records
                    } else {
                        this.listData = this.listData.concat(records)
                    }
                    this.pageTotal = total
                    // this.inSearching = false
                    if (records.length > 0) {
                        this.pageNum++
                    }
                })
            },
            onReachBottom() {
                this.getList();
            },
            toSampleDetail(item) {
                // uni.setStorageSync("sampleDetail", item);
                uni.navigateTo({
                    url: "/pages/sample-check-list/sample-detail/index?id="+item.id
                })

            },
            scanQrCode(){
                uni.scanCode({
                    scanType:["qrCode"],
                    success: res=>{
                        this.sampleSheetNumber = res.result;
                        this.searchNewSample();
                    }
                });
            },
            searchNewSample(){
                if(!this.sampleSheetNumber){
                    this.$msg("请输入或扫描抽样单号");
                    return
                }
                _checkModel.getSampleInfoByNJB(this.sampleSheetNumber,res=>{
                    const {code,data,message} = res;
                    if(code === 200){
                        if(data && data.ahSampleSheet){
                            this.searchSample = data.ahSampleSheet;
                        }else{
                            this.$msg("未查询到抽样单信息");
                        }
                    }else{
                        this.$msg(message);
                    }
                })
            }
        }
    }
</script>

<style scoped>

    .quick-task {
        height: 100%;
        width: 100%;
    }


    .first-step {
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding-top: 20vh;
    }

    .first-step button {
        width: 90%;
        margin-top: 20vh;
    }

    .first-step image {
        width: 60vw;
        margin-left: 10vw;
    }

    /*.quick-list {
        padding-top: 100px;
    }*/

    .tools {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20 upx;
    }

    .detail view {
        height: 1.8em;
        line-height: 1.8em !important;
        border: none;
        color: gray;
    }

    .taskDetail {
        /*border: 1rpx solid #8799a3;*/
        box-shadow: 0 0 25 upx #aaa;
        border-radius: 10 rpx;
        overflow: hidden;
    }
</style>
