zhouwx
2026-06-18 5612bbd431d10589a06c7ed3584de2cad1b5ea0a
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<template>
  <div class="app-container">
    <div style="display: flex;justify-content: space-between">
      <el-form :inline="true" style="display: flex;align-items: center;flex-wrap: wrap;" >
        <el-form-item>
          <el-button
              type="primary"
              plain
              icon="Plus"
              @click="openDialog('add',{})"
          >新增</el-button>
        </el-form-item>
        <el-form-item label="审批状态:" >
          <el-select v-model="data.queryParams.status" placeholder="请选择" >
            <el-option
                v-for="item in data.stateOptions"
                :key="item.id"
                :label="item.value"
                :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="审批人:" >
          <el-select
              clearable
              v-model="data.userName"
              filterable
              remote
              @change="selectValue"
              reserve-keyword
              placeholder="请输入审批人名称"
              remote-show-suffix
              :remote-method="getPeopleList"
              style="width: 100%"
          >
            <el-option
                v-for="item in data.peopleList"
                :key="item.id"
                :label="item.name"
                :value="item.name"
            />
          </el-select>
        </el-form-item>
        <el-form-item >
          <el-button
              type="primary"
              @click="getList"
          >查询</el-button>
          <el-button
              type="primary"
              plain
              @click="reset"
          >重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="dataList" :border="true">
      <el-table-column label="序号" type="index" align="center" width="80" />
      <el-table-column label="申购单号" prop="subscribeNum" align="center"  />
      <el-table-column label="危化品名称" align="center"  class-name="subscribe-quantity-cell" width="200">
        <template #default="scope">
          <div style="width: 100%; height: 100%;display: flex; flex-direction: column;justify-content: center;align-items: center; ">
            <div
              v-for="(item, index) in scope.row.subscribeHazmats"
              :key="item.id"
              style="
              width: 100%;
              text-align: center;
              height: 70px;
             display: flex;
             align-items: center;
             justify-content: center;
              border-bottom: 1px solid #ebeef5;"
              :style="{
                borderBottom: index === scope.row.subscribeHazmats.length - 1 ? 'none' : '1px solid #ebeef5'
                }"
            >
              <span>{{ item.hazmatName }}</span>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="申购数量" align="center" class-name="subscribe-quantity-cell">
      <template #default="scope">
        <div style="width: 100%; height: 100%;display: flex; flex-direction: column;justify-content: center;align-items: center; ">
          <div
            v-for="(item, index) in scope.row.subscribeHazmats"
            style="
            width: 100%;
            text-align: center;
             height:70px;
             display: flex;
             align-items: center;
             justify-content: center;
 
            border-bottom: 1px solid #ebeef5;"
            :style="{
              borderBottom: index === scope.row.subscribeHazmats.length - 1 ? 'none' : '1px solid #ebeef5'
            }"
          >
            {{ item.hazmatCount }}
          </div>
        </div>
      </template>
      </el-table-column>
      <el-table-column label="申购人" prop="subscribePersonName" align="center"  />
      <el-table-column label="审批人" prop="checkName" align="center"/>
      <el-table-column label="申购文件" prop="fileName" align="center">
        <template #default="scope">
          <el-link v-if="scope.row.fileName" style="" type="primary" @click="openFile(scope.row.filePath)">{{scope.row.fileName}}</el-link>
          <span v-else></span>
        </template>
      </el-table-column>
      <el-table-column label="审批状态" prop="status" align="center">
        <template #default="scope">
          <span> {{scope.row.status == 0 ? '未审批' :scope.row.status == 1 ?'审批通过':scope.row.status == 2 ?'审批驳回':''}}</span><span></span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" >
        <template #default="scope">
          <el-button v-if="scope.row.status == 0" link type="primary" @click="openDialog('edit',scope.row)">编辑</el-button>
          <el-button v-if="scope.row.status == 0" link type="danger" @click="handleDelete(scope.row)">删除</el-button>
          <el-button link type="primary" @click="openDialog('view',scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
 
    <editDialog ref="dialogRef" @getList=getList></editDialog>
  </div>
</template>
 
