新建党组织选择框完成

<template>

  <div>

      <!-- label-width="100px" -->

    <h2>选择框交互成功</h2>

    <el-col id="main">

      <el-form

        label-position="right"

        :model="ruleForm"

        ref="ruleForm"

        class="demo-ruleForm"

        style="margin-top:20px"

      >

        <el-form-item label="上级党组织名称" :required="true">

          <el-input v-model="ruleForm.organizationSuperior"></el-input>

        </el-form-item>

        <el-form-item label="党组织名称" :required="true">

          <el-input v-model="ruleForm.organizationName"></el-input>

        </el-form-item>

     

        <el-form-item label="请选择所在院系" :required="true">

   <el-select v-model="ruleForm.departmentCode" placeholder="所在院系" >

      <el-option v-for="d in showDepartment" :value="d.departmentName">{{d.departmentName}}</el-option>

    </el-select>

    </el-form-item>

     

        <el-form-item style="text-align: center;margin:100px 0px;">

          <el-button type="primary" @click="submitForm('ruleForm')"

            >立即创建</el-button

          >

          <el-button @click="resetForm('ruleForm')">重置</el-button>

        </el-form-item>

      </el-form>

    </el-col>

  </div>

</template>

<script>

import axios from 'axios'

export default {

  name: "index",

  data() {

    return {

      ruleForm: {

        organizationName: "",

        organizationSuperior: "",

        departmentCode: "",

      },

      showDepartment:{},

    };

  },

   mounted() {

      // 展示院系

         this.faculty();

  },

  methods: {

       open4() {

        this.$message.error('错了哦,这是一条错误消息');

      },

    // 展示院系

    faculty(){

    var  token = localStorage.getItem('token')

    axios.get('http://hrdj.vipgz6.91tunnel.com/system/departmentList',

     { headers: { "content-type": "application/json",token  }},

    ).then((res) => {

      console.log(res.data.data);

      this.showDepartment  = res.data.data;

    }).catch(err=>{

      console.log("展示失败",err);

    })

    },

  // 提交

    submitForm(formName) {

      // 输入框为空给用户提示

      if( this.ruleForm.organizationSuperior === "") {

          this.$message.error('请输入上级党组织名称');

      }else if(this.ruleForm.organizationName ==="") {

          this.$message.error('请输入党组织名称');

      }else if( this.ruleForm.departmentCode === ""){

          this.$message.error('请选择所在院系');

      } else {

        this.$message({

          message: '创建成功',

          type: 'success'

        });

      }

      this.$refs[formName].validate((valid) => {

        if (valid) {

         var data = JSON.stringify(this.ruleForm);

         console.log("this.ruleForm)等于",data)

    var  token = localStorage.getItem('token')

    axios.post('http://hrdj.vipgz6.91tunnel.com/organizationManagement/addOrganization',data,

     { headers: { "content-type": "application/json",token  }},

    ).then((res) => {

      console.log(res.data);

       this.ruleForm.organizationName ="";

         this.ruleForm.organizationSuperior = "" ;

          this.ruleForm.departmentCode = "";

    }).catch(err=>{

      console.log("提交失败",err);

    })

        } else {

          console.log("错误!!!");

          return false;

        }

      });

    },

    resetForm(formName) {

      this.$refs[formName].resetFields();

    },

  },

};

</script>

<style scoped>

/* h3 a {

  margin-left: 10px;

  color: #000;

  text-decoration: none;

  border-top-right-radius: 20px;

} */

h2 {

  background-color: #fff;

  margin-bottom: 20px;

  border-left: 5px solid #de2910;

  padding-left: 10px;

}

div{

  width: 100%;

}

#main {

  width: 100%;

  background-color: #fff;

  margin: auto;

  

  padding:10px 50% 1px 5%;

}

/deep/[class*=el-col-] {

  float: none;

}

</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你希望直接通过选择完成,而不使用按钮来触发选择的显示,你可以将选择的显示状态与一个变量绑定,并通过监听变量的改变来显示或隐藏选择。 以下是一个示例代码,演示了如何使用选择完成: ```html <template> <view> <view class="label">请选择电梯</view> <picker v-model="pickerValue" mode="multiSelector" @change="onChange"> <view class="picker"> <view class="picker-column"> <picker-view-column> <view v-for="(country, index) in countryList" :key="index">{{ country }}</view> </picker-view-column> </view> <view class="picker-column"> <picker-view-column> <view v-for="(city, index) in cityList[pickerValue[0]]" :key="index">{{ city }}</view> </picker-view-column> </view> </view> </picker> </view> </template> <script> export default { data() { return { countryList: ['中国', '美国', '英国'], cityList: [ ['北京', '上海', '广州'], ['纽约', '洛杉矶', '芝加哥'], ['伦敦', '曼彻斯特', '伯明翰'] ], pickerValue: [0, 0] }; }, watch: { pickerValue(newValue) { console.log('选择的国家:', this.countryList[newValue[0]]); console.log('选择的城市:', this.cityList[newValue[0]][newValue[1]]); } } }; </script> ``` 在上面的示例中,选择的显示状态由pickerValue变量控制,通过双向绑定v-model来实现。当选择的值发生变化时,watch监听函数会触发,你可以在其中进行相应的操作。在这个示例中,我将选择的国家和城市打印到了控制台上,你可以根据需要进行相应的处理。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值