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
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
<script lang="ts" setup>
import {onMounted, reactive, ref} from "vue";
import {useRoute, useRouter} from "vue-router"
import request from "@/utils/request"
import {ElMessage} from "element-plus";
import deepClone from "@/utils/deepClone"
import { useI18n } from 'vue-i18n'
 
//语言获取
const { t } = useI18n()
const router = useRouter()
const route = useRoute()
let produceList = ref([])
 
 
 
 
let ruleForm = ref({
  id:0,
  customerName: '',
  grade: '',
  moneyLimit: '',
  address: '',
  contact: '',
  phone: ''
 
})
 
 
 
onMounted(()=>{
 
  //获取传过来的数据进行判断
  const str = route.query.id
  if (typeof str != 'undefined' && str != null && str !== '' && str !== '\n' && str !== '\r'){
    ruleForm.value.id = Number(str)
 
    request.post(`/customer/getSelectCustomer/1/100`,ruleForm.value).then((res) => {
      if(res.code==200){
        ruleForm.value=deepClone(res.data.data[0])
 
      }else{
        ElMessage.warning(res.msg)
        router.push("/login")
      }
    })
  }
 
 
})
 
 
//保存提交
const submitForm = () => {
  //表头数据校验
  const customerName = ruleForm.value.customerName
  if(customerName === null || customerName === undefined || customerName === ''){
    ElMessage.error(t('customer.pleaseEnterTheCustomerName'))
    return
  }
  const grade = ruleForm.value.grade
  if(grade === null || grade === undefined || grade === ''){
    ElMessage.error(t('customer.pleaseEnterCustomerLevel'))
    return
  }
  const moneyLimit = ruleForm.value.moneyLimit
  if(moneyLimit === null || moneyLimit === undefined || moneyLimit === ''){
    ElMessage.error(t('customer.pleaseEnterTheAmountOfFunds'))
    return
  }
  const address = ruleForm.value.address
  if(address === null || address === undefined || address === ''){
    ElMessage.error(t('customer.pleaseEnterTheContactAddress'))
    return
  }
  const contact = ruleForm.value.contact
  if(contact === null || contact === undefined || contact === ''){
    ElMessage.error(t('customer.pleaseEnterTheContactPerson'))
    return
  }
  const phone = ruleForm.value.phone
  if(phone === null || phone === undefined || phone === ''){
    ElMessage.error(t('customer.pleaseEnterTheContactPhoneNumber'))
    return
  }
 
  let flowData = ref({
    customer: ruleForm
  })
 
  request.post("/customer/insertCustomer", flowData.value).then((res) => {
    if(res.code==200 && res.data===true){
      resetForm()
      ElMessage.success(t('basicData.msg.saveSuccess'))
    }else{
      ElMessage.warning("保存失败")
      router.push("/login")
    }
  }).catch((err)=>{
    ElMessage.error('系统错误')
    router.push("/login")
  })
 
}
//重置输入框
const resetForm = () => {
  ruleForm.value.customerName=""
  ruleForm.value.grade=""
  ruleForm.value.moneyLimit=""
  ruleForm.value.address=""
  ruleForm.value.contact=""
  ruleForm.value.phone=""
}
</script>
 
<template>
  <div class="main-div">
 
    <div class="order-primary" >
      <el-row>
        <el-col  :span="2"><el-text>{{ $t('customer.customerName') }}:</el-text></el-col>
        <el-col  :span="5"><el-input style="font-size: large;color: #181818" v-model="ruleForm.customerName"  ></el-input></el-col>
      </el-row>
      <el-row>
        <el-col  :span="2"><el-text>{{ $t('customer.customerGrade') }}:</el-text></el-col>
        <el-col  :span="5"><el-input style="font-size: large;color: #181818" v-model="ruleForm.grade"  ></el-input></el-col>
      </el-row>
      <el-row>
        <el-col  :span="2"><el-text>{{ $t('customer.moneyLimit') }}:</el-text></el-col>
        <el-col  :span="5"><el-input style="font-size: large;color: #181818" v-model="ruleForm.moneyLimit"  ></el-input></el-col>
      </el-row>
      <el-row>
        <el-col  :span="2"><el-text>{{ $t('customer.address') }}:</el-text></el-col>
        <el-col  :span="5"><el-input style="font-size: large;color: #181818" v-model="ruleForm.address"  ></el-input></el-col>
      </el-row>
      <el-row>
        <el-col  :span="2"><el-text>{{ $t('customer.contacts') }}:</el-text></el-col>
        <el-col  :span="5"><el-input style="font-size: large;color: #181818" v-model="ruleForm.contact"  ></el-input></el-col>
      </el-row>
      <el-row>
        <el-col  :span="2"><el-text>{{ $t('customer.telephone') }}:</el-text></el-col>
        <el-col  :span="5"><el-input style="font-size: large;color: #181818" v-model="ruleForm.phone"  ></el-input></el-col>
      </el-row>
      <el-row>
        <el-col  :span="2"><el-button type="primary" @click="submitForm()">{{ $t('basicData.save') }}</el-button></el-col>
        <el-col  :span="2"><el-button @click="resetForm()">{{ $t('customer.resetting') }}</el-button></el-col>
      </el-row>
    </div>
 
  </div>
 
 
</template>
 
 
<style scoped>
.main-div{
  width: 100%;
  height: 100%;
}
 
.div-form{
  height:70%;
  width: 40%;
}
.el-row{
  margin-bottom: 0.5rem;
}
</style>