<script setup>
import {getCurrentInstance, onMounted, onUnmounted, reactive, ref, toRefs} from "vue";
import {ElMessage, ElMessageBox} from "element-plus";
import {delCompany, getCompany} from "@/api/hazardousChemicals/company";
import editDialog from "./components/editDialog.vue";
import {getUser} from "@/api/hazardousChemicals/user";
import {renderAsync} from "docx-preview";
import {delSubscribe, getSubscribeList} from "@/api/hazardousChemicals/subscribeApply";
const { proxy } = getCurrentInstance();
const loading = ref(false);
const dialogRef = ref();
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    status: null,
    subscribePersonId:null,
    checkId:null
  },
  total: 0,
  dataList: [],
  stateOptions:[
    {
      id: 0,
      value: '未审批'
    },
    {
      id: 1,
      value: '审批通过'
    },
    {
      id: 2,
      value: '审批驳回'
    },
  ],
  peopleList:[],
  userName:''
});
 
const { queryParams, total, dataList } = toRefs(data);
const classHourRef = ref();
onMounted(()=>{
  getList()
  getPeopleList("")
})
 
onUnmounted(()=>{
 
})
 
const getList = async () => {
  loading.value = true
  const res = await getSubscribeList(data.queryParams).catch(error => {
    loading.value = false
    return
  })
  if(res.code == 200){
    data.dataList = res.data.list
    data.total = res.data.total
  }else{
    ElMessage.warning(res.message)
  }
  loading.value = false
}
 
const openDialog = (type, value) => {
  dialogRef.value.openDialog(type, value);
}
 
/** 重置新增的表单以及其他数据  */
function reset() {
  data.queryParams = {
    pageNum: 1,
    pageSize: 10,
    status: null,
    subscribePersonId:null,
    checkId:null
  }
  data.userName = ''
  getList()
  getPeopleList("")
}
const handleDelete = (val) => {
  ElMessageBox.confirm(
      '确定删除此条数据?',
      '提示',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
      .then( async() => {
        const res = await delSubscribe(val.id)
        if(res.code == 200){
          ElMessage.success('数据删除成功')
          await getList()
        }else{
          ElMessage.warning(res.message)
        }
      })
}
const getPeopleList = async (val)=>{
  let queryParams = {}
  if(val != ""){
     queryParams = {
      name: val
    }
  }else {
     queryParams = {
      pageNum: 1,
      pageSize: 10
    }
  }
  const res = await getUser(queryParams)
  if (res.code == 200) {
    data.peopleList = res.data.list
  } else {
    ElMessage.warning(res.message)
  }
}
const selectValue =  (val) => {
  if(!val){
    data.queryParams.checkId = null
  }
  data.peopleList.forEach(item => {
    if(item.name === val){
      data.queryParams.checkId = item.id
    }
  })
}
const openFile = async(path)=>{
  const ext = path.split('.').pop().toLowerCase();
  if (ext === 'doc' || ext === 'xls' || ext === 'xlsx' || ext === 'ppt' || ext === 'pptx') {
    ElMessageBox.confirm(`暂不支持线上预览.${ext}文件,是否下载查看?`, '提示', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning' }).then(() => {
      window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
    }).catch(() => {
      console.log('取消预览')
    });
    return
  }else if(ext === 'pdf' || ext === 'jpg'||  ext === 'jpeg' || ext === 'png' ){
    window.open(`${import.meta.env.VITE_APP_BASE_API}/${path}`, '_blank');
  }else{
    try {
      // 1. 获取文件
      const response = await fetch(import.meta.env.VITE_APP_BASE_API + '/' + path);
      const arrayBuffer = await response.arrayBuffer();
      // 2. 创建新窗口
      const win = window.open('', '_blank');
      win.document.write(`
      <!DOCTYPE html>
      <html>
        <head>
          <title>预览</title>
          <style>
            body { margin: 20px; font-family: Arial; }
            .docx-container { width: 100%; height: 100%; }
          </style>
        </head>
        <body>
          <div id="container" class="docx-container"></div>
        </body>
      </html>
    `);
      // 3. 渲染 DOCX
      await renderAsync(arrayBuffer, win.document.getElementById('container'));
 
    } catch (error) {
      console.error('预览失败:', error);
      alert(`预览失败: ${error.message}`);
    }
  }
}
</script>
<style scoped>
/* 只对申购数量这一列生效 */
:deep(.subscribe-quantity-cell .cell) {
  padding: 0 !important; /* 关键:把默认的padding清零,优先级拉满 */
}
</style>