123 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			123 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/*
 | 
						||
 * @Author: zwq
 | 
						||
 * @Date: 2022-08-24 11:19:43
 | 
						||
 * @LastEditors: zwq
 | 
						||
 * @LastEditTime: 2024-04-09 16:56:16
 | 
						||
 * @Description:
 | 
						||
 */
 | 
						||
import { listData } from "@/api/system/dict/data"; //数据字典接口
 | 
						||
export default {
 | 
						||
  data() {
 | 
						||
    /* eslint-disable */
 | 
						||
    return {
 | 
						||
      urlOptions: {
 | 
						||
        createURL: '', //新增接口
 | 
						||
        updateURL: '', //编辑提交接口
 | 
						||
        infoURL: '', //编辑时获取单条数据接口
 | 
						||
        codeURL: null, //获取code接口(返回结果为dataForm.code字段)
 | 
						||
        optionArrUrl: [], //需要获取下拉框的方法数组
 | 
						||
        optionArr: {}, //需要获取下拉框的方法数组的返回结果
 | 
						||
        dictNameList: [], //数据字典name数组
 | 
						||
        dictArr: {}, //需要获取数据字典的方法数组的返回结果
 | 
						||
      },
 | 
						||
      visible: false,
 | 
						||
      setData: false, // 是否需要【编辑时获取单条数据接口】返回的数据操作
 | 
						||
    }
 | 
						||
  },
 | 
						||
  created() {
 | 
						||
  },
 | 
						||
  activated() {
 | 
						||
  },
 | 
						||
  methods: {
 | 
						||
    init(id) {
 | 
						||
      this.dataForm.id = id || "";
 | 
						||
      this.visible = true;
 | 
						||
      if (this.urlOptions.optionArrUrl.length > 0) {
 | 
						||
        this.getArr()
 | 
						||
      }
 | 
						||
      if (this.urlOptions.dictNameList.length > 0) {
 | 
						||
        this.getDict()
 | 
						||
      }
 | 
						||
      this.$nextTick(() => {
 | 
						||
        this.$refs["dataForm"].resetFields();
 | 
						||
        if (this.dataForm.id) {
 | 
						||
          this.urlOptions.infoURL(id).then(response => {
 | 
						||
            this.dataForm = response.data;
 | 
						||
            if (this.setData) {
 | 
						||
              this.setDataForm()
 | 
						||
            }
 | 
						||
          });
 | 
						||
        } else {
 | 
						||
          if (this.urlOptions.codeURL) {
 | 
						||
            this.getCode()
 | 
						||
          }
 | 
						||
				}
 | 
						||
      });
 | 
						||
    },
 | 
						||
    /** 获取code */
 | 
						||
		getCode() {
 | 
						||
			this.urlOptions.codeURL()
 | 
						||
				.then(({ data: res }) => {
 | 
						||
					this.dataForm.code = res;
 | 
						||
				})
 | 
						||
				.catch(() => {});
 | 
						||
		},
 | 
						||
    /** 获取下拉框数组 */
 | 
						||
    getArr() {
 | 
						||
      const params = {
 | 
						||
        pageSize: 100,
 | 
						||
        pageNo: 1,
 | 
						||
      }
 | 
						||
      this.urlOptions.optionArrUrl.forEach((item, index) => {
 | 
						||
        item(params).then(({ data: res }) => {
 | 
						||
          this.$set(this.urlOptions.optionArr, `arr${index}`, res.list)
 | 
						||
        })
 | 
						||
          .catch(() => {
 | 
						||
          });
 | 
						||
      });
 | 
						||
    },
 | 
						||
    /** 查询字典数据列表 */
 | 
						||
    getDict() {
 | 
						||
      this.urlOptions.dictNameList.forEach((item,index)=>{
 | 
						||
        const queryParams = {
 | 
						||
          pageNo: 1,
 | 
						||
          pageSize: 99,
 | 
						||
          dictType: item,
 | 
						||
        }
 | 
						||
        listData(queryParams).then(response => {
 | 
						||
          this.$set(this.urlOptions.dictArr, `dict${index}`, response.data.list)
 | 
						||
        });
 | 
						||
      })
 | 
						||
    },
 | 
						||
    // 表单提交
 | 
						||
    dataFormSubmit() {
 | 
						||
      this.$refs["dataForm"].validate((valid) => {
 | 
						||
        if (!valid) {
 | 
						||
          return false;
 | 
						||
        }
 | 
						||
        // 修改的提交
 | 
						||
        if (this.dataForm.id) {
 | 
						||
          this.urlOptions.updateURL(this.dataForm).then(response => {
 | 
						||
            this.$modal.msgSuccess("修改成功");
 | 
						||
            this.visible = false;
 | 
						||
            this.$emit("refreshDataList");
 | 
						||
          });
 | 
						||
          return;
 | 
						||
        }
 | 
						||
        // 添加的提交
 | 
						||
        this.urlOptions.createURL(this.dataForm).then(response => {
 | 
						||
          this.$modal.msgSuccess("新增成功");
 | 
						||
          this.visible = false;
 | 
						||
          this.$emit("refreshDataList");
 | 
						||
        });
 | 
						||
      });
 | 
						||
    },
 | 
						||
    /** 清空form */
 | 
						||
    formClear() {
 | 
						||
      if (this.$refs.dataForm!==undefined) {
 | 
						||
          this.$refs.dataForm.resetFields();
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
}
 |