|
@@ -0,0 +1,189 @@
|
|
|
|
+/*
|
|
|
|
+ 添加信息
|
|
|
|
+ author:zsy
|
|
|
|
+ date:2023-08-02
|
|
|
|
+ */
|
|
|
|
+<template>
|
|
|
|
+ <div class="add-message">
|
|
|
|
+ <el-form
|
|
|
|
+ :model="ruleForm"
|
|
|
|
+ :rules="rules"
|
|
|
|
+ ref="ruleForm"
|
|
|
|
+ label-width="100px"
|
|
|
|
+ class="demo-ruleForm"
|
|
|
|
+ >
|
|
|
|
+ <el-form-item label="用户名称" prop="uname">
|
|
|
|
+ <el-input v-model="ruleForm.uname"></el-input>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="地址ID" prop="addressid">
|
|
|
|
+ <el-select v-model="ruleForm.addressid" placeholder="地址">
|
|
|
|
+ <el-option
|
|
|
|
+ v-for="item in addressData"
|
|
|
|
+ :key="item.addressid"
|
|
|
|
+ :label="item.addressname"
|
|
|
|
+ :value="item.addressid"
|
|
|
|
+ >
|
|
|
|
+ </el-option>
|
|
|
|
+ </el-select>
|
|
|
|
+ <!-- <el-input v-model="ruleForm.addressid"></el-input> -->
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="等级ID" prop="levelid">
|
|
|
|
+ <el-select v-model="ruleForm.levelid" placeholder="等级">
|
|
|
|
+ <el-option
|
|
|
|
+ v-for="item in levelData"
|
|
|
|
+ :key="item.jrid"
|
|
|
|
+ :label="item.levelname"
|
|
|
|
+ :value="item.jrid"
|
|
|
|
+ >
|
|
|
|
+ </el-option>
|
|
|
|
+ </el-select>
|
|
|
|
+ <!-- <el-input v-model="ruleForm.latitude"></el-input> -->
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item label="电话号码" prop="tel">
|
|
|
|
+ <el-input v-model="ruleForm.tel"></el-input>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ <el-form-item>
|
|
|
|
+ <el-button type="primary" @click="updateForm('ruleForm')" v-if="isUpdate"
|
|
|
|
+ >修改</el-button
|
|
|
|
+ >
|
|
|
|
+ <el-button type="primary" @click="submitForm('ruleForm')" v-else
|
|
|
|
+ >提交</el-button
|
|
|
|
+ >
|
|
|
|
+ <el-button @click="resetForm('ruleForm')">重置</el-button>
|
|
|
|
+ </el-form-item>
|
|
|
|
+ </el-form>
|
|
|
|
+ </div>
|
|
|
|
+</template>
|
|
|
|
+
|
|
|
|
+<script>
|
|
|
|
+import {getLocation} from '@/api/location'
|
|
|
|
+import {getLevel} from '@/api/level'
|
|
|
|
+import {addMessage , showMessage ,updateInfo} from '@/api/message'
|
|
|
|
+export default {
|
|
|
|
+ data() {
|
|
|
|
+ return {
|
|
|
|
+ isUpdate: false,
|
|
|
|
+ ruleForm: {
|
|
|
|
+ uname: "",
|
|
|
|
+ addressid: "",
|
|
|
|
+ levelid: "",
|
|
|
|
+ tel: "",
|
|
|
|
+ },
|
|
|
|
+ addressData:[],
|
|
|
|
+ levelData:[],
|
|
|
|
+ rules: {
|
|
|
|
+ uname: [{ required: true, message: "请输入用户名称", trigger: "blur" }],
|
|
|
|
+ tel: [{ required: true, message: "请输入电话号", trigger: "blur" }],
|
|
|
|
+ addressid: [{ required: true, message: "请输入地址", trigger: "blur" }],
|
|
|
|
+ levelid: [{ required: true, message: "请输入等级", trigger: "blur" }],
|
|
|
|
+ },
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ /* /获取地址列表 */
|
|
|
|
+ getLocationList(){
|
|
|
|
+ getLocation().then((res)=>{
|
|
|
|
+ this.addressData = res.data
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ /* 获取等级列表 */
|
|
|
|
+ getLevelList(){
|
|
|
|
+ getLevel().then((res)=>{
|
|
|
|
+ this.levelData = res.data
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ /* 提交功能 */
|
|
|
|
+ submitForm(formName) {
|
|
|
|
+ this.$refs[formName].validate((valid) => {
|
|
|
|
+ if (valid) {
|
|
|
|
+ addMessage({
|
|
|
|
+ uname: this.ruleForm.uname,
|
|
|
|
+ addressid: this.ruleForm.addressid,
|
|
|
|
+ levelid: this.ruleForm.levelid,
|
|
|
|
+ tel: this.ruleForm.tel
|
|
|
|
+ })
|
|
|
|
+ .then((res) => {
|
|
|
|
+ this.$message({
|
|
|
|
+ message: "提交成功",
|
|
|
|
+ type: "success",
|
|
|
|
+ });
|
|
|
|
+ this.$refs[formName].resetFields();
|
|
|
|
+ this.$router.push('/message/messageList')
|
|
|
|
+ })
|
|
|
|
+ .catch((err) => {
|
|
|
|
+ console.log(err);
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ console.log("error submit!!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /* 重置 */
|
|
|
|
+ resetForm(formName) {
|
|
|
|
+ this.$refs[formName].resetFields();
|
|
|
|
+ },
|
|
|
|
+ /* 根据id获取信息 */
|
|
|
|
+ showMessageList(id){
|
|
|
|
+ showMessage({
|
|
|
|
+ id: id
|
|
|
|
+ }).then((res)=>{
|
|
|
|
+ console.log(res.data[0])
|
|
|
|
+ this.ruleForm = res.data[0]
|
|
|
|
+ this.ruleForm = {
|
|
|
|
+ uname: res.data[0].jrname,
|
|
|
|
+ addressid: res.data[0].jraddressesid,
|
|
|
|
+ levelid: res.data[0].jrlevel,
|
|
|
|
+ tel: res.data[0].jrtel
|
|
|
|
+ }
|
|
|
|
+ }).catch((err)=>{
|
|
|
|
+ console.log(err)
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ /* 修改功能 */
|
|
|
|
+ updateForm(formName) {
|
|
|
|
+ this.$refs[formName].validate((valid) => {
|
|
|
|
+ if (valid) {
|
|
|
|
+ updateInfo({
|
|
|
|
+ id: this.$route.query.id,
|
|
|
|
+ uname: this.ruleForm.uname,
|
|
|
|
+ addressid: this.ruleForm.addressid,
|
|
|
|
+ levelid: this.ruleForm.levelid,
|
|
|
|
+ tel: this.ruleForm.tel
|
|
|
|
+ })
|
|
|
|
+ .then((res) => {
|
|
|
|
+ this.$message({
|
|
|
|
+ message: "提交成功",
|
|
|
|
+ type: "success",
|
|
|
|
+ });
|
|
|
|
+ this.$refs[formName].resetFields();
|
|
|
|
+ this.$router.push('/message/messageList')
|
|
|
|
+ })
|
|
|
|
+ .catch((err) => {
|
|
|
|
+ console.log(err);
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ console.log("error submit!!");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ created(){
|
|
|
|
+ this.getLocationList();
|
|
|
|
+ this.getLevelList();
|
|
|
|
+ if(this.$route.query.id){
|
|
|
|
+ this.isUpdate = true
|
|
|
|
+ let _id = this.$route.query.id
|
|
|
|
+ this.showMessageList(_id)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style scoped>
|
|
|
|
+.add-message {
|
|
|
|
+ width: 70%;
|
|
|
|
+ margin: 100px auto 0;
|
|
|
|
+}
|
|
|
|
+</style>
|