Commit 990b8215 by 赵雅纹

Merge branch 'feature-zyw-sc' into 'dev_7.1.0'

Feature zyw sc

See merge request !88
parents 1b001430 f52d1736
// component/uploadImg/uploadImg.js // component/uploadImg/uploadImg.js
var app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
...@@ -33,21 +37,23 @@ Component({ ...@@ -33,21 +37,23 @@ Component({
chooseImg(){ chooseImg(){
let that = this; let that = this;
let pics = this.data.pics; let pics = this.data.pics;
var url = envInfo.ctx + '/merchant/upload/pic'
wx.chooseImage({ wx.chooseImage({
count: 5 - pics.length, // 最多可以选择的图片5张, count: 5 - pics.length, // 最多可以选择的图片5张,
sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有 sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有 sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
success: function (res) { success: function (res) {
var imgsrc = res.tempFilePaths; var imgsrcs = res.tempFilePaths;
pics = pics.concat(imgsrc); imgsrcs.forEach(src => {
pics.push(src);
});
that.setData({ that.setData({
pics: pics pics: pics
}); });
console.log(that.data.pics) that.moreImgUpload({
// that.moreImgUpload({ url: url,//这里是你图片上传的接口
// url: 'https://........',//这里是你图片上传的接口 path: imgsrcs//这里是选取的图片的地址数组
// path: that.data.pics//这里是选取的图片的地址数组 });
// });
}, },
fail: function () { fail: function () {
// fail // fail
...@@ -67,26 +73,35 @@ Component({ ...@@ -67,26 +73,35 @@ Component({
wx.uploadFile({ wx.uploadFile({
url: data.url, url: data.url,
filePath: data.path[i], filePath: data.path[i],
name: 'file',//这里根据自己的实际情况改 name: 'imgs',//这里根据自己的实际情况改
formData: null,//这里是上传图片时一起上传的数据 formData: null,//这里是上传图片时一起上传的数据
success: (resp) => { header: {
'buyer-token': wx.getStorageSync('token')
},
success: (res) => {
if (res.statusCode == 200) {
var imgdata = JSON.parse(res.data);
var img = imgdata.data[0];
success++;//图片上传成功,图片上传成功的变量+1 success++;//图片上传成功,图片上传成功的变量+1
console.log(resp) // this.data.params.sspList.push({
console.log(i); // cover: 0,
//这里可能有BUG,失败也会执行这里,所以这里应该是后台返回过来的状态码为成功时,这里的success才+1 // url: img.url
// });
// that.setData({
// 'params.sspList': this.data.params.sspList
// })
wxService.nextTick(() => {
that.triggerEvent('_uploadImg', img)
})
}
}, },
fail: (res) => { fail: (res) => {
fail++;//图片上传失败,图片上传失败的变量+1 fail++;//图片上传失败,图片上传失败的变量+1
console.log('fail:' + i + "fail:" + fail);
}, },
complete: () => { complete: () => {
console.log(i);
i++;//这个图片执行完上传后,开始上传下一张 i++;//这个图片执行完上传后,开始上传下一张
if (i == data.path.length) { //当图片传完时,停止调用 if (i == data.path.length) { //当图片传完时,停止调用
console.log('执行完毕');
console.log('成功:' + success + " 失败:" + fail);
} else {//若图片还没有传完,则继续调用函数 } else {//若图片还没有传完,则继续调用函数
console.log(i);
data.i = i; data.i = i;
data.success = success; data.success = success;
data.fail = fail; data.fail = fail;
......
// component/uploadVideo/uploadVideo.js // component/uploadVideo/uploadVideo.js
var app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
*/ */
properties: { properties: {
video:{ // 显示视频
type: String,
value: ''
}
}, },
/** /**
...@@ -21,9 +28,43 @@ Component({ ...@@ -21,9 +28,43 @@ Component({
*/ */
methods: { methods: {
//点击上传图片 //点击上传图片
uploadVideo(){ uploadVideo(src){
console.log('1111') console.log(envInfo)
this.chooseVideo() var url = envInfo.ctx + '/merchant/upload/file'
var that = this
console.log(url)
wx.uploadFile({
url: url,//服务器接口
// method: 'POST',//这句话好像可以不用
filePath: src,
header: {
'content-type': 'multipart/form-data',
'buyer-token': wx.getStorageSync('token')
},
name: 'files',//服务器定义的Key值
success: function (res) {
if (res.statusCode == 200){
var imgdata = JSON.parse(res.data);
var img = imgdata.data[0];
console.log(img)
wxService.nextTick(() => {
that.triggerEvent('_uploadVideo', img)
})
}
},
fail: function () {
}
})
},
// 刪除視頻
deleteImage() {
this.setData({
video: ''
})
wxService.nextTick(() => {
this.triggerEvent('_deleteVideo', true)
})
}, },
//选取图片 //选取图片
...@@ -40,6 +81,7 @@ Component({ ...@@ -40,6 +81,7 @@ Component({
that.setData({ that.setData({
video: video video: video
}) })
that.uploadVideo(that.data.video)
} }
}) })
} }
......
<!--component/uploadVideo/uploadVideo.wxml--> <!--component/uploadVideo/uploadVideo.wxml-->
<view class="page-upload-img"> <view class="page-upload-img">
<view class="video_area" wx:if="{{video}}"> <view class="video_area" wx:if="{{video}}">
<icon size="16" type="clear" catchtap="deleteImage" />
<video class="video_item" src="{{video}}" controls></video> <video class="video_item" src="{{video}}" controls></video>
<!-- 防止视频组件层级太高,导致部分机型覆盖悬浮按钮 --> <!-- 防止视频组件层级太高,导致部分机型覆盖悬浮按钮 -->
<!-- <cover-image <!-- <cover-image
...@@ -11,7 +12,7 @@ ...@@ -11,7 +12,7 @@
/>--> />-->
</view> </view>
<view class="upload-wrap" wx:if="{{!video}}" bindtap="uploadVideo"> <view class="upload-wrap" wx:if="{{!video}}" bindtap="chooseVideo">
<view class="upload-text">+视频</view> <view class="upload-text">+视频</view>
</view> </view>
</view> </view>
......
...@@ -30,3 +30,14 @@ ...@@ -30,3 +30,14 @@
width: 160rpx; width: 160rpx;
height: 160rpx; height: 160rpx;
} }
.video_area{
position: relative;
}
.video_area icon {
position: absolute;
right: -10rpx;
top: -10rpx;
background: #ffffff;
border-radius: 50%;
z-index: 99;
}
\ No newline at end of file
...@@ -110,51 +110,12 @@ wxService.page({ ...@@ -110,51 +110,12 @@ wxService.page({
}) })
}, },
chooseImage: function (event) { // 选择图片
// wx.chooseImage({ // 上传图片
// count: 1, _uploadImg(e){
// success: res => { console.log(e)
// var tempFilePaths = res.tempFilePaths
// wx.uploadFile({
// url: app.globalData.ctx + 'returnOrder/uploadReturnGoodsImg',
// filePath: tempFilePaths[0],
// header: { token: wx.getStorageSync('token') },
// name: 'file',
// success: res_ => {
// this.setData({
// imageDomain: JSON.parse(res_.data).data.imageDomain,
// tempFilePaths: this.data.tempFilePaths.concat(JSON.parse(res_.data).data.imageDomain + JSON.parse(res_.data).data.imgPath)
// })
// }
// })
// }
// })
let that = this;
let tempFilePaths = this.data.tempFilePaths;
wx.chooseImage({
count: 5 - tempFilePaths.length, // 最多可以选择的图片5张,
sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
success: function (res) {
var imgsrc = res.tempFilePaths;
tempFilePaths = tempFilePaths.concat(imgsrc);
that.setData({
tempFilePaths: tempFilePaths
});
console.log(that.data.tempFilePaths)
// that.moreImgUpload({
// url: 'https://........',//这里是你图片上传的接口
// path: that.data.pics//这里是选取的图片的地址数组
// });
},
fail: function () {
// fail
},
complete: function () {
// complete
}
})
}, },
checkPro(e) { checkPro(e) {
var index = e.currentTarget.dataset.index var index = e.currentTarget.dataset.index
const { cartList } = this.data const { cartList } = this.data
......
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
<text class="img-number">最多5张</text> <text class="img-number">最多5张</text>
</view> </view>
<view class="form-input"> <view class="form-input">
<upload-img/> <upload-img bind:_uploadImg="_uploadImg"/>
</view> </view>
</view> </view>
</view> </view>
......
...@@ -3,7 +3,7 @@ const app = getApp() ...@@ -3,7 +3,7 @@ const app = getApp()
const wxService = require('../../../../utils/wxService') const wxService = require('../../../../utils/wxService')
const utils = require('../../../../utils/util') const utils = require('../../../../utils/util')
const { memberId } = wx.getStorageSync('_baseUserInfo') const { memberId } = wx.getStorageSync('_baseUserInfo')
const envInfo = require('../../../../config/index').envInfo
wxService.page({ wxService.page({
...@@ -21,6 +21,7 @@ wxService.page({ ...@@ -21,6 +21,7 @@ wxService.page({
stcList: [], stcList: [],
userId: memberId userId: memberId
}, },
video:'',
pageNo:1, pageNo:1,
pageSize:100 pageSize:100
}, },
...@@ -65,8 +66,15 @@ wxService.page({ ...@@ -65,8 +66,15 @@ wxService.page({
} }
}) })
for (var i in data.sspList){ for (var i in data.sspList){
if (data.sspList[i].url){
this.data.pics.push(app.globalData.imageUrl + data.sspList[i].url) this.data.pics.push(app.globalData.imageUrl + data.sspList[i].url)
} }
if (data.sspList[i].videoUrl){
this.setData({
video: app.globalData.imageUrl + data.sspList[i].videoUrl
})
}
}
this.setData({ this.setData({
pics: this.data.pics pics: this.data.pics
...@@ -101,6 +109,8 @@ wxService.page({ ...@@ -101,6 +109,8 @@ wxService.page({
}) })
}, },
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
...@@ -120,6 +130,7 @@ wxService.page({ ...@@ -120,6 +130,7 @@ wxService.page({
chooseImg(){ chooseImg(){
let that = this; let that = this;
let pics = this.data.pics ; let pics = this.data.pics ;
var url = envInfo.ctx + '/merchant/upload/pic'
wx.chooseImage({ wx.chooseImage({
count: 5 - pics.length, // 最多可以选择的图片5张, count: 5 - pics.length, // 最多可以选择的图片5张,
sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有 sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
...@@ -134,7 +145,7 @@ wxService.page({ ...@@ -134,7 +145,7 @@ wxService.page({
}); });
// console.log(',..............',that.data.pics) // console.log(',..............',that.data.pics)
that.moreImgUpload({ that.moreImgUpload({
url: 'http://buyer.devapi.bigaka.net/merchant/upload/pic',//这里是你图片上传的接口 url: url,//这里是你图片上传的接口
path: imgsrcs//这里是选取的图片的地址数组 path: imgsrcs//这里是选取的图片的地址数组
}); });
}, },
...@@ -149,7 +160,6 @@ wxService.page({ ...@@ -149,7 +160,6 @@ wxService.page({
// 关联商品 // 关联商品
_selectGoods(e){ _selectGoods(e){
console.log('444',e)
this.setData({ this.setData({
proGoods: e.detail proGoods: e.detail
}) })
...@@ -192,7 +202,6 @@ wxService.page({ ...@@ -192,7 +202,6 @@ wxService.page({
that.setData({ that.setData({
'params.sspList': this.data.params.sspList 'params.sspList': this.data.params.sspList
}) })
console.log('\\\\\\\\\\\\', that.data.params.sspList)
} }
}, },
fail: (res) => { fail: (res) => {
...@@ -213,6 +222,42 @@ wxService.page({ ...@@ -213,6 +222,42 @@ wxService.page({
}) })
}, },
// 删除图片
deleteImage(event) {
var pics = this.data.pics
pics.splice(event.currentTarget.dataset.index, 1)
this.setData({
pics: pics
})
var sspList = this.data.params.sspList
for (var i in sspList) {
if (sspList[i].url) {
sspList.splice(event.currentTarget.dataset.index, 1)
}
}
},
// 上传视频
_uploadVideo(e){
console.log(e)
this.data.params.sspList.push({
cover: 0,
videoUrl: e.detail
});
},
// 删除视频
_deleteVideo(e){
var sspList = this.data.params.sspList
for (var i in sspList){
if (sspList[i].videoUrl){
console.log(i)
sspList.splice(i,1)
}
}
},
// 发布笔记 // 发布笔记
formSubmit(e){ formSubmit(e){
console.log(e) console.log(e)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<view class="page-upload-img"> <view class="page-upload-img">
<view class="flex-wrp"> <view class="flex-wrp">
<view class="flex-item" wx:for="{{pics}}" wx:key="{{index}}"> <view class="flex-item" wx:for="{{pics}}" wx:key="{{index}}">
<icon size="16" type="clear" catchtap="deleteImage" data-index="{{index}}" />
<image class="item-img" src="{{item}}" /> <image class="item-img" src="{{item}}" />
</view> </view>
<view class="flex-item" hidden="{{pics.length >= 5}}"> <view class="flex-item" hidden="{{pics.length >= 5}}">
...@@ -12,7 +13,7 @@ ...@@ -12,7 +13,7 @@
</view> </view>
</view> </view>
<view class="flex-item"> <view class="flex-item">
<upload-video/> <upload-video bind:_uploadVideo="_uploadVideo" bind:_deleteVideo="_deleteVideo" video="{{video}}"/>
</view> </view>
</view> </view>
</view> </view>
......
...@@ -86,6 +86,13 @@ page{ ...@@ -86,6 +86,13 @@ page{
width: 21%; width: 21%;
height: 160rpx; height: 160rpx;
margin-left: 20rpx; margin-left: 20rpx;
} position: relative;
}
.flex-item icon {
position: absolute;
right: -10rpx;
top: -10rpx;
background: #ffffff;
border-radius: 50%; }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment