childModal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div>
  3. <a-modal class="modalBox" :title="titleText" v-model="isshow" @cancle="cancel" :centered="true">
  4. <a-form :form="form" @submit="handleSubmit">
  5. <!-- 上级菜单 -->
  6. <a-form-item label="上级菜单" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  7. <div >
  8. <span >{{ parentTitle }}</span>
  9. </div>
  10. </a-form-item>
  11. <!-- 类型 -->
  12. <a-form-item label="类型" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  13. <a-select
  14. id="childModal-type"
  15. allowClear
  16. @change="selectChange"
  17. :disabled="disabled"
  18. v-decorator="[
  19. 'formData.type',
  20. {
  21. initialValue: formData.type,
  22. rules: [{ required: true, message: '请选择状态!' }] },
  23. ]"
  24. style="width: 100%"
  25. placeholder="请选择菜单类型"
  26. >
  27. <a-select-option :value="0">页面类型</a-select-option>
  28. <a-select-option :value="1">按钮类型</a-select-option>
  29. </a-select>
  30. </a-form-item>
  31. <!-- 名称 -->
  32. <a-form-item label="名称" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  33. <a-input
  34. placeholder="请输入名称(最多30个字符)"
  35. :maxLength="30"
  36. id="childModal-name"
  37. allowClear
  38. v-decorator="['formData.name', {
  39. initialValue: formData.name,getValueFromEvent: $filterEmpty,
  40. rules: [{ required: true, message: '请输入名称(最多30个字符)!' },{pattern:'^[^<|>]{1,30}$',message:'请输入不含<或>的字符,最多30个字符'}] }]"
  41. />
  42. </a-form-item>
  43. <!-- 路由英文名 -->
  44. <!-- <a-form-item v-if="!formData.type" label="路由英文名" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  45. <a-input
  46. placeholder="请输入路由英文名"
  47. v-decorator="['formData.routeName', {
  48. initialValue: formData.routeName,
  49. rules: [{ required: true, message: '请输入路由英文名!' }] }]"
  50. />
  51. </a-form-item> -->
  52. <!-- 路径 -->
  53. <!-- <a-form-item v-if="!formData.type" label="路径" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  54. <a-input placeholder="请输入路径"
  55. v-decorator="['formData.routePath', {
  56. initialValue: formData.routePath,
  57. rules: [{ required: true, message: '请输入路径!' }] }]"
  58. />
  59. </a-form-item> -->
  60. <!-- 请求路径 -->
  61. <!-- <a-form-item v-if="formData.type==1" label="请求路径" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  62. <a-input placeholder="请输入请求路径"
  63. v-decorator="['formData.urlPath', {
  64. initialValue: formData.urlPath,
  65. rules: [{ required: true, message: '请输入请求路径!' }] }]"
  66. />
  67. </a-form-item> -->
  68. <!-- 前端权限编码 -->
  69. <a-form-item label="前端权限编码" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  70. <a-input
  71. placeholder="请输入前端权限编码"
  72. allowClear
  73. id="childModal-code"
  74. v-decorator="[
  75. 'formData.code',
  76. {
  77. initialValue: formData.code,getValueFromEvent: $filterEmpty,
  78. rules: [{ required: true, message: '请输入前端权限编码!' }] },
  79. ]"
  80. />
  81. </a-form-item>
  82. <!-- 后台权限编码 -->
  83. <a-form-item label="后台权限编码" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  84. <a-input
  85. placeholder="请输入后台权限编码"
  86. allowClear
  87. id="childModal-permission"
  88. v-decorator="[
  89. 'formData.permission',
  90. {initialValue: formData.permission,getValueFromEvent: $filterEmpty,},
  91. ]"
  92. />
  93. </a-form-item>
  94. <!-- 图标 -->
  95. <!-- <a-form-item v-if="!formData.type" label="图标" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  96. <a-input
  97. placeholder="请输入图标名称"
  98. v-decorator="['formData.icon', {
  99. initialValue: formData.icon,
  100. rules: [] }]"
  101. />
  102. </a-form-item> -->
  103. <!-- 前端组件 -->
  104. <!-- <a-form-item v-if="!formData.type" label="前端组件" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  105. <a-input
  106. placeholder="请输入前端组件路径"
  107. v-decorator="['formData.componentPath', {
  108. initialValue: formData.componentPath,
  109. rules: [{ required: true, message: '请输入前端组件路径!' }] }]"
  110. />
  111. </a-form-item> -->
  112. <!-- 第三方链接 -->
  113. <!-- <a-form-item v-if="!formData.type" label="第三方链接" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  114. <a-input
  115. placeholder="请输入第三方链接地址"
  116. v-decorator="['formData.urlPath', {
  117. initialValue: formData.urlPath,
  118. rules: [] }]"
  119. />
  120. </a-form-item> -->
  121. <!-- 排序值 -->
  122. <a-form-item label="排序值" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  123. <a-input
  124. type="number"
  125. placeholder="请输入排序值"
  126. allowClear
  127. id="childModal-sort"
  128. v-decorator="['formData.sort', {
  129. initialValue: formData.sort,getValueFromEvent: $filterEmpty,
  130. rules: [] }]"
  131. />
  132. </a-form-item>
  133. <!-- 连锁可用 -->
  134. <!-- <a-form-item v-if="parentType=='store'" label="连锁可用" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  135. <a-radio-group
  136. name="radioGroup"
  137. v-decorator="[
  138. 'formData.chainOrgUse',
  139. {
  140. initialValue: formData.chainOrgUse,
  141. rules: [{ required: true, message: '请选择!' }] },
  142. ]"
  143. >
  144. <a-radio :value="1">是</a-radio>
  145. <a-radio :value="0">否</a-radio>
  146. </a-radio-group>
  147. </a-form-item> -->
  148. <!-- 单店可用 -->
  149. <!-- <a-form-item v-if="parentType=='store'" label="单店可用" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  150. <a-radio-group
  151. name="radioGroup"
  152. v-decorator="[
  153. 'formData.singleOrgUse',
  154. {
  155. initialValue: formData.singleOrgUse,
  156. rules: [{ required: true, message: '请选择!' }] },
  157. ]"
  158. >
  159. <a-radio :value="1">是</a-radio>
  160. <a-radio :value="0">否</a-radio>
  161. </a-radio-group>
  162. </a-form-item> -->
  163. <!-- 状态 -->
  164. <a-form-item label="启用" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  165. <a-radio-group
  166. name="radioGroup"
  167. id="childModal-status"
  168. v-decorator="[
  169. 'formData.status',
  170. {
  171. initialValue: formData.status,
  172. rules: [{ required: true, message: '请选择状态!' }] },
  173. ]"
  174. >
  175. <a-radio :value="1">是</a-radio>
  176. <a-radio :value="0">否</a-radio>
  177. </a-radio-group>
  178. </a-form-item>
  179. <a-form-item :wrapper-col="{ span: 12, offset: 6 }">
  180. <a-button type="primary" @click="handleSubmit()" id="childModal-handleSubmit">
  181. 保存
  182. </a-button>
  183. <a-button :style="{ marginLeft: '8px' }" @click="handleCancel()" id="childModal-handleCancel">
  184. 取消
  185. </a-button>
  186. </a-form-item>
  187. </a-form>
  188. </a-modal>
  189. </div>
  190. </template>
  191. <script>
  192. import { STable, VSelect } from '@/components'
  193. import { saveYyMenu, saveMdMenu } from '@/api/menu.js'
  194. export default {
  195. name: 'ChildModal',
  196. components: {
  197. STable, VSelect
  198. },
  199. props: {
  200. visible: {
  201. type: Boolean,
  202. default: false
  203. },
  204. parentType: {
  205. type: String,
  206. default: ''
  207. },
  208. data: {
  209. type: Object,
  210. default: function () {
  211. return {}
  212. }
  213. }
  214. },
  215. data () {
  216. return {
  217. isshow: this.visible,
  218. titleText: '',
  219. disabled: false,
  220. parentTitle: '',
  221. formLayout: 'horizontal',
  222. form: this.$form.createForm(this, { name: 'childModal' }),
  223. formData: {
  224. parentId: '',
  225. name: '',
  226. routePath: '',
  227. icon: '',
  228. routeName: '',
  229. code: '',
  230. permission: '',
  231. componentPath: '',
  232. urlPath: '',
  233. sort: '',
  234. type: undefined,
  235. // chainOrgUse: 1,
  236. // singleOrgUse: 1,
  237. status: 1 // 活动状态
  238. }
  239. }
  240. },
  241. methods: {
  242. cancel (e) {
  243. this.clear()
  244. this.$emit('close')
  245. },
  246. selectChange (val) {
  247. this.formData.type = val
  248. console.log(val)
  249. },
  250. // 保存提交
  251. handleSubmit () {
  252. const _this = this
  253. this.form.validateFields((err, values) => {
  254. if (!err) {
  255. console.log(values.formData, ' formData.type222222222')
  256. const saveRequest = this.parentType == 'store' ? saveMdMenu : saveYyMenu
  257. saveRequest(Object.assign(this.formData, values.formData)).then(res => {
  258. console.log(res, 'res--save')
  259. if (res.status + '' === '200') {
  260. this.$message.success(res.message ? res.message : '保存成功')
  261. this.$emit('refresh')
  262. setTimeout(function () {
  263. _this.cancel()
  264. }, 300)
  265. } else {
  266. // this.$message.warning(res.message)
  267. }
  268. })
  269. }
  270. })
  271. },
  272. // 取消
  273. handleCancel () {
  274. this.cancel()
  275. },
  276. clear () {
  277. this.form.resetFields()
  278. this.parentTitle = ''
  279. this.formData.parentId = ''
  280. this.formData.name = ''
  281. this.formData.routePath = ''
  282. this.formData.icon = ''
  283. this.formData.routeName = ''
  284. this.formData.componentPath = ''
  285. this.formData.urlPath = ''
  286. this.formData.sort = ''
  287. this.formData.type = ''
  288. this.formData.status = 1
  289. // this.formData.chainOrgUse = 1
  290. // this.formData.singleOrgUse = 1
  291. this.formData.code = ''
  292. this.formData.permission = ''
  293. }
  294. },
  295. mounted () {
  296. },
  297. beforeCreate () {
  298. this.form = this.$form.createForm(this, { name: 'childModal' })
  299. },
  300. watch: {
  301. visible (newValue, oldValue) {
  302. this.isshow = newValue
  303. },
  304. isshow (newValue, oldValue) {
  305. if (newValue) {
  306. if (this.data.id) { // 添加子菜单
  307. this.titleText = '新增子菜单'
  308. this.disabled = false
  309. console.log(this.data, 'this.data')
  310. this.formData.parentId = this.data.id
  311. this.parentTitle = this.data.name
  312. } else { // 添加顶菜单
  313. this.titleText = '新增顶菜单'
  314. this.formData.type = 0
  315. this.disabled = true
  316. }
  317. } else {
  318. this.cancel()
  319. }
  320. }
  321. }
  322. }
  323. </script>
  324. <style >
  325. .modalBox{
  326. }
  327. .ant-modal-footer {
  328. display: none;
  329. }
  330. </style>