<template>
    <div class="testdiv">
        <div class="divborder newSearchDiv" style="margin:0px;">
            <div class="filter">
                <label>{{$t('1132')}}：</label>
                <Cascader
                    :data="datalevel"
                    :value="leveldata"
                    trigger="hover"
                    style="display:inline-block;width:200px;"
                    @on-change="changeLevel"
                ></Cascader>
            </div>
            <div class="filter">
                <label>{{$t('600234')}}：</label>
                <Button class="twoWord" @click="toolSelect()">{{toolname}}</Button>
                <!-- <Select
                    v-model="brand"
                    label-in-value
                    clearable
                    class="searchSelect"
                    style="margin-left:10px;"
                >
                    <Option v-for="item in brandList" :value="item" :key="item">{{ item }}</Option>
                </Select>-->
            </div>
            <div class="filter">
                <label>{{$t('600050')}}：</label>
                <Select
                    v-model="changeReason"
                    label-in-value
                    clearable
                    class="searchSelect"
                    style="margin-left:10px;"
                >
                    <Option
                        v-for="item in reasonList"
                        :value="item.value"
                        :key="item.value"
                    >{{ item.name }}</Option>
                </Select>
            </div>
            <div class="filter">
                <label>{{$t('600235')}}：</label>
                <Select
                    v-model="changeUser"
                    label-in-value
                    clearable
                    class="searchSelect"
                    style="margin-left:10px;"
                >
                    <Option v-for="item in userList" :value="item.name" :key="item.id">{{ item.name }}</Option>
                </Select>
            </div>
            <div class="searchBtn">
                <Button
                    type="primary"
                    class="twoWord"
                    icon="ios-search"
                    @click="search()"
                >{{$t('1001')}}</Button>
                <Button
                    type="success"
                    class="twoWord"
                    icon="md-add-circle"
                    @click="add()"
                >{{$t('1002')}}</Button>
                <Button
                    type="warning"
                    class="twoWord"
                    icon="ios-create-outline"
                    @click="edit()"
                >{{$t('1003')}}</Button>
                <Button
                    type="error"
                    class="twoWord intervalRight"
                    icon="md-close-circle"
                    @click="dele()"
                >{{$t('1004')}}</Button>
                <Button
                    type="primary"
                    class="fourWord"
                    icon="md-trash"
                    @click="clearSearch()"
                >{{$t('1039')}}</Button>
                <Button
                    type="primary"
                    class="fourWord"
                    icon="md-download"
                    @click="loadexcel()"
                >{{$t('1005')}}</Button>
                <Upload
                    style="display:inline-block"
                    ref="upload"
                    :action="action"
                    name="excel-file"
                    :headers="headers"
                    :show-upload-list="false"
                    :on-format-error="handleFormatError"
                    :on-success="handleSuccess"
                    :on-error="handleError"
                    :format="['xlsx']"
                >
                    <Button type="primary" class="fourWord" icon="md-cloud-upload">{{$t('1006')}}</Button>
                </Upload>
                <Button
                    type="primary"
                    class="fourWord"
                    icon="ios-cloud-download"
                    @click="downexcel()"
                >{{$t('1007')}}</Button>
            </div>
        </div>
        <div class="divborder newTableDiv">
            <Table
                class="tableClass"
                @on-current-change="handleRowChange"
                highlight-row
                :data="tableData1"
                :columns="tableColumns1"
            ></Table>
            <div class="pageDiv">
                <div class="pageDirection">
                    <Page
                        :total="total"
                        :current="page"
                        @on-change="changePage"
                        show-elevator
                        show-sizer
                        show-total
                        @on-page-size-change="handlePageSize"
                        :page-size-opts="[10,20,30,40,100]"
                    ></Page>
                </div>
            </div>
        </div>
        <Modal class="newModalClass" v-model="addmodal" :styles="{width:'800px'}">
            <p slot="header">
                <span v-if="type===1">{{$t('1002')}}</span>
                <span v-if="type===2">{{$t('1003')}}</span>
            </p>
            <div class="modal_body long">
                <div class="filter">
                    <label>
                        <i>*</i>
                        {{$t('1040')}}：
                    </label>
                    <Select
                        v-model="addobj.machine_id"
                        clearable
                        label-in-value
                        filterable
                        class="searchSelect"
                        @on-change="getMachineCode"
                    >
                        <Option
                            v-for="item in machineList"
                            :value="item.machine_id"
                            :key="item.machine_id"
                        >{{ item.machine_code }}</Option>
                    </Select>
                </div>
                <div class="filter">
                    <label>{{$t('1041')}}：</label>
                    <Input class="searchInput" type="text" v-model="addobj.machine_name" disabled />
                </div>
                <div class="filter">
                    <label>
                        <i>*</i>
                        {{$t('600041')}}：
                    </label>
                    <!-- <Input class="searchInput" type="text" v-model="addobj.spec" /> -->
                    <Select
                        v-model="addobj.spindle_id"
                        clearable
                        label-in-value
                        class="searchSelect"
                        @on-change="getCutter"
                    >
                        <Option
                            v-for="item in spindleList"
                            :value="item.spindle_id"
                            :key="item.spindle_name"
                        >{{ item.spindle_name }}</Option>
                    </Select>
                </div>
                <div class="filter">
                    <label>
                        <i>*</i>
                        {{$t(600042)}}：
                    </label>
                    <Select
                        v-model="addobj.cutter_location_name"
                        label-in-value
                        clearable
                        class="searchSelect"
                        @on-change="getChangeRecord"
                    >
                        <Option
                            v-for="item in cutList"
                            :value="item.cutter_location_name"
                            :key="item.cutter_location_name"
                        >{{ item.cutter_location_name }}</Option>
                    </Select>
                </div>
                <div class="filter">
                    <label>{{$t('600043')}}：</label>
                    <Input class="searchInput" type="text" v-model="addobj.tool_name" disabled />
                </div>
                <div class="filter">
                    <label>{{$t('600044')}}：</label>
                    <Input class="searchInput" type="text" v-model="addobj.drawingcode" disabled />
                </div>
                <div class="filter">
                    <label>{{$t('600048')}}：</label>
                    <DatePicker
                        class="searchInput"
                        type="datetime"
                        :value="addobj.change_time"
                        format="yyyy-MM-dd HH:mm:ss"
                        @on-change="dateChange"
                    ></DatePicker>
                </div>
                <div class="filter">
                    <label>{{$t('600011')}}：</label>
                    <Input class="searchInput" type="text" v-model="addobj.supplier" disabled />
                </div>
                <div class="filter">
                    <label>{{$t('600045')}}：</label>
                    <Input class="searchInput" type="text" v-model="addobj.programno" disabled />
                </div>
                <div class="filter">
                    <label>{{$t('600037')}}：</label>
                    <Input class="searchInput" type="text" v-model="addobj.ratedlife" disabled />
                </div>
                <div class="filter">
                    <label>
                        <i>*</i>
                        {{$t('600046')}}：
                    </label>
                    <Input class="searchInput" type="number" v-model="addobj.residual_life" />
                </div>
                <div class="filter">
                    <label>
                        <i>*</i>
                        {{$t('600047')}}：
                    </label>
                    <Input class="searchInput" type="number" v-model="addobj.surplus_life" />
                </div>
                <div class="filter">
                    <label>{{$t('1030')}}：</label>
                    <Input class="searchInput" type="text" v-model="addobj.comment" />
                </div>
                <div>
                    <div class="filter">
                        <label>
                            <i>*</i>
                            {{$t(600050)}}：
                        </label>
                        <Select
                            v-model="addobj.change_reason"
                            clearable
                            class="searchSelect"
                            @on-change="imgShow"
                        >
                            <Option
                                v-for="item in reasonList"
                                :value="item.value"
                                :key="item.value"
                            >{{ item.name }}</Option>
                        </Select>
                    </div>
                    <div class="imgBox" style="margin-left:124px" v-show="reasonIndex!=0">
                        <div class="uploadMax" style="width:100px;height:100px;">
                            <img :src="reasonImg" alt />
                            <input
                                type="file"
                                name
                                ref="fileIntimg"
                                id="addfile"
                                @change="unloadimg(1)"
                                accept="image/png, image/gif, image/jpeg"
                            />
                        </div>
                        <Button
                            type="primary"
                            style="width:100px;text-align:center"
                            @click="changeImg(1)"
                        >更换原因图片</Button>
                    </div>
                </div>
            </div>
            <div slot="footer">
                <Button type="text" size="large" @click="closeadd()">{{$t('1033')}}</Button>
                <Button type="primary" size="large" @click="adddata(1)">{{$t('1002')}}</Button>
            </div>
        </Modal>
        <Modal class="newModalClass" v-model="editmodal" :styles="{width:'800px'}">
            <p slot="header">{{$t('1003')}}</p>
            <div class="modal_body long">
                <div class="filter">
                    <label>
                        <i>*</i>
                        {{$t('1041')}}：
                    </label>
                    <Input class="searchInput" type="text" v-model="editobj.machine_name" disabled />
                </div>
                <div class="filter">
                    <label>{{$t('1040')}}：</label>
                    <Input class="searchInput" type="text" v-model="editobj.machine_code" disabled />
                </div>
                <div class="filter">
                    <label>
                        <i>*</i>
                        {{$t('600041')}}：
                    </label>
                    <Input class="searchInput" type="text" v-model="editobj.spindle_name" disabled />
                </div>
                <div class="filter">
                    <label>
                        <i>*</i>
                        {{$t(600042)}}：
                    </label>
                    <Input
                        class="searchInput"
                        type="text"
                        v-model="editobj.cutter_location_name"
                        disabled
                    />
                </div>
                <div class="filter">
                    <label>{{$t('600043')}}：</label>
                    <Input class="searchInput" type="text" v-model="editobj.tool_name" disabled />
                </div>
                <div class="filter">
                    <label>{{$t('600044')}}：</label>
                    <Input class="searchInput" type="text" v-model="editobj.drawingcode" disabled />
                </div>

                <div class="filter">
                    <label>{{$t('600011')}}：</label>
                    <Input class="searchInput" type="text" v-model="editobj.supplier" disabled />
                </div>
                <div class="filter">
                    <label>{{$t('600045')}}：</label>
                    <Input class="searchInput" type="text" v-model="editobj.programno" disabled />
                </div>
                <div class="filter">
                    <label>{{$t('600037')}}：</label>
                    <Input class="searchInput" type="text" v-model="editobj.ratedlife" disabled />
                </div>
                <div class="filter">
                    <label>{{$t('600046')}}：</label>
                    <Input class="searchInput" type="number" v-model="editobj.residual_life" />
                </div>
                <div class="filter">
                    <label>{{$t('600047')}}：</label>
                    <Input class="searchInput" type="number" v-model="editobj.surplus_life" />
                </div>
                <div class="filter">
                    <label>{{$t('600048')}}：</label>
                    <DatePicker
                        class="searchInput"
                        type="datetime"
                        :value="editobj.change_time"
                        format="yyyy-MM-dd HH:mm:ss"
                        @on-change="dateChange"
                    ></DatePicker>
                </div>
                <div class="filter">
                    <label>{{$t('1030')}}：</label>
                    <Input class="searchInput" type="text" v-model="editobj.comment" />
                </div>
                <div>
                    <div class="filter">
                        <label>
                            <i>*</i>
                            {{$t(600050)}}：
                        </label>
                        <Select
                            v-model="editobj.change_reason"
                            clearable
                            class="searchSelect"
                            @on-change="imgShow"
                        >
                            <Option
                                v-for="item in reasonList"
                                :value="item.value"
                                :key="item.value"
                            >{{ item.name }}</Option>
                        </Select>
                    </div>
                    <div class="imgBox" style="margin-left:124px" v-show="reasonIndex!=0">
                        <div class="uploadMax" style="width:100px;height:100px;">
                            <img :src="reasonImg" alt />
                            <input
                                type="file"
                                name
                                ref="fileIntimg1"
                                id="editfile"
                                @change="unloadimg(2)"
                                accept="image/png, image/gif, image/jpeg"
                            />
                        </div>
                        <Button
                            type="primary"
                            style="width:100px;text-align:center"
                            @click="changeImg(2)"
                        >更换原因图片</Button>
                    </div>
                </div>
            </div>
            <div slot="footer">
                <Button type="text" size="large" @click="editmodal=false">{{$t('1033')}}</Button>
                <Button type="primary" size="large" @click="editPost()">{{$t('1003')}}</Button>
            </div>
        </Modal>
        <Modal class="newModalClass" title="选择刀具" v-model="toolmodal" :styles="{width:'700px'}">
            <div class="modal_body">
                <div class="filter">
                    <Input
                        class="searchInput"
                        style="margin-right:20px"
                        type="text"
                        v-model="toolfilter"
                        placeholder="请输入刀具名称/图纸号"
                    />
                    <Button type="primary" icon="ios-search" @click="getTool()">{{$t('1001')}}</Button>
                </div>
                <Table
                    class="tableClass"
                    :data="toollist"
                    :columns="toolColumn"
                    @on-current-change="handleRowChange1"
                    highlight-row
                    @on-row-dblclick="handleSelectRow1"
                ></Table>
            </div>
        </Modal>
    </div>
