董国庆
2 天以前 b4ac09eb2e493aab92557628e0436189337e2939
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<template>
  <div class="list">
    <TableCustom :queryForm="form" :height="null" :tableData="tableData" :total="total" @handlePageChange="handlePageChange" @handleSizeChange="handleSizeChange" >
      <template #search>
        <el-form :model="form" labelWidth="auto" inline>
          <el-form-item label="所属项目课题方案:">
            <el-input v-model="form.projectName" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="实验编号:">
            <el-input v-model="form.experimentCode" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="创建时间:">
            <el-date-picker
              v-model="form.createTime"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="yyyy-MM-dd"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="状态:">
            <el-select v-model="form.status" placeholder="请选择">
              <el-option label="全部" :value="null"></el-option>
              <el-option label="草稿箱" :value="-1"></el-option>
              <el-option label="已发送待提交" :value="1"></el-option>
              <el-option label="已提交" :value="2"></el-option>
              <el-option label="已封存" :value="3"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="">
            <el-button type="default" @click="resetForm">重置</el-button>
            <el-button type="primary" @click="handleSearch" style="margin-left: 10px;">查询</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template #setting>
        <div class="tableTitle">
          <div class="flex a-center">
            <div 
              class="title"
              :class="{active:currentType == 'list'}"
              @click="handleTypeChange('list')"
            >取样操作记录列表</div>
            <div 
              v-if="isProcessEngineer"
              class="title"
              :class="{active:currentType == 'draft'}"
              @click="handleTypeChange('draft')"
            >草稿箱</div>
          </div>
          <el-button v-if="isProcessEngineer" @click="handleAddSample" class="el-icon-plus" type="primary">
            新增取样操作记录</el-button
          >
        </div>
      </template>
      <template #table>
        <el-table-column
          v-for="(column, index) in currentColumns"
          :key="index"
          :prop="column.prop"
          :label="column.label"
        ></el-table-column>
        <el-table-column label="样品总数/待接收/已接收" v-if="isChemist">
          <template slot-scope="scope">
            {{ getSampleStatus(scope.row) }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button v-if="currentType == 'list'" type="text" @click="handleDetail(scope.row.id)">详情</el-button>
            <template v-if="currentType == 'draft'">
              <el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
              <el-button type="text" @click="handleDelete(scope.row)" style="color: #F56C6C;">删除</el-button>
            </template>
          </template>
        </el-table-column>
      </template>
    </TableCustom>
    <!-- 删除确认弹窗 -->
    <ShowDelConfirm 
      :title="changeStatusTitle" 
      :tip="changeStatusTip" 
      :show="changeStatus"
      @close="changeStatus = false" 
      @confirm="handleChangeStatusConfirm" 
    />
  </div>
</template>
 
<script>
import ShowDelConfirm from "@/components/showDelConfirm/index.vue";
import { getList, deleteById } from './service'
 
export default {
  name: "ProjectList",
  components: {
    ShowDelConfirm
  },
  data() {
    return {
      userRole: '', // 用户角色
      currentType: 'list', // 当前显示类型:list-列表,draft-草稿箱
      form: {
        experimentCode: "",
        experimentName: "",
        projectName: "",
        createTime: [],
        status: null,
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      // 确认弹窗相关数据
      changeStatus: false,
      changeStatusTitle: "",
      changeStatusTip: "",
      currentOperationRow: null, // 当前操作的行数据
      // 不同角色的表头配置
      columnConfig: {
        default: [
          { prop: 'projectName', label: '所属项目课题方案' },
          { prop: 'experimentCode', label: '实验编号' },
          { prop: 'experimentName', label: '实验名称' },
          { prop: 'samplingCode', label: '取样单编号' },
          { prop: 'createBy', label: '创建人' },
          { prop: 'createTime', label: '创建时间' },
          { prop: 'sendTo', label: '发送对象' },
          { prop: 'sendTime', label: '发送时间' }
        ],
        '4': [
          { prop: 'projectName', label: '所属项目课题方案' },
          { prop: 'experimentCode', label: '实验编号' },
          { prop: 'experimentName', label: '实验名称' },
          { prop: 'samplingCode', label: '取样单编号' },
          { prop: 'createBy', label: '创建人' },
          { prop: 'createTime', label: '创建时间' },
          // { prop: 'sampleCount', label: '样品总数' },
          // { prop: 'receivedCount', label: '待接收' },
          // { prop: 'completedCount', label: '已接收' }
        ]
      }
    };
  },
  computed: {
    // 获取当前角色的表头配置
    currentColumns() {
      return this.columnConfig[this.userRole] || this.columnConfig.default;
    },
    // 判断是否为化验师角色
    isChemist() {
      return this.userRole == '4';
    },
    // 判断是否为工艺工程师角色
    isProcessEngineer() {
      return this.userRole == '3'; // 假设工艺工程师的角色代码为2
    }
  },
  created() {
    this.getUserRole();
    this.getTableData();
  },
  methods: {
    getSampleStatus(row) {
      const send = row.sendCount || 0;
      const receive = row.receiveCount || 0;
      const received = row.receivedCount || 0;
      const total = send + receive + received;
      return `${total} / ${receive} / ${received}`;
    },
    // 获取用户角色
    getUserRole() {
      const userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}');
      this.userRole = userInfo.roleType || '';
    },
    resetForm() {
      this.form = {
        experimentCode: "",
        experimentName: "",
        projectName: "",
        createTime: [],
        status: null,
        pageNum: 1,
        pageSize: 10
      };
      this.handleSearch();
    },
    async handleSearch() {
      const params = {
        experimentCode: this.form.experimentCode,
        experimentName: this.form.experimentName,
        projectName: this.form.projectName,
        startTime: this.form.createTime[0] || null,
        endTime: this.form.createTime[1] || null,
        status: this.currentType == 'draft' ? -1 : this.form.status,
        pageNum: this.form.pageNum,
        pageSize: this.form.pageSize
      };
      try {
        const res = await getList(params)
        this.tableData = res.data.records || [];
        this.total = res.data.total || 0;
      } catch (error) {
        console.error("查询失败:", error);
      }
    },
    handleAddSample() {
      this.$router.push({
        path: "/sampleManage/addSample",
      });
    },
    handleEdit(row) {
      this.$router.push({
        path: "/sampleManage/addSample",
        query: {
          id: row.id,
          type: 'edit'
        }
      });
    },
    handleDelete(row) {
      this.currentOperationRow = row;
      this.changeStatusTitle = "确认要删除这条信息吗?";
      this.changeStatusTip = "删除后信息无法找回";
      this.changeStatus = true;
    },
    handleDetail(id) {
      this.$router.push({
        path: "/sampleManage/addSample",
        query: {
          id: id,
          type: 'detail'
        }
      });
    },
    handleTypeChange(type) {
      this.currentType = type;
      this.getTableData();
    },
    getTableData() {
      this.handleSearch();
    },
    handlePageChange(pageNum) {
      this.form.pageNum = pageNum;
      this.getTableData();
    },
    handleSizeChange(pageSize) {
      this.form.pageSize = pageSize;
      this.getTableData();
    },
    handleChangeStatusConfirm() {
      // 处理删除逻辑
      deleteById({
        id: this.currentOperationRow.id
      }).then(() => {
        this.$message.success("删除成功");
        this.changeStatus = false;
        this.getTableData();
      }).catch(error => {
        this.$message.error("删除失败");
      });
    },
  },
};
</script>
 
<style scoped lang="less">
.list {
  height: 100%;
}
.flex {
  display: flex;
  align-items: center;
}
.tableTitle {
  display: flex;
  padding-bottom: 20px;
  justify-content: space-between;
  align-items: center;
  .title {
    background: #fafafc;
    border-radius: 8px 8px 0px 0px;
    border: 1px solid #dcdfe6;
    padding: 16px 29px;
    font-weight: 400;
    font-size: 18px;
    color: #606266;
    width: unset;
    cursor: pointer;
    margin-right: 16px;
    &:last-child {
      margin-right: 0;
    }
    &.active {
      color: #049c9a;
      background: #ffffff;
      border-radius: 8px 8px 0px 0px;
      border: 1px solid #049c9a;
      font-weight: bold;
    }
  }
}
</style>