<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="140px">
      <el-form-item label="单据类型" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择单据类型" @change="onQueryTypeChange">
          <el-option
            v-for="dict in dict.type.asset_order_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="单据编号" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入单据编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请日期" prop="applicationDate">
        <el-date-picker clearable
          v-model="queryParams.applicationDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择申请日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="申请部门" prop="applicationDepartment">
        <el-input
          v-model="queryParams.applicationDepartment"
          placeholder="请输入申请部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="queryParams.orderType === '1'" label="【调整】资产编号" prop="adjustmentAssetNumber">
        <el-input
          v-model="queryParams.adjustmentAssetNumber"
          placeholder="请输入【调整】资产编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="queryParams.orderType === '2'" label="【调拨】调出部门" prop="allocationCallOutDepartment">
        <el-input
          v-model="queryParams.allocationCallOutDepartment"
          placeholder="请输入【调拨】调出部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="queryParams.orderType === '2'" label="【调拨】调出经办人" prop="allocationCallOutBy">
        <el-input
          v-model="queryParams.allocationCallOutBy"
          placeholder="请输入【调拨】调出经办人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="queryParams.orderType === '2'" label="【调拨】调出日期" prop="allocationCallOutDate">
        <el-date-picker clearable
          v-model="queryParams.allocationCallOutDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择【调拨】调出日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item v-if="queryParams.orderType === '2'" label="【调拨】调入部门" prop="allocationCallInDepartment">
        <el-input
          v-model="queryParams.allocationCallInDepartment"
          placeholder="请输入【调拨】调入部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="queryParams.orderType === '2'" label="【调拨】调入经办人" prop="allocationCallInBy">
        <el-input
          v-model="queryParams.allocationCallInBy"
          placeholder="请输入【调拨】调入经办人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="queryParams.orderType === '2'" label="【调拨】调入日期" prop="allocationCallInDate">
        <el-date-picker clearable
          v-model="queryParams.allocationCallInDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择【调拨】调入日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item v-if="queryParams.orderType === '3'" label="【借出】借出部门" prop="lendDepartment">
        <el-input
          v-model="queryParams.lendDepartment"
          placeholder="请输入【借出】借出部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="queryParams.orderType === '3'" label="【借出】经手人" prop="lendBySponsor">
        <el-input
          v-model="queryParams.lendBySponsor"
          placeholder="请输入【借出】经手人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-if="queryParams.orderType === '3'" label="【借出】往来单位" prop="lendPassingUnit">
        <el-input
          v-model="queryParams.lendPassingUnit"
          placeholder="请输入【借出】往来单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原因说明" prop="reason">
        <el-input
          v-model="queryParams.reason"
          placeholder="请输入原因说明"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制单人" prop="preparedBy">
        <el-input
          v-model="queryParams.preparedBy"
          placeholder="请输入制单人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="制单部门" prop="preparedDepartment">
        <el-input
          v-model="queryParams.preparedDepartment"
          placeholder="请输入制单部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属公司" prop="corporation">
        <el-input
          v-model="queryParams.corporation"
          placeholder="请输入所属公司"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="记录状态" prop="recordStatus">
        <el-select v-model="queryParams.recordStatus" placeholder="请选择记录状态" clearable>
          <el-option
            v-for="dict in dict.type.asset_record_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['order:order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['order:order:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['order:order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['order:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="序号"
        type="index"
        width="50">
      </el-table-column>
      <!-- <el-table-column label="编号" align="center" prop="id" /> -->
      <el-table-column label="单据编号" align="center" prop="orderNumber" />
      <el-table-column label="单据类型" align="center" prop="orderType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.asset_order_type" :value="scope.row.orderType"/>
        </template>
      </el-table-column>
      <el-table-column v-if="queryParams.orderType !== '1'" label="资产总原值" align="center" prop="assetTotalOriginalValue" />
      <el-table-column v-if="queryParams.orderType !== '1'" label="资产总净值" align="center" prop="assetTotalNetValue" />
      <el-table-column label="申请日期" align="center" prop="applicationDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applicationDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请部门" align="center" prop="applicationDepartmentName" />
      <el-table-column v-if="queryParams.orderType === '1'" label="【调整】资产编号" align="center" prop="adjustmentAssetNumber" />
      <el-table-column v-if="queryParams.orderType === '1'" label="【调整】资产原信息" align="center" prop="adjustmentOriginalAssetInfo">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-search" @click="onSelectOriginalAssetInfo(scope.row.adjustmentOriginalAssetInfo)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column v-if="queryParams.orderType === '2'" label="【调拨】调出部门" align="center" prop="allocationCallOutDepartmentName" />
      <el-table-column v-if="queryParams.orderType === '2'" label="【调拨】调出经办人" align="center" prop="allocationCallOutBy" />
      <el-table-column v-if="queryParams.orderType === '2'" label="【调拨】调出日期" align="center" prop="allocationCallOutDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.allocationCallOutDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="queryParams.orderType === '2'" label="【调拨】调入部门" align="center" prop="allocationCallInDepartmentName" />
      <el-table-column v-if="queryParams.orderType === '2'" label="【调拨】调入经办人" align="center" prop="allocationCallInBy" />
      <el-table-column v-if="queryParams.orderType === '2'" label="【调拨】调入日期" align="center" prop="allocationCallInDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.allocationCallInDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column v-if="queryParams.orderType === '2'" label="【调拨】新管理人" align="center" prop="allocationNewResponsiblePerson" />
      <el-table-column v-if="queryParams.orderType === '2'" label="【调拨】新功能位置编号" align="center" prop="allocationNewLocationNumber" />
      <el-table-column v-if="queryParams.orderType === '3'" label="【借出】借出部门" align="center" prop="lendDepartmentName" />
      <el-table-column v-if="queryParams.orderType === '3'" label="【借出】经手人" align="center" prop="lendBySponsor" />
      <el-table-column v-if="queryParams.orderType === '3'" label="【借出】往来单位" align="center" prop="lendPassingUnit" />
      <el-table-column label="原因说明" align="center" prop="reason" />
      <el-table-column label="制单人" align="center" prop="preparedBy" />
      <el-table-column label="制单部门" align="center" prop="preparedDepartmentName" />
      <el-table-column label="所属公司" align="center" prop="corporationName" />
      <el-table-column label="记录状态" align="center" prop="recordStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.asset_record_status" :value="scope.row.recordStatus"/>
        </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="handleUpdate(scope.row)"
            v-hasPermi="['order:order:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['order:order:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改资产单据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <el-form-item label="单据编号" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="单据编号（系统自动生成）" disabled/>
        </el-form-item>
        <el-form-item label="单据类型" prop="orderType">
          <el-select v-model="form.orderType" placeholder="请选择单据类型" @change="onFormTypeChange">
            <el-option
              v-for="dict in dict.type.asset_order_type"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="form.orderType !== 1" label="资产总原值" prop="assetTotalOriginalValue">
          <el-input v-model="form.assetTotalOriginalValue" placeholder="请输入资产总原值" />
        </el-form-item>
        <el-form-item v-if="form.orderType !== 1" label="资产总净值" prop="assetTotalNetValue">
          <el-input v-model="form.assetTotalNetValue" placeholder="请输入资产总净值" />
        </el-form-item>
        <el-form-item label="申请日期" prop="applicationDate">
          <el-date-picker clearable
            v-model="form.applicationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择申请日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="申请部门" prop="applicationDepartment">
          <el-input v-model="form.applicationDepartment" placeholder="请输入申请部门" />
        </el-form-item>
        <el-form-item v-if="form.orderType === 1" label="【调整】资产编号" prop="adjustmentAssetNumber">
          <el-input v-model="form.adjustmentAssetNumber" placeholder="请输入【调整】资产编号" />
        </el-form-item>
        <el-form-item v-if="form.orderType === 1" label="【调整】资产原信息" prop="adjustmentOriginalAssetInfo">
          <el-input v-model="form.adjustmentOriginalAssetInfo" type="textarea" placeholder="系统自动补充" disabled/>
        </el-form-item>
        <el-form-item v-if="form.orderType === 2" label="【调拨】调出部门" prop="allocationCallOutDepartment">
          <el-input v-model="form.allocationCallOutDepartment" placeholder="请输入【调拨】调出部门" />
        </el-form-item>
        <el-form-item v-if="form.orderType === 2" label="【调拨】调出经办人" prop="allocationCallOutBy">
          <el-input v-model="form.allocationCallOutBy" placeholder="请输入【调拨】调出经办人" />
        </el-form-item>
        <el-form-item v-if="form.orderType === 2" label="【调拨】调出日期" prop="allocationCallOutDate">
          <el-date-picker clearable
            v-model="form.allocationCallOutDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择【调拨】调出日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item v-if="form.orderType === 2" label="【调拨】调入部门" prop="allocationCallInDepartment">
          <el-input v-model="form.allocationCallInDepartment" placeholder="请输入【调拨】调入部门" />
        </el-form-item>
        <el-form-item v-if="form.orderType === 2" label="【调拨】调入经办人" prop="allocationCallInBy">
          <el-input v-model="form.allocationCallInBy" placeholder="请输入【调拨】调入经办人" />
        </el-form-item>
        <el-form-item v-if="form.orderType === 2" label="【调拨】调入日期" prop="allocationCallInDate">
          <el-date-picker clearable
            v-model="form.allocationCallInDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择【调拨】调入日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item v-if="form.orderType === 2" label="【调拨】新管理人" prop="allocationNewResponsiblePerson">
          <el-input v-model="form.allocationNewResponsiblePerson" placeholder="请输入【调拨】新管理人" />
        </el-form-item>
        <el-form-item v-if="form.orderType === 2" label="【调拨】新功能位置编号" prop="allocationNewLocationNumber">
          <el-input v-model="form.allocationNewLocationNumber" placeholder="请输入【调拨】新功能位置编号" />
        </el-form-item>
        <el-form-item v-if="form.orderType === 3" label="【借出】借出部门" prop="lendDepartment">
          <el-input v-model="form.lendDepartment" placeholder="请输入【借出】借出部门" />
        </el-form-item>
        <el-form-item v-if="form.orderType === 3" label="【借出】经手人" prop="lendBySponsor">
          <el-input v-model="form.lendBySponsor" placeholder="请输入【借出】经手人" />
        </el-form-item>
        <el-form-item v-if="form.orderType === 3" label="【借出】往来单位" prop="lendPassingUnit">
          <el-input v-model="form.lendPassingUnit" placeholder="请输入【借出】往来单位" />
        </el-form-item>
        <el-form-item label="原因说明" prop="reason">
          <el-input v-model="form.reason" placeholder="请输入原因说明" />
        </el-form-item>
        <!-- <el-form-item label="制单人" prop="preparedBy">
          <el-input v-model="form.preparedBy" placeholder="系统自动补充" disabled />
        </el-form-item>
        <el-form-item label="制单部门" prop="preparedDepartment">
          <el-input v-model="form.preparedDepartment" placeholder="系统自动补充" disabled />
        </el-form-item>
        <el-form-item label="所属公司" prop="corporation">
          <el-input v-model="form.corporation" placeholder="系统自动补充" disabled />
        </el-form-item> -->
        <!-- <el-form-item label="记录状态" prop="recordStatus">
          <el-select v-model="form.recordStatus" placeholder="请选择记录状态">
            <el-option
              v-for="dict in dict.type.asset_record_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 【调整】资产信息 -->
    <el-dialog title="资产调整" :visible.sync="openAdjustment" width="900px" append-to-body>
      <el-descriptions title="资产原信息" v-if="adjustmentOriginalAssetInfo" :column="3" border>
        <el-descriptions-item label="资产ID" v-if="adjustmentOriginalAssetInfo.id">{{adjustmentOriginalAssetInfo.id}}</el-descriptions-item>
        <el-descriptions-item label="资产名称" v-if="adjustmentOriginalAssetInfo.name">{{adjustmentOriginalAssetInfo.name}}</el-descriptions-item>
        <el-descriptions-item label="资产条码" v-if="adjustmentOriginalAssetInfo.code">{{adjustmentOriginalAssetInfo.code}}</el-descriptions-item>
        <el-descriptions-item label="资产编号" v-if="adjustmentOriginalAssetInfo.number">{{adjustmentOriginalAssetInfo.number}}</el-descriptions-item>
        <el-descriptions-item label="资产分类" v-if="adjustmentOriginalAssetInfo.categoryNumber">{{adjustmentOriginalAssetInfo.categoryNumber}}</el-descriptions-item>
        <el-descriptions-item label="规格型号" v-if="adjustmentOriginalAssetInfo.specificationsModel">{{adjustmentOriginalAssetInfo.specificationsModel}}</el-descriptions-item>
        <el-descriptions-item label="ABC分类" v-if="adjustmentOriginalAssetInfo.abcCategory">{{adjustmentOriginalAssetInfo.abcCategory}}</el-descriptions-item>
        <el-descriptions-item label="管理状态" v-if="adjustmentOriginalAssetInfo.manageStatus">{{adjustmentOriginalAssetInfo.manageStatus}}</el-descriptions-item>
        <el-descriptions-item label="使用部门" v-if="adjustmentOriginalAssetInfo.userDepartment">{{adjustmentOriginalAssetInfo.userDepartment}}</el-descriptions-item>
        <el-descriptions-item label="管理部门" v-if="adjustmentOriginalAssetInfo.department">{{adjustmentOriginalAssetInfo.department}}</el-descriptions-item>
        <el-descriptions-item label="责任人" v-if="adjustmentOriginalAssetInfo.responsiblePerson">{{adjustmentOriginalAssetInfo.responsiblePerson}}</el-descriptions-item>
        <el-descriptions-item label="所在位置编号" v-if="adjustmentOriginalAssetInfo.locationNumber">{{adjustmentOriginalAssetInfo.locationNumber}}</el-descriptions-item>
        <el-descriptions-item label="资产性质" v-if="adjustmentOriginalAssetInfo.property">{{adjustmentOriginalAssetInfo.property}}</el-descriptions-item>
        <el-descriptions-item label="购置日期" v-if="adjustmentOriginalAssetInfo.purchaseDate">{{adjustmentOriginalAssetInfo.purchaseDate}}</el-descriptions-item>
        <el-descriptions-item label="启用日期" v-if="adjustmentOriginalAssetInfo.commissioningDate">{{adjustmentOriginalAssetInfo.commissioningDate}}</el-descriptions-item>
        <el-descriptions-item label="资产原值（元）" v-if="adjustmentOriginalAssetInfo.originalValue">{{adjustmentOriginalAssetInfo.originalValue}}</el-descriptions-item>
        <el-descriptions-item label="使用年限">{{adjustmentOriginalAssetInfo.durableYears}}</el-descriptions-item>
        <el-descriptions-item label="资产净值（元）" v-if="adjustmentOriginalAssetInfo.netValue">{{adjustmentOriginalAssetInfo.netValue}}</el-descriptions-item>
        <el-descriptions-item label="资产残值（元）" v-if="adjustmentOriginalAssetInfo.residualValue">{{adjustmentOriginalAssetInfo.residualValue}}</el-descriptions-item>
        <el-descriptions-item label="累计折旧（元）" v-if="adjustmentOriginalAssetInfo.accumulatedDepreciation">{{adjustmentOriginalAssetInfo.accumulatedDepreciation}}</el-descriptions-item>
        <el-descriptions-item label="最近折旧日期" v-if="adjustmentOriginalAssetInfo.lastDepreciationDate">{{adjustmentOriginalAssetInfo.lastDepreciationDate}}</el-descriptions-item>
        <el-descriptions-item label="折旧方式" v-if="adjustmentOriginalAssetInfo.depreciationMethod">{{adjustmentOriginalAssetInfo.depreciationMethod}}</el-descriptions-item>
        <el-descriptions-item label="合同编号" v-if="adjustmentOriginalAssetInfo.contractNumber">{{adjustmentOriginalAssetInfo.contractNumber}}</el-descriptions-item>
        <el-descriptions-item label="出厂编号" v-if="adjustmentOriginalAssetInfo.id">{{adjustmentOriginalAssetInfo.factoryNumber}}</el-descriptions-item>
        <el-descriptions-item label="制造商" v-if="adjustmentOriginalAssetInfo.id">{{adjustmentOriginalAssetInfo.manufacturer}}</el-descriptions-item>
        <el-descriptions-item label="供应商" v-if="adjustmentOriginalAssetInfo.id">{{adjustmentOriginalAssetInfo.supplier}}</el-descriptions-item>
        <el-descriptions-item label="资产用途" v-if="adjustmentOriginalAssetInfo.id">{{adjustmentOriginalAssetInfo.purpose}}</el-descriptions-item>
        <el-descriptions-item label="维保到期日期" v-if="adjustmentOriginalAssetInfo.id">{{adjustmentOriginalAssetInfo.maintenanceDate}}</el-descriptions-item>
        <el-descriptions-item label="维修电话" v-if="adjustmentOriginalAssetInfo.id">{{adjustmentOriginalAssetInfo.maintenanceTel}}</el-descriptions-item>
        <el-descriptions-item label="维修人员" v-if="adjustmentOriginalAssetInfo.id">{{adjustmentOriginalAssetInfo.maintenanceUser}}</el-descriptions-item>
        <el-descriptions-item label="所属公司" v-if="adjustmentOriginalAssetInfo.id">{{adjustmentOriginalAssetInfo.corporation}}</el-descriptions-item>
        <el-descriptions-item label="记录状态" v-if="adjustmentOriginalAssetInfo.id">{{adjustmentOriginalAssetInfo.recordStatus}}</el-descriptions-item>
        <el-descriptions-item label="备注">
          <el-tag size="small">学校</el-tag>
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/order/order";

