rk
2025-09-29 218e84d2264e413f31a2f3957f05bb7b8ad42d5d
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
<template>
  <GlobalWindow :title="title" width="500px" @close="close" :visible.sync="visible" :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="type">
        <el-radio-group v-model="form.type">
          <el-radio :label="0">安泰公务车</el-radio>
          <el-radio :label="1">安泰物流车</el-radio>
          <el-radio :label="2">其他</el-radio>
        </el-radio-group>
      </el-form-item>-->
      <el-form-item label="选择分类:" prop="cateId">
<!--        <el-cascader v-model="form.cateId" @change="changeSel" :options="cateList" :props="{
          label: 'name',
          value: 'id',
          children: 'childCategoryList',
          checkStrictly: true
        }"></el-cascader>-->
        <treeselect
            @select="cateChange"
            v-model="form.cateId"
            placeholder="请选择"
            :options="cateList"
            :normalizer="normalizeOptions1"
            :default-expand-level="1"
            noChildrenText="没有子选项"
            noOptionsText="没有可选项"
            noResultsText="没有匹配的结果" />
      </el-form-item>
      <el-form-item label="选择组织:" prop="groupId">
        <treeselect
            @input="changeSel"
            v-model="form.groupId"
            placeholder="请选择"
            :options="companyTree"
            :normalizer="normalizeOptions"
            :default-expand-level="1"
            noChildrenText="没有子选项"
            noOptionsText="没有可选项"
            noResultsText="没有匹配的结果" />
<!--        <el-select v-model="form.groupId" @change="changeSel" clearable filterable placeholder="请选择">
              <template v-for="item in companyList">
                <el-option  v-if="item.countNum && item.countNum>0" :key="item.id" :label="item.name" :value="item.id">
                </el-option>
              </template>
        </el-select>-->
      </el-form-item>
      <el-form-item label="选择车主:" prop="memberId">
        <el-select v-model="form.memberId" clearable filterable placeholder="请选择">
          <el-option v-for="item in memberList" :key="item.id" :label="item.name" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import { allList } from '@/api/business/member'
import { fetchList } from '@/api/business/category.js'
import { create, updateById } from '@/api/business/cars'
import { companyGetList, fetchList as companyTree } from '@/api/business/company'
import { Message } from 'element-ui'
export default {
  name: 'OperaInternalCompanyWindow',
  extends: BaseOpera,
  components: { GlobalWindow },
  data () {
    return {
      // 表单数据
      memberList: [],
      form: {
        id: null,
        code: null,
        memberId: null,
        // type: 0,
        groupId: null,
        cateId: null
      },
      selectCate: null,
      cateList: [],
      companyList: [],
      companyTree: [],
      // 验证规则
      rules: {
        code: [{ required: true, message: '请输入车牌号' }],
        groupId: [{ required: true, message: '请选择组织' }]
        /* type: [
          { required: true, message: '请选择备注' }
        ] */
      }
    }
  },
  created () {
    this.config({
      api: '/business/cars',
      'field.id': 'id'
    })
  },
  methods: {
    open (title, target) {
      this.title = title
      this.visible = true
      this.getCate()
      this.getfindCompanyTreePage()
      // 新建组织
      if (target == null) {
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.form[this.configData['field.id']] = null
          this.form.type = 0
        })
      }
      // 编辑
      // this.$nextTick(() => {
      //   for (const key in this.form) {
      //     this.form[key] = target[key]
      //   }
      // })
    },
    cateChange(node){
      this.selectCate = node
    },
    // 规范化选项数据的方法
    normalizeOptions1 (node) {
      if (!node.childCategoryList || !node.childCategoryList.length) {
        // 去掉children=[]的children属性
        delete node.childCategoryList
      }
      var node1 = {
        id: node.id,
        label: node.name,
        parentId: node.parentId,
        children: node.childCategoryList,
      }
      return node1
    },
    normalizeOptions (node) {
      if (!node.childList || !node.childList.length) {
        // 去掉children=[]的children属性
        delete node.childList
      }
      return {
        id: node.id,
        label: node.name,
        children: node.childList
      }
    },
    changeSel () {
      const { form } = this
      if (form.groupId) {
        this.loadMember()
      }
      this.form.memberId = ''
    },
    confirm () {
      console.log('form', this.form.cateId)
      const { form } = this
      if(this.selectCate && this.selectCate.childCategoryList &&  this.selectCate.childCategoryList.length) {
        return Message.error('请选择二级分类')
      }
      this.$refs.form.validate((valid) => {
        if (valid) {
          const fn = form.id ? updateById : create
          fn({
            ...form
            // cateId: form.cateId[1]
          }).then(res => {
            Message.success('保存成功')
            this.visible = false
            this.$emit('success')
          })
        }
      })
    },
    close () {
      this.visible = false
      this.$emit('close')
    },
    handleChange (val) {
 
    },
    getCate () {
      fetchList({
        model: { type: 1 },
        capacity: 1000,
        page: 1
      }).then(res => {
        if (res && res.records && res.records.length > 0) {
          res.records[0].fsStatus = 1
          this.cateList = res.records || []
 
        }
      })
    },
    getCompany () {
      companyGetList({
        model: { }, // 有员工的数据
        capacity: 10000,
        page: 1
      }).then(res => {
        this.companyList = res.records || []
      })
    },
    getfindCompanyTreePage () {
      companyTree()
        .then(res => {
          if (res && res.length > 0) {
            res[0].fsStatus = 1
            this.companyTree = res
          }
        })
    },
    loadMember () {
      const { form } = this
      allList({
        type: 2,
        companyId: form.groupId
 
      })
        .then(res => {
          this.memberList = res
        })
        .catch(e => {
          // this.$tip.apiFailed(e)
        })
        .finally(() => {
          this.isWorking = false
        })
    }
  }
}
</script>