</template>
<script>
import axios from "@/libs/api.request";
import { constants } from "crypto";
export default {
    name: "route",
    data() {
        return {
            action:
                axios.publicPath +
                "tools/upload/submit?templateName=ToolsChange",
            headers: {
                token: localStorage.getItem("token"),
                timestamp: localStorage.getItem("timestamp"),
                nonce: localStorage.getItem("nonce"),
                sign: localStorage.getItem("sign"),
            },
            datalevel: [],
            leveldata: [],
            sectionid: 0,
            toolid: "",
            toollist: [],
            drawingcode: "",
            changeReason: "",
            reasonList: [
                {
                    value: "SM",
                    name: "计数寿命到",
                },
                {
                    value: "MS",
                    name: "磨损",
                },
                {
                    value: "BR",
                    name: "崩刃",
                },
                {
                    value: "DD",
                    name: "断刃",
                },
                {
                    value: "HX",
                    name: "换型",
                },
                {
                    value: "ZL",
                    name: "产品质量问题",
                },
                {
                    value: "OTHER",
                    name: "其他",
                },
            ],
            changeUser: "",
            userList: [],
            tableData1: [],
            total: 0,
            page: 1,
            pagesize: 10,
            addmodal: false,
            addobj: {},
            editobj: {},
            editmodal: false,
            detailobj: {},
            type: 0,
            machineList: [],
            spindleList: [],
            cutList: [],
            tableColumns1: [
                {
                    type: "index2",
                    title: this.$t("1008"),
                    key: "xuhao",
                    render: (h, params) => {
                        return h(
                            "span",
                            params.index + (this.page - 1) * this.pagesize + 1
                        );
                    },
                    width: 70,
                },
                {
                    title: "设备编号",
                    key: "equip_code",
                },
                {
                    title: "设备名称",
                    key: "equip_name",
                },
                {
                    title: "设备位置",
                    key: "section_dsc",
                },
                {
                    title: "刀具名称",
                    key: "tool_name",
                },
                {
                    title: "刀具图纸号",
                    key: "tool_drawno",
                },
                {
                    title: "程序号",
                    key: "programno",
                },
                {
                    title: "主轴号",
                    key: "mainaxis",
                },
                {
                    title: "刀位号",
                    key: "tool_no",
                },
                {
                    title: "额定寿命",
                    key: "rating_life",
                },
                {
                    title: "剩余寿命",
                    key: "residual_life",
                },
                {
                    title: "更换人员",
                    key: "change_user",
                },
                {
                    title: "更换时间",
                    key: "change_time",
                },
                {
                    title: "更换原因",
                    key: "change_reason",
                    render: (h, params) => {
                        let reason = "";
                        switch (params.row.change_reason) {
                        case "SM":
                            reason = "寿命到达";
                            break;
                        case "BR":
                            reason = "崩刃";
                            break;
                        case "DD":
                            reason = "断刀";
                            break;
                        case "ZL":
                            reason = "产品质量问题";
                            break;
                        case "MS":
                            reason = "磨损";
                            break;
                        case "OTHER":
                            reason = "其他";
                            break;
                        case "GD":
                            reason = "正常";
                            break;
                        case "HX":
                            reason = "换型";
                            break;
                        default:
                            reason = "-";
                            break;
                        }
                        return h("div", reason);
                    },
                },
                {
                    title: "备注",
                    key: "comment",
                },
                {
                    title: "图片",
                    key: "url_path",
                    render: (h, params) => {
                        if (params.row.url_path) {
                            return h("div", [
                                h("img", {
                                    domProps: {
                                        src: params.row.url_path,
                                        alt: "加载失败",
                                    },
                                    style: {
                                        display: "block",
                                        width: "50px",
                                        height: "50px",
                                    },
                                }),
                            ]);
                        } else {
                            return h("div", "");
                        }
                    },
                },
            ],
            toolfilter: "",
            toolmodal: false,
            toolname: "点击选择",
            toolColumn: [
                {
                    title: "刀具名称",
                    key: "name",
                },
                {
                    title: "刀具图纸号",
                    key: "drawingcode",
                },
            ],
            reasonImg: "",
            reasonIndex: 0,
        };
    },
    created() {
        this.initlevel();
        this.search();
        this.getTool();
        this.getUser();
        this.getMachine();

        // 格式化表格样式
        this.tableColumns1 = this.$time.initTableTitle(this.tableColumns1);
    },
    methods: {
        search() {
            var params = {
                sectionid: this.sectionid,
                toolid: this.toolid,
                drawingcode: this.supplier,
                change_reason: this.changeReason,
                change_user: this.changeUser,
                page: this.page,
                pagesize: this.pagesize,
            };
            axios
                .request({
                    url: "/tools/ToolChange/GetChangeRecordList",
                    params,
                    method: "get",
                })
                .then((res) => {
                    this.total = res.data.total;
                    this.tableData1 = res.data.data;
                    // this.mockTableData1(res.data.data);
                });
        },
        initlevel() {
            // 初始化产线层级
            axios
                .request({
                    url: "config/ProjectLevelSection/GetSectionTree",
                    method: "get",
                })
                .then((res) => {
                    const arr = [];
                    this.datalevel = res.data.data;
                    arr.push(res.data.data[0].value);
                    this.leveldata = arr;
                });
        },
        changeLevel(data) {
            this.sectionid = data[data.length - 1];
            this.getTool();
            this.getMachine();
        },
        getTool() {
            let data = {
                sectionid: this.sectionid,
                toolfilter: this.toolfilter,
                count: 50,
            };
            axios
                .request({
                    url: "/tools/ToolConfig/ToolList",
                    data,
                    method: "post",
                })
                .then((res) => {
                    if (res.data.ret == 1) {
                        // console.log(res.data.data)
                        this.toollist = res.data.data;
                    }
                });
        },
        getUser() {
            let params = {
                page: 1,
                pagesize: 9999999,
            }; axios
                .request({
                //   url: '/tools/ToolChange/GetChangeUserNameList',
                    url: "/config/user/GetUsers",
                    params,
                    method: 'get'
                })
                .then((res) => {
                    if (res.data.ret == 1) {
                        let arr = [],
                            arr1 = [];
                        this.userList = res.data.data;
                    }
                });
            // axios
            //     .request({
            //         url: "/config/user/GetUsers",
            //         params,
            //         method: "get",
            //     })
            //     .then((res) => {
            //         if (res.data.ret == 1) {
            //             this.userlist = res.data.data;
            //         }
            //     });
        },
        getMachine() {
            axios
                .request({
                    url:
                        "/tools/ToolChangeManagementDev/getMachineList?sectionID=" +
                        this.sectionid,
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret == 1) {
                        // console.log(res.data.data);
                        this.machineList = res.data.data;
                    }
                });
        },
        getMachineCode(val) {
            if (val) {
                this.addobj.machine_name = this.machineList[
                    this.machineList.findIndex(
                        (ele) => ele.machine_id == val.value
                    )
                ].machine_name;

                this.addobj.machine_id = val.value;
                this.addobj.machine_code = val.label;
                console.log(this.addobj.machine_name);
                console.log(this.addobj.machine_id);
                console.log(this.addobj.machine_code);
                this.getSpinle();
            }

            // console.log(this.addobj.machine_code)
        },
        getSpinle() {
            // if (val) {
            axios
                .request({
                    url:
                        "/tools/ToolChangeManagementDev/getSpindleList?machine_id=" +
                        this.addobj.machine_id,
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret == 1) {
                        this.spindleList = res.data.data;
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                        this.spindleList = [];
                    }
                });
            // }
        },
        getCutter(val) {
            if (val) {
                this.addobj.spindle_id = val.value;
                this.addobj.spindle_name = val.label;
                axios
                    .request({
                        url:
                            "/tools/ToolChangeManagementDev/getCutterLocationList?spindle_id=" +
                            this.addobj.spindle_id,
                        method: "get",
                    })
                    .then((res) => {
                        if (res.data.ret == 1) {
                            this.cutList = res.data.data;
                        }
                    });
            }
        },
        getChangeRecord(val) {
            if (val) {
                let params = {
                    machine_id: this.addobj.machine_id,
                    spindle_id: this.addobj.spindle_id,
                    cutter_location_name: this.addobj.cutter_location_name,
                };
                axios
                    .request({
                        url:
                            "tools/ToolChangeManagementDev/getChangeRecordOtherInfo",
                        params,
                        method: "get",
                    })
                    .then((res) => {
                        if (res.data.ret == 1) {
                            console.log(res.data.data);
                            let obj = {};
                            obj = res.data.data;
                            this.addobj = Object.assign({}, this.addobj, obj);
                        }
                    });
            }
        },
        dateChange(val) {
            this.addobj.change_time = val;
        },
        imgShow(val) {
            this.reasonIndex = this.reasonList.findIndex(
                (ele) => ele.value == val
            );
            if (this.reasonIndex == 0) {
                this.reasonImg = '';
                this.editobj.url_path = '';
            }
        },
        dateChange(val) {
            this.addobj.change_time = val;
            if (this.type == 2) {
                this.editobj.change_time = val;
            }
        },
        unloadimg(a) {
            // 上传照片
            let file;
            if (a == 1) {
                file = this.$refs.fileIntimg.files[0];
            }
            if (a == 2) {
                file = this.$refs.fileIntimg1.files[0];
            }
            const data = new FormData();
            data.append("file", file);
            axios
                .request({
                    url: "/tools/upload/UploadImage",
                    data,
                    method: "post",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        this.$Message.success(this.$t(100378));
                        this.reasonImg = axios.publicPath + res.data.data;
                        this.addobj.cover = axios.publicPath + res.data.data;
                        if (this.type == 2) {
                            this.editobj.url_path =
                                axios.publicPath + res.data.data;
                        }
                    } else {
                        this.$Message.error(res.data.msg);
                    }
                })
                .catch((err) => {
                    this.$Message.error(err.msg);
                });
        },
        add() {
            this.addobj = {};
            this.reasonImg = "";
            this.type = 1;
            this.addmodal = true;
        },
        adddata(type) {
            if (
                !this.addobj.machine_id ||
                !this.addobj.spindle_id ||
                !this.addobj.cutter_location_name ||
                !this.addobj.change_reason
            ) {
                this.$Message.error(this.$t("930055"));
                return false;
            }

            if (!this.addobj.residual_life || !this.addobj.surplus_life) {
                this.$Message.error(this.$t("930055"));
                return false;
            }
            var reg = /^[1-9]*[1-9][0-9]*$/;
            if (
                this.addobj.residual_life != "" &&
                !reg.test(this.addobj.residual_life)
            ) {
                this.$Message.error("旧刀剩余寿命" + this.$t("1590017"));
                return false;
            }
            if (
                this.addobj.surplus_life != "" &&
                !reg.test(this.addobj.surplus_life)
            ) {
                this.$Message.error("新刀已使用寿命" + this.$t("1590017"));
                return false;
            }
            let data = {};
            data = this.addobj;
            console.log(data);

            axios
                .request({
                    url: "/tools/ToolLife/toolChangeEditTwo",
                    data,
                    method: "post",
                })
                .then((res) => {
                    console.log(res.data);
                    if (res.data.ret === 1) {
                        this.$Message.success(this.$t("1055"));
                        this.addmodal = false;
                        this.search();
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                    }
                });
        },
        clearSearch() {
            this.leveldata = [];
            this.toolid = "";
            this.supplier = "";
            this.changeReason = "";
            this.changeUser = "";
            this.toolname = "点击选择";
            this.sectionid = "";
            this.search();
        },
        edit() {
            if (!this.detailobj.id) {
                this.$Message.error(this.$t(1043));
                return false;
            }
            this.editmodal = true;
            this.type = 2;
            this.getChangeDetail();
        },
        editPost() {
            let data = {};
            data = {
                id: this.editobj.id,
                surplus_life: this.editobj.surplus_life,
                residual_life: this.editobj.residual_life,
                change_time: this.editobj.change_time,
                comment: this.editobj.comment,
                change_reason: this.editobj.change_reason,
                url_path: this.editobj.url_path,
            };
            // console.log(data);
            axios
                .request({
                    url: "/tools/ToolChangeManagementDev/ChangeRecordEdit",
                    data,
                    method: "post",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        // console.log(res.data);
                        this.$Message.success(this.$t("1060"));
                        this.editmodal = false;
                        this.search();
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                    }
                });
        },
        dele() {
            if (!this.detailobj.id) {
                this.$Message.error(this.$t(1043));
                return false;
            } else {
                this.$Modal.confirm({
                    title: this.$t("1004"),
                    content: this.$t("1018"),
                    width: "300px",
                    closable: true,
                    okText: this.$t("1004"),
                    onOk: () => {
                        let data = {
                            id: this.detailobj.id,
                        };
                        axios
                            .request({
                                url: "/tools/ToolChange/Delete",
                                data,
                                method: "post",
                            })
                            .then((res) => {
                                if (res.data.ret === 1) {
                                    this.$Message.success(this.$t("1058"));
                                    this.page = 1;
                                    this.pagesize = 10;
                                    this.search();
                                    this.detailobj = {};
                                    this.editobj = {};
                                } else {
                                    this.$Message.error(this.$t(res.data.msg));
                                }
                            });
                    },
                });
            }
        },
        changeImg(a) {
            if (a == 1) {
                document.getElementById("addfile").click();
            }
            if (a == 2) {
                document.getElementById("editfile").click();
            }
        },
        getChangeDetail() {
            axios
                .request({
                    url:
                        "/tools/ToolChangeManagementDev/getChangeRecordDetail?id=" +
                        this.detailobj.id,

                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        this.editobj = res.data.data;
                        if (this.editobj.change_reason == "SM") {
                            this.reasonIndex = 0;
                        } else {
                            this.reasonIndex = -1;
                            this.reasonImg = this.editobj.url_path;
                        }
                    } else {
                        this.$Message.error(res.data.msg);
                    }
                });
        },
        toolSelect() {
            this.toolfilter = "";
            this.toolmodal = true;
            this.getTool();
        },
        handleRowChange(currentRow, oldCurrentRow) {
            this.detailobj = currentRow;
        },
        handlePageSize(value) {
            this.pagesize = value;
            this.tableData1 = this.search();
        },
        changePage(value) {
            this.page = value;
            this.tableData1 = this.search();
        },
        closeadd() {
            this.addmodal = false;
        },
        loadexcel() {
            axios
                .request({
                    url: "/config/download/GetTemplate?name=ToolsChange",
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        window.location.href =
                            axios.publicPath + "" + res.data.data;
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                    }
                });
        },
        downexcel() {
            var params = {
                sectionId: this.sectionid,
                toolid: this.toolid,
                change_reason: this.changeReason,
                // toexcel: 0,
            };
            axios
                .request({
                    url: "/tools/ToolChange/ExportRecords",
                    params,
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        window.location.href =
                            axios.publicPath + "" + res.data.data;
                    } else {
                        this.$$Message.error(res.data.msg);
                    }
                });
        },
        handleFormatError(file) {
            this.$Message.error(
                this.$t("950396") + file.name + this.$t("950397")
            );
        },
        handleSuccess(res, file) {
            if (res.ret == 1) {
                this.$Message.success(this.$t("950398"));
                this.search();
            } else {
                if (typeof res.msg !== "number") {
                    inittip(res.msg);
                } else {
                    this.$Message.error(this.$t("" + res.msg));
                }
            }
        },
        handleError() {
            this.$Message.error(this.$t("2010006") + "!");
        },
        handleRowChange1(currentRow, oldCurrentRow) {
            this.toolid = currentRow.name;
            this.drawingcode = currentRow.drawingcode;
            this.toolname = currentRow.name;
        },
        handleSelectRow1(data, i) {
            this.toolid = data.name;
            this.drawingcode = data.drawingcode;
            this.toolname = data.name;
            this.toolmodal = false;
        },
    },
};
</script>
<style lang="less" scoped>
.newModalClass {
    .long {
        display: flex;
        flex-wrap: wrap;

        .filter {
            margin-right: 105px;
            label {
                width: 120px;
            }
        }
    }
}
</style>
