renkang
2025-01-03 ccf28d1fed1aa2e5437dbe64b5133ba1cbde6ec7
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
<template>
  <GlobalWindow width="800px" :title="title" :visible.sync="visible" :confirm-working="isWorking" @confirm="confirm">
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="线路名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入线路名称" v-trim />
      </el-form-item>
      <div class="head">
        <div class="title">巡检点</div>
        <el-button type="primary" @click="openModal">添加巡检点</el-button>
      </div>
      <el-table :data="list" stripe>
        <el-table-column prop="code" label="巡检点编码" min-width="100px"></el-table-column>
        <el-table-column prop="pointName" label="巡检点名称" min-width="100px"></el-table-column>
        <el-table-column prop="name" label="扫码打卡" min-width="100px">
          <template v-slot="scope">
            <el-switch v-model="scope.row.needScancode" :disabled="true" @change="changeStatus" :active-value="0"
              :inactive-value="1"></el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="排序码" min-width="100px">
          <template v-slot="scope">
            <el-input v-model="scope.row.sortnum" class="w100"></el-input>
          </template>
        </el-table-column>
        <el-table-column prop="name" label="操作" min-width="100px">
          <template v-slot="scope">
            <span class="red cu" @click="handleDel(scope)">删除</span>
          </template>
        </el-table-column>
      </el-table>
 
 
    </el-form>
    <!--  -->
    <el-dialog title="添加巡检点" :close-on-click-modal="false" append-to-body :visible.sync="isShowModal" width="880px">
      <!-- <el-select class="w400" v-model="selPoint" clearable multiple filterable>
        <el-option v-for="item in pointList" :value="item.id" :label="item.name"></el-option>
      </el-select> -->
      <el-form ref="searchForm" :model="searchForm" label-width="80px" inline>
        <el-form-item label="巡检点" prop="name">
          <el-input v-model="searchForm.name" placeholder="请输入巡检点名称/编码" @keypress.enter.native="search"></el-input>
        </el-form-item>
        <el-form-item label="巡检区域">
          <el-cascader v-model="searchForm.areaIds" @change="changeSel" placeholder="请选择巡检区域" clearable
            :options="areaList" :props="{
              label: 'name',
              value: 'id',
              children: 'childCategoryList'
            }"></el-cascader>
        </el-form-item>
        <el-button type="primary" @click="initData">搜索</el-button>
        <el-button @click="reset">重置</el-button>
        <el-button type="primary" @click="editClick()" icon="el-icon-plus"
                   v-permissions="['business:ywpatrolpoint:create']">新建巡检点</el-button>
      </el-form>
 
      <el-table @selection-change="handleSelectionChange" v-loading="isWorking.search" :data="pointList" stripe>
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column prop="code" label="巡检点编码" min-width="100px"></el-table-column>
        <el-table-column prop="name" label="巡检点名称" min-width="100px"></el-table-column>
        <el-table-column prop="deviceName" label="关联设备" min-width="100px"></el-table-column>
        <el-table-column prop="areaName" label="巡检区域" min-width="100px"></el-table-column>
      </el-table>
      <pagination class="mt10" @size-change="handleSizeChange" @current-change="handlePageChange" :pagination="pagination">
      </pagination>
 
      <span slot="footer" class="dialog-footer">
        <el-button @click="isShowModal = false">取 消</el-button>
        <el-button type="primary" @click="subModal">确 定</el-button>
      </span>
    </el-dialog>
    <OperaYwPatrolPointWindow ref="operaYwPatrolPointWindow" @success="handlePageChange" />
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import OperaYwPatrolPointWindow from '@/views/Inspection/components/OperaYwPatrolPointWindow'
import Pagination from '@/components/common/Pagination'
import { fetchList as getFetchList } from '@/api/Inspection/ywPatrolPoint'
import { create, updateById, detailById } from '@/api/Inspection/ywPatrolLine'
import { Message } from 'element-ui'
import { fetchList } from '@/api/business/category'
export default {
  name: 'OperaYwPatrolLineWindow',
  extends: BaseOpera,
  components: { GlobalWindow, Pagination,OperaYwPatrolPointWindow },
  data() {
    return {
      // 表单数据
      form: {
        name: '',
      },
      selPoint: [],
 
      pointList: [],
      selList: [],
      areaList: [],
      searchForm: {
        name: '',
        areaId: '',
        areaIds: []
      },
      pagination: {
        pageSize: 10,
        page: 1,
        total: 0
      },
 
      list: [],
      isWorking: false,
      isShowModal: false,
      // 验证规则
      rules: {
        name: [{ required: true, message: '请输入' }],
        selPoint: [{ type: 'array', required: true, message: '请输入' }],
      },
    }
  },
  created() {
    this.config({
      api: '/Inspection/ywPatrolLine',
    })
  },
  methods: {
    editClick(row) {
        this.$refs.operaYwPatrolPointWindow.open('新建巡检点')
      // this.$refs.operaYwPatrolPointWindow.initData()
    },
    confirm() {
      const { form, list } = this
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (list.length == 0) return Message.warning('请先选择巡检点')
          form.linePointList = list
          this.isWorking = true
          let fn = form.id ? updateById : create
          fn({ ...form }).then(res => {
            Message.success('保存成功')
            this.isWorking = false
            this.close()
          }, () => {
            this.isWorking = false
          })
        }
      })
 
    },
    getDetail(row) {
      detailById(row.id).then(res => {
        this.form = res
        this.list = res.linePointList || []
      })
    },
    getProject() {
      fetchList({
        model: { type: 4 },
        capacity: 1000,
        page: 1,
      }).then(res => {
        this.areaList = res.records || []
      })
    },
    initData() {
      const { searchForm, pagination } = this
      getFetchList({
        page: pagination.page,
        capacity: pagination.pageSize,
        model: { ...searchForm }
      }).then(res => {
        this.pointList = res.records || []
        this.pagination.total = res.total
      })
    },
    handleSelectionChange(val) {
      this.selList = val
    },
    reset() {
      this.searchForm = {
        name: '',
        areaId: '',
        areaIds: []
      }
      this.initData()
    },
    handleSizeChange(val) {
      this.pagination.pageSize = val
      this.initData()
    },
    handlePageChange(val) {
      this.pagination.page = val
      this.initData()
    },
    handleDel(row) {
      this.list.splice(row.$index, 1)
 
    },
    changeStatus(row) {
 
    },
    openModal() {
      this.getProject()
      this.reset()
      this.isShowModal = true
    },
    changeSel(e) {
      if (e && e.length == 1) {
      } else if (e && e.length == 2) {
        this.$set(this.searchForm, 'areaId', e[1])
      } else {
      }
      this.initData()
    },
    subModal() {
      // this.list = this.selList.map(item => {
      //   return {
      //     needScancode: 0,
      //     pointName: item.name,
      //     pointId: item.id,
      //     code: item.code
      //   }
      // })
      this.selList.forEach(item => {
        const index = this.list.findIndex(i => i.code === item.code)
        if (index === -1) {
          this.list.push({
            needScancode: 0,
            pointName: item.name,
            pointId: item.id,
            code: item.code
          })
        }
      })
      this.isShowModal = false
    },
    close() {
      this.visible = false
      this.$emit('success')
    }
  }
}
</script>
<style lang="scss" scoped>
.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
 
  div {
    font-weight: 500;
  }
}
</style>