compartmentDialog.js 3.35 KB
Newer Older
刘弈臻's avatar
刘弈臻 committed
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
const COMPARTMENT = '添加子级行政区划'

var compartmentDialog = {
  data: function () {
    return {
      form: {
        parentId: '',
        parentName: '',
        id: '',
        name: '',
        comLevel: '',
        code: '',
        sort: ''
      },
      props: [
        {
          label: '上级菜单',
          prop: 'parentName',
          defaultProp: 'parentId',
          inputType: 'inputTree',
          defaultProps: {
            children: 'children',
            label: 'name'
          }
        },
        {
          label: '区划名称',
          prop: 'name',
          inputType: 'input'
        },
        {
          label: '区划代码',
          prop: 'code',
          inputType: 'input'
        },
        {
          label: '区划级别',
          prop: 'comLevel',
          inputType: 'select'
        },
        {
          label: '排序',
          prop: 'sort',
          inputType: 'input'
        }
      ],
      rules: {
        name: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ],
        comLevel: [
          { required: true, message: '不能为空', trigger: 'change' }
        ],
        sort: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created: function () {
    this.init()
  },
  methods: {
    init: function () {
      this.getComLevel()
      this.getParentName()
    },
    getParentName: function () {
      let self = this
      api({
        url: '/sys/compartment/list',
        type: 'get',
        successFuc: function (res) {
          if (res.code === CONFIG.SUCCESS) {
            self.setOptions('parentName', self.props, res.data)
          }
        }
      })
    },
    // 类型
    getComLevel: function (data = {}) {
      var self = this
      api({
        url: '/sys/compartment/comLevel',
        type: 'get',
        successFuc: function (res) {
          if (res.code === CONFIG.SUCCESS) {
            self.setOptions('comLevel', self.props, res.data)
          }
        }
      })
    },
    // Dialog 打开的回调
    openDialogHandle: function () {
      var self = this
      this.$nextTick(function () {
        if (self.title1 === COMPARTMENT) {
          self.$set(self.props[0], 'reference', false)
        }
        if (self.title1 === CONFIG.EDIT || self.title1 === CONFIG.ADD || self.title1 === COMPARTMENT) {
          self.clearValidate('compartmentForm')
        }
        if (self.title1 === CONFIG.EDIT) {
          self.validate('compartmentForm')
        }
      })
    },
    // Dialog 关闭的回调
    closeDialogHandle: function () {
      if (this.title1 === CONFIG.EDIT || this.title1 === CONFIG.ADD) {
        this.clearForm('compartmentForm')
      }
      if (this.title1 === COMPARTMENT) {
        this.props[0].reference = true
      }
    },
    // 确定
    confirmHandle: function () {
      this.$refs.compartmentForm.submitHandle()
      this.close('compartmentDialog')
    },
    submitHandle: function (data) {
      this.close('compartmentDialog')
    },
    // 取消
    cancelHandle: function () {
      this.close('compartmentDialog')
    }

  }
}