<template>
  <div class="app-container">
    <div class="header">
      <el-button icon="el-icon-d-arrow-left" plain type="primary" class="back" @click="goBack">返回</el-button>
      <h1>{{ '【' + deviceInfo.name + '】' }}设备明细</h1>
    </div>
    <el-divider></el-divider>
    <el-descriptions class="descriptions" :column="column" border style="text-align: center;">
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="key" class="el-input__icon input-icon" />
          出厂编号
        </template>
        {{ deviceInfo.code }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="dict" class="el-input__icon input-icon" />
          设备名称
        </template>
        {{ deviceInfo.name }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="bug" class="el-input__icon input-icon" />
          设备类别
        </template>
        {{ deviceInfo.type }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="TeenyiconsYenSolid" class="el-input__icon input-icon" />
          购买价格
        </template>
        {{ deviceInfo.cost }} 元
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="date" class="el-input__icon input-icon" />
          购置时间
        </template>
        {{ parseTime(deviceInfo.acquisitionTime, '{y}-{m}-{d}') }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="Branding" class="el-input__icon input-icon" />
          设备品牌
        </template>
        {{ deviceInfo.brand }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="date" class="el-input__icon input-icon" />
          预计使用年限
        </template>
        {{ deviceInfo.expectLife }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="TeenyiconsYenSolid" class="el-input__icon input-icon" />
          单日成本
        </template>
        {{ deviceInfo.dayCost }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="place" class="el-input__icon input-icon" />
          存放地点
        </template>
        {{ deviceInfo.place }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="dept" class="el-input__icon input-icon" />
          管理部门
        </template>
        {{ deviceInfo.dept ? deviceInfo.dept.deptName : '' }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="dept" class="el-input__icon input-icon" />
          状态
        </template>
        {{ statusTypeText(deviceInfo.status) }}
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <svg-icon slot="prefix" icon-class="remark" class="el-input__icon input-icon" />
          备注
        </template>
        {{ deviceInfo.remark }}
      </el-descriptions-item>
    </el-descriptions>

    <el-divider></el-divider>
    <el-row :gutter="20">
      <!-- 维保记录 -->
      <el-col :span="12" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <h3>维保记录</h3>
          </div>
          <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddExpense"
                v-hasPermi="['device:record:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                @click="handleDeleteExpense" v-hasPermi="['device:record:remove']">删除</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExportExpense"
                v-hasPermi="['device:record:export']">导出</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="info" plain icon="el-icon-s-release" size="mini" @click="handleScrap"
                v-hasPermi="['device:record:add']">{{ scrapButtonName
                }}</el-button>
            </el-col>
          </el-row>
          <el-table v-loading="loading" :data="expenseList" @selection-change="handleSelectionExpenseChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="负责人" align="center" prop="userId">
              <template slot-scope="scope">
                {{ scope.row.user ? scope.row.user.nickName : '' }}
              </template>
            </el-table-column>
            <el-table-column label="费用类型" align="center" prop="expenseType">
              <template slot-scope="scope">
                <el-tag :type="expenseTypeStyle(scope.row.expenseType)">{{ expenseTypeText(scope.row.expenseType)
                  }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="费用金额" align="center" prop="expense" />
            <el-table-column label="发生日期" align="center" prop="occurDate">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.occurDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" prop="remark" />
            <el-table-column label="附件" align="center" prop="document">
              <template slot-scope="scope">
                <el-link type="primary" @click="reviewWord(`${baseUrl}${'/profile/upload' + scope.row.document}`)">
                  {{ getFileName(scope.row.document) }}
                </el-link>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdateExpense(scope.row)"
                  v-hasPermi="['device:record:edit']">修改</el-button>
                <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteExpense(scope.row)"
                  v-hasPermi="['device:record:remove']">删除</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination v-show="expenseTotal > 0" :total="expenseTotal" :autoScroll="false"
            :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getExpenseList" />
        </el-card>
      </el-col>
      <el-col :span="12" :xs="24">
        <!-- 移交、申领记录 -->
        <el-card>
          <div slot="header" class="clearfix">
            <h3>{{ cardName }}</h3>
          </div>
          <el-row v-if="routeType == 'supply'" :gutter="10" class="mb8">
            <el-col :span="1.5">
              <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddHandover"
                v-hasPermi="['device:record:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                @click="handleDeleteHandover" v-hasPermi="['device:record:remove']">删除</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExportHandover"
                v-hasPermi="['device:record:export']">导出</el-button>
            </el-col>
          </el-row>
          <!-- 设备申领记录 -->
          <el-table v-if="routeType == 'equipment'" v-loading="loading" :data="approvalList">
            <el-table-column type="index" width="55" align="center" label="序号" />
            <el-table-column label="申请人" align="center" prop="user.nickName">
              <template slot-scope="scope">
                {{ scope.row.applierUser ? scope.row.applierUser.nickName : '' }}
              </template>
            </el-table-column>
            <el-table-column label="使用部门" align="center" prop="dept.deptName">
              <template slot-scope="scope">
                {{ scope.row.dept ? scope.row.dept.deptName : '' }}
              </template>
            </el-table-column>
            <el-table-column label="项目编号" align="center" prop="project.projectNumber">
              <template slot-scope="scope">
                {{ scope.row.project ? scope.row.project.projectNumber : '' }}
              </template>
            </el-table-column>
            <el-table-column label="项目名称" align="center" prop="project.projectName">
              <template slot-scope="scope">
                {{ scope.row.project ? scope.row.project.projectName : '' }}
              </template>
            </el-table-column>
            <el-table-column label="申请时间" align="center" prop="applyDate">
              <template slot-scope="scope">
                {{ scope.row.applyDate }}
              </template>
            </el-table-column>
            <el-table-column label="归还时间" align="center" prop="returnDate">
              <template slot-scope="scope">
                {{ scope.row.returnDate }}
              </template>
            </el-table-column>
            <el-table-column label="设备状况" align="center" prop="state">
              <template slot-scope="scope">
                <el-tag :type="stateTypeStyle(scope.row)">{{ stateTypeText(scope.row) }}</el-tag>
              </template>
            </el-table-column>
          </el-table>
          <pagination v-show="approvalTotal > 0" :total="approvalTotal" :autoScroll="false"
            :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getApprovalList" />

          <!-- 设备移交记录 -->
          <el-table v-if="routeType == 'supply'" v-loading="loading" :data="handoverList"
            @selection-change="handleSelectionHandoverChange">
            <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="移交人" align="center" prop="handoverUser.nickName">
              <template slot-scope="scope">
                {{ scope.row.handoverUser ? scope.row.handoverUser.nickName : '' }}
              </template>
            </el-table-column>
            <el-table-column label="移交部门" align="center" prop="handoverDept.deptName">
              <template slot-scope="scope">
                {{ scope.row.handoverDept ? scope.row.handoverDept.deptName : '' }}
              </template>
            </el-table-column>
            <el-table-column label="接收人" align="center" prop="receiveUser.nickName">
              <template slot-scope="scope">
                {{ scope.row.receiveUser ? scope.row.receiveUser.nickName : '' }}
              </template>
            </el-table-column>
            <el-table-column label="接收部门" align="center" prop="receiveDept.deptName">
              <template slot-scope="scope">
                {{ scope.row.receiveDept ? scope.row.receiveDept.deptName : '' }}
              </template>
            </el-table-column>
            <el-table-column label="移交日期" align="center" prop="handoverDate">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.handoverDate, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="设备软件说明" align="center" prop="description" />
            <el-table-column label="交接原因" align="center" prop="reason" />
            <el-table-column label="备注" align="center" prop="remark" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdateHandover(scope.row)"
                  v-hasPermi="['device:record:edit']">修改</el-button>
                <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteHandover(scope.row)"
                  v-hasPermi="['device:record:remove']">删除</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination v-show="handoverTotal > 0" :total="handoverTotal" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getHandoverList" />
        </el-card>
      </el-col>
    </el-row>
    <!-- 添加或修改cmc设备费用对话框 -->
    <el-dialog :title="title" :visible.sync="expenseOpen" width="500px" append-to-body>
      <el-form ref="expenseForm" :model="expenseForm" :rules="rules" label-width="80px">
        <el-form-item label="负责人" prop="userId">
          <el-select v-model="expenseForm.userId" filterable clearable style="width:220px">
            <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId"
              v-if="item.nickName != 'admin'">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="费用类型" prop="expenseType">
          <el-select v-model="expenseForm.expenseType" placeholder="请选择" clearable @change="expenseTypePath">
            <el-option label="保险费" value="0"></el-option>
            <el-option label="维修/保养费" value="1"></el-option>
            <el-option label="检定费" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="费用金额" prop="expense">
          <el-input v-model="expenseForm.expense" placeholder="请输入费用金额" />
        </el-form-item>
        <el-form-item label="发生日期" prop="occurDate">
          <el-date-picker clearable v-model="expenseForm.occurDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择发生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="expenseForm.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="附件" prop="document">
          <FileUpload :limit="1" :filePathName="expenseName"
            :fileType="['doc', 'docx', 'xls', 'xlsx', 'pdf', 'rar', 'zip']" @input="getExpensePath"></FileUpload>
          <div v-if="expenseModifyOpen">
            <transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear"
              tag="ul">
              <li key="li01" class="el-upload-list__item ele-upload-list__item-content">
                <el-link :href="`${baseUrl}${'/profile/upload' + expenseForm.document}`" :underline="false"
                  target="_blank">
                  <span class="el-icon-document" style="color:#0011ff;text-decoration: underline;">
                    {{ getFileName(expenseForm.document) }}
                  </span>
                </el-link>
              </li>
            </transition-group>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitExpenseForm">确 定</el-button>
        <el-button @click="expenseCancel">取 消</el-button>
      </div>
    </el-dialog>.
    <!-- 添加或修改cmc设备移交对话框 -->
    <el-dialog :title="title" :visible.sync="handoverOpen" width="500px" append-to-body>
      <el-form ref="handoverForm" :model="handoverForm" :rules="rules" label-width="80px">
        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
            <el-form-item label="移交部门" prop="handoverDeptId">
              <el-select v-model="handoverForm.handoverDeptId" filterable clearable style="width:120px"
                @change="deptChange">
                <el-option v-for="item in deptList" :key="item.deptId" :label="item.deptName" :value="item.deptId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="移交人" prop="handoverUserId">
              <el-select v-model="handoverForm.handoverUserId" filterable clearable style="width:120px">
                <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId"
                  v-if="item.nickName != 'admin'">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" :xs="24">
            <el-form-item label="接收部门" prop="receiveDeptId">
              <el-select v-model="handoverForm.receiveDeptId" filterable clearable style="width:120px"
                @change="deptChange">
                <el-option v-for="item in deptList" :key="item.deptId" :label="item.deptName" :value="item.deptId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="接收人" prop="receiveUserId">
              <el-select v-model="handoverForm.receiveUserId" filterable clearable style="width:120px">
                <el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId"
                  v-if="item.nickName != 'admin'">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="移交日期" prop="handoverDate">
          <el-date-picker clearable v-model="handoverForm.handoverDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择移交日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="设备软件说明" prop="description">
          <el-input v-model="handoverForm.description" placeholder="请输入设备软件说明" />
        </el-form-item>
        <el-form-item label="交接原因" prop="reason">
          <el-input v-model="handoverForm.reason" placeholder="请输入交接原因" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="handoverForm.remark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitHandoverForm">确 定</el-button>
        <el-button @click="handoverCancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改cmc设备报废对话框 -->
    <el-dialog :title="title" :visible.sync="scrapOpen" width="500px" append-to-body>
      <el-form ref="scrapForm" :model="scrapForm" :rules="rules" label-width="80px">
        <el-form-item label="原价值" prop="cost">
          <el-input v-model="scrapForm.cost" placeholder="请输入原价值" />
        </el-form-item>
        <el-form-item label="报废日期" prop="scrapDate">
          <el-date-picker clearable v-model="scrapForm.scrapDate" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择报废日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报废原因" prop="reason">
          <el-input v-model="scrapForm.reason" placeholder="请输入报废原因" />
        </el-form-item>
        <el-form-item label="处理结果" prop="deal">
          <el-input v-model="scrapForm.deal" placeholder="请输入处理结果" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="scrapForm.remark" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="附件" prop="document">
          <FileUpload :limit="1" :filePathName="'设备/报废'" :fileType="['doc', 'docx', 'xls', 'xlsx', 'pdf', 'rar', 'zip']"
            @input="getScrapPath"></FileUpload>
          <div v-if="scrapModifyOpen">
            <transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear"
              tag="ul">
              <li key="li01" class="el-upload-list__item ele-upload-list__item-content">
                <el-link :href="`${baseUrl}${'/profile/upload' + scrapForm.document}`" :underline="false"
                  target="_blank">
                  <span class="el-icon-document" style="color:#0011ff;text-decoration: underline;">
                    {{ getFileName(scrapForm.document) }}
                  </span>
                </el-link>
              </li>
            </transition-group>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitScrapForm">确 定</el-button>
        <el-button @click="scrapCancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getDevice } from '@/api/oa/device/device.js'
import { listDeviceApproval } from "@/api/oa/device/deviceApproval";
import { listDeviceHandover, getDeviceHandover, delDeviceHandover, addDeviceHandover, updateDeviceHandover } from "@/api/oa/device/deviceHandover";
import { listDeviceExpense, getDeviceExpense, delDeviceExpense, addDeviceExpense, updateDeviceExpense } from "@/api/oa/device/deviceExpense";
import { listDeviceScrap, getDeviceScrap, delDeviceScrap, addDeviceScrap, updateDeviceScrap } from "@/api/oa/device/deviceScrap";
import { listDept } from '@/api/system/dept';
import { listUser } from '@/api/system/user';
export default {
  data() {
    let validateApproval = (rule, value, callback) => {
      setTimeout(() => {
        if (!value) {
          return callback(new Error('请输入金额'));
        }
        if (!this.isNumber(Number(value))) {
          callback(new Error('请输入数字值'));
        } else {
          callback();
        }
      }, 100)
    }
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      // 遮罩层
      loading: true,
      // 选中数组
      expenseIds: [],
      handoverIds: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      approvalTotal: 0,
      expenseTotal: 0,
      handoverTotal: 0,
      // cmc设备审批表格数据
      approvalList: [],
      expenseList: [],
      handoverList: [],
      userList: [],
      deptList: [],
      cardName: '',
      column: 4,
      deviceInfo: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      expenseOpen: false,
      expenseModifyOpen: false,
      handoverOpen: false,
      scrapOpen: false,
      scrapModifyOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      expenseForm: {
        userId: 17,
      },
      handoverForm: {},
      scrapForm: {},
      // 表单校验
      rules: {
      },
      loading: false,
      routeType: '',
      scrapButtonName: '',
      expenseName: ''
    }
  },
  created() {
    if (this.$route.query) {
      this.routeType = this.$route.query.type
      if (this.routeType == 'equipment') {
        this.cardName = '申领记录';
        this.getApprovalList();
      }
      else {
        this.cardName = '移交记录';
        this.getHandoverList();
      }
      getDevice(this.$route.query.deviceId).then(res => {
        this.deviceInfo = res.data;
      })
      this.getExpenseList();
      this.getDeptList();
      this.getUserList();
      this.getScrapStatus();
    }
    if (this.$store.state.app.device == 'desktop') {

    } else {
      this.column = 1
    }
  },
  methods: {
    getApprovalList() {
      this.queryParams.modifyDevices = this.$route.query.deviceId
      listDeviceApproval(this.queryParams).then(res => {
        this.approvalList = res.rows;
        this.approvalTotal = res.total;
      })
    },
    getExpenseList() {
      this.queryParams.deviceId = this.$route.query.deviceId
      listDeviceExpense(this.queryParams).then(res => {
        this.expenseList = res.rows;
        this.expenseTotal = res.total;
      })
    },
    getHandoverList() {
      this.queryParams.deviceId = this.$route.query.deviceId
      listDeviceHandover(this.queryParams).then(res => {
        this.handoverList = res.rows;
        this.handoverTotal = res.total;
      })
    },
    getDeptList() {
      listDept({ pageSize: 9999, pageNum: 1 }).then(res => {
        this.deptList = res.data
      })
    },
    getUserList() {
      listUser({ pageSize: 9999, pageNum: 1 }).then(res => {
        this.userList = res.rows
      })
    },
    deptChange(val) {
      listUser({ pageSize: 9999, pageNum: 1, deptId: val }).then(res => {
        this.userList = res.rows
      })
    },
    getScrapStatus() {
      this.queryParams.deviceId = this.$route.query.deviceId
      listDeviceScrap(this.queryParams).then(res => {
        if (res.total > 0)
          this.scrapButtonName = '查看报废信息';
        else
          this.scrapButtonName = '前往报废';
      })
    },
    goBack() {
      let obj = { path: "/device/detail" }
      this.$tab.closeOpenPage(obj);
      this.$router.push({ path: '/oa/device/' + this.routeType });
    },
    //费用附件路径
    getExpensePath(val) {
      let arr = val.split('/upload')
      this.expenseForm.document = arr[1]
      if (val == "") {
        this.expenseForm.document = ""
      }
    },
    //报废附件路径
    getScrapPath(val) {
      let arr = val.split('/upload')
      this.scrapForm.document = arr[1]
      if (val == "") {
        this.scrapForm.document = ""
      }
    },
    getFileName(name) {
      if (name) {
        let arr = name.split('/')
        return arr[arr.length - 1];
      }
    },
    /** 搜索按钮操作 */
    handleExpenseQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.deviceId = this.$route.query.deviceId;
      this.getExpenseList();
    },
    // 多选框选中数据
    handleSelectionExpenseChange(selection) {
      this.expenseIds = selection.map(item => item.deviceExpenseId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleAddExpense() {
      this.expenseOpen = true;
      this.title = "添加设备费用明细";
    },
    handleUpdateExpense(row) {
      const deviceExpenseId = row.deviceExpenseId || this.expenseIds
      getDeviceExpense(deviceExpenseId).then(response => {
        this.expenseForm = response.data;
        this.expenseOpen = true;
        this.expenseModifyOpen = true;
        this.title = "修改设备费用明细";
      });
    },
    handleDeleteExpense(row) {
      const deviceExpenseIds = row.deviceExpenseId || this.expenseIds;
      this.$modal.confirm('是否确认删除设备费用编号为"' + deviceExpenseIds + '"的数据项？').then(function () {
        return delDeviceExpense(deviceExpenseIds);
      }).then(() => {
        this.getExpenseList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    handleExportExpense() {
      this.download('oa/deviceExpense/export', {
        ...this.queryParams
      }, `deviceExpense_${new Date().getTime()}.xlsx`)
    },
    // 表单重置
    resetExpense() {
      this.expenseForm = {
        deviceExpenseId: null,
      };
      this.resetForm("expenseForm");
    },
    submitExpenseForm() {
      this.$refs["expenseForm"].validate(valid => {
        if (valid) {
          this.expenseForm.deviceId = this.$route.query.deviceId
          if (this.expenseForm.deviceExpenseId != null) {
            updateDeviceExpense(this.expenseForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.expenseOpen = false;
              this.expenseModifyOpen = false;
              this.getExpenseList();
            });
          } else {
            addDeviceExpense(this.expenseForm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.expenseOpen = false;
              this.getExpenseList();
            });
          }
        }
      });
    },
    expenseCancel() {
      this.expenseOpen = false;
      this.expenseModifyOpen = false;
      this.resetExpense();
    },

    /* 申领记录 */
    /** 搜索按钮操作 */
    handleApprovalQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.modifyDevices = this.$route.query.deviceId;
      this.getApprovalList();
    },
    handleExportApproval() {
      this.download('oa/deviceApproval/export', {
        ...this.queryParams
      }, `deviceApproval_${new Date().getTime()}.xlsx`)
    },

    /* 移交记录 */
    /** 搜索按钮操作 */
    handleHandoverQuery() {
      this.queryParams.pageNum = 1;
      this.getHandoverList();
    },
    // 多选框选中数据
    handleSelectionHandoverChange(selection) {
      this.handoverIds = selection.map(item => item.deviceHandoverId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    handleAddHandover() {
      this.resetHandover();
      this.handoverOpen = true;
      this.title = "添加设备移交明细";
    },
    handleUpdateHandover(row) {
      this.resetHandover();
      const deviceHandoverId = row.deviceHandoverId || this.handoverIds
      getDeviceHandover(deviceHandoverId).then(response => {
        this.handoverForm = response.data;
        this.handoverOpen = true;
        this.title = "修改设备移交明细";
      });
    },
    handleDeleteHandover(row) {
      const deviceHandoverIds = row.deviceHandoverId || this.handoverIds;
      this.$modal.confirm('是否确认删除设备移交编号为"' + deviceHandoverIds + '"的数据项？').then(function () {
        return delDeviceHandover(deviceHandoverIds);
      }).then(() => {
        this.getHandoverList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    handleExportHandover() {
      this.download('oa/deviceHandover/export', {
        ...this.queryParams
      }, `deviceHandover_${new Date().getTime()}.xlsx`)
    },
    // 表单重置
    resetHandover() {
      this.handoverForm = {
        deviceHandoverId: null,
      };
      this.resetForm("handoverForm");
    },
    submitHandoverForm() {
      this.$refs["handoverForm"].validate(valid => {
        if (valid) {
          this.handoverForm.deviceId = this.$route.query.deviceId
          if (this.handoverForm.deviceHandoverId != null) {
            updateDeviceHandover(this.handoverForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.handoverOpen = false;
              this.getHandoverList();
            });
          } else {
            addDeviceHandover(this.handoverForm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.handoverOpen = false;
              this.getHandoverList();
            });
          }
        }
      });
    },
    handoverCancel() {
      this.handoverOpen = false;
      this.resetHandover();
    },

    /* 报废记录 */
    handleScrap() {
      if (this.scrapButtonName == '查看报废信息')
        this.handleUpdateScrap();
      else
        this.handleAddScrap();
    },
    handleAddScrap() {
      this.resetScrap();
      this.scrapOpen = true;
      this.title = "添加设备报废信息";
    },
    handleUpdateScrap() {
      this.resetScrap();
      this.scrapForm.deviceId = this.$route.query.deviceId
      listDeviceScrap(this.scrapForm).then(response => {
        this.scrapForm = response.rows[0];
        this.scrapOpen = true;
        this.scrapModifyOpen = true;
        this.title = "修改设备报废信息";
      });
    },
    // 表单重置
    resetScrap() {
      this.scrapForm = {
        deviceScrapId: null,
      };
      this.resetForm("scrapForm");
    },
    submitScrapForm() {
      this.$refs["scrapForm"].validate(valid => {
        if (valid) {
          this.scrapForm.deviceId = this.$route.query.deviceId
          if (this.scrapForm.deviceScrapId != null) {
            updateDeviceScrap(this.scrapForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.scrapOpen = false;
              this.scrapModifyOpen = false;
              getDevice(this.$route.query.deviceId).then(res => {
                this.deviceInfo = res.data;
              });
              this.getScrapStatus();
            });
          } else {
            addDeviceScrap(this.scrapForm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.scrapOpen = false;
              getDevice(this.$route.query.deviceId).then(res => {
                this.deviceInfo = res.data;
              });
              this.getScrapStatus();
            });
          }
        }
      });
    },
    scrapCancel() {
      this.scrapOpen = false;
      this.scrapModifyOpen = false;
      this.resetScrap();
    },
    isNumber(value) {
      return typeof value === 'number' && /^\d+(\.\d+)?$/.test(value);
    },
    expenseTypePath(val) {
      if (val == '0') {
        this.expenseName = '设备/保险费'
      }
      if (val == '1') {
        this.expenseName = '设备/维修保养费'
      }
      if (val == '3') {
        this.expenseName = '设备/检定费'
      }
    },
    expenseTypeText(row) {
      if (row == '0') {
        return '保险费'
      }
      if (row == '1') {
        return '维修/保养费'
      }
      if (row == '3') {
        return '检定费'
      }
    },
    expenseTypeStyle(row) {
      if (row == '0') {
        return 'primary'
      }
      if (row == '1') {
        return 'warning'
      }
      if (row == '3') {
        return 'success'
      }
    },
    stateTypeText(row) {
      if (!row.repairDevices || row.repairDevices.indexOf(this.$route.query.deviceId) == -1) {
        return '完好'
      }
      else {
        return '需维修'
      }
    },
    stateTypeStyle(row) {
      if (!row.repairDevices || row.repairDevices.indexOf(this.$route.query.deviceId) == -1) {
        return 'success'
      }
      else {
        return 'danger'
      }
    },
    statusTypeText(row) {
      if (row == '0') {
        return '被领用'
      }
      if (row == '1') {
        return '可领用'
      }
      if (row == '2') {
        return '维修中'
      }
      if (row == '3') {
        return '已停用'
      }
      if (row == '4') {
        return '已报废'
      }
      if (row == '5') {
        return '已处置'
      }
    },
    statusType(row) {
      if (row == '0') {
        return 'warning'
      }
      if (row == '1') {
        return 'success'
      }
      if (row == '2') {
        return 'primary'
      }
      if (row == '3') {
        return 'danger'
      }
      if (row == '4') {
        return 'info'
      }
      if (row == '5') {
        return ''
      }
    }
  },
}
</script>

<style lang="scss" scoped>
.header {
  position: relative;
  text-align: center;

  .back {
    position: absolute;
    left: 12px;
    top: -10px;
  }
}

.descriptions {
  padding: 20px 50px;
}


::v-deep .el-descriptions-item__label.is-bordered-label {
  color: #121212;
  background: rgba($color: #46a6ff, $alpha: 0.1);
  width: 200px;
}

::v-deep .el-descriptions .is-bordered .el-descriptions-item__cell {
  border: 1px solid #2d3f62;
}
</style>