Mr.Shi
2023-08-11 5a7fb4358eb902ce139096f20ef3c0625adcd7f4
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
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="submission"
  >
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="绑定工序" prop="procedureIds">
        <el-select v-model="form.procedureIds" multiple filterable clearable placeholder="请选择绑定工序" @change="selectP">
          <el-checkbox style="margin-left: 20px" v-model="checked" @change='selectAll'>全选</el-checkbox>
          <el-option
            v-for="item in options"
            :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 { getProductes, updateById } from '@/api/ext/companyUserExt'
export default {
  name: 'OperaCategoryExtWindow',
  extends: BaseOpera,
  components: { GlobalWindow },
  props: {
    id: {
      type: String,
      required: false,
      default: () => ''
    }
  },
  data () {
    return {
      checked: false,
      options: [], // 工序数据
      form: { // 表单数据
        id: null,
        departmentId: null,
        procedureIds: []
      },
      rules: { // 验证规则
        procedureIds: [
          { required: true, message: '请选择工序', trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    this.config({
      api: '/system/user',
      'field.id': 'id'
    })
  },
  methods: {
    open (title, target) {
      this.title = title
      this.visible = true
      // console.log(target)
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        this.form.id = target.userId
        this.getProducte()
        const tps = target.procedureIds.split(',')
        this.form.procedureIds = []
        for (const item of tps) {
          this.form.procedureIds.push(parseInt(item))
        }
        
        this.selectP()
      })
    },
    // 提交工序
    submission () {
      this.isWorking = true
      this.$refs.form.validate((valid) => {
        if (valid) {
          updateById(this.form).then(res => {
            // this.$tip.success('绑定成功')
            this.visible = false
            this.isWorking = false
            this.$emit('success', '1')
            setTimeout(() => {
              this.$dialog.attentionConfirm('工序绑定成功,用户需重新登录后生效').then(() => {})
            }, 300)
          }).catch(e => {
            this.$tip.error(e)
            this.isWorking = false
          })
        } else {
          return false
        }
      })
    },
    // 获取工序数据
    getProducte () {
      getProductes({ orginId: this.form.departmentId})
        .then((res) => {
          this.options = res
          this.selectP()
        }).catch((err) => {
          console.log(err)
        })
    },
    selectAll () {
      this.form.procedureIds = []
      if (this.checked) {
        this.options.forEach((item) => { this.form.procedureIds.push( item.id )});
      }
    },
    selectP () {
      this.checked = false
      console.log(this.form.procedureIds.length, this.options.length);
      if (this.form.procedureIds.length === this.options.length) {
        this.checked = true
      }
    }
  }
}
</script>