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.
		
		
		
		
		
			
		
			
				
					
					
						
							195 lines
						
					
					
						
							5.5 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							195 lines
						
					
					
						
							5.5 KiB
						
					
					
				
								import { $wuxActionSheet } from '../../../../dist/index'
							 | 
						|
								import { createAssociation } from '../../utils/api'
							 | 
						|
								const config = require('../../../../utils/config')
							 | 
						|
								
							 | 
						|
								Page({
							 | 
						|
								  data: {
							 | 
						|
								    name: '创建社群',
							 | 
						|
								    associationInfo: {
							 | 
						|
								      avatar: '../../images/ic_tianjiatouxiang@2x.png',
							 | 
						|
								      name: '',
							 | 
						|
								      introduce: ''
							 | 
						|
								    },
							 | 
						|
								    dialogVisible: false,
							 | 
						|
								    userInfo: {
							 | 
						|
								      nickname: '',
							 | 
						|
								      partyFlag: ''
							 | 
						|
								    }
							 | 
						|
								  },
							 | 
						|
								  onShow () {
							 | 
						|
								    
							 | 
						|
								  },
							 | 
						|
								  onLoad (options) {
							 | 
						|
								    const { nickname, partyFlag } = options
							 | 
						|
								    this.setData({
							 | 
						|
								      userInfo: Object.assign(this.data.userInfo, { nickname, partyFlag })
							 | 
						|
								    })
							 | 
						|
								  },
							 | 
						|
								  // 创建社群
							 | 
						|
								  createAssociation () {
							 | 
						|
								    if (this.data.associationInfo['avatar'] === '../../images/ic_tianjiatouxiang@2x.png') {
							 | 
						|
								      wx.showToast({
							 | 
						|
								        title: '请上传群头像',
							 | 
						|
								        icon: 'none',
							 | 
						|
								        duration: 1000
							 | 
						|
								      })
							 | 
						|
								      return false
							 | 
						|
								    } else if (this.data.associationInfo['name'] === '') {
							 | 
						|
								      wx.showToast({
							 | 
						|
								        title: '请输入群名称',
							 | 
						|
								        icon: 'none',
							 | 
						|
								        duration: 1000
							 | 
						|
								      })
							 | 
						|
								      return false
							 | 
						|
								    } else if (this.data.associationInfo['introduce'] === '') {
							 | 
						|
								      wx.showToast({
							 | 
						|
								        title: '请输入群介绍',
							 | 
						|
								        icon: 'none',
							 | 
						|
								        duration: 1000
							 | 
						|
								      })
							 | 
						|
								      return false
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    const para = {
							 | 
						|
								      groupName: this.data.associationInfo['name'],
							 | 
						|
								      groupAvatar: this.data.associationInfo['avatar'],
							 | 
						|
								      groupIntroduction: this.data.associationInfo['introduce']
							 | 
						|
								    }
							 | 
						|
								    wx.showLoading({
							 | 
						|
								      title: '加载中',
							 | 
						|
								    })
							 | 
						|
								    createAssociation(para).then(res => {
							 | 
						|
								      wx.hideLoading()
							 | 
						|
								      this.setData({
							 | 
						|
								        dialogVisible: !this.data.dialogVisible
							 | 
						|
								      })
							 | 
						|
								    }).catch(err => {
							 | 
						|
								      console.log(err)
							 | 
						|
								    })
							 | 
						|
								  },
							 | 
						|
								  // input框双向绑定
							 | 
						|
								  oberseInput (e) {
							 | 
						|
								    this.data.associationInfo = Object.assign(this.data.associationInfo, { name: e.detail.value})
							 | 
						|
								    this.setData({
							 | 
						|
								      associationInfo: this.data.associationInfo
							 | 
						|
								    })
							 | 
						|
								  },
							 | 
						|
								  // textarea双向绑定
							 | 
						|
								  oberseTextarea (e) {
							 | 
						|
								    this.data.associationInfo = Object.assign(this.data.associationInfo, { introduce: e.detail.value})
							 | 
						|
								    this.setData({
							 | 
						|
								      associationInfo: this.data.associationInfo
							 | 
						|
								    })
							 | 
						|
								  },
							 | 
						|
								  // 选择图片
							 | 
						|
								  chooseImage () {
							 | 
						|
								    const that = this
							 | 
						|
								    $wuxActionSheet().showSheet({
							 | 
						|
								      buttons: [{
							 | 
						|
								          text: '拍照'
							 | 
						|
								        },
							 | 
						|
								        {
							 | 
						|
								          text: '从相册中获取'
							 | 
						|
								        },
							 | 
						|
								      ],
							 | 
						|
								      className: 'dialog-class',
							 | 
						|
								      buttonClicked(index, item) {
							 | 
						|
								        if (index === 0) {
							 | 
						|
								          wx.chooseImage({
							 | 
						|
								            count: 1,
							 | 
						|
								            sizeType: ['original', 'compressed'],
							 | 
						|
								            sourceType: ['camera'],
							 | 
						|
								            success (res) {
							 | 
						|
								              wx.uploadFile({
							 | 
						|
								                url: config.BASEURL() + 'group/topic/upload',
							 | 
						|
								                filePath: res.tempFilePaths[0],
							 | 
						|
								                name: 'file',
							 | 
						|
								                header: {
							 | 
						|
								                  'Content-Type': 'multipart/form-data'
							 | 
						|
								                },
							 | 
						|
								                success (fileres) {
							 | 
						|
								                  const data = JSON.parse(fileres.data)
							 | 
						|
								                  if (data.code === 0 && data.msg === 'success') {
							 | 
						|
								                    that.data.associationInfo = Object.assign(that.data.associationInfo, { avatar: data.data})
							 | 
						|
								                    that.setData({
							 | 
						|
								                      associationInfo: that.data.associationInfo
							 | 
						|
								                    })
							 | 
						|
								                  } else {
							 | 
						|
								                    wx.showToast({
							 | 
						|
								                      title: '上传图片失败,请重试'
							 | 
						|
								                    })
							 | 
						|
								                  }
							 | 
						|
								                },
							 | 
						|
								                fail (err) {
							 | 
						|
								                   console.log(err)
							 | 
						|
								                   imageList.pop()
							 | 
						|
								                   wx.showToast({
							 | 
						|
								                     title: '上传图片失败,请重试'
							 | 
						|
								                   })
							 | 
						|
								                   that.setData({
							 | 
						|
								                    imageList
							 | 
						|
								                  })
							 | 
						|
								                }
							 | 
						|
								              })
							 | 
						|
								            }
							 | 
						|
								          })
							 | 
						|
								        } else if (index === 1) {
							 | 
						|
								          wx.chooseImage({
							 | 
						|
								            count: 1,
							 | 
						|
								            sizeType: ['original', 'compressed'],
							 | 
						|
								            sourceType: ['album'],
							 | 
						|
								            success (res) {
							 | 
						|
								              wx.uploadFile({
							 | 
						|
								                url: config.BASEURL() + 'group/topic/upload',
							 | 
						|
								                filePath: res.tempFilePaths[0],
							 | 
						|
								                name: 'file',
							 | 
						|
								                header: {
							 | 
						|
								                  'Content-Type': 'multipart/form-data'
							 | 
						|
								                },
							 | 
						|
								                success (fileres) {
							 | 
						|
								                  const data = JSON.parse(fileres.data)
							 | 
						|
								                  if (data.code === 0 && data.msg === 'success') {
							 | 
						|
								                    that.data.associationInfo = Object.assign(that.data.associationInfo, { avatar: data.data})
							 | 
						|
								                    that.setData({
							 | 
						|
								                      associationInfo: that.data.associationInfo
							 | 
						|
								                    })
							 | 
						|
								                  } else {
							 | 
						|
								                    wx.showToast({
							 | 
						|
								                      title: '上传图片失败,请重试'
							 | 
						|
								                    })
							 | 
						|
								                  }
							 | 
						|
								                },
							 | 
						|
								                fail (err) {
							 | 
						|
								                   console.log(err)
							 | 
						|
								                   imageList.pop()
							 | 
						|
								                   wx.showToast({
							 | 
						|
								                     title: '上传图片失败,请重试'
							 | 
						|
								                   })
							 | 
						|
								                   that.setData({
							 | 
						|
								                    imageList
							 | 
						|
								                  })
							 | 
						|
								                }
							 | 
						|
								              })
							 | 
						|
								            }
							 | 
						|
								          })
							 | 
						|
								        }
							 | 
						|
								        return true
							 | 
						|
								      },
							 | 
						|
								      cancelText: '取消',
							 | 
						|
								      cancel() {},
							 | 
						|
								      destructiveButtonClicked() {},
							 | 
						|
								    })
							 | 
						|
								  },
							 | 
						|
								  // 关闭弹框
							 | 
						|
								  closeDialog () {
							 | 
						|
								    wx.navigateTo({
							 | 
						|
								      url: '/pages/association/association'
							 | 
						|
								    })
							 | 
						|
								  },
							 | 
						|
								  // 弹框确定按钮
							 | 
						|
								  confirmDialog () {
							 | 
						|
								    wx.navigateTo({
							 | 
						|
								      url: '/pages/association/association'
							 | 
						|
								    })
							 | 
						|
								  }
							 | 
						|
								})
							 |