<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" @submit.native.prevent :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 prop="outFactoryById">
                <el-select v-model="queryParams.outFactoryById" 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="outFactoryTime"> </el-table-column>
            <el-table-column label="加急" align="center" prop="clothSpeedName" />
            <el-table-column label="提交人" align="center" prop="outFactoryBy"> </el-table-column>
            <el-table-column label="状态" align="center" prop="flowStatus">
                <template slot-scope="scope">
                    <el-tag type="danger" v-if="scope.row.refundId !=null">已撤销</el-tag>
                    <dict-tag v-else :options="dict.type.order_cloth_flow_status" :value="scope.row.flowStatus" />
                </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: 'queryFactoryRecords',
    dicts: ['order_cloth_flow_status'],
    data() {
        return {
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            recordsList: [],
            // 查询参数
            queryParams: {
                washCode: undefined,
                orgId: undefined,
                outFactoryById: undefined,
                beginOutFactoryTime: undefined,
                endOutFactoryTime: undefined,
                clothType: '1',
                flowStatus: 3
            },
            dateRange: '',
            //门店下拉数据
            storelist: [],
            //提交人数据
            userList: []
        }
    },
    created() {
        this.getList()
        this.getStoreList()
        this.getuserList()
    },
    computed: {},
    methods: {
        /** 查询公告列表 */
        getList() {
            this.loading = true

            if (this.dateRange.length) {
                this.queryParams.beginOutFactoryTime = this.dateRange[0]
                this.queryParams.endOutFactoryTime = this.dateRange[1]
            }
            // this.addDateRange(this.queryParams, this.dateRange)

            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) => {
                this.storelist = response.data
            })
        },
        // 获取提交人数据
        getuserList() {
            AllUser({}).then((response) => {
                this.userList = 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>
