<template>
    <div class="app-container" id="">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
        
        <el-form-item prop="keyWord">
          <el-input
            v-model="queryParams.keyWord"
            placeholder="请输入关键字"
            clearable :maxlength="20"
            style="width: 220px"
          />
        </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>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        <el-table v-loading="loading" :data="tableList" border>
          <el-table-column
            type="index"
            width="55"
            label="序号"
            align="center"
            :index="index => (queryParams.pageNum - 1) * queryParams.pageSize + index + 1"
          />
          <el-table-column label="创建时间" align="center" prop="createTime" :show-overflow-tooltip="true"/>
          <el-table-column label="创建人" align="center" prop="createBy" :show-overflow-tooltip="true"/>
          <el-table-column label="报告编号" align="center" prop="reportNum" :show-overflow-tooltip="true"/>
          <el-table-column label="操作" align="center"  :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-search"
                @click="handleView(scope.row)"
              >
                查看
              </el-button>
            </template>

          </el-table-column>
      </el-table>
      <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          :page-sizes="[10, 20, 50, 100]"
          @pagination="getList"
      />

      <el-dialog
        title="查看"
        :visible.sync="dialogVisible"
        width="80%"
        custom-class="dialog"
        close="handleClose"
      >
        <el-form :model="dialogForm" label-width="80px" ref="dialogForm" :inline="true" >
          <el-form-item label="关键词" prop="keyWord"  >
            <el-input v-model="dialogForm.keyWord"  style="width: 240px"/>
          </el-form-item>
           <el-form-item>
            <el-button
                type="primary"
                icon="el-icon-search"
                size="mini"
                @click="handleQueryDialog"
                >查询</el-button
            >
            <el-button
                icon="el-icon-refresh"
                size="mini"
                @click="resetQueryDialog"
                >重置</el-button
            >
         </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="dialogList" border>
          <el-table-column
            type="index"
            width="55"
            label="序号"
            align="center"
            :index="index => (dialogForm.pageNum - 1) * dialogForm.pageSize + index + 1"
          />
          <el-table-column label="物资名称" align="center" prop="typeModelName" :show-overflow-tooltip="true"/>
          <el-table-column label="规格型号" align="center" prop="typeName" :show-overflow-tooltip="true"/>
          <el-table-column label="设备编码" align="center" prop="maCode" :show-overflow-tooltip="true"/>
          <el-table-column label="本次检验时间" align="center" prop="checkTimeSynch" :show-overflow-tooltip="true"/>
          <el-table-column label="下次检验时间" align="center" prop="nextCheckTimeSynch" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column label="检验人" align="center" prop="checkMan" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column label="检验结果" align="center" prop="result" :show-overflow-tooltip="true"></el-table-column>
        </el-table>
      <pagination
          v-show="totalDialog > 0"
          :total="totalDialog"
          :page.sync="dialogForm.pageNum"
          :limit.sync="dialogForm.pageSize"
          :page-sizes="[10, 20, 50, 100]"
          @pagination="getDialogList"
      />
      </el-dialog>
    </div>
</template>

<script>
import {
    getSynchListApi,getSynchDetailsListApi
} from '@/api/ma/device';
export default {
    name: 'DeviceInBound',
    dicts: [],
    data() {
        return {
            // 遮罩层
            loading: false,
            // 选中数组
            ids: [],
            // 弹出层标题
            title: '查看',
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 主表格数据
            tableList: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                keyWord: null,
            },
            dialogVisible:false,
            dialogList:[],
            dialogForm:{
                pageNum: 1,
                pageSize: 10,
                keyWord: null,
                parentId:null,
            },
            totalDialog:0,
        }
    },
    created() {
        this.getList()
    },
    methods: {
      // 获取列表
      async getList() {
          this.loading = true
          const params = {
                keyWord: this.queryParams.keyWord,
                pageSize: this.queryParams.pageSize,
                pageNum: this.queryParams.pageNum
            }
          const res = await getSynchListApi(params)
          this.loading = false
          if(res.rows.length>0){
            this.tableList = res.rows;
          }else{
            this.tableList=[]
          }
          this.total = res.total;
      },
      /** 搜索按钮操作 */
      handleQuery() {
          this.queryParams.pageNum = 1
          this.getList()
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.keyWord  = ""
        this.resetForm('queryForm')
        this.handleQuery()
      },

      handleView(row){
        this.dialogVisible = true;
        this.dialogForm.parentId = row.id;
        this.dialogForm.keyWord = row.keyWord;
        this.dialogForm.pageNum = 1;
        this.dialogForm.pageSize = 10;
        this.getDialogList()
      },

      getDialogList(){
        const params = {
          keyWord: this.dialogForm.keyWord,
          parentId: this.dialogForm.parentId,
          pageSize: this.dialogForm.pageSize,
          pageNum: this.dialogForm.pageNum
        }
        getSynchDetailsListApi(params).then(res=>{
          if(res.rows.length>0){
            this.dialogList = res.rows;
          }else{
            this.dialogList=[]
          }
          this.totalDialog = res.total;
        })
      },

      handleQueryDialog(){
        this.dialogForm.pageNum = 1;
        this.getDialogList()
      },

      resetQueryDialog(){
        this.dialogForm.keyWord  = "";
        this.dialogForm.pageNum = 1;
        this.dialogForm.pageSize = 10;
        this.getDialogList()
      },

      handleClose(){
        this.dialogForm.keyWord  = "";
      }

    },
}
</script>
<style lang="scss" scoped>
::v-deep.el-table .fixed-width .el-button--mini {
    width: 60px !important;
    margin-bottom: 10px;
}
.clickText {
  color: #02a7f0;
  cursor: pointer;
}
</style>
