石广澎
2023-12-01 9cb389b74302ce6b0a2333328922e7c462234a56
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
<template>
  <win-sm :title="setting.title" @close="close" :width="'800px'" :loading="loading">
    <el-form ref="ruleForm" :model="formData" :rules="rules" class="demo-ruleForm" label-width="100px">
      <!--      <el-form-item label="编号" prop="warehouseCode">
              <el-input disabled v-model="formData.warehouseCode" clearable maxlength="20" show-word-limit style="width: 100%" />
            </el-form-item>-->
      <el-form-item label="仓库名称" prop="warehouseName">
        <el-input v-model="formData.warehouseName" placeholder="请输入仓库名称" clearable maxlength="20" show-word-limit
                  style="width: 100%"/>
      </el-form-item>
      <el-form-item label="仓库类型" prop="classificationCode">
        <el-select v-model="formData.classificationCode" clearable placeholder="请选择仓库类型" style="width: 100%">
          <el-option
              v-for="item in classList"
              :key="item.dict_code"
              :label="item.dict_label"
              :value="item.dict_code"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="所属机构" prop="agencyId">
        <el-cascader
            v-model="formData.agencyId"
            placeholder="请选择所属机构"
            :options="treeList"
            :props="{checkStrictly: true,emitPath: false,value:'id'}"
            style="width: 100%"></el-cascader>
      </el-form-item>
      <el-form-item label="地址">
        <el-input
            style="width: 100%"
            maxlength="200"
            show-word-limit
            type="textarea"
            :rows="3"
            placeholder="请输入内容"
            v-model="formData.adress"/>
 
      </el-form-item>
      <el-form-item label="状态" prop="states">
        <el-radio-group v-model="formData.states">
          <el-radio :label="1" border>启用</el-radio>
          <el-radio :label="0" border>禁用</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <div slot="footer" align="center" class="dialog-footer">
      <my-button name="取消" site="form" @click="close"/>
      <my-button name="保存" site="form" @click="save"/>
    </div>
  </win-sm>
</template>
 
<script>
import winSm from '@/components/win/win-sm';
import myButton from '@/components/myButton/myButton';
import * as finsystenant from '@/api/baseSetting/finsystenant';
import {findParentIds} from '@/utils/index';
 
export default {
  components: {winSm, myButton},
  props: {
    setting: {
      type: Object,
      default: () => {
      },
    },
  },
  data() {
    return {
      loading: true,
      classList: [],
      treeList: [],
      checkAll: false,
      checkedList: [],
      formData: {
        warehouseCode: null,
        classificationId: null,
        classificationCode: null,
        states: 1,
        agencyId: ''
      },
      rules: {
        warehouseName: [{required: true, message: '请输入', trigger: 'blur'}],
        classificationCode: [{required: true, message: '请选择', trigger: 'blur'}],
        agencyId: [{required: true, message: '请选择', trigger: ['blur', 'change']}],
        states: [{required: true, message: '请选择状态', trigger: 'blur'}],
      },
    };
  },
  async created() {
    await this.class_List();
    await this.tree_List();
    this.loading = false
    if (this.setting.info) {
      this.formData = Object.assign({}, JSON.parse(this.setting.info));
    }
  },
  methods: {
    async class_List() {
      await finsystenant.classList().then((res) => {
        if (res) {
          res.map(item => {
            item.dict_code = item.dict_code.toString()
          })
          this.classList = res;
        }
      });
    },
    async tree_List() {
      await finsystenant.getTree().then((res) => {
        if (res) {
          this.treeList = res;
          this.$set(this.formData, 'agencyIds', findParentIds(this.treeList, this.formData.agencyId))
        }
      });
    },
    getEditInfo(id) {
    },
    close() {
      this.$emit('close');
    },
    save() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          const params = Object.assign({}, this.formData);
          if (this.loading) return
          this.loading = true
          if (this.setting.id) {
            // 编辑接口
            finsystenant.editstore(params).then((res) => {
              this.loading = false
              if (res) {
                this.$message.success('保存成功!');
                this.close();
                this.$emit('search');
              } else {
                this.$message.error('保存失败');
              }
            }).catch(()=>{
              this.loading = false
            });
          } else {
            params.orgId = this.setting.orgId;
            finsystenant.addstore(params).then((res) => {
              this.loading = false
              if (res) {
                this.$message.success('保存成功!');
                this.close();
                this.$emit('search');
              } else {
                this.$message.error('保存失败');
              }
            }).catch(()=>{
              this.loading = false
            });
          }
        } else {
          this.$message.error('校验未通过,请检查。');
        }
      });
    },
  },
};
</script>