<template>
  <div>
    <el-card class="el-card">
      <el-form :model="filterQuery" class="query-form" size="mini" :inline="true">
        <el-form-item class="query-form-item" label="设备编号:">
          <el-input v-model="filterQuery.orderId" placeholder="请输入设备编号"
                    clearable="true"></el-input>
        </el-form-item>
        <el-form-item class="query-form-item" label="产品DI:">
          <el-input v-model="filterQuery.nameCode" placeholder="请输入产品DI"
                    clearable="true"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button-group style="margin-left: 10px;display:flex;">
            <el-button type="primary" icon="el-icon-refresh" @click="onReset">重置</el-button>
            <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
          </el-button-group>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="list" style="width: 100%" highlight-current-row
                @current-change="handleSelectionChange"
                border>
        <el-table-column label="领用部门" prop="fromDeptName" ></el-table-column>
        <el-table-column label="领用仓库" prop="fromInvName" ></el-table-column>
        <el-table-column label="领用货位" prop="fromInvSpaceName" ></el-table-column>
        <el-table-column label="领用日期" prop="createTime" ></el-table-column>
        <el-table-column label="领用人" prop="createUserName"></el-table-column>

      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :limit.sync="filterQuery.limit"
        :page.sync="filterQuery.page"
        @pagination="getList"
      ></pagination>
    </el-card>


    <el-tabs type="border-card" style="margin: 15px">
      <!--单据业务详情-->
      <el-tab-pane>
        <span slot="label">设备详情</span>
        <el-table v-loading="bizDetailLoading" :data="bizDetailList" style="width: 100%" border
                  :row-style="rowStyle"
                  row-key="id"
        >
          <el-table-column label="序号" type="index"></el-table-column>
          <el-table-column label="设备名称" prop="productName" width="180"></el-table-column>
          <el-table-column label="设备编号" prop="code" width="180" show-overflow-tooltip></el-table-column>
          <el-table-column label="产品DI" prop="nameCode" width="180"></el-table-column>
          <el-table-column label="生产日期" prop="productionDate" width="180"></el-table-column>
          <el-table-column label="失效日期" prop="expireDate" width="180"></el-table-column>
          <el-table-column label="批次号" prop="batchNo" width="180"></el-table-column>
          <el-table-column label="规格型号" prop="ggxh" width="180"></el-table-column>
          <el-table-column label="医疗器械注册/备案人名称" prop="ylqxzcrbarmc" width="180"></el-table-column>
          <el-table-column label="批准文号" prop="zczbhhzbapzbh" width="180"></el-table-column>
<!--          <el-table-column label="操作" >-->
          <!--            <template slot-scope="scope">-->
          <!--              <el-button-->
          <!--                type="text"-->
          <!--                size="small"-->
          <!--                @click.native.stop="addMAOrder(scope.row)"-->
          <!--              >养护-->
          <!--              </el-button-->
          <!--              >-->
          <!--            </template>-->
          <!--          </el-table-column>-->
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <pagination
      v-show="bizTotal>0"
      :total="bizTotal"
      :page.sync="filterQuery.page"
      :limit.sync="filterQuery.limit"
      @pagination="getBizDetailList"
    />

    <el-dialog
      title="新增设备养护记录"
      :visible.sync="formVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="85%"
      v-if="formVisible"
    >
      <deviceMAOrderModify
        :deviceMAOrder="deviceMAOrder"
        :closeDialog="closeDialog"
      >
      </deviceMAOrderModify>
    </el-dialog>

  </div>
</template>

<script>
import {getDeviceReceiveOrderList} from "@/api/dev/deviceReceiveOrder";
import deviceMAOrderModify from "@/views/dev/DeviceMAOrderModify.vue";
import {selectByorderIdFk} from "@/api/dev/deviceReceiveOrder";
export default {
  name: "AssetManage",
  data() {
    return {
      filterQuery: {
        code: null,
        nameCode: null,
        status: 2,
        page: 1,
        limit: 20,
        orderIdFk:""
      },
      bizDetailLoading: false,
      bizDetailList:[],
      list: [],
      total: 0,
      bizTotal:0,
      loading: false,
      idQuery: null,
      formVisible: false,
      deviceMAOrder: {
        code: null,
        deptName: null,
        createUser: null,
        createTime: null,
        collOrderId: null
      }
    };
  },
  methods: {
    onReset() {
      this.$router.push({
        path: "",
      });
      this.filterQuery = {
        code: null,
        nameCode: null,
        status: 2,
        page: 1,
        limit: 20
      };
      this.getList();
    },
    onSubmit() {
      this.filterQuery.page = 1;
      this.getList();
    },
    handleSelectionChange(val){
      this.filterQuery.orderIdFk= val.orderId;
      this.filterQuery.status=null;
      this.getBizDetailList();
    },
    getBizDetailList(){
      this.bizDetailLoading = true;
      selectByorderIdFk(this.filterQuery).then((res) => {
        this.bizDetailLoading = false;
        if (res.code === 20000) {
          this.bizDetailList = res.data.list || [];
          this.bizTotal = res.data.total;
        } else {
          this.$message.error(res.message);
          this.bizDetailList = [];
        }
      }).catch((error) =>{
        this.bizDetailLoading = false;
        this.$message.error(error.message);
        this.bizDetailList = [];
        this.bizTotal = 0;
      })
    },
    getList() {
      this.loading = true;
      getDeviceReceiveOrderList(this.filterQuery).then((res) => {
        this.loading = false;
        if (res.code === 20000) {
          this.list = res.data.list || [];
          this.total = res.data.total || 0;
        } else {
          this.$message.error(res.message);
          this.list = [];
          this.total = 0;
        }
      }).catch((error) => {
        this.loading = false;
        this.$message.error(error.message);
        this.list = [];
        this.total = 0;
      })
    },
    closeDialog() {
      this.formVisible = false;
      this.getList();
    },
    addMAOrder(row) {
      this.deviceMAOrder = {
        code: row.code,
        createUser: this.$store.getters.adminId,
        deptName: row.fromDeptName,
        deptCode: row.fromDeptName,
        invCode: row.fromInvCode,
        invName: row.fromInvName,
        invSpaceCode:row.fromInvSpaceCode,
        invSpaceName: row.fromInvSpaceName,
        createTime: new Date().toLocaleString(),
        collOrderId: row.orderIdFk
      }
      this.formVisible = true;
    },
  },
  components: {
    deviceMAOrderModify
  },
  mounted() {
    document.body.ondrop = function (event) {
      event.preventDefault();
      event.stopPropagation();
    };
  },
  created() {
    this.getList();
  },
};
</script>

<style type="text/scss" lang="scss">
</style>

