<template>
  <div>
    <div class="divborder">
      <div class="filter">
        <label>父级设备类型:</label>
        <Select v-model="filterObj.machineFType" @on-change="machineFTypeChange($event)" label-in-value clearable style="width:160px;">
          <Option v-for="item in initPageData.machineFTypeList" :value="item.id" :key="item.id">{{ item.title }}</Option>
        </Select>
      </div>
      <div class="filter">
        <label>子级设备类型:</label>
        <Select v-model="filterObj.machineCType" @on-change="machineCTypeChange($event)" label-in-value clearable style="width:160px;">
          <Option v-for="item in initPageData.machineCTypeList" :value="item.id" :key="item.id">{{ item.title }}</Option>
        </Select>
      </div>

      <div class="buttonall">
        <Button type="primary" @click="search(1,10)">{{$t('1001')}}</Button>
        <Button type="success" @click="add()">添加</Button>
        <Button type="warning" @click="edit()">修改</Button>
        <Button type="error" @click="del()">删除</Button>
        <Button type="primary" @click="downModel()">查看模板</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 icon="md-cloud-upload" type="primary">{{$t('upload-excel')}}</Button>
        </Upload>
      </div>
    </div>

    <div class="divborder">
      <Table style="margin-top:10px" ref="table1" width='100%' @on-current-change="handleRowChange" highlight-row :data="tableData1"
        :columns="tableColumns1"></Table>
    </div>

    <div class="divborder">
      <Table style="margin-top:10px" ref="table2" width='100%' @on-current-change="handleRowChange2" highlight-row
        :data="tableData2" :columns="tableColumns2"></Table>
      <div style="margin: 10px;overflow: hidden">
        <div style="float: right;">
          <Page :total="total2" :current="page2" @on-change="changePage2" show-elevator show-sizer show-total
            @on-page-size-change="handlePageSize2" :page-size-opts="[10,20,30,40,100]"></Page>
        </div>
      </div>
    </div>

    <div class="mt20">
      <div class="clear" style="clear: both;">
        <span class="unstandard">未定义失效模式工单</span>
        <Button class="ml20" type="primary" @click="search2">查询</Button>
      </div>
      <div class="clear"></div>
      <div class="filter">
        <label style="width: 55px;">时间范围:</label>
        <DatePicker type="datetimerange" @on-change="timechange" :value="filterObj.time" format="yyyy-MM-dd hh:mm:ss"
          placement="bottom-end" split-panels placeholder="Select date" style="width: 300px"></DatePicker>
      </div>
    </div>
    <div class="divborder">
      <Table style="margin-top:10px" ref="table3" width='100%' @on-current-change="handleRowChange3" highlight-row
        :data="tableData3" :columns="tableColumns3" @on-selection-change="selectionChange"></Table>
      <div style="margin: 10px;overflow: hidden">
        <div style="float: right;">
          <Page :total="total3" :current="page3" @on-change="changePage3" show-elevator show-sizer show-total
            @on-page-size-change="handlePageSize3" :page-size-opts="[10,20,30,40,100]"></Page>
        </div>
        <div class="fl">
          <Button type="primary" @click="defineFaultInfo()">定义故障信息</Button>
        </div>

      </div>
    </div>

    <Modal :title="modalTitle" v-model="addModal" @on-ok="handleSubmit('addObj')" :loading="loading" :styles="{top: '40px',width:'600px'}">
      <div class="modal_body" style="width:100%!important;padding:0 20px;">
        <Form ref="addObj" :model="addObj" label-position="left" :label-width="80">
          <Tabs type="card" style="overflow: hidden !important;" v-model="tab" @on-click="changeTab($event)">
            <TabPane :label="modalTitle+'故障类型'" :disabled="(optType==='add'?false:(optType==='edit'&&selectedObj2!=null?true:false))">
              <FormItem label="故障类型">
                <input class="publicinput" type="text" v-model="addObj.faultType">
              </FormItem>
            </TabPane>
            <TabPane :label="modalTitle+'失效模式'" :disabled="(optType==='add'?false:(optType==='edit'&&selectedObj2!=null?false:true))">
              <FormItem label="故障类型">
                <Select v-model="addObj.faultTypeDrop" :disabled="optType==='add'?false:true" @on-change="faultChangeAdd($event)"
                  label-in-value clearable style="width:160px;">
                  <Option v-for="item in addObj.faultList" :value="item.id" :key="item.id">{{ item.title }}</Option>
                </Select>
              </FormItem>
              <FormItem label="失效模式">
                <input class="publicinput" type="text" v-model="addObj.failureMode">
              </FormItem>
              <FormItem label="是否启用">
                <Select v-model="addObj.status" @on-change="faultChangeAdd($event)" label-in-value clearable style="width:160px;">
                  <Option :value="1" :key="1">启用</Option>
                  <Option :value="0" :key="0">停用</Option>
                </Select>
              </FormItem>
            </TabPane>
          </Tabs>
        </Form>
      </div>
    </Modal>

    <Modal title="定义故障信息" v-model="defineFaultInfoModal" @on-ok="DefineFaultInfoSubmit('defineFaultInfoObj')" :loading="loading"
      :styles="{top: '40px',width:'600px'}">
      <div class="modal_body" style="width:100%!important;padding:0 20px;">
        <Form ref="defineFaultInfoObj" :model="defineFaultInfoObj" label-position="left" :label-width="80">
          <FormItem label="故障类型">
            <Select v-model="defineFaultInfoObj.faultType" @on-change="faultChangeDefine($event)" label-in-value
              clearable style="width:160px;">
              <Option v-for="item in defineFaultInfoObj.faultList" :value="item.id" :key="item.id">{{ item.title }}</Option>
            </Select>
          </FormItem>
          <FormItem label="失效模式">
            <Select v-model="defineFaultInfoObj.failureMode" label-in-value clearable style="width:160px;">
              <Option v-for="item in defineFaultInfoObj.failureModeList" :value="item.id" :key="item.id">{{ item.title }}</Option>
            </Select>
          </FormItem>
        </Form>
      </div>
    </Modal>

  </div>
