AaCommodityFlModal.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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="pic">
  14. <j-image-upload isMultiple v-model="model.pic" ></j-image-upload>
  15. </a-form-model-item>
  16. <a-form-model-item label="分类名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
  17. <a-input v-model="model.name" placeholder="请输入分类名称" ></a-input>
  18. </a-form-model-item>
  19. <a-form-model-item label="分类名称-英语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
  20. <a-input v-model="model.nameEnglish" placeholder="请输入分类名称" ></a-input>
  21. </a-form-model-item>
  22. <!-- <a-form-model-item label="分类名称-德语" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
  23. <a-input v-model="model.nameGerman" placeholder="请输入分类名称" ></a-input>
  24. </a-form-model-item>-->
  25. <a-form-model-item label="顶部背景资源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="assets">
  26. <j-upload v-model="model.assets" :reNewFile="true" :multiple="false" :beforeUpload="this.beforeUploadHandler" ></j-upload>
  27. <template slot="extra">
  28. <span>推荐比例16:9</span>
  29. </template>
  30. </a-form-model-item>
  31. </a-form-model>
  32. </a-spin>
  33. </j-modal>
  34. </template>
  35. <script>
  36. import { httpAction } from '@/api/manage'
  37. import { validateDuplicateValue } from '@/utils/util'
  38. export default {
  39. name: "AaCommodityFlModal",
  40. components: {
  41. },
  42. data () {
  43. return {
  44. title:"操作",
  45. width:800,
  46. visible: false,
  47. model:{
  48. },
  49. labelCol: {
  50. xs: { span: 24 },
  51. sm: { span: 5 },
  52. },
  53. wrapperCol: {
  54. xs: { span: 24 },
  55. sm: { span: 16 },
  56. },
  57. confirmLoading: false,
  58. validatorRules: {
  59. },
  60. url: {
  61. add: "/aa/aaCommodityFl/add",
  62. edit: "/aa/aaCommodityFl/edit",
  63. },
  64. expandedRowKeys:[],
  65. pidField:""
  66. }
  67. },
  68. created () {
  69. //备份model原始值
  70. this.modelDefault = JSON.parse(JSON.stringify(this.model));
  71. },
  72. methods: {
  73. add (obj) {
  74. this.modelDefault=''
  75. this.edit(Object.assign(this.modelDefault , obj));
  76. },
  77. edit (record) {
  78. this.model = Object.assign({}, record);
  79. this.visible = true;
  80. },
  81. close () {
  82. this.$emit('close');
  83. this.visible = false;
  84. this.$refs.form.clearValidate()
  85. },
  86. handleOk () {
  87. const that = this;
  88. // 触发表单验证
  89. this.$refs.form.validate(valid => {
  90. if (valid) {
  91. that.confirmLoading = true;
  92. let httpurl = '';
  93. let method = '';
  94. if(!this.model.id){
  95. httpurl+=this.url.add;
  96. method = 'post';
  97. }else{
  98. httpurl+=this.url.edit;
  99. method = 'put';
  100. }
  101. if(this.model.id && this.model.id === this.model[this.pidField]){
  102. that.$message.warning("父级节点不能选择自己");
  103. that.confirmLoading = false;
  104. return;
  105. }
  106. httpAction(httpurl,this.model,method).then((res)=>{
  107. if(res.success){
  108. that.$message.success(res.message);
  109. this.$emit('ok');
  110. }else{
  111. that.$message.warning(res.message);
  112. }
  113. }).finally(() => {
  114. that.confirmLoading = false;
  115. that.close();
  116. })
  117. }else{
  118. return false
  119. }
  120. })
  121. },
  122. handleCancel () {
  123. this.close()
  124. },
  125. submitSuccess(formData,flag){
  126. if(!formData.id){
  127. let treeData = this.$refs.treeSelect.getCurrTreeData()
  128. this.expandedRowKeys=[]
  129. this.getExpandKeysByPid(formData[this.pidField],treeData,treeData)
  130. this.$emit('ok',formData,this.expandedRowKeys.reverse());
  131. }else{
  132. this.$emit('ok',formData,flag);
  133. }
  134. },
  135. getExpandKeysByPid(pid,arr,all){
  136. if(pid && arr && arr.length>0){
  137. for(let i=0;i<arr.length;i++){
  138. if(arr[i].key==pid){
  139. this.expandedRowKeys.push(arr[i].key)
  140. this.getExpandKeysByPid(arr[i]['parentId'],all,all)
  141. }else{
  142. this.getExpandKeysByPid(pid,arr[i].children,all)
  143. }
  144. }
  145. }
  146. },
  147. beforeUploadHandler(file) {
  148. let fileType = file.type;
  149. if(fileType.indexOf('image')<0 && fileType.indexOf('video')<0){
  150. this.$message.warning('请上传图片或视频');
  151. return false;
  152. }
  153. return true;
  154. },
  155. }
  156. }
  157. </script>