jiangping
2024-11-23 8ac30411bb33e406e0ed5a2b6e2edaf7ab59f11f
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
<template>
  <GlobalWindow :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 v-loading="isWorking.search" :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" @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="500px">
      <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>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isShowModal = false">取 消</el-button>
        <el-button type="primary" @click="subModal">确 定</el-button>
      </span>
    </el-dialog>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import { getFetchList } from '@/api/Inspection/ywPatrolPoint'
import { create } from '@/api/Inspection/ywPatrolLine'
import { Message } from 'element-ui'
export default {
  name: 'OperaYwPatrolLineWindow',
  extends: BaseOpera,
  components: { GlobalWindow },
  data() {
    return {
      // 表单数据
      form: {
        name: '',
      },
      selPoint: [],
      pointList: [],
      list: [],
      isShowModal: false,
      // 验证规则
      rules: {
        name: [{ required: true, message: '请输入' }],
        selPoint: [{ type: 'array', required: true, message: '请输入' }],
      }
    }
  },
  created() {
    this.config({
      api: '/Inspection/ywPatrolLine',
    })
  },
  methods: {
    confirm() {
      const { form, list } = this
      if (list.length == 0) return Message.warning('请先选择巡检点')
      form.linePointList = list
      create({ ...form }).then(res => {
        if (res.code == 200) {
          Message.success('保存成功')
          this.close()
        }
      })
    },
    initData() {
      getFetchList({}).then(res => {
        this.pointList = res || []
      })
    },
    handleDel(row) {
      this.list.splice(row.$index, 1)
 
    },
    changeStatus(row) {
 
    },
    openModal() {
      this.selPoint = this.list.map(i => i.id)
      this.isShowModal = true
    },
    subModal() {
      const { selPoint, pointList, list } = this
      if (selPoint.length == 0) return Message.warning('请先选择巡检点')
      let arr = []
      // 取出选中列表
      pointList.forEach(item => {
        selPoint.forEach(item2 => {
          if (item.id === item2) {
            arr.push(item)
          }
        })
      })
      // 同list去重
      list.forEach(item => {
        arr.forEach((item2, i) => {
          if (item.id === item2.id) {
            arr.splice(i, 1)
          }
        })
      })
      // 添加
      arr.forEach(i => {
        this.list.push({
          needScancode: '1',
          pointName: i.name,
          pointId: i.id,
          code: i.code,
          id: i.id
        })
      })
      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>