</template>
<script>
import axios from '@/libs/api.request'

export default {
    name: 'tpm-setting',
    components: {

    },
    data () {
        return {
            action: axios.publicPath + 'tpm/Upload/Submit?templateName=FaultType',
            headers: {
                token: localStorage.getItem('token'),
                timestamp: localStorage.getItem('timestamp'),
                nonce: localStorage.getItem('nonce'),
                sign: localStorage.getItem('sign')
            },
            filterObj: {
                machineFType: 0, // 父级设备类型
                machineCType: 0, // 子级设备类型
                machineFTypeName: '',
                machineCTypeName: '',
                time: ['2017-11-01 12:00:00', '2020-02-19 12:00:00']
            },
            initPageData: {
                machineFTypeList: [], // 父级设备类型 下拉菜单
                machineCTypeList: [] // 子级设备类型 下拉菜单
            },

            tableData1: [],
            tableColumns1: [{ // 列表字段属性集合
                type: 'index2',
                title: this.$t(1008),
                key: 'xuhao',
                render: (h, params) => {
                    return h('span', params.index + 1)
                },
                width: 60
            },
            {
                title: '设备父级类型',
                key: 'machineFTypeName'
            },
            {
                title: '设备子级类型',
                key: 'machineCTypeName'
            },
            {
                title: '故障类型',
                key: 'faultType' // ele.repairtime+分钟

            }
            ],

            total2: 0,
            page2: 1,
            pagesize2: 10, // 列表pagesize
            tableData2: [],
            tableColumns2: [{ // 列表字段属性集合
                type: 'index2',
                title: this.$t(1008),
                key: 'xuhao',
                render: (h, params) => {
                    return h('span', params.index + (this.page2 - 1) * this.pagesize2 + 1)
                },
                width: 60
            },
            {
                title: '设备父级类型',
                key: 'machineFTypeName'
            },
            {
                title: '设备子级类型',
                key: 'machineCTypeName'
            },
            {
                title: '故障类型',
                key: 'faultType'
            },
            {
                title: '失效模式',
                key: 'failureMode' // ele.repairtime+分钟
            },
            {
                title: '状态',
                key: 'status' // ele.repairtime+分钟
            }
            ],

            total3: 0,
            page3: 1,
            pagesize3: 10, // 列表pagesize
            selection: [], // 多选容器
            tableData3: [],
            tableColumns3: [{ // 列表字段属性集合
                type: 'index2',
                title: this.$t(1008),
                key: 'xuhao',
                render: (h, params) => {
                    return h('span', params.index + (this.page3 - 1) * this.pagesize3 + 1)
                },
                width: 60
            },
            {
                title: '备注',
                key: 'remark'
            },
            {
                title: '故障描述',
                key: 'fault_description'
            },
            {
                title: '维修排查过程',
                key: 'repair_process'
            },
            {
                title: '故障原因',
                key: 'real_faultid_desc' // ele.repairtime+分钟
            },
            {
                title: '所用备件',
                key: 'sparepart' // ele.repairtime+分钟
            },
            {
                title: '报修时间',
                key: 'reporttime' // ele.repairtime+分钟
            },
            {
                title: '停机时间（分钟）',
                key: 'stoptime', // ele.repairtime+分钟
                width: 140
            },
            {
                title: '维修人',
                key: 'add_repairmid_name' // ele.repairtime+分钟
            },
            {
                type: 'selection',
                width: 60,
                align: 'center'
            }
            ],

            selectedObj1: null, // 选中对象容器
            selectedObj2: null, // 选中对象容器
            selectedObj3: null, // 选中对象容器

            addModal: false, // 添加Modal的开关
            loading: true,
            modalTitle: '',
            optType: 'add', // add,edit
            tab: 0,
            addObj: {
                type: 1, // 1->故障类型,2->失效模式
                faultType: '', // mTypeVal 故障类型文本框
                faultList: [], // listid 故障类型下拉列表
                faultTypeDrop: 0,
                failureMode: '', // title 失效模式
                status: 1
            },

            defineFaultInfoModal: false,
            defineFaultInfoObj: {
                faultType: '', // mTypeVal 故障类型文本框
                faultList: [], // listid 故障类型下拉列表
                failureMode: '', // title 失效模式
                failureModeList: []
            }

        }
    },
    mounted () {
        this.initMachineFTypeList()
    },
    methods: {
        initMachineFTypeList () {
            axios.request({
                url: '/config/MachineType/GetEditDcategory',
                method: 'get'
            }).then(res => {
                if (res.data.data != undefined && res.data.data.length > 0) {
                    this.initPageData.machineFTypeList = res.data.data
                } else {
                    this.initPageData.machineFTypeList = []
                }
            })
        },
        machineFTypeChange (data) {
            let params = {
                id: data === undefined ? 0 : data.value
            }
            this.filterObj.machineFTypeName = data.label
            axios.request({
                url: '/config/MachineType/GetLastMachineType',
                params,
                method: 'get'
            }).then(res => {
                if (res.data.data != undefined && res.data.data.length > 0) {
                    this.initPageData.machineCTypeList = res.data.data
                } else {
                    this.initPageData.machineCTypeList = []
                }
                this.filterObj.machineCType = 0
            })
        },
        machineCTypeChange (data) {
            this.filterObj.machineCTypeName = data.label
        },
        timechange (value) {
            this.filterObj.time = value
        },

        handleRowChange (currentRow, oldCurrentRow) { // 选中一条数据，触发事件
            if (this.selectedObj2 != null) {
                this.$refs.table2.clearCurrentRow()
                this.selectedObj2 = null
            }
            if (this.selectedObj3 != null) {
                this.$refs.table3.clearCurrentRow()
                this.selectedObj3 = null
            }
            this.selectedObj1 = currentRow
        },

        changePage2 (value) { // 换页事件
            this.page2 = value
            this.tableData2 = this.search(this.page2, this.pagesize2)
        },
        handleRowChange2 (currentRow, oldCurrentRow) { // 选中一条数据，触发事件
            if (this.selectedObj1 != null) {
                this.$refs.table1.clearCurrentRow()
                this.selectedObj1 = null
            }
            if (this.selectedObj3 != null) {
                this.$refs.table3.clearCurrentRow()
                this.selectedObj3 = null
            }
            this.selectedObj2 = currentRow
        },
        handlePageSize2 (value) { // 切换分页页数，触发事件
            this.pagesize2 = value
            this.tableData2 = this.search(this.page2, this.pagesize2)
        },

        changePage3 (value) { // 换页事件
            this.page3 = value
            this.tableData3 = this.search(this.page3, this.pagesize3)
        },
        handleRowChange3 (currentRow, oldCurrentRow) { // 选中一条数据，触发事件
            if (this.selectedObj1 != null) {
                this.$refs.table1.clearCurrentRow()
                this.selectedObj1 = null
            }
            if (this.selectedObj2 != null) {
                this.$refs.table2.clearCurrentRow()
                this.selectedObj2 = null
            }
            this.selectedObj3 = currentRow
        },
        handlePageSize3 (value) { // 切换分页页数，触发事件
            this.pagesize3 = value
            this.tableData3 = this.search(this.page3, this.pagesize3)
        },

        search (page, pagesize) { // 点击查询，触发事件
            if (this.filterObj.machineCType === 0) {
                alert('请选择子级设备类型！')
                return false
            }
            // 获取故障列表
            axios.request({
                url: '/tpm/FaultType/GetFaultTypeList?machinetypeid=' + (this.filterObj.machineCType === 0 ? this.filterObj
                    .machineFType : this.filterObj.machineCType),
                method: 'get'
            }).then(res => {
                if (res.data.ret === 1) {
                    let data = []
                    res.data.data.forEach(item => {
                        if (item) {
                            data.push({
                                machineFTypeName: this.filterObj.machineFTypeName,
                                machineCTypeName: this.filterObj.machineCTypeName,
                                faultType: item.faulttype,
                                id: item.listid
                            })
                        }
                    })
                    this.tableData1 = data
                }
            })
            // 获取失效模式列表
            let params = {
                machinetypeid: this.filterObj.machineCType,
                page: this.page2,
                pagesize: this.pagesize2
            }
            axios.request({
                url: '/tpm/FaultType/GetFailureModeList',
                params,
                method: 'get'
            }).then(res => {
                if (res.data.ret === 1) {
                    this.total2 = res.data.total
                    let data = []
                    res.data.data.forEach(item => {
                        if (item) {
                            data.push({
                                machineFTypeName: this.filterObj.machineFTypeName,
                                machineCTypeName: this.filterObj.machineCTypeName,
                                faultType: item.faulttype,
                                failureMode: item.faultcontents,
                                status: item.status === 1 ? '启用' : '停用',
                                faultTypeID: item.faulttypeid,
                                failureModeID: item.faultcontentid
                            })
                        }
                    })
                    this.tableData2 = data
                }
            })

            this.getUnstandardRepairInfo()
        },
        search2 () {
            this.getUnstandardRepairInfo()
        },
        getUnstandardRepairInfo () {
            if (this.filterObj.machineCType === 0) {
                alert('请选择子级设备类型！')
                return false
            }
            // 获取非标维修列表
            let params = {
                machineType: this.filterObj.machineCType === 0 ? this.filterObj.machineFType : this.filterObj.machineCType,
                starttime: this.filterObj.time[0],
                endtime: this.filterObj.time[1],
                page: this.page3,
                pagesize: this.pagesize3
            }
            axios.request({
                url: '/tpm/Repair/getUnstandardRepairInfo',
                params,
                method: 'get'
            }).then(res => {
                // let res = {
                //   data: {
                //     "total": 36,
                //     "page": 1,
                //     "pagesize": 10,
                //     "ret": 1,
                //     "msg": 1,
                //     "data": [{
                //       "id": 478,
                //       "remark": "A车刹车电机晃动厉害",
                //       "fault_description": "天桥纠偏刹车棍电机一直晃动，至今没有合理的解决方案",
                //       "repair_process": "一直晃动",
                //       "real_faultid_desc": "设计缺陷",
                //       "sparepartid": "",
                //       "createtime": 1547209927,
                //       "stoptime": 237,
                //       "nickname": "张南南",
                //       "reporttime": "2019-01-11 20:32",
                //       "add_repairmid_name": "",
                //       "sparepart": "充电电锤(1401772)*1",
                //       "checktime": 1547224195
                //     }, {
                //       "id": 483,
                //       "remark": "B  车天桥刹车数为   0    实际瓦纸刹车太大，导致断纸多次\n请尽快维修",
                //       "fault_description": "B车下层天桥刹车轮驱动马达脱落",
                //       "repair_process": "马达脱落",
                //       "real_faultid_desc": "厂家设计缺陷，更换不到一年脱落，",
                //       "sparepartid": "",
                //       "createtime": 1547241344,
                //       "stoptime": 6715,
                //       "nickname": "张南南",
                //       "reporttime": "2019-01-12 05:15",
                //       "add_repairmid_name": "张南南",
                //       "sparepart": "",
                //       "checktime": 1547644256
                //     }]
                //   }
                // }
                if (res.data.ret === 1) {
                    this.total3 = res.data.total
                    let data = []
                    if (res.data.data != 1) {
                        res.data.data.forEach(item => {
                            if (item) {
                                data.push({
                                    remark: item.remark,
                                    fault_description: item.fault_description,
                                    repair_process: item.repair_process,
                                    real_faultid_desc: item.real_faultid_desc,
                                    sparepart: item.sparepart,
                                    reporttime: item.reporttime,
                                    stoptime: item.stoptime,
                                    add_repairmid_name: item.add_repairmid_name,
                                    id: item.id
                                })
                            }
                        })
                    }
                    this.tableData3 = data
                }
            })
        },
        add () {
            if (this.filterObj.machineCType === 0) {
                alert('请选择子级设备类型！')
                return false
            }
            this.optType = 'add'
            this.addModal = true
            this.modalTitle = '添加'
            this.tab = 0
            this.initAddModal() // 初始化
            // this.$refs.addObj.resetFields()
        },
        edit () {
            if (this.selectedObj1 === null && this.selectedObj2 == null) {
                alert('请选择要修改的数据！')
                return false
            }
            this.tab = this.selectedObj1 != null ? 0 : 1
            this.optType = 'edit'
            this.addModal = true
            this.modalTitle = '修改'
            this.initEditModal() // 初始化
            // this.$refs.addObj.resetFields()
        },
        initAddModal () {
            let params = {
                machinetypeid: this.filterObj.machineCType
            }
            let temp = []
            axios.request({
                url: '/tpm/FaultType/GetFaultTypeList',
                params,
                method: 'get'
            }).then(res => {
                if (res.data.ret === 1 && res.data.data != undefined) {
                    res.data.data.forEach(item => {
                        temp.push({
                            title: item.faulttype,
                            id: item.listid
                        })
                    })
                }
                this.addObj.faultList = temp
            })
        },
        initEditModal () {
            let params = {
                machinetypeid: this.filterObj.machineCType
            }
            let temp = []
            axios.request({
                url: '/tpm/FaultType/GetFaultTypeList',
                params,
                method: 'get'
            }).then(res => {
                if (res.data.ret === 1 && res.data.data != undefined) {
                    res.data.data.forEach(item => {
                        temp.push({
                            title: item.faulttype,
                            id: item.listid
                        })
                    })
                }
                this.addObj.faultList = temp
                if (this.selectedObj1 != null) {
                    this.addObj.faultType = this.selectedObj1.faultType
                }
                if (this.selectedObj2 != null) {
                    this.addObj.faultTypeDrop = this.selectedObj2.faultTypeID
                    this.addObj.failureMode = this.selectedObj2.failureMode
                }
            })
        },
        del () { // 删除
            if (this.selectedObj1 === null && this.selectedObj2 === null && this.selectedObj3 === null) {
                alert(this.$t(1043))
                return false
            } else {
                if (confirm('确认删除该条数据吗')) {
                    let url = ''
                    if (this.selectedObj1 != null) {
                        url = '/tpm/FaultType/DeleteFaultType?typeid=' + this.selectedObj1.id
                    } else if (this.selectedObj2 != null) {
                        url = '/tpm/FaultType/DeleteInvalidMode?contentid=' + this.selectedObj2.failureModeID
                    }
                    // console.log(this.selectedObj1)
                    // console.log(this.selectedObj2)
                    // console.log(url)
                    axios.request({
                        url: url,
                        method: 'post'
                    }).then(res => {
                        if (res.data.ret === 1) {
                            this.$Message.success(this.$t(1058))
                            this.search(1, 10)
                        } else {
                            this.$Message.error(this.$t(res.data.msg))
                        }
                    })
                }
            }
        },
        faultChangeAdd (selectedRow) {

        },
        handleSubmit (name) {
            if (this.optType === 'add') {
                this.addHandle()
            } else {
                this.editHandle()
            }
            // post
        },
        addHandle () {
            // 验证
            if (this.tab === 0) { // 添加故障类型
                if (this.addObj.faultType === '') {
                    this.$Message.error('故障类型不能为空')
                    // 解决ok按钮loading的问题
                    this.clearLoading()
                    return false
                }
                let data = {
                    title: this.addObj.faultType,
                    typeid: this.filterObj.machineCType
                }
                axios.request({
                    url: '/tpm/FaultType/AddFaultType',
                    data,
                    method: 'post'
                }).then(res => {
                    if (res.data.ret === 1) { // res.data.ret === 1
                        this.$Message.success(this.$t(1055))
                        this.addModal = false
                        this.search(1, 10)
                    } else {
                        this.$Message.error(this.$t(1056))
                        // 解决ok按钮loading的问题
                        this.clearLoading()
                        return false
                    }
                })
            } else { // 添加失效模式
                if (this.addObj.faultTypeDrop === 0) {
                    this.$Message.error('请选择故障类型')
                    // 解决ok按钮loading的问题
                    this.clearLoading()
                    return false
                }
                if (this.addObj.failureMode === '') {
                    this.$Message.error('请输入失效模式')
                    // 解决ok按钮loading的问题
                    this.clearLoading()
                    return false
                }
                let data = {
                    title: this.addObj.failureMode, // 失效模式
                    typeid: this.filterObj.machineCType, // 设备子类型
                    listid: this.addObj.faultTypeDrop // 故障类型
                }
                axios.request({
                    url: '/tpm/FaultType/AddFaultType',
                    data,
                    method: 'post'
                }).then(res => {
                    if (res.data.ret === 1) { // res.data.ret === 1
                        this.$Message.success(this.$t(1055))
                        this.addModal = false
                        this.search(1, 10)
                    } else {
                        this.$Message.error(this.$t(1056))
                        // 解决ok按钮loading的问题
                        this.clearLoading()
                    }
                })
            }
        },
        editHandle () {
            // 验证
            if (this.tab === 0) { // 修改故障类型
                if (this.addObj.faultType === '') {
                    this.$Message.error('故障类型不能为空')
                    // 解决ok按钮loading的问题
                    this.clearLoading()
                    return false
                }
                let data = {
                    faulttypeid: this.selectedObj1.id,
                    faulttype: this.addObj.faultType
                }
                axios.request({
                    url: '/tpm/FaultType/EditFaultType',
                    data,
                    method: 'post'
                }).then(res => {
                    if (res.data.ret === 1) { // res.data.ret === 1
                        this.$Message.success(this.$t(1060))
                        this.addModal = false
                        this.search(1, 10)
                    } else {
                        this.$Message.error(this.$t(1061))
                        // 解决ok按钮loading的问题
                        this.clearLoading()
                    }
                })
            } else { // 修改失效模式
                if (this.addObj.faultTypeDrop === 0) {
                    this.$Message.error('请选择故障类型')
                    // 解决ok按钮loading的问题
                    this.clearLoading()
                    return false
                }
                if (this.addObj.failureMode === '') {
                    this.$Message.error('请输入失效模式')
                    // 解决ok按钮loading的问题
                    this.clearLoading()
                    return false
                }
                let data = {
                    faultcontentid: this.selectedObj2.failureModeID, // 失效模式id
                    faultcontent: this.addObj.failureMode, // 失效模式内容
                    status: this.addObj.status, // 是否启用1启用，0停用
                    faulttypeid: this.selectedObj2.faultTypeID, // 故障类型id
                    faulttype: '' // 没用？
                }
                axios.request({
                    url: '/tpm/FaultType/EditInvalidMode',
                    data,
                    method: 'post'
                }).then(res => {
                    if (res.data.ret === 1) { // res.data.ret === 1
                        this.$Message.success(this.$t(1060))
                        this.addModal = false
                        this.search(1, 10)
                    } else {
                        this.$Message.error(this.$t(1061))
                        // 解决ok按钮loading的问题
                        this.clearLoading()
                    }
                })
            }
        },
        selectionChange (selection) {
            this.selection = selection
        },
        defineFaultInfo () {
            if (this.selection.length === 0) {
                alert('请先选择数据！')
                return false
            }
            this.defineFaultInfoModal = true
            this.initDefineFaultInfoModal()
        },
        initDefineFaultInfoModal () {
            let params = {
                machinetypeid: this.filterObj.machineCType
            }
            let temp = []
            axios.request({
                url: '/tpm/FaultType/GetFaultTypeList',
                params,
                method: 'get'
            }).then(res => {
                if (res.data.ret === 1 && res.data.data != undefined) {
                    res.data.data.forEach(item => {
                        temp.push({
                            title: item.faulttype,
                            id: item.listid
                        })
                    })
                }
                this.defineFaultInfoObj.faultList = temp
            })
            this.defineFaultInfoObj.faultType = 0
            this.defineFaultInfoObj.failureMode = 0
        },
        faultChangeDefine (row) {
            let params = {
                faulttypeid: row.value
            }
            let temp = []
            axios.request({
                url: '/tpm/FaultType/GetInvalidModesByTypeId',
                params,
                method: 'get'
            }).then(res => {
                if (res.data.ret === 1 && res.data.data != undefined) {
                    res.data.data.forEach(item => {
                        temp.push({
                            title: item.title,
                            id: item.id
                        })
                    })
                }
                this.defineFaultInfoObj.failureModeList = temp
            })
            this.defineFaultInfoObj.failureMode = 0
        },
        DefineFaultInfoSubmit () {
            if (this.defineFaultInfoObj.faultType === 0) {
                this.$Message.error('请选择故障类型')
                // 解决ok按钮loading的问题
                this.clearLoading()
                return false
            }
            if (this.defineFaultInfoObj.failureMode === 0) {
                this.$Message.error('请选择失效模式')
                // 解决ok按钮loading的问题
                this.clearLoading()
                return false
            }
            let ids = []
            if (this.selection.length > 0) {
                this.selection.forEach(item => {
                    ids.push(item.id)
                })
            }
            let data = {
                id: ids.toString(), // 失效模式id
                fault_id: this.defineFaultInfoObj.faultType, // 失效模式内容
                content_id: this.defineFaultInfoObj.failureMode
            }
            axios.request({
                url: '/tpm/Repair/batchDefineRepairFault',
                data,
                method: 'get'
            }).then(res => {
                if (res.data.ret === 1) { // res.data.ret === 1
                    this.$Message.success('定义成功')
                    this.addModal = false
                    this.search(1, 10)
                } else {
                    this.$Message.error('定义失败')
                    // 解决ok按钮loading的问题
                    this.clearLoading()
                }
            })
        },

        changeTab (e) {
            // 初始化数据
            if (this.optType === 'add') {
                this.addObj.faultType = ''
                this.addObj.faultTypeDrop = 0
                this.addObj.failureMode = ''
            }
        },
        clearLoading () {
            this.loading = false
            this.$nextTick(() => {
                this.loading = true
            })
        },
        changeDate (dateA) {
            var dateee = new Date(dateA).toJSON()
            var date = new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(
                /\.[\d]{3}Z/,
                '')
            return date
        },
        importFromExcel () {
            const file = this.$refs.fileInt.files[0]
            const data = new FormData()
            data.append('file', file)
            axios.request({
                url: '/tpm/Upload/Submit?templateName=FaultType',
                data,
                method: 'post'
            }).then(res => {
                if (res.data.ret === 1) {
                    this.$Message.success(this.$t(100378))
                } else {
                    this.$Message.error(this.$t(res.data.msg));
                }
            }).catch(err => {
                alert(err.data.msg)
            })
        },
        downModel () {
            axios.request({
                url: '/config/download/GetTemplate?name=FaultType',
                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))
                }
            })
        },
        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'))
            } else {
                if ((res.msg + '').indexOf(',') != -1) {
                    inittip(res.msg)
                } else {
                    this.$Message.error(this.$t(res.msg))
                }
            }
        },
        handleError () {
            this.$Message.error(this.$t('950399')) // 数据导入失败！
        }

    }
}
</script>
<style lang="less" scoped>
  .unstandard {
    border-radius: 5px;
    padding: 6px;
    width: 150px;
    text-align: center;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    float: left;
  }
</style>
