123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <template>
- <a-modal
- centered
- class="addZone-modal"
- :footer="null"
- :maskClosable="false"
- :title="modalTit"
- v-model="isShow"
- @cancel="isShow=false"
- :width="500">
- <!-- 表单 -->
- <a-form-model
- ref="ruleForm"
- :model="form"
- :rules="zoneRules"
- id="addZone-modal-form"
- :label-col="formItemLayout.labelCol"
- :wrapper-col="formItemLayout.wrapperCol"
- >
- <a-form-model-item label="所属区域">
- {{ parentData&&parentData.subareaName }}
- </a-form-model-item>
- <a-form-model-item label="分区名称" prop="subareaAreaName">
- <a-input
- id="addZone-modal-subareaAreaName"
- :maxLength="30"
- v-model.trim="form.subareaAreaName"
- @change="filterEmpty"
- placeholder="请输入分区名称(最多30个字符)"
- allowClear />
- </a-form-model-item>
- </a-form-model>
- <div class="btn-cont">
- <a-button id="addZone-modal-back" @click="isShow = false" >取消</a-button>
- <a-button type="primary" style="margin-left: 15px;" id="addZone-modal-save" @click="handleSave">保存</a-button>
- </div>
- </a-modal>
- </template>
- <script>
- import { subareaSaveSubareaArea } from '@/api/subarea'
- export default {
- name: 'MarketingDivisionAddZoneModal',
- components: { },
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- },
- parentData: {
- type: Object,
- default: function () {
- return null
- }
- }
- },
- computed: {
- // 弹窗标题
- modalTit () {
- return (this.parentData && this.parentData.subareaAreaSn ? '编辑' : '新增') + '分区'
- }
- },
- data () {
- return {
- spinning: false,
- isShow: this.openModal, // 是否打开弹框
- // 表单label设置
- formItemLayout: {
- labelCol: { span: 4 },
- wrapperCol: { span: 18 }
- },
- // 提交数据
- form: {
- subareaAreaName: '' // 分区名称
- },
- // 表单验证规则
- zoneRules: {
- subareaAreaName: [
- { required: true, message: '请输入分区名称', trigger: 'blur' }
- ]
- }
- }
- },
- methods: {
- // 分区名称过滤
- filterEmpty () {
- let str = this.form.subareaAreaName
- str = str.replace(/\ +/g, '')
- str = str.replace(/[ ]/g, '')
- str = str.replace(/[\r\n]/g, '')
- this.form.subareaAreaName = str
- },
- // 保存
- handleSave () {
- const _this = this
- _this.$refs.ruleForm.validate(valid => {
- if (valid) {
- const formData = JSON.parse(JSON.stringify(_this.form))
- // 编辑
- if (this.parentData.subareaAreaSn) {
- formData.subareaAreaSn = this.parentData.subareaAreaSn
- }
- formData.subareaSn = this.parentData.subareaSn
- // console.log(formData, 'formData')
- _this.spinning = true
- subareaSaveSubareaArea(formData).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- _this.$emit('ok')
- _this.isShow = false
- _this.spinning = false
- } else {
- _this.spinning = false
- }
- })
- } else {
- return false
- }
- })
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.$emit('close')
- this.$refs.ruleForm.resetFields()
- this.form.subareaAreaName = ''
- } else {
- if (this.parentData.subareaAreaSn) {
- this.form.subareaAreaName = this.parentData.subareaAreaName
- }
- }
- }
- }
- }
- </script>
- <style lang="less">
- .marketingDivisionSetEdit-modal{
- .ant-modal-body {
- padding: 40px 40px 24px;
- }
- .btn-cont {
- text-align: center;
- margin: 35px 0 10px;
- }
- .tree-node{
- height: 300px;
- overflow: auto;
- .tree-box{
- .tree-parent{
- display: flex;
- align-items: center;
- border-bottom: 1px solid #eee;
- padding: 0 10px;
- > span{
- margin:0 5px;
- &:first-child{
- flex-grow: 1;
- }
- &:last-child{
- cursor: pointer;
- }
- }
- }
- .tree-child{
- padding: 10px 10px 10px 35px;
- display: flex;
- align-items: center;
- flex-wrap:wrap ;
- > div{
- margin:0 5px;
- }
- }
- }
- }
- }
- </style>
|