马宇豪
2023-07-13 01f3e49f3763a25ef67a4c3e5786491703a1aece
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
<template>
  <el-dialog :title="title" v-model="isShowDialog" width="80%">
    <el-row style="margin-bottom: 20px">
      <div class="basic-line" style="display:flex;white-space:nowrap;line-height: 40px">
        <span>作业编号:</span>
        <el-input v-model="searPara.workPermitNo" placeholder="作业编号"/>
      </div>
      <div class="basic-line">
        <span>作业类型:</span>
        <el-select v-model="searPara.workType">
          <el-option
              v-for="item in workType"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
      </div>
      <div style="margin-left: 20px">
        <el-button type="primary" @click="getData">查询</el-button>
        <el-button plain @click="clearSearch">重置</el-button>
      </div>
    </el-row>
    <el-table ref="TableRef" :data="otherWorks" style="width: 100%" border @selection-change="handleSelectionChange" :row-key="(row) => { return row.workApplyId }">
      <el-table-column type="selection" width="55" />
<!--            <el-table-column type="index" label="序号" width="60" />-->
      <el-table-column prop="workTypeDesc" label="作业类型" show-overflow-tooltip></el-table-column>
      <el-table-column prop="workLevelDesc" label="作业等级" show-overflow-tooltip></el-table-column>
      <el-table-column prop="workPermitNo" label="作业编号" show-overflow-tooltip></el-table-column>
      <el-table-column prop="workLocation" label="作业地点" show-overflow-tooltip></el-table-column>
      <el-table-column prop="workContent" label="作业内容" show-overflow-tooltip></el-table-column>
<!--            <el-table-column label="操作" width="150">-->
<!--              <template #default="scope">-->
<!--                <el-button size="small" text type="primary" @click="onOpenDialogRef('新增', '')">新增</el-button>-->
<!--                <el-button size="small" text type="primary" @click="onOpenDialogRef('修改', scope.row)">修改</el-button>-->
<!--                <el-button size="small" style="color: red" text type="primary" @click="onRowDel(scope.row)">删除</el-button>-->
<!--              </template>-->
<!--            </el-table-column>-->
    </el-table>
      <template #footer>
          <span class="dialog-footer">
              <el-button @click="isShowDialog = !isShowDialog" size="default">取 消</el-button>
              <el-button type="primary" v-throttle @click="onSubmit" size="default">确 定</el-button>
          </span>
      </template>
  </el-dialog>
</template>
 
<script lang="ts">
import { reactive, toRefs, onMounted, defineComponent, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { userApi } from '/@/api/systemManage/user';
import {workApplyApi} from "/@/api/specialWorkSystem/workApply";
 
// 定义接口来定义对象的类型
interface type {}
interface WorkSelectState {
    title: string
    isShowDialog: boolean
    searPara: object
    otherWorks: []
  workType: Array<any>
  selected: Array<any>
}
interface User {
 
}
export default defineComponent({
    name: 'workSelect',
    setup(props, context) {
        const userRef = ref()
        const state = reactive<WorkSelectState>({
            title: '',
            isShowDialog: false,
            searPara: {
              workPermitNo: '',
              workType: null
            },
            otherWorks: [],
            selected: [],
            workType: [
              {
                label: "动火作业",
                value: 1
              },
              {
                label: "受限空间作业",
                value: 2
              },
              {
                label: "吊装作业",
                value: 3
              },
              {
                label: "动土作业",
                value: 4
              },
              {
                label: "断路作业",
                value: 5
              },
              {
                label: "高处作业",
                value: 6
              },
              {
                label: "临时用电作业",
                value: 7
              },
              {
                label: "盲板抽堵作业",
                value: 8
              }
            ]
        });
        const TableRef = ref()
      const multipleSelection = ref<User[]>([])
        // 打开弹窗
        const openDialog = (works: Array<String>) => {
          state.isShowDialog = true
          getData().then(()=>refreshTableSelection(works))
        };
 
        const refreshTableSelection = (works) => {
            if (TableRef.value) {
              for (let i = 0; i < state.otherWorks.length; i++) {
                if (works.includes(state.otherWorks[i].workApplyId)){
                  TableRef.value.toggleRowSelection(state.otherWorks[i], true)
                } else{
                  TableRef.value.toggleRowSelection(state.otherWorks[i], false)
                }
              }
            }
        }
 
        // 获取相关作业列表
        const getData = async () => {
          let res = await workApplyApi().getOtherWork(state.searPara);
          if (res.data.code === '200') {
            state.otherWorks = JSON.parse(JSON.stringify(res.data.data))
          } else {
            ElMessage({
              type: 'warning',
              message: res.data.msg
            });
          }
        };
 
 
      const clearSearch = ()=>{
        state.searPara = {
          workPermitNo: '',
          workType: null
        }
        getData()
      }
 
      const handleSelectionChange = (val: User[]) => {
        multipleSelection.value = val
        state.selected = JSON.parse(JSON.stringify(val)).map(i=>i.workApplyId)
      }
 
      const onSubmit = ()=>{
        context.emit('refreshWorks')
        state.selected = []
        clearSearch()
        state.isShowDialog = false
      }
 
        // 页面加载时
        onMounted(() => {});
        return {
            userRef,
          TableRef,
            handleSelectionChange,
            openDialog,
            getData,
            clearSearch,
            onSubmit,
            ...toRefs(state)
        };
    }
});
</script>