<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="140px" class="queryForm">
      <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">
        <treeselect
          v-model="queryParams.applicationDepartment"
          :options="deptOptions"
          placeholder="请选择申请部门"
          @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">
        <treeselect
          v-model="queryParams.allocationCallOutDepartment"
          :options="deptOptions"
          placeholder="请选择【调拨】调出部门"
          @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">
        <treeselect
          v-model="queryParams.allocationCallInDepartment"
          :options="deptOptions"
          placeholder="请选择【调拨】调入部门"
          @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">
        <treeselect
          v-model="queryParams.lendDepartment"
          :options="deptOptions"
          placeholder="请选择【借出】借出部门"
          @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">
        <treeselect
          v-model="queryParams.preparedDepartment"
          :options="deptOptions"
          placeholder="请选择制单部门"
          @keyup.enter.native="handleQuery"
        />   
      </el-form-item>
      <el-form-item label="所属公司" prop="corporation">
        <treeselect
          v-model="queryParams.corporation"
          :options="deptOptions"
          placeholder="请选择所属公司"
          @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 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="assetTotalOriginalValue" />
      <el-table-column v-if="queryParams.orderType !== '1'" label="资产总净值" align="center" prop="assetTotalNetValue" />
      <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 v-if="queryParams.orderType === '1'" type="text" icon="el-icon-search" @click="onSelectOriginalAssetInfo(scope.row)">查看</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 === '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="lendPassingUnitName" />
      <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" fixed="right">
        <template slot-scope="scope">
          <el-button
            v-if="queryParams.orderType !== '1'"
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="onSelectopenDetail(scope.row)"
            v-hasPermi="['order:order:edit']"
          >明细</el-button>
          <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="资产总原值（系统自动补充）" disabled/>
        </el-form-item>
        <el-form-item v-if="form.orderType !== 1" label="资产总净值" prop="assetTotalNetValue">
          <el-input v-model="form.assetTotalNetValue" placeholder="资产总净值（系统自动补充）" disabled/>
        </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">
          <treeselect
            v-model="form.applicationDepartment"
            :options="deptOptions"
            placeholder="请选择申请部门"
            @keyup.enter.native="handleQuery"
          />  
        </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">
          <treeselect
            v-model="form.allocationCallOutDepartment"
            :options="deptOptions"
            placeholder="请选择【调拨】调出部门"
            @keyup.enter.native="handleQuery"
          />  
        </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">
          <treeselect
            v-model="form.allocationCallInDepartment"
            :options="deptOptions"
            placeholder="请选择【调拨】调入部门"
            @keyup.enter.native="handleQuery"
          /> 
        </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 === 3" label="【借出】借出部门" prop="lendDepartment">
          <treeselect
            v-model="form.lendDepartment"
            :options="deptOptions"
            placeholder="请选择【借出】借出部门"
            @keyup.enter.native="handleQuery"
          /> 
        </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">
          <treeselect
            v-model="form.lendPassingUnit"
            :options="deptOptions"
            placeholder="请选择【调拨】调入部门"
            @keyup.enter.native="handleQuery"
          />
        </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>
      <p class="msg" v-if="form.orderType !== 1"><i class="el-icon-info"></i> 保存生成单据后，记得完善单据明细后再提交哦</p>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="form.orderType === 1 || form.existDetail" type="warning" @click="submitForm(1)">提 交</el-button>
        <el-button type="primary" @click="submitForm(0)">保 存</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 【调整】资产信息 -->
    <el-dialog title="资产调整信息" :visible.sync="openAdjustment" width="900px" append-to-body>
      <AssetInfo :title="'现资产信息'" :assetInfo="adjustmentAssetInformation"/>
      <div style="height: 20px;"></div>
      <AssetInfo :title="'资产原信息'" :assetInfo="adjustmentOriginalAssetInfo"/>
    </el-dialog>

    <el-dialog title="单据详细信息" :visible.sync="openDetail" width="1300px" append-to-body>
      <OrderDetail v-if="openDetail" :orderInfo="orderInfo"/>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/order/order";
import { deptTreeSelect } from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Order",
  dicts: ['asset_order_type', 'asset_record_status'],
  components: {
    AssetInfo: () => import('@/components/asset/assetCard.vue'),
    OrderDetail: () => import('@/views/order/detail/index.vue'),
    Treeselect,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产单据表格数据
      orderList: [],
      orderType: 1,
      // 资产原信息
      openAdjustment: false,
      adjustmentOriginalAssetInfo: null,
      adjustmentAssetInformation: null,
      // 单据详细
      openDetail: false,
      orderInfo: null,
      // 部门树选项
      deptOptions: [],
      // 弹出层标题
      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" }
        // ],
        reason: [
          { required: true, message: "原因说明不能为空", trigger: "blur" }
        ],
        recordStatus: [
          { required: true, message: "记录状态不能为空", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.orderType = 1
    this.getDeptTree()
    this.getList();
  },
  methods: {
    /** 查询资产单据列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    onSelectOriginalAssetInfo(row) {
      this.adjustmentAssetInformation = row.adjustmentAssetInformation
      const json = JSON.parse(row.adjustmentOriginalAssetInfo)
      this.adjustmentOriginalAssetInfo = json
      this.openAdjustment = true
      console.log('资产原信息:', json)
    },
    onSelectopenDetail(order) {
      this.orderInfo = order
      console.log('单据信息:', order)
      this.openDetail = true
    },
    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;
        console.log('修改表单信息:', this.form)
        if (response.data.recordStatus > 0) {
          this.$modal.msgWarning("已提交单据不可修改")
          return;
        }
        this.open = true;
        this.title = "修改资产单据";
      });
    },
    /** 提交按钮 */
    submitForm(recordStatus) {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            this.form.recordStatus = recordStatus
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.recordStatus = recordStatus
            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>

<style lang="less" scoped>
/deep/ .vue-treeselect{
  display:inline-block;
}
.queryForm{
  /deep/ .vue-treeselect{
    width: 205px;
    height: 32px;
  }
}
.msg {
  text-align: center;
  color: red;
}
</style>
