<template>
    <div class="app-container" id="returnFinshed">
        <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="100px"
        >
            <el-form-item label="关键字">
                <el-input
                    v-model="queryParams.keyWord"
                    placeholder="请输入关键字"
                    clearable
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="退料单位">
                <el-input
                    v-model="queryParams.unitName"
                    placeholder="请输入单位名称"
                    clearable
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="工程名称">
                <el-input
                    v-model="queryParams.proName"
                    placeholder="请输入工程名称"
                    clearable
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="工机具类型">
                <el-input
                    v-model="queryParams.maType"
                    placeholder="请输入工机具类型"
                    clearable
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="协议号">
                <el-input
                    v-model="queryParams.agreementId"
                    placeholder="请选择协议号"
                    clearable
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="完成情况">
                <el-input
                    v-model="queryParams.status"
                    placeholder="请选择完成情况"
                    clearable
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>

            <el-form-item label="退料申请时间">
                <el-input
                    v-model="queryParams.sTime"
                    placeholder="请输入退料申请时间"
                    clearable
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item>
                <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="handleQuery"
                    >查询</el-button
                >
                <el-button
                    icon="el-icon-refresh"
                    size="mini"
                    @click="resetQuery"
                    >重置</el-button
                >
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <!-- :disabled="multiple" -->
                <el-button
                    type="warning"
                    plain
                    size="mini"
                    @click="handleFinish"
                    >完成退料</el-button
                >
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="primary"
                    plain
                    icon="el-icon-download"
                    size="mini"
                    @click="handleExport"
                    >导出</el-button
                >
            </el-col>

            <right-toolbar
                :showSearch.sync="showSearch"
                @queryTable="getList"
            ></right-toolbar>
        </el-row>

        <el-table
            v-loading="loading"
            :data="typeList"
            @selection-change="handleSelectionChange"
        >
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column
                label="序号"
                align="center"
                width="80"
                type="index"
                :index="indexContinuation(queryParams.pageNum, queryParams.pageSize)"
            >
                <!-- <template slot-scope="scope">
                    <span>{{
                        (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
                    }}</span>
                </template> -->
            </el-table-column>
            <el-table-column
                label="退料单号"
                align="center"
                prop="dictName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="退料单位名称"
                align="center"
                prop="dictName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="退料工程名称"
                align="center"
                prop="dictName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="退料工机具类型"
                align="center"
                prop="dictName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="退料人员"
                align="center"
                prop="dictName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="退料人联系电话"
                align="center"
                prop="dictName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="退料申请时间"
                align="center"
                prop="dictName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="协议号"
                align="center"
                prop="dictName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="退料状态"
                align="center"
                prop="dictName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="操作"
                align="center"
                class-name="small-padding fixed-width"
                width="250"
            >
                <template slot-scope="scope">
                    <el-button
                        size="mini"
                        type="primary"
                        icon="el-icon-zoom-in"
                        @click="handleUpdate(scope.row, 'see')"
                        >查看</el-button
                    >
                    <el-button
                        size="mini"
                        type="warning"
                        @click="handleFinish(scope.row, 'see')"
                        >完成退料</el-button
                    >
                    <el-button
                        size="mini"
                        type="primary"
                        icon="el-icon-document"
                        @click="handleUpdateOrder(scope.row)"
                        >退料单</el-button
                    >
                </template>
            </el-table-column>
        </el-table>

        <pagination
            v-show="total > 0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
        />

        <!-- 添加或修改参数配置对话框 -->
        <el-dialog
            :title="title"
            :visible.sync="open"
            width="1000px"
            append-to-body
        >
            <el-form
                :model="queryParams"
                ref="queryForm"
                size="small"
                :inline="true"
                v-show="showSearch"
                label-width="100px"
            >
                <el-row>
                    <el-form-item label="关键字" prop="dictName">
                        <el-input
                            v-model="queryParams.dictName"
                            placeholder="请输入借出方单位"
                            clearable
                            style="width: 240px"
                            @keyup.enter.native="handleQuery"
                        />
                    </el-form-item>
                    <el-form-item label="类型名称" prop="dictName">
                        <el-input
                            v-model="queryParams.dictName"
                            placeholder="请输入借入方单位"
                            clearable
                            style="width: 240px"
                            @keyup.enter.native="handleQuery"
                        />
                    </el-form-item>
                    <el-form-item label="规格型号" prop="dictName">
                        <el-input
                            v-model="queryParams.dictName"
                            placeholder="请输入关键字"
                            clearable
                            style="width: 240px"
                            @keyup.enter.native="handleQuery"
                        />
                    </el-form-item>
                    <el-form-item>
                        <el-button
                            type="primary"
                            icon="el-icon-search"
                            size="mini"
                            @click="handleQuery"
                            >查询</el-button
                        >
                        <el-button
                            icon="el-icon-refresh"
                            size="mini"
                            @click="resetQuery"
                            >重置</el-button
                        >
                    </el-form-item>
                </el-row>
            </el-form>

            <el-table
                v-loading="loading"
                :data="typeList"
                height="500px"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column
                    label="类型名称"
                    align="center"
                    prop="dictName"
                    :show-overflow-tooltip="true"
                />
                <el-table-column
                    label="规格型号"
                    align="center"
                    prop="dictName"
                    :show-overflow-tooltip="true"
                />
                <el-table-column
                    label="编码"
                    align="center"
                    prop="dictName"
                    :show-overflow-tooltip="true"
                />
                <el-table-column
                    label="退料数量"
                    align="center"
                    prop="dictName"
                    :show-overflow-tooltip="true"
                />
                <el-table-column
                    label="合格入库数"
                    align="center"
                    class-name="small-padding fixed-width"
                    width="200"
                >
                    <template slot-scope="scope">
                        <el-input
                            v-model="scope.row.dictName"
                            placeholder="请输入退料数量"
                            clearable
                        />
                    </template>
                </el-table-column>
                <el-table-column
                    label="待修数"
                    align="center"
                    class-name="small-padding fixed-width"
                    width="200"
                >
                    <template slot-scope="scope">
                        <el-input
                            v-model="scope.row.dictName"
                            placeholder="请输入待修数"
                            clearable
                        />
                    </template>
                </el-table-column>
                <el-table-column
                    label="报废数"
                    align="center"
                    class-name="small-padding fixed-width"
                    width="200"
                >
                    <template slot-scope="scope">
                        <el-input
                            v-model="scope.row.dictName"
                            placeholder="请输入报废数"
                            clearable
                        />
                    </template>
                </el-table-column>
            </el-table>

            <pagination
                v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
            />
            <!-- <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" @click="submitForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div> -->
        </el-dialog>
        <dialogForm
            :dialogTitle="title"
            :isShowFlag.sync="isShowOneFlag"
            :priKey="priKey"
        ></dialogForm>
        <el-dialog
            v-loading.fullscreen.lock="fullscreenLoading"
            :title="title"
            :visible.sync="openOne"
            append-to-body
            width="400px"
        >
            <div class="submit_box">
                <div>
                    <i
                        class="el-icon-circle-check"
                        style="color: #ff9900; font-size: 30px"
                    ></i>
                </div>
                <div class="submit_box_title">
                    <div>{{ openTextOne }}</div>
                    <div>{{ openTextTwo }}</div>
                </div>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel">返回</el-button>
                <el-button type="primary" @click="submitOpenOneForm()"
                    >确定</el-button
                >
            </div>
        </el-dialog>
        <el-dialog
            v-loading.fullscreen.lock="fullscreenLoading"
            :title="title"
            :visible.sync="openTwo"
            append-to-body
            width="400px"
        >
            <div class="submit_box_two">
                <div>
                    <i
                        class="el-icon-circle-check"
                        style="color: #00c196; font-size: 30px"
                    ></i>
                </div>
                <div class="submit_box_title">{{ openTextThree }}！</div>
            </div>
            <div slot="footer" class="dialog-footer"></div>
        </el-dialog>
    </div>
</template>

<script>
import {
    listType,
    getType,
    delType,
    addType,
    updateType,
    refreshCache,
} from '@/api/system/dict/type'
import dialogForm from './dialogForm.vue'
export default {
    components: { dialogForm },
    name: 'ReturnFinshed',
    dicts: ['sys_normal_disable'],
    data() {
        return {
            fullscreenLoading: false,
            openOne: false,
            openTwo: false,
            openTextOne: '',
            openTextTwo: '',
            openTextThree: '',
            isShowOneFlag: false,
            // 遮罩层
            loading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 字典表格数据
            typeList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                dictName: undefined,
                dictType: undefined,
                status: undefined,
                keyWord: '',
                unitName: '',
                proName: '',
                maType: '',
                agreementId: '',
                status: '',
                sTime: '',
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                dictName: [
                    {
                        required: true,
                        message: '字典名称不能为空',
                        trigger: 'blur',
                    },
                ],
                dictType: [
                    {
                        required: true,
                        message: '字典类型不能为空',
                        trigger: 'blur',
                    },
                ],
            },
        }
    },
    created() {
        // this.getList();
    },
    methods: {
        /** 查询字典类型列表 */
        getList() {
            this.loading = true
            // listType(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            //   this.typeList = response.rows;
            //   this.total = response.total;
            this.loading = false
            // }
            // );
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                dictId: undefined,
                dictName: undefined,
                dictType: undefined,
                status: '0',
                remark: undefined,
            }
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.resetForm('queryForm')
            this.handleQuery()
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset()
            this.open = true
            this.title = '计划借调'
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.dictId)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset()
            const dictId = row.dictId || this.ids
            getType(dictId).then((response) => {
                this.form = response.data
                this.open = true
                this.title = '修改'
            })
        },
        // 退料单
        handleUpdateOrder() {
            this.title = '查看'
            this.isShowOneFlag = true
        },
        // 完成退料
        handleFinish() {
            // this.title = "确认操作";
            // this.openTextOne = "确认完成退料么?";
            // this.openTextTwo = "确认完成退料么?";
            // this.openOne = true
        },
        submitOpenOneForm() {
            this.openTextThree = '完成退料成功！'
            this.openTwo = true
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    if (this.form.dictId != undefined) {
                        updateType(this.form).then((response) => {
                            this.$modal.msgSuccess('修改成功')
                            this.open = false
                            this.getList()
                        })
                    } else {
                        addType(this.form).then((response) => {
                            this.$modal.msgSuccess('新增成功')
                            this.open = false
                            this.getList()
                        })
                    }
                }
            })
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const dictIds = row.dictId || this.ids
            this.$modal
                .confirm('是否确认删除所选择的数据项？')
                .then(function () {
                    return delType(dictIds)
                })
                .then(() => {
                    this.getList()
                    this.$modal.msgSuccess('删除成功')
                })
                .catch(() => {})
        },
        /** 导出按钮操作 */
        handleExport() {
            // this.download('system/dict/type/export', {
            //   ...this.queryParams
            // }, `type_${new Date().getTime()}.xlsx`)
        },
        /** 刷新缓存按钮操作 */
        handleRefreshCache() {
            refreshCache().then(() => {
                this.$modal.msgSuccess('刷新成功')
                this.$store.dispatch('dict/cleanDict')
            })
        },
    },
}
</script>
<style lang="scss" scoped>
.submit_box {
    display: flex;
    justify-content: flex-start;
    align-items: center;

    .submit_box_title {
        display: flex;
        flex-direction: column;
        margin-left: 15px;

        :first-child {
            font-size: 14px;
            font-weight: 600;
        }

        :last-child {
            margin-top: 6px;
            font-size: 12px;
        }
    }
}

.submit_box_two {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    margin-left: 30%;

    .submit_box_title {
        display: flex;
        flex-direction: column;
        margin-left: 10px;
        font-size: 18px;
        font-weight: 600;
    }
}
</style>
