ll
liukangdong
2024-11-25 42a22be5d9258450f66f56c7915959b8bebba6ce
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
<template>
  <GlobalWindow :title="title" :visible.sync="visible" width="620px" :confirm-working="isWorking" @confirm="confirm">
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="巡检点编码" prop="code">
        <el-input v-model="form.code" placeholder="请输入名称" v-trim />
      </el-form-item>
      <el-form-item label="巡检点名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入巡检点名称" v-trim />
      </el-form-item>
      <el-form-item label="巡检设备">
        <el-select v-model="form.deviceId">
          <el-option v-for="item in deviceList" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属区域" prop="areaId">
        <el-cascader v-model="form.areaIds" @change="changeSel" placeholder="请选择巡检区域" clearable :options="cateList"
          :props="{
            label: 'name',
            value: 'id',
            children: 'childCategoryList',
          }"></el-cascader>
      </el-form-item>
      <el-form-item label="经纬度">
        <el-input v-model="form.lnglat" disabled v-trim />
      </el-form-item>
      <el-form-item>
        <mapDrag class="mapbox" @center="getCenter" />
      </el-form-item>
      <el-form-item label="巡检内容" prop="content">
        <el-input type="textarea" :rows="4" v-model="form.content" placeholder="请输入" />
      </el-form-item>
      <el-form-item label="上传图片" prop="imgurl">
        <UploadAvatarImage :file="{ 'imgurlfull': form.imgurlfull, 'imgurl': form.imgurl }"
          :uploadData="{ folder: 'ywPatrol/' }" @uploadSuccess="uploadAvatarSuccess" @uploadEnd="isUploading = false"
          @uploadBegin="isUploading = true" />
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import UploadAvatarImage from '@/components/common/UploadAvatarImage'
import mapDrag from '@/components/common/map/mapDrag.vue'
import { fetchList } from '@/api/business/category'
import { detail } from '@/api/Inspection/ywPatrolPoint'
export default {
  name: 'OperaYwPatrolPointWindow',
  extends: BaseOpera,
  components: { GlobalWindow, UploadAvatarImage, mapDrag },
  data() {
    return {
      // 表单数据
      form: {
        name: '',
        code: '',
        content: '',
        imgurl: '',
        areaId: 0,
        areaIds: [],
        addr: ''
      },
      deviceList: [],
      cateList: [],
      // 验证规则
      rules: {
        name: [{ required: true, message: '请输入' }],
        code: [{ required: true, message: '请输入' }],
      },
      isUploading: false,
    }
  },
  created() {
    this.config({
      api: '/Inspection/ywPatrolPoint',
      'field.id': 'id'
    })
  },
  methods: {
    open(title, row) {
      this.title = title
      this.visible = true
      if (row && row.id) {
        this.getDetail(row)
      }
    },
    getDetail(row) {
      detail(row.id).then(res => {
        this.form = { ...res } 
        // this.$set(this.form, 'areaId', res.areaId)
        // console.log('res', res)
        // console.log('res', this.form)
        this.initData(res.areaId)
      })
    },
    initData(areaId) {
      fetchList({
        model: { type: 4 },
        capacity: 1000,
        page: 1,
      }).then(res => {
        this.cateList = res.records || []
        console.log('this.form.areaId', this.form)
 
        if (areaId) {
          this.cateList.forEach(item => {
            if (item.childCategoryList) {
              item.childCategoryList.forEach(item2 => {
                if (item2.id == areaId) {
                  this.$set(this.form, 'areaIds', [item.id, item2.id])
                  console.log('areaIds', this.form)
 
                }
              })
            }
          })
        }
      })
 
    },
    getCenter(data) {
      // console.log(data)
      // this.$set(this.form, 'postion', data.address)
      if(data.lng){
        this.$set(this.form, 'lnglat', data.lng + ',' + data.lat)
      }else{
        this.$set(this.form, 'lnglat', '')
      }
      this.$set(this.form, 'longitude', data.lng)
      this.$set(this.form, 'latitude', data.lat)
    },
    changeSel(e) {
      if (e && e.length == 2) {
        this.$set(this.form, 'areaId', e[1])
      } else {
        this.$set(this.form, 'areaId', '')
      }
    },
    uploadAvatarSuccess(file) {
      this.form.imgurl = file.imgurl
      this.form.imgurlfull = file.imgurlfull
    },
  }
}
</script>
<style lang="scss" scoped>
.mapbox {
  width: 100%;
  height: 400px;
  margin-bottom: 20px;
  float: left;
}
</style>