<template>
    <div class="app-container" id="constructionSite">
        <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="100px"
        >
            <el-form-item label="关键字" prop="keyWord">
                <el-input
                    v-model="queryParams.keyWord"
                    placeholder="请输入关键字"
                    clearable
                    maxlength="50"
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="单位名称" prop="unitId">
                <el-select
                    v-model="queryParams.unitId"
                    placeholder="请选择单位名称"
                    clearable
                >
                    <el-option
                        v-for="item in unitList"
                        :key="item.unitId"
                        filterable
                        :label="item.unitName"
                        :value="item.unitId"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="工程名称" prop="lotId">
                <el-select
                    v-model="queryParams.lotId"
                    filterable
                    placeholder="请选择工程名称"
                    clearable
                >
                    <el-option
                        v-for="item in projectList"
                        :key="item.projectId"
                        :label="item.projectName"
                        :value="item.projectId"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="联系人姓名" prop="backMan">
                <el-input
                    maxlength="50"
                    v-model="queryParams.backMan"
                    placeholder="请输入联系人姓名"
                    clearable
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="联系人电话" prop="backPhone">
                <el-input
                    v-model="queryParams.backPhone"
                    placeholder="请输入联系人电话"
                    clearable
                    onkeyup="this.value = this.value.replace(/[^\d]/g,'');"
                    maxlength="11"
                    style="width: 240px"
                    @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="完成情况" prop="status">
                <el-select
                    v-model="queryParams.status"
                    filterable
                    placeholder="请选择完成情况"
                    clearable
                >
                    <el-option
                        v-for="item in statusList"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </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">
                <el-button
                    type="primary"
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    @click="handleAdd"
                    >直转申请</el-button
                >
            </el-col>
            <el-col :span="1.5">
                <el-button
                    type="warning"
                    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="tableList">
            <!-- <el-table-column type="selection" width="55" align="center" /> -->
            <!-- <el-table-column
                label="序号"
                align="center"
                width="80"
                type="index"
            >
                <template scope="scope">
                    <span>{{
                        (queryParams.pageNum - 1) * 10 + scope.$index + 1
                    }}</span>
                </template>
            </el-table-column> -->
            <el-table-column
                align="center"
                label="序号"
                type="index"
                :index="
                    indexContinuation(queryParams.pageNum, queryParams.pageSize)
                "
            />
            <el-table-column
                label="转让方单位名称"
                align="center"
                prop="backUnitName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="转让方工程名称"
                align="center"
                prop="backProName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="接收方单位名称"
                align="center"
                prop="leaseUnitName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="接收方工程名称"
                align="center"
                prop="leaseProName"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="转让方联系人及电话"
                align="center"
                prop="backMan"
                :show-overflow-tooltip="true"
            >
                <template slot-scope="scope">
                    <div>
                        {{ scope.row.backMan || '/' }}
                        <span v-if="scope.row.backMan && scope.row.backPhone"
                            >:</span
                        >
                        {{ scope.row.backPhone || '/' }}
                    </div>
                    <!-- <span>{{ scope.row.backMan || '/'}}</span><span>{{ scope.row.backPhone || '/' }}</span> -->
                </template>
            </el-table-column>
            <el-table-column
                label="接收方联系人及电话"
                align="center"
                prop="leaseMan"
                :show-overflow-tooltip="true"
            >
                <template slot-scope="scope">
                    <div>
                        {{ scope.row.leaseMan || '/' }}
                        <span v-if="scope.row.leaseMan && scope.row.leasePhone"
                            >:</span
                        >
                        {{ scope.row.leasePhone || '/' }}
                    </div>
                    <!-- <span>{{ scope.row.leaseMan || '/'}}</span><span>{{ scope.row.leasePhone || '/' }}</span> -->
                </template>
            </el-table-column>
            <el-table-column
                label="办理时间"
                align="center"
                prop="createTime"
                :show-overflow-tooltip="true"
            />
            <el-table-column
                label="状态"
                align="center"
                prop="status"
                :show-overflow-tooltip="true"
            >
                <template slot-scope="scope">
                    <span v-if="scope.row.status == 0">待审批</span>
                    <span v-if="scope.row.status == 1" style="color: #02a7f0"
                        >审批同意</span
                    >
                    <span v-if="scope.row.status == 2" style="color: red"
                        >审批拒绝</span
                    >
                </template>
            </el-table-column>
            <!-- <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" @click="handleView(scope.row)"
                        >查看</el-button
                    >
                    <el-button
                        size="mini"
                        type="primary"
                        v-if="scope.row.status == 0"
                        @click="handleExame(scope.row)"
                    >
                        审核
                    </el-button>
                    <el-button
                        size="mini"
                        type="info"
                        @click="handlePrint(scope.row)"
                        >直转单</el-button
                    >
                    <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(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="1200px"
            append-to-body
            :close-on-click-modal="false"
        >
            <el-form
                :model="dialogParams"
                ref="dialogForm"
                :rules="rules"
                size="small"
                :inline="true"
                label-width="100px"
            >
                <el-row>
                    <el-form-item label="退料单位" prop="backUnitId">
                        <el-select
                            v-model="dialogParams.backUnitId"
                            filterable
                            clearable
                            @change="GetProData"
                            style="width: 240px"
                            placeholder="请选择"
                            :disabled="handleState == 1"
                        >
                            <el-option
                                v-for="item in backUnitList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="退料工程" prop="backProId">
                        <el-select
                            v-model="dialogParams.backProId"
                            filterable
                            clearable
                            @change="GetUnitData"
                            style="width: 240px"
                            placeholder="请选择"
                            :disabled="handleState == 1"
                        >
                            <el-option
                                v-for="item in backProjectList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="退料协议编号" prop="backAgreementCode">
                        <el-input
                            v-model="dialogParams.backAgreementCode"
                            placeholder="请输入退料协议编号"
                            clearable
                            disabled
                            style="width: 240px"
                        />
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="退料人" prop="backMan">
                        <el-input
                            v-model="dialogParams.backMan"
                            placeholder="请输入退料人"
                            clearable
                            maxlength="50"
                            :disabled="handleState == 1"
                            style="width: 240px"
                        />
                    </el-form-item>
                    <el-form-item label="退料人电话" prop="backPhone">
                        <el-input
                            v-model="dialogParams.backPhone"
                            placeholder="请输入退料人电话"
                            clearable
                            onkeyup="this.value = this.value.replace(/[^\d]/g,'');"
                            maxlength="11"
                            :disabled="handleState == 1"
                            style="width: 240px"
                        />
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="领料单位" prop="leaseUnitId">
                        <el-select
                            v-model="dialogParams.leaseUnitId"
                            filterable
                            clearable
                            @change="GetProData2"
                            style="width: 240px"
                            placeholder="请选择"
                            :disabled="handleState == 1"
                        >
                            <el-option
                                v-for="item in leaseUnitList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="领料工程" prop="leaseProId">
                        <el-select
                            v-model="dialogParams.leaseProId"
                            filterable
                            clearable
                            @change="GetUnitData2"
                            style="width: 240px"
                            placeholder="请选择"
                            :disabled="handleState == 1"
                        >
                            <el-option
                                v-for="item in leaseProjectList"
                                :key="item.id"
                                :label="item.name"
                                :value="item.id"
                            ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item
                        label="领料协议编号"
                        prop="leaseAgreementCode"
                    >
                        <el-input
                            v-model="dialogParams.leaseAgreementCode"
                            placeholder="请输入领料协议编号"
                            clearable
                            disabled
                            style="width: 240px"
                        />
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="领料人" prop="leaseMan">
                        <el-input
                            v-model="dialogParams.leaseMan"
                            placeholder="请输入领料人"
                            clearable
                            maxlength="50"
                            :disabled="handleState == 1"
                            style="width: 240px"
                        />
                    </el-form-item>
                    <el-form-item label="领料人电话" prop="leasePhone">
                        <el-input
                            v-model="dialogParams.leasePhone"
                            placeholder="请输入领料人电话"
                            clearable
                            maxlength="11"
                            onkeyup="this.value = this.value.replace(/[^\d]/g,'');"
                            :disabled="handleState == 1"
                            style="width: 240px"
                        />
                    </el-form-item>
                </el-row>
                <el-row>
                    <el-form-item label="关键字" prop="keyWord">
                        <el-input
                            v-model="dialogParams.keyWord"
                            placeholder="请输入关键字"
                            clearable
                            maxlength="50"
                            style="width: 240px"
                        />
                    </el-form-item>
                    <el-form-item>
                        <el-button
                            type="primary"
                            icon="el-icon-search"
                            size="mini"
                            @click="handleDialogQuery"
                            >查询</el-button
                        >
                        <el-button
                            icon="el-icon-refresh"
                            size="mini"
                            @click="resetDialogQuery"
                            >重置</el-button
                        >
                    </el-form-item>
                </el-row>
            </el-form>

            <el-table
                v-loading="dialogLoading"
                :data="deviceList"
                height="350px"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column label="序号" align="center" type="index" />
                <el-table-column
                    label="机具名称"
                    align="center"
                    prop="typeName"
                    :show-overflow-tooltip="true"
                />
                <el-table-column
                    label="机具规格"
                    align="center"
                    prop="typeModelName"
                    :show-overflow-tooltip="true"
                />
                <el-table-column
                    label="编码"
                    align="center"
                    prop="maCode"
                    :show-overflow-tooltip="true"
                />
                <el-table-column
                    label="当前在用量"
                    align="center"
                    prop="useNum"
                    :show-overflow-tooltip="true"
                />
                <el-table-column
                    label="直转数量"
                    align="center"
                    class-name="small-padding fixed-width"
                    width="200"
                >
                    <template slot-scope="scope">
                        <el-input-number
                            v-model="scope.row.directNum"
                            controls-position="right"
                            style="width: 100%"
                            :min="1"
                            :max="Number(scope.row.num)"
                            clearable
                            :disabled="handleState == 1 || handleState == 2"
                        ></el-input-number>
                        <!-- <el-input
              v-model="scope.row.directNum"
              placeholder="请输入直转数量"
              clearable
            /> -->
                    </template>
                </el-table-column>
            </el-table>

            <div
                slot="footer"
                class="dialog-footer"
                style="text-align: center"
                v-if="handleState == 0"
            >
                <el-button type="primary" @click="submitForm">保存</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
            <div
                slot="footer"
                class="dialog-footer"
                style="text-align: right"
                v-if="handleState == 2"
            >
                <el-button type="primary" @click="pass">同意</el-button>
                <el-button type="danger" @click="refuse">不同意</el-button>
            </div>
        </el-dialog>

        <!-- 直转单弹窗 -->
        <el-dialog :visible.sync="openPrint" width="1000px" append-to-body>
            <div style="height: 500px; overflow-y: scroll; padding: 0 20px">
                <vue-easy-print tableShow ref="remarksPrintRef" class="print">
                    <div
                        class="title"
                        style="
                            text-align: center;
                            font-weight: 600;
                            font-size: 16px;
                        "
                        >直转单</div
                    >
                    <div
                        class="info"
                        style="margin-top: 10px; display: flex; flex-wrap: wrap"
                    >
                        <div
                            class="item"
                            style="
                                width: 40%;
                                flex-shrink: 0;
                                margin-bottom: 5px;
                                font-size: 14px;
                            "
                        >
                            <span>退料单位：</span>
                            {{ dialogParams.backUnitName }}
                        </div>
                        <div
                            class="item"
                            style="
                                width: 60%;
                                flex-shrink: 0;
                                margin-bottom: 5px;
                                font-size: 14px;
                            "
                        >
                            <span>退料工程：</span>
                            {{ dialogParams.backProName }}
                        </div>
                        <div
                            class="item"
                            style="
                                width: 40%;
                                flex-shrink: 0;
                                margin-bottom: 5px;
                                font-size: 14px;
                            "
                        >
                            <span>领料单位：</span>
                            {{ dialogParams.leaseUnitName }}
                        </div>
                        <div
                            class="item"
                            style="
                                width: 60%;
                                flex-shrink: 0;
                                margin-bottom: 5px;
                                font-size: 14px;
                            "
                        >
                            <span>领料工程：</span>
                            {{ dialogParams.leaseProName }}
                        </div>
                    </div>
                    <div style="width: 100%">
                        <el-table
                            :data="deviceList"
                            class="table"
                            border
                            style="margin-top: 20px; padding: 1px; width: 100%"
                        >
                            <!--          <el-table-column type="selection" width="55" align="center" />-->
                            <el-table-column
                                label="序号"
                                align="center"
                                type="index"
                            />
                            <el-table-column
                                label="机具名称"
                                align="center"
                                prop="typeName"
                            />
                            <el-table-column
                                label="规格型号"
                                align="center"
                                prop="typeModelName"
                            />
                            <el-table-column
                                label="计量单位"
                                align="center"
                                prop="unitName"
                            />
                            <el-table-column
                                label="设备编码"
                                align="center"
                                prop="maCode"
                            />
                            <el-table-column
                                label="直转数量"
                                align="center"
                                prop="directNum"
                            />
                        </el-table>
                    </div>

                    <div
                        class="fillIn"
                        style="
                            margin-top: 30px;
                            display: flex;
                            justify-content: space-between;
                        "
                    >
                        <div class="item" style="width: 25%">
                            <span>审核：</span>
                        </div>
                        <div class="item" style="width: 25%">
                            <span>办理人：</span>
                        </div>
                        <div class="item" style="width: 25%">
                            <span>操作人：</span>
                        </div>
                    </div>
                </vue-easy-print>
            </div>
            <div slot="footer" class="dialog-footer" style="text-align: center">
                <el-button type="primary" @click="print">打 印</el-button>
                <el-button @click="openPrint = false">关 闭</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import {
    getUnitList,
    getProjectList,
    getProData,
    getUnitData,
    getAgreementInfoById,
} from '@/api/claimAndRefund/receive'
import {
    getWorkSiteList,
    getUseringData,
    submitWorkSite,
    getDetailInfo,
    passWorkSite,
    refuseWorkSite,
} from '@/api/claimAndRefund/constructionSite'
import { getInfo } from '@/api/login'
import vueEasyPrint from 'vue-easy-print'
export default {
    name: 'ConstructionSite',
    dicts: ['sys_normal_disable'],
    components: { vueEasyPrint },
    data() {
        return {
            // 遮罩层
            loading: false,
            // 选中数组
            selectedList: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 单位数据
            unitList: [],
            user: {},
            // 工程数据
            projectList: [],
            // 总条数
            total: 0,
            // 表格数据
            tableList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                keyWord: '',
                unitId: '',
                lotId: '',
                backMan: '',
                backPhone: '',
                status: undefined,
            },
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            dialogId: undefined,
            openPrint: false,
            handleState: 0, //0新增1查看2审批
            dialogLoading: false,
            dialogParams: {},
            deviceList: [], //弹窗table数据
            backUnitList: [], //退料单位列表
            backProjectList: [], //退料项目列表
            leaseUnitList: [], //领料单位列表
            leaseProjectList: [], //领料项目列表
            // 表单参数
            form: {},
            statusList: [
                { id: '', name: '请选择' },
                { id: '0', name: '未完成' },
                { id: '1', name: '已完成' },
            ], //集合
            // 表单校验
            rules: {
                //backUnitId backProId leaseUnitId leaseProId
                backUnitId: [
                    {
                        required: true,
                        message: '请选择退料单位',
                        trigger: 'blur',
                    },
                ],
                backProId: [
                    {
                        required: true,
                        message: '请选择退料项目',
                        trigger: 'blur',
                    },
                ],
                leaseUnitId: [
                    {
                        required: true,
                        message: '请选择领料单位',
                        trigger: 'blur',
                    },
                ],
                leaseProId: [
                    {
                        required: true,
                        message: '请选择领料项目',
                        trigger: 'blur',
                    },
                ],
            },
        }
    },
    created() {
        this.getUserInfo()
        this.getUnitList()
        this.getProjectList()
        this.getList()

        this.GetUnitData()
        this.GetProData()
        this.GetUnitData2()
        this.GetProData2()
    },
    methods: {
        // 获取用户信息
        async getUserInfo() {
            const res = await getInfo()
            this.user = res.user
        },

        //获取单位类型 ,getUnitList, getProjectList
        getUnitList() {
            getUnitList().then((response) => {
                this.unitList = response.data
            })
        },
        getProjectList() {
            getProjectList().then((response) => {
                this.projectList = response.data
            })
        },
        /** 查询列表 */
        getList() {
            this.loading = true
            getWorkSiteList(this.queryParams).then((response) => {
                this.tableList = 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.queryParams.unitId = ''
            this.queryParams.lotId = ''
            this.resetForm('queryForm')
            this.handleQuery()
        },

        // 获取 单位 列表数据
        async GetUnitData() {
            const params = {
                id: this.dialogParams.backProId,
            }
            const res = await getUnitData(params)
            this.backUnitList = res.data

            this.GetAgreementInfoById()
        },
        // 获取 工程名称 列表数据
        async GetProData() {
            const params = {
                id: this.dialogParams.backUnitId,
            }
            const res = await getProData(params)
            this.backProjectList = res.data

            this.GetAgreementInfoById()
        },
        // 获取 协议id
        async GetAgreementInfoById() {
            if (this.dialogParams.backUnitId && this.dialogParams.backProId) {
                const params = {
                    unitId: this.dialogParams.backUnitId,
                    projectId: this.dialogParams.backProId,
                }
                const res = await getAgreementInfoById(params)
                if (!(res.data && res.data.agreementId)) {
                    this.$message.error('当前单位和工程未上传')
                    this.dialogParams.backUnitId = null
                    this.dialogParams.backProId = null
                    this.GetUnitData()
                    this.GetProData()
                } else {
                    this.dialogParams.backAgreementId = res.data.agreementId
                    this.dialogParams.backAgreementCode = res.data.agreementCode
                    this.getDialogList()
                }
            }
        },

        /** 查询设备列表 */
        getDialogList() {
            this.dialogLoading = true
            let param = {
                keyWord: this.dialogParams.keyWord,
                agreementId: this.dialogParams.backAgreementId,
            }
            getUseringData(param).then((response) => {
                // console.log(response)
                if (response.code == 200) {
                    this.deviceList = response.rows
                    this.deviceList.forEach((item) => {
                        this.$set(item, 'directNum', 1)
                    })
                    this.dialogLoading = false
                } else {
                    this.dialogLoading = false
                }
            })
        },

        // 获取 单位 列表数据
        async GetUnitData2() {
            const params = {
                id: this.dialogParams.leaseProId,
            }
            const res = await getUnitData(params)
            this.leaseUnitList = res.data

            this.GetAgreementInfoById2()
        },
        // 获取 工程名称 列表数据
        async GetProData2() {
            const params = {
                id: this.dialogParams.leaseUnitId,
            }
            const res = await getProData(params)
            this.leaseProjectList = res.data

            this.GetAgreementInfoById2()
        },
        // 获取 协议id
        async GetAgreementInfoById2() {
            if (this.dialogParams.leaseUnitId && this.dialogParams.leaseProId) {
                const params = {
                    unitId: this.dialogParams.leaseUnitId,
                    projectId: this.dialogParams.leaseProId,
                }
                const res = await getAgreementInfoById(params)
                console.log(res, 'GetAgreementInfoById2')
                if (!(res.data && res.data.agreementId)) {
                    this.$message.error('当前单位和工程未上传')
                    this.dialogParams.leaseUnitId = null
                    this.dialogParams.leaseProId = null
                    this.GetUnitData2()
                    this.GetProData2()
                } else {
                    // this.dialogParams.leaseAgreementId = res.data.agreementId;
                    // this.dialogParams.leaseAgreementCode = res.data.agreementCode;
                    this.$set(
                        this.dialogParams,
                        'leaseAgreementId',
                        res.data.agreementId,
                    )
                    this.$set(
                        this.dialogParams,
                        'leaseAgreementCode',
                        res.data.agreementCode,
                    )
                }
            }
        },
        /** 搜索按钮操作 */
        handleDialogQuery() {
            if (this.handleState == 0) {
                this.getDialogList()
            } else {
                this.getDetail()
            }
        },
        /** 重置按钮操作 */
        resetDialogQuery() {
            if (this.handleState == 0) {
                this.$set(this.dialogParams, 'keyWord', '')
                this.getDialogList()
            } else {
                this.$set(this.dialogParams, 'keyWord', '')
                this.getDetail()
            }
        },
        /** 工地直转--打开弹窗 */
        handleAdd() {
            this.resetForm('dialogForm')
            this.dialogParams = {}
            this.deviceList = []
            this.open = true
            this.title = '工地直转'
            this.handleState = 0
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.selectedList = selection.map((item) => item)
            // console.log(this.selectedList)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs['dialogForm'].validate((valid) => {
                if (valid) {
                    if (this.selectedList.length > 0) {
                        let arr = []
                        this.selectedList.forEach((item, index) => {
                            arr[index] = {
                                typeId: item.typeId,
                                maId: item.maId,
                                directNum: item.directNum,
                            }
                        })

                        let param = {
                            directApplyInfo: this.dialogParams,
                            directApplyInfoDetails: arr,
                        }
                        console.log(param)
                        submitWorkSite(param).then((response) => {
                            if (response.code == 200) {
                                this.$modal.msgSuccess('新增成功')
                                this.open = false
                                this.getList()
                            } else {
                                this.$modal.msgSuccess('新增失败')
                            }
                        })
                    } else {
                        this.$modal.msgError('请选择直转数据')
                    }
                }
            })
        },
        handleView(row) {
            console.log(row, '查看')
            this.dialogId = row.id
            this.getDetail()
            this.open = true
            this.handleState = 1
        },
        /** 修改按钮操作 */
        handleExame(row) {
            console.log(row, '审核')
            this.dialogId = row.id
            this.getDetail()
            this.open = true
            this.handleState = 2
        },
        getDetail() {
            let param = {
                keyWord: this.dialogParams.keyWord,
                id: this.dialogId,
            }
            getDetailInfo(param).then((res) => {
                if (res.code == 200) {
                    let keyWord = this.dialogParams.keyWord
                    this.dialogParams = res.data
                    this.dialogParams.keyWord = keyWord
                    this.$set(
                        this.dialogParams,
                        'backUnitId',
                        Number(res.data.backUnitId),
                    )
                    this.$set(
                        this.dialogParams,
                        'backProId',
                        Number(res.data.backProId),
                    )
                    // this.$set(this.dialogParams,'backAgreementCode',res.data.tagreementCode)
                    this.$set(
                        this.dialogParams,
                        'leaseUnitId',
                        Number(res.data.leaseUnitId),
                    )
                    this.$set(
                        this.dialogParams,
                        'leaseProId',
                        Number(res.data.leaseProId),
                    )
                    this.deviceList = res.data.directApplyDetails
                    this.deviceList.forEach((item) => {
                        item.typeName = item.kindName
                        item.typeModelName = item.modelName
                        // item.num = item.useNum
                    })
                }
            })
        },
        pass() {
            // console.log(this.dialogParams)
            let data = this.dialogParams
            let backList = this.deviceList.map((item) => {
                item.status = 0
                item.typeCode = item.modelName
                item.preNum = item.directNum
                item.unitNames = item.unitName
                return item
            })
            console.log(backList, 'backList------')
            let backApplyInfo = {
                types: 2,
                unitId: data.backUnitId,
                proId: data.backProId,
                agreementId: data.backAgreementId,
                agreementCode: data.backAgreementCode,
                companyId: null,
                createBy: this.user.userName,
                backApplyInfo: {
                    backPerson: data.backMan,
                    phone: data.backPhone,
                    remark: '',
                },
                backApplyDetails: backList,
            }
            // console.log(backApplyInfo,'backApplyInfo------')
            let leaseList = this.deviceList.map((item) => {
                item.status = 0
                item.typeCn = item.typeName
                item.guigeCn = item.modelName
                item.preNum = item.directNum
                item.unitCn = item.unitName
                return item
            })
            // console.log(leaseList,'leaseList---------')
            let leaseApplyInfo = {
                types: 2,
                unitId: data.leaseUnitId,
                proId: data.leaseProId,
                agreementId: data.leaseAgreementId,
                agreementCode: data.leaseAgreementCode,
                companyId: null,
                createBy: this.user.userName,
                taskType: 29,
                taskStatus: 30,
                leaseApplyInfo: {
                    leasePerson: data.leaseMan,
                    phone: data.leasePhone,
                    remark: '',
                },
                leaseApplyDetails: leaseList,
            }
            // console.log(leaseApplyInfo)
            let param = {
                id: this.dialogParams.id,
                backApplyInfo: backApplyInfo,
                leaseApplyInfo: leaseApplyInfo,
            }
            passWorkSite(param).then((res) => {
                if (res.code == 200) {
                    this.open = false
                    this.$modal.msgSuccess('操作成功')
                    this.getList()
                } else {
                    this.$modal.msgError('操作失败')
                }
            })
        },
        refuse(row) {
            console.log(this.dialogParams)
            let param = {
                id: this.dialogParams.id,
            }
            refuseWorkSite(param).then((res) => {
                if (res.code == 200) {
                    this.open = false
                    this.$modal.msgSuccess('操作成功')
                    this.getList()
                } else {
                    this.$modal.msgError('操作失败')
                }
            })
        },
        //打开领料单
        async handlePrint(row) {
            this.openPrint = true

            this.getDetail({ id: row.id })

            // this.leaseApplyDetails = res.rows[0].leaseApplyDetails
            // this.leaseApplyData = res.rows[0]
        },
        // 领料单 打印
        print() {
            this.$refs.remarksPrintRef.print()
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            // const dictIds = row.dictId || this.selectedList;
            // 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`,
            )
        },
    },
}
</script>
<style lang="scss" scoped>
.print {
    .title {
        text-align: center;
        font-weight: 600;
        font-size: 16px;
    }
    .info {
        margin-top: 10px;
        display: flex;
        flex-wrap: wrap;

        .item {
            width: 50%;
            flex-shrink: 0;
            margin-bottom: 5px;
            font-size: 14px;
        }
    }

    .fillIn {
        margin-top: 15px;
        display: flex;
        justify-content: space-between;
    }
}
::v-deep.el-table .fixed-width .el-button--mini {
    width: 60px !important;
    margin-bottom: 10px;
}
</style>
