1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<template>
  <div class="app-container">
    <!-- 搜索表单 -->
    <el-form ref="queryForm" :model="queryParams" :inline="true" size="small">
      <el-form-item label="样品编号" prop="sampleCode">
        <el-input v-model="queryParams.sampleCode" placeholder="请输入样品编号" clearable style="width: 180px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="样品名称" prop="sampleName">
        <el-input v-model="queryParams.sampleName" placeholder="请输入样品名称" clearable style="width: 180px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="客户名称" prop="custom">
        <el-input v-model="queryParams.custom" placeholder="请输入客户名称" clearable style="width: 180px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="领用人" prop="receiveUser">
        <el-input v-model="queryParams.receiveUser" placeholder="请输入领用人" clearable style="width: 150px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="时间范围" prop="timeRange">
        <el-date-picker
          v-model="timeRange"
          type="daterange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          value-format="yyyy-MM-dd"
          style="width: 240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button type="success" icon="el-icon-download" @click="handleExport">导出</el-button>
      </el-form-item>
    </el-form>
 
    <!-- 数据表格 -->
    <lims-table
      :tableData="tableData"
      :column="tableColumn"
      :page="page"
      :tableLoading="tableLoading"
      @pagination="handlePagination"
    >
      <template #operation="{ row }">
        <el-button type="text" size="mini" @click="handleFlow(row)">流转记录</el-button>
      </template>
    </lims-table>
 
    <!-- 流转记录弹窗 -->
    <el-dialog title="样品流转记录" :visible.sync="flowVisible" width="70%">
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in flowData"
          :key="index"
          :timestamp="item.operateTime"
          placement="top"
          :color="getTimelineColor(item.status)"
        >
          <el-card>
            <h4>{{ item.operateType }}</h4>
            <p>操作人:{{ item.operator }}</p>
            <p>状态:{{ item.statusName }}</p>
            <p v-if="item.remark">备注:{{ item.remark }}</p>
          </el-card>
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>
 
<script>
import limsTable from '@/components/Table/lims-table.vue'
import { pageSampleRecord, getSampleFlow, exportSampleRecord } from '@/api/report/sampleRecord'
 
export default {
  name: 'SampleRecord',
  components: { limsTable },
  data() {
    return {
      queryParams: {},
      timeRange: [],
      tableData: [],
      tableLoading: false,
      page: { total: 0, size: 10, current: 1 },
      flowVisible: false,
      flowData: [],
      tableColumn: [
        { label: '样品编号', prop: 'sampleCode', minWidth: '140px' },
        { label: '样品名称', prop: 'sampleName', minWidth: '150px' },
        { label: '委托编号', prop: 'entrustCode', minWidth: '140px' },
        { label: '领用人', prop: 'receiveUser', minWidth: '80px' },
        { label: '领用时间', prop: 'receiveTime', minWidth: '160px' },
        { label: '领用数量', prop: 'receiveNum', minWidth: '100px' },
        { label: '领用用途', prop: 'purpose', minWidth: '120px' },
        { label: '客户名称', prop: 'custom', minWidth: '150px' },
        { label: '存放位置', prop: 'location', minWidth: '120px' },
        { label: '当前状态', prop: 'status', minWidth: '100px', dataType: 'tag', formatData: (val) => this.formatStatus(val), formatType: (val) => this.formatStatusType(val) },
        {
          label: '操作',
          dataType: 'slot',
          slot: 'operation',
          minWidth: '100px'
        }
      ]
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList() {
      this.tableLoading = true
      const params = { ...this.queryParams }
      if (this.timeRange && this.timeRange.length === 2) {
        params.startTime = this.timeRange[0]
        params.endTime = this.timeRange[1]
      }
      pageSampleRecord({ ...params, ...this.page })
        .then(res => {
          this.tableData = res.data.records || []
          this.page.total = res.data.total || 0
        })
        .finally(() => (this.tableLoading = false))
    },
    handleQuery() {
      this.page.current = 1
      this.getList()
    },
    resetQuery() {
      this.queryParams = {}
      this.timeRange = []
      this.handleQuery()
    },
    handleExport() {
      const params = { ...this.queryParams }
      if (this.timeRange && this.timeRange.length === 2) {
        params.startTime = this.timeRange[0]
        params.endTime = this.timeRange[1]
      }
      exportSampleRecord(params).then(res => {
        this.downloadFile(res, '样品领样记录.xlsx')
      })
    },
    handleFlow(row) {
      getSampleFlow(row.id).then(res => {
        this.flowData = res.data || []
        this.flowVisible = true
      })
    },
    handlePagination({ page, limit }) {
      this.page.current = page
      this.page.size = limit
      this.getList()
    },
    formatStatus(val) {
      const map = { 0: '在库', 1: '已领用', 2: '已归还', 3: '已处理' }
      return map[val] || ''
    },
    formatStatusType(val) {
      const map = { 0: 'success', 1: 'warning', 2: 'info', 3: 'danger' }
      return map[val] || ''
    },
    getTimelineColor(status) {
      const map = { 0: '#67C23A', 1: '#E6A23C', 2: '#909399', 3: '#F56C6C' }
      return map[status] || '#409EFF'
    },
    downloadFile(data, fileName) {
      const blob = new Blob([data])
      const url = window.URL.createObjectURL(blob)
      const link = document.createElement('a')
      link.href = url
      link.download = fileName
      link.click()
      window.URL.revokeObjectURL(url)
    }
  }
}
</script>