<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" style="width: 200px" placeholder="请选择门店" 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>
                <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="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.takeClothTime ? scope.row.takeClothTime : '--' }}
                </template>
            </el-table-column>
        </Page>
    </div>
</template>

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

export default {
    name: 'queryEntryRecord',
    dicts: ['order_cloth_flow_status'],
    data() {
        return {
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            recordsList: [],
            // 查询参数
            queryParams: {
                washCode: undefined,
                orgId: undefined,
                clothType: '1',
                beginInFactoryTime: undefined,
                endInFactoryTime: undefined,
                flowStatus: 1
            },
            dateRange: '',
            //门店下拉数据
            storelist: []
        }
    },
    created() {
        this.getList()
        this.getStoreList()
    },
    computed: {},
    methods: {
        /** 查询公告列表 */
        getList() {
            this.loading = true

            if (this.dateRange.length) {
                this.queryParams.beginInFactoryTime = this.dateRange[0]
                this.queryParams.endInFactoryTime = 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
            })
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm('queryForm')
            this.dateRange = ''
            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>
