爱简收旧衣按件回收后端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
4.6 KiB

9 months ago
  1. <template>
  2. <j-modal
  3. :title="title"
  4. :width="width"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. switchFullscreen
  8. @ok="handleOk"
  9. @cancel="handleCancel"
  10. cancelText="关闭">
  11. <a-spin :spinning="confirmLoading">
  12. <a-form-model ref="form" :model="model" :rules="validatorRules">
  13. <a-form-model-item label="父级节点" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pid">
  14. <j-tree-select
  15. ref="treeSelect"
  16. placeholder="请选择父级节点"
  17. v-model="model.pid"
  18. dict="common_city,name,open,sort,id"
  19. pidField="pid"
  20. pidValue="0"
  21. hasChildField="has_child"
  22. >
  23. </j-tree-select>
  24. </a-form-model-item>
  25. <a-form-model-item label="城市名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
  26. <a-input v-model="model.name" placeholder="请输入城市名称" ></a-input>
  27. </a-form-model-item>
  28. <a-form-model-item label="排序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sort">
  29. <a-input v-model="model.sort" placeholder="请输入排序" ></a-input>
  30. </a-form-model-item>
  31. <a-form-model-item label="开通情况" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="open">
  32. <j-switch v-model="model.open" ></j-switch>
  33. </a-form-model-item>
  34. </a-form-model>
  35. </a-spin>
  36. </j-modal>
  37. </template>
  38. <script>
  39. import { httpAction } from '@/api/manage'
  40. import { validateDuplicateValue } from '@/utils/util'
  41. export default {
  42. name: "CommonCityModal",
  43. components: {
  44. },
  45. data () {
  46. return {
  47. title:"操作",
  48. width:800,
  49. visible: false,
  50. model:{
  51. },
  52. labelCol: {
  53. xs: { span: 24 },
  54. sm: { span: 5 },
  55. },
  56. wrapperCol: {
  57. xs: { span: 24 },
  58. sm: { span: 16 },
  59. },
  60. confirmLoading: false,
  61. validatorRules: {
  62. },
  63. url: {
  64. add: "/commonCity/commonCity/add",
  65. edit: "/commonCity/commonCity/edit",
  66. },
  67. expandedRowKeys:[],
  68. pidField:"pid"
  69. }
  70. },
  71. created () {
  72. //备份model原始值
  73. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  74. },
  75. methods: {
  76. add (obj) {
  77. this.modelDefault.pid=''
  78. this.edit(Object.assign(this.modelDefault , obj));
  79. },
  80. edit (record) {
  81. this.model = Object.assign({}, record);
  82. this.visible = true;
  83. },
  84. close () {
  85. this.$emit('close');
  86. this.visible = false;
  87. this.$refs.form.clearValidate()
  88. },
  89. handleOk () {
  90. const that = this;
  91. // 触发表单验证
  92. this.$refs.form.validate(valid => {
  93. if (valid) {
  94. that.confirmLoading = true;
  95. let httpurl = '';
  96. let method = '';
  97. if(!this.model.id){
  98. httpurl+=this.url.add;
  99. method = 'post';
  100. }else{
  101. httpurl+=this.url.edit;
  102. method = 'put';
  103. }
  104. if(this.model.id && this.model.id === this.model[this.pidField]){
  105. that.$message.warning("父级节点不能选择自己");
  106. that.confirmLoading = false;
  107. return;
  108. }
  109. httpAction(httpurl,this.model,method).then((res)=>{
  110. if(res.success){
  111. that.$message.success(res.message);
  112. this.$emit('ok');
  113. }else{
  114. that.$message.warning(res.message);
  115. }
  116. }).finally(() => {
  117. that.confirmLoading = false;
  118. that.close();
  119. })
  120. }else{
  121. return false
  122. }
  123. })
  124. },
  125. handleCancel () {
  126. this.close()
  127. },
  128. submitSuccess(formData,flag){
  129. if(!formData.id){
  130. let treeData = this.$refs.treeSelect.getCurrTreeData()
  131. this.expandedRowKeys=[]
  132. this.getExpandKeysByPid(formData[this.pidField],treeData,treeData)
  133. this.$emit('ok',formData,this.expandedRowKeys.reverse());
  134. }else{
  135. this.$emit('ok',formData,flag);
  136. }
  137. },
  138. getExpandKeysByPid(pid,arr,all){
  139. if(pid && arr && arr.length>0){
  140. for(let i=0;i<arr.length;i++){
  141. if(arr[i].key==pid){
  142. this.expandedRowKeys.push(arr[i].key)
  143. this.getExpandKeysByPid(arr[i]['parentId'],all,all)
  144. }else{
  145. this.getExpandKeysByPid(pid,arr[i].children,all)
  146. }
  147. }
  148. }
  149. }
  150. }
  151. }
  152. </script>