<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item prop="washCode">
                <el-input v-model="queryParams.washCode" placeholder="请输入衣服条码" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item prop="dateRange">
                <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item prop="orgId">
                <el-select v-model="queryParams.orgId" placeholder="请选择门店" style="width: 200px" clearable>
                    <el-option v-for="item in storelist" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
            </el-form-item>
            <el-form-item prop="checkClothById">
                <el-select v-model="queryParams.checkClothById" style="width: 200px" placeholder="请选择提交人" clearable>
                    <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-tabs v-model="queryParams.clothType" @tab-click="handleQuery">
            <el-tab-pane label="衣服" name="1"></el-tab-pane>
            <el-tab-pane label="附件" name="2"></el-tab-pane>
        </el-tabs>
        <Page uri="/mapi/order/clothItem/findFactoryClothPage" :request-params="queryParams" ref="pagination">
            <el-table-column label="衣物条码" align="center" prop="washCode" />
            <el-table-column label="所属门店" align="center" prop="orgName">
                <template slot-scope="scope">
                    {{ scope.row.orgName ? scope.row.orgName : '--' }}
                </template>
            </el-table-column>
            <el-table-column label="衣物名称" align="center" prop="clothItemName" />
            <el-table-column label="是否重洗" align="center" prop="repeatCount">
                <template slot-scope="scope">
                    <span v-if="scope.row.repeatCount && scope.row.repeatCount > 0" style="color: red"> 重洗 {{ scope.row.repeatCount }} 次 </span>
                    <span v-else> 否 </span>
                </template>
            </el-table-column>
            <el-table-column label="颜色" align="center" prop="clothColorName">
                <template slot-scope="scope">
                    {{ getColor(scope.row.orderClothColors) }}
                </template>
            </el-table-column>
            <el-table-column label="加急" align="center" prop="clothSpeedName" />
            <el-table-column label="状态" align="center" prop="flowStatus">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.order_cloth_flow_status" :value="scope.row.flowStatus" />
                </template>
            </el-table-column>
            <el-table-column label="检查时间" align="center" prop="takeClothTime">
                <template slot-scope="scope">
                    {{ scope.row.checkClothTime ? scope.row.checkClothTime : '--' }}
                </template>
            </el-table-column>
        </Page>
    </div>
</template>

<script>
import { listfindFactoryClothPage } from '@/api/system/inquiry'
import { allOrg } from '@/api/system/store'
import { AllUser } from '@/api/system/user'

export default {
    name: 'queryInspectRecords',
    dicts: ['order_cloth_flow_status'],
    data() {
        return {
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            clothingList: [],
            // 查询参数
            queryParams: {
                washCode: undefined,
                orgId: undefined,
                beginCheckClothTime: undefined,
                endCheckClothTime: undefined,
                clothType: '1',
                flowStatus: 2
            },
            dateRange: '',
            //门店下拉数据
            storelist: [],
            //提交人数据
            userList: []
        }
    },
    created() {
        this.getList()
        this.getStoreList()
        this.getuserList()
    },
    computed: {},
    methods: {
        /** 查询公告列表 */
        getList() {
            this.loading = true
            if (this.dateRange.length) {
                this.queryParams.beginCheckClothTime = this.dateRange[0]
                this.queryParams.endCheckClothTime = this.dateRange[1]
            }
            if (this.queryParams.orgId) {
                const obj = this.storelist.find((item) => item.id === this.queryParams.orgId)
                this.queryParams.sourceType = obj.sourceType
            }
            this.$nextTick(() => {
                this.$refs.pagination.handleSearch(true)
            })
        },
        /** 获取门店下拉数据 */
        getStoreList() {
            allOrg({
                sourceType: '02'
            }).then((response) => {
                console.log(response)
                this.storelist = response.data
            })
        },
        // 获取提交人数据
        getuserList() {
            AllUser({}).then((response) => {
                this.userList = response.data
            })
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm('queryForm')
            this.handleQuery()
        },
        //获取颜色
        getColor(data) {
            if (data && data != null) {
                const _color = []
                data.forEach((item) => {
                    _color.push(item.clothColorName)
                })
                return _color.join(',')
            } else {
                return '--'
            }
        }
    }
}
</script>
<style></style>