export default {
  name: "Order",
  dicts: ['asset_order_type', 'asset_record_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产单据表格数据
      orderList: [],
      orderType: 1,
      // 资产原信息
      openAdjustment: false,
      adjustmentOriginalAssetInfo: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNumber: null,
        orderType: '1',
        applicationDate: null,
        applicationDepartment: null,
        adjustmentAssetNumber: null,
        allocationCallOutDepartment: null,
        allocationCallOutBy: null,
        allocationCallOutDate: null,
        allocationCallInDepartment: null,
        allocationCallInBy: null,
        allocationCallInDate: null,
        lendDepartment: null,
        lendBySponsor: null,
        lendPassingUnit: null,
        reason: null,
        preparedBy: null,
        preparedDepartment: null,
        corporation: null,
        recordStatus: null
      },
      orderType: null,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        // orderNumber: [
        //   { required: true, message: "单据编号不能为空", trigger: "blur" }
        // ],
        orderType: [
          { required: true, message: "单据类型不能为空", trigger: "change" }
        ],
        // assetTotalOriginalValue: [
        //   { required: true, message: "资产总原值不能为空", trigger: "blur" }
        // ],
        // assetTotalNetValue: [
        //   { required: true, message: "资产总净值不能为空", trigger: "blur" }
        // ],
        // preparedBy: [
        //   { required: true, message: "制单人不能为空", trigger: "blur" }
        // ],
        // preparedDepartment: [
        //   { required: true, message: "制单部门不能为空", trigger: "blur" }
        // ],
        // corporation: [
        //   { required: true, message: "所属公司不能为空", trigger: "blur" }
        // ],
        recordStatus: [
          { required: true, message: "记录状态不能为空", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.orderType = 1
    this.getList();
  },
  methods: {
    /** 查询资产单据列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    onSelectOriginalAssetInfo(info) {
      const json = JSON.parse(info)
      this.adjustmentOriginalAssetInfo = json
      this.openAdjustment = true
      console.log('资产原信息:', json)
    },
    onQueryTypeChange() {
      this.orderType = Number(this.queryParams.orderType)
      this.queryParams.assetTotalOriginalValue = null,
      this.queryParams.assetTotalNetValue = null,
      this.queryParams.adjustmentAssetNumber = null,
      this.queryParams.adjustmentOriginalAssetInfo = null,
      this.queryParams.allocationCallOutDepartment = null,
      this.queryParams.allocationCallOutBy = null,
      this.queryParams.allocationCallOutDate = null,
      this.queryParams.allocationCallInDepartment = null,
      this.queryParams.allocationCallInBy = null,
      this.queryParams.allocationCallInDate = null,
      this.queryParams.allocationNewResponsiblePerson = null,
      this.queryParams.allocationNewLocationNumber = null,
      this.queryParams.lendDepartment = null,
      this.queryParams.lendBySponsor = null,
      this.queryParams.lendPassingUnit = null
      this.handleQuery()
    },
    onFormTypeChange() {
      this.form.assetTotalOriginalValue = null,
      this.form.assetTotalNetValue = null,
      this.form.adjustmentAssetNumber = null,
      this.form.adjustmentOriginalAssetInfo = null,
      this.form.allocationCallOutDepartment = null,
      this.form.allocationCallOutBy = null,
      this.form.allocationCallOutDate = null,
      this.form.allocationCallInDepartment = null,
      this.form.allocationCallInBy = null,
      this.form.allocationCallInDate = null,
      this.form.allocationNewResponsiblePerson = null,
      this.form.allocationNewLocationNumber = null,
      this.form.lendDepartment = null,
      this.form.lendBySponsor = null,
      this.form.lendPassingUnit = null
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNumber: null,
        orderType: null,
        assetTotalOriginalValue: null,
        assetTotalNetValue: null,
        applicationDate: null,
        applicationDepartment: null,
        adjustmentAssetNumber: null,
        adjustmentOriginalAssetInfo: null,
        allocationCallOutDepartment: null,
        allocationCallOutBy: null,
        allocationCallOutDate: null,
        allocationCallInDepartment: null,
        allocationCallInBy: null,
        allocationCallInDate: null,
        allocationNewResponsiblePerson: null,
        allocationNewLocationNumber: null,
        lendDepartment: null,
        lendBySponsor: null,
        lendPassingUnit: null,
        reason: null,
        preparedBy: null,
        preparedDepartment: null,
        corporation: null,
        recordStatus: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.orderType = this.orderType
      // 默认未提交
      this.form.recordStatus = 0
      this.open = true;
      this.title = "添加资产单据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        if (response.data.recordStatus > 0) {
          this.$modal.msgWarning("已提交单据不可修改")
          return;
        }
        this.open = true;
        this.title = "修改资产单据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除资产单据编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
