chenlu
2024-05-21 18fb477ea840e3dd4b19ff63f68f994d31fab43b
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
<script setup>
import request from "@/utils/request"
import {onMounted, ref, watch} from "vue";
import {useI18n} from "vue-i18n"
import {ElMessage} from "element-plus"
import {useRouter,useRoute} from "vue-router"
const { t } = useI18n()
const router = useRouter()
const route = useRoute()
 
 
let basic = ref({
  operateType:'',
  type : '',
  input:''
})
let options=ref([
  { label: "库存组织",
    value: "inventoryOrganization",
  },
  { label: "领出",
    value: "takeOut",
  },
  { label: "材料出库类型",
    value: "outboundType",
  },
  { label: "材料返库类型",
    value: "returningType",
  },
])
 
let props = defineProps({
  rowIndex:{
    Object,
    default: null
  }
})
onMounted(() =>{
  if(props.rowIndex){
    basic.value.operateType =  props.rowIndex.operateType
    basic.value.type =  props.rowIndex.type
    basic.value.input =  props.rowIndex.operateTypeName
  }
})
 
const emit =  defineEmits(['gaveParent'])
const saveBasicData =  () =>{
  if (basic.value.operateType[0]==='inventoryOrganization'){
    basic.value.type='库存组织'
  }
  else if(basic.value.operateType[0]==='takeOut'){
    basic.value.type='领出'
  }
  else if(basic.value.operateType[0]==='outboundType'){
    basic.value.type='材料出库类型'
  }
  else if(basic.value.operateType[0]==='returningType'){
    basic.value.type='材料返库类型'
  }
  if(basic.value.operateType[0]==='' || basic.value.input===''){
    return
  }
  request.post(`/BasicWarehouse/addBasicWarehouse`, basic.value).then(res => {
    if (res.data) {
      ElMessage.success('保存成功')
      emit('gaveParent', true)
    }
  }).catch((err)=>{
    ElMessage.error('系统错误')
    router.push("/login")
  })
}
const updateBasicData =  () =>{
  let submitArr  = props.rowIndex
  submitArr.operateType = basic.value.operateType
  submitArr.type = basic.value.type
  submitArr.operateTypeName = basic.value.input
  if(basic.value.input===''){
    ElMessage.warning('请输入数据')
  }else{
    request.post(`/BasicWarehouse/updateBasicWarehouse`, submitArr).then(res => {
      if (res.data) {
        ElMessage.success('修改成功')
        emit('gaveParent', true)
      }
    }).catch((err)=>{
      ElMessage.error('系统错误')
      router.push("/login")
    })
  }
 
 
}
 
const handleChange = (value) => {
  const filterArr = options.value.filter((item) =>item.value === value[0]
  ).map((item) =>item.children.filter((item) =>item.value === value[1]))
}
 
 
</script>
 
<template>
  <div>
    <el-row>
      <el-col :span="4">基础类型:</el-col>
      <el-col :span="12">
        <el-cascader
            v-model="basic.operateType"
            :options="options"
            clearable
            placeholder=""
            :disabled="props.rowIndex"
        />
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="4">名称:</el-col>
      <el-col :span="12">
        <el-input v-model="basic.input"/>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="4"></el-col>
      <el-col :span="12">
        <el-button v-show="!props.rowIndex" @click="saveBasicData" type="primary">新增</el-button>
        <el-button v-show="props.rowIndex" @click="updateBasicData" type="primary">修改</el-button>
 
      </el-col>
    </el-row>
 
  </div>
</template>
 
<style scoped>
div{
  text-align: center;
}
.el-row{
  margin-top: 10px;
}
</style>