|
@@ -0,0 +1,193 @@
|
|
|
+<template>
|
|
|
+ <div class="addList">
|
|
|
+ <el-form
|
|
|
+ ref="ruleForm"
|
|
|
+ :model="ruleForm"
|
|
|
+ :rules="rules"
|
|
|
+ label-width="100px"
|
|
|
+ class="demo-ruleForm"
|
|
|
+ >
|
|
|
+ <el-form-item label="用户名称" prop="uname">
|
|
|
+ <el-input v-model="ruleForm.uname" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="地址名称" prop="addressid">
|
|
|
+ <el-select v-model="ruleForm.addressid" placeholder="请选择地址名称">
|
|
|
+ <el-option
|
|
|
+ v-for="item in addressList"
|
|
|
+ :key="item.addressid"
|
|
|
+ :value="item.addressid"
|
|
|
+ :label="item.addressname"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="等级名称" prop="levelid">
|
|
|
+ <el-select v-model="ruleForm.levelid" placeholder="请选择等级名称">
|
|
|
+ <el-option
|
|
|
+ v-for="item in levelList"
|
|
|
+ :key="item.jrid"
|
|
|
+ :value="item.jrid"
|
|
|
+ :label="item.levelname"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="电话号码" prop="tel">
|
|
|
+ <el-input v-model="ruleForm.tel" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" @click="submitForm('ruleForm')" v-if="open"
|
|
|
+ >修改</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 { showAddresses } from "@/api/address.js";
|
|
|
+import { showLevel } from "@/api/level.js";
|
|
|
+import {
|
|
|
+ insertAllMessage,
|
|
|
+ showOneMessage,
|
|
|
+ updateMessage,
|
|
|
+} from "@/api/message.js";
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ ruleForm: {
|
|
|
+ uname: "",
|
|
|
+ addressid: "",
|
|
|
+ levelid: "",
|
|
|
+ tel: "",
|
|
|
+ arr1: "",
|
|
|
+ },
|
|
|
+ addressList: [],
|
|
|
+ levelList: [],
|
|
|
+ rules: {
|
|
|
+ uname: [{ required: true, message: "请输入用户名称", trigger: "blur" }],
|
|
|
+ addressid: [
|
|
|
+ { required: true, message: "请选择地址名称", trigger: "change" },
|
|
|
+ ],
|
|
|
+ tel: [{ required: true, message: "请输入电话号码", trigger: "blur" }],
|
|
|
+ levelid: [
|
|
|
+ { required: true, message: "请选择等级名称", trigger: "change" },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ id: "",
|
|
|
+ open: false,
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.id = this.$route.query.ids;
|
|
|
+ if (this.id) {
|
|
|
+ this.open = true;
|
|
|
+ showOneMessage({
|
|
|
+ id: this.id,
|
|
|
+ })
|
|
|
+ .then((res) => {
|
|
|
+ if (res.code == 101) {
|
|
|
+ this.ruleForm.uname = res.data[0].jrname;
|
|
|
+ this.ruleForm.addressid = res.data[0].jraddressesid;
|
|
|
+ this.ruleForm.tel = res.data[0].jrtel;
|
|
|
+ this.ruleForm.levelid = res.data[0].jrlevel;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.open = false;
|
|
|
+ }
|
|
|
+ this.getAddress();
|
|
|
+ this.getLevel();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 获取所有地址
|
|
|
+ getAddress() {
|
|
|
+ showAddresses()
|
|
|
+ .then((res) => {
|
|
|
+ this.addressList = res.data;
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // 获取所有等级
|
|
|
+ getLevel() {
|
|
|
+ showLevel()
|
|
|
+ .then((res) => {
|
|
|
+ this.levelList = res.data;
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ submitForm(formName) {
|
|
|
+ this.$refs[formName].validate((valid) => {
|
|
|
+ if (valid) {
|
|
|
+ if (this.open) {
|
|
|
+ // 修改
|
|
|
+ updateMessage({
|
|
|
+ id: this.id,
|
|
|
+ uname: this.ruleForm.uname,
|
|
|
+ addressid: this.ruleForm.addressid,
|
|
|
+ levelid: this.ruleForm.levelid,
|
|
|
+ tel: this.ruleForm.tel,
|
|
|
+ })
|
|
|
+ .then((res) => {
|
|
|
+ if (res.code == 101) {
|
|
|
+ this.$message({
|
|
|
+ message: res.message,
|
|
|
+ type: "success",
|
|
|
+ });
|
|
|
+ this.resetForm("ruleForm");
|
|
|
+ this.$router.push("./messageList");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err, "失败");
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 添加
|
|
|
+ insertAllMessage({
|
|
|
+ uname: this.ruleForm.uname,
|
|
|
+ addressid: this.ruleForm.addressid,
|
|
|
+ levelid: this.ruleForm.levelid,
|
|
|
+ tel: this.ruleForm.tel,
|
|
|
+ })
|
|
|
+ .then((res) => {
|
|
|
+ if (res.code == 101) {
|
|
|
+ this.$message({
|
|
|
+ message: res.message,
|
|
|
+ type: "success",
|
|
|
+ });
|
|
|
+ this.resetForm("ruleForm");
|
|
|
+ this.$router.push("./messageList");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err) => {
|
|
|
+ console.log(err);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.log("error submit!!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ resetForm(formName) {
|
|
|
+ this.$refs[formName].resetFields();
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.addList {
|
|
|
+ width: 70%;
|
|
|
+ margin: 200px auto 0;
|
|
|
+}
|
|
|
+</style>
|