445 lines
13 KiB
JavaScript
445 lines
13 KiB
JavaScript
// pages/mine/shop/shopedit.js
|
|
const app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
shopId: '',
|
|
shopBean: null,
|
|
StatusBar: app.globalData.StatusBar,
|
|
CustomBar: app.globalData.CustomBar,
|
|
startDate: "",
|
|
endDate: "",
|
|
shopName: "", //商店名称
|
|
shopAddress: "", //商店地址
|
|
index: null,
|
|
date: '2018-12-25', //营业时间
|
|
shopLicensePhotos: [], //商店营业执照
|
|
shopLogoPhotos: [], //商店Logo
|
|
shopVideos: [],
|
|
textareaBValue: '', //店铺简介,
|
|
isBusiness: true, //是否开业
|
|
selTradeList: [], //行业类型
|
|
selTemplateId: '1',
|
|
selTradeNames: '请选择行业'
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
shopId: options.shopId
|
|
})
|
|
this.getShopDetail()
|
|
},
|
|
//获取商店详情
|
|
getShopDetail() {
|
|
let _self = this
|
|
wx.showLoading({
|
|
title: '加载中...',
|
|
})
|
|
app.http.get(app.urls.getShopDetail.format({
|
|
shopId: _self.data.shopId
|
|
}), {
|
|
header: {
|
|
token: app.globalData.token
|
|
}
|
|
})
|
|
.then(res => {
|
|
wx.hideLoading({})
|
|
_self.setData({
|
|
shopBean: res.data
|
|
})
|
|
_self.setDataToView()
|
|
})
|
|
.catch(err => {
|
|
wx.hideLoading({})
|
|
})
|
|
},
|
|
//回写数据
|
|
setDataToView() {
|
|
let _self = this
|
|
|
|
if (_self.data.shopBean.shopLogo != '') {
|
|
let ids = _self.data.shopBean.shopLogo
|
|
_self.data.shopLogoPhotos.push({
|
|
id: ids,
|
|
path: app.baseUrls.tradeUrl + app.baseImgUrl + ids
|
|
})
|
|
|
|
}
|
|
|
|
if (_self.data.shopBean.shopVideo != '') {
|
|
let ids = _self.data.shopBean.shopVideo
|
|
let idsList = ids.split(',')
|
|
idsList.forEach(el => {
|
|
if (el != '') {
|
|
_self.data.shopVideos.push({
|
|
id: el,
|
|
videoUrl: app.baseUrls.tradeUrl + app.baseImgUrl + el,
|
|
path: '/images/ic_video_default.png',
|
|
})
|
|
}
|
|
})
|
|
}
|
|
var ids = _self.data.shopBean.industryId
|
|
var idsList = ids.split(',')
|
|
var names = _self.data.shopBean.industryName
|
|
var nameList = names.split(',')
|
|
for (var i = 0; i < idsList.length; i++) {
|
|
if (idsList[i] != '') {
|
|
var item = {
|
|
id: idsList[i],
|
|
name: nameList[i]
|
|
}
|
|
_self.data.selTradeList.push(item)
|
|
}
|
|
}
|
|
//行业IDs
|
|
this.setData({
|
|
shopName: _self.data.shopBean.shopName,
|
|
shopAddress: _self.data.shopBean.shopAddress,
|
|
textareaBValue: _self.data.shopBean.shopSummary,
|
|
isBusiness: _self.data.shopBean.isOpen == 0 ? false : true,
|
|
date: _self.data.shopBean.openDate,
|
|
selTemplateId: _self.data.shopBean.shopTemplateId,
|
|
shopLogoPhotos: _self.data.shopLogoPhotos,
|
|
shopVideos: _self.data.shopVideos,
|
|
selTradeNames: _self.data.shopBean.industryName,
|
|
selTradeList: _self.data.selTradeList
|
|
})
|
|
},
|
|
//更新
|
|
doUpdateShop() {
|
|
if (this.checkParams()) {
|
|
wx.showLoading({
|
|
title: '修改中...',
|
|
})
|
|
// doUpdateShopInfo
|
|
let _self = this
|
|
let industryIds = ''
|
|
_self.data.selTradeList.forEach(el => {
|
|
industryIds += el.id + ','
|
|
})
|
|
app.http.put(app.urls.doUpdateShopInfo.format({
|
|
shopId: _self.data.shopId
|
|
}), {
|
|
header: {
|
|
token: app.globalData.token
|
|
},
|
|
data: {
|
|
shopName: _self.data.shopName,
|
|
shopAddress: _self.data.shopAddress,
|
|
shopSummary: _self.data.textareaBValue,
|
|
openDate: _self.data.date,
|
|
shopLogo: _self.data.shopLogoPhotos[0].id,
|
|
industryIds: industryIds,
|
|
shopTemplateId: _self.data.selTemplateId,
|
|
isOpen: _self.data.isBusiness ? '1' : '0',
|
|
shopVideo: _self.data.shopVideos.length > 0 ? _self.data.shopVideos[0].id : ''
|
|
}
|
|
})
|
|
.then(res => {
|
|
wx.hideLoading({})
|
|
wx.showToast({
|
|
title: '修改成功',
|
|
icon: 'success',
|
|
success(res) {
|
|
wx.navigateBack({
|
|
delta: 1,
|
|
})
|
|
}
|
|
})
|
|
})
|
|
.catch(err => {
|
|
wx.hideLoading({})
|
|
})
|
|
}
|
|
},
|
|
PickerChange(e) {
|
|
this.setData({
|
|
index: e.detail.value
|
|
})
|
|
},
|
|
//选择模板样式
|
|
choosetemplate(e) {
|
|
this.setData({
|
|
selTemplateId: e.detail.value
|
|
})
|
|
},
|
|
DateChange(e) {
|
|
this.setData({
|
|
date: e.detail.value
|
|
})
|
|
},
|
|
|
|
checkIsBusiness(e) {
|
|
this.setData({
|
|
isBusiness: e.detail.value
|
|
})
|
|
},
|
|
//选择营业执照
|
|
ChooseLicenseP() {
|
|
let _self = this
|
|
wx.chooseImage({
|
|
count: 1, //默认9
|
|
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
|
|
sourceType: ['album', 'camera'], //从相册选择
|
|
success: (res) => {
|
|
res.tempFilePaths.forEach(element => {
|
|
_self.doUploadImg(1, element)
|
|
});
|
|
}
|
|
});
|
|
},
|
|
//选择logo
|
|
ChooseLogoP() {
|
|
let _self = this
|
|
wx.chooseImage({
|
|
count: 1, //默认9
|
|
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
|
|
sourceType: ['album', 'camera'], //从相册选择
|
|
success: (res) => {
|
|
res.tempFilePaths.forEach(element => {
|
|
_self.doUploadImg(2, element)
|
|
});
|
|
}
|
|
});
|
|
},
|
|
//删除Logo
|
|
DelLogoP(e) {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '确定要删除该图片吗?',
|
|
cancelText: '取消',
|
|
confirmText: '确定',
|
|
success: res => {
|
|
if (res.confirm) {
|
|
this.data.shopLogoPhotos.splice(e.currentTarget.dataset.index, 1)
|
|
this.setData({
|
|
shopLogoPhotos: this.data.shopLogoPhotos
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
//删除营业执照
|
|
DelLicenseP(e) {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '确定要删除该图片吗?',
|
|
cancelText: '取消',
|
|
confirmText: '确定',
|
|
success: res => {
|
|
if (res.confirm) {
|
|
this.data.shopLicensePhotos.splice(e.currentTarget.dataset.index, 1)
|
|
this.setData({
|
|
shopLicensePhotos: this.data.shopLicensePhotos
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
//进行图片上传 type 1 营业执照 2 logo
|
|
doUploadImg(type, path) {
|
|
let _self = this
|
|
app.http.uplaod(app.urls.doUploadImg, {
|
|
name: 'image',
|
|
path: path,
|
|
header: {
|
|
token: app.globalData.token
|
|
}
|
|
})
|
|
.then(res => {
|
|
var id = JSON.parse(res).data
|
|
let pathStr = app.urls.baseImgUrl + id
|
|
let item = {
|
|
id: id,
|
|
path: pathStr
|
|
}
|
|
if (type == 2) {
|
|
//Logo
|
|
let tempList = _self.data.shopLogoPhotos.concat(item)
|
|
_self.setData({
|
|
shopLogoPhotos: tempList
|
|
})
|
|
} else {
|
|
//营业执照
|
|
let tempList = _self.data.shopLicensePhotos.concat(item)
|
|
_self.setData({
|
|
shopLicensePhotos: tempList
|
|
})
|
|
}
|
|
})
|
|
.catch(err => {
|
|
wx.hideLoading({})
|
|
})
|
|
},
|
|
inputWatch(e) {
|
|
let key = e.currentTarget.dataset.model
|
|
this.setData({
|
|
[key]: e.detail.value
|
|
})
|
|
},
|
|
ViewLogoImg(e) {
|
|
var tempList = [e.currentTarget.dataset.url]
|
|
wx.previewImage({
|
|
urls: tempList,
|
|
current: e.currentTarget.dataset.url
|
|
});
|
|
},
|
|
ViewLicImg(e) {
|
|
var tempList = [e.currentTarget.dataset.url]
|
|
wx.previewImage({
|
|
urls: tempList,
|
|
current: e.currentTarget.dataset.url
|
|
});
|
|
},
|
|
viewVideo(e) {
|
|
var tempList = [{
|
|
url: e.currentTarget.dataset.url,
|
|
type: 'video'
|
|
}]
|
|
wx.previewMedia({
|
|
sources: tempList,
|
|
current: 0,
|
|
showmenu: false
|
|
})
|
|
},
|
|
delVideo(e) {
|
|
let _self = this
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '确定要删除该视频吗?',
|
|
cancelText: '取消',
|
|
confirmText: '确定',
|
|
success: res => {
|
|
if (res.confirm) {
|
|
_self.data.shopVideos.splice(e.currentTarget.dataset.index, 1)
|
|
_self.setData({
|
|
shopVideos: _self.data.shopVideos
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
textareaBInput(e) {
|
|
this.setData({
|
|
textareaBValue: e.detail.value
|
|
})
|
|
},
|
|
checkParams() {
|
|
var _self = this
|
|
if (_self.data.shopName == '') {
|
|
wx.showToast({
|
|
title: '商店名称为必填项',
|
|
icon: 'none'
|
|
})
|
|
return false
|
|
}
|
|
if (_self.data.shopAddress == '') {
|
|
wx.showToast({
|
|
title: '店铺地址为必填项',
|
|
icon: 'none'
|
|
})
|
|
return false
|
|
}
|
|
if (_self.data.selTradeList.length <= 0) {
|
|
wx.showToast({
|
|
title: '请选择行业',
|
|
icon: 'none'
|
|
})
|
|
return false
|
|
}
|
|
if (_self.data.date == '') {
|
|
wx.showToast({
|
|
title: '请选择开业时间',
|
|
icon: 'none'
|
|
})
|
|
return false
|
|
}
|
|
if (_self.data.shopLogoPhotos.length <= 0) {
|
|
wx.showToast({
|
|
title: '请上传店铺Logo',
|
|
icon: 'none'
|
|
})
|
|
return false
|
|
}
|
|
|
|
return true
|
|
},
|
|
showModal(e) {
|
|
this.setData({
|
|
modalName: e.currentTarget.dataset.target
|
|
})
|
|
},
|
|
hideModal(e) {
|
|
this.setData({
|
|
modalName: null
|
|
})
|
|
},
|
|
showChooseTrade() {
|
|
wx.navigateTo({
|
|
url: './choosetrade',
|
|
})
|
|
},
|
|
onShow() {
|
|
let _self = this
|
|
if (_self.data.selTradeList.length > 0) {
|
|
var names = ''
|
|
_self.data.selTradeList.forEach(el => {
|
|
names += el.name + ','
|
|
})
|
|
_self.setData({
|
|
selTradeNames: names
|
|
})
|
|
}
|
|
},
|
|
//选择视屏
|
|
chooseVideo() {
|
|
let _self = this
|
|
wx.chooseMedia({
|
|
count: 1,
|
|
mediaType: ['video'],
|
|
sourceType: ['album', 'camera'], //从相册选择
|
|
maxDuration: 30,
|
|
success: (res) => {
|
|
_self.doUploadVideo(res)
|
|
}
|
|
});
|
|
},
|
|
doUploadVideo(e) {
|
|
wx.showLoading({
|
|
title: '上传中...',
|
|
})
|
|
let _self = this
|
|
app.http.upload(app.urls.doUploadVideo, {
|
|
name: 'video',
|
|
path: e.tempFiles[0].tempFilePath,
|
|
header: {
|
|
token: app.globalData.token
|
|
}
|
|
})
|
|
.then(res => {
|
|
wx.hideLoading({})
|
|
let pathStr = e.tempFiles[0].thumbTempFilePath
|
|
var id = JSON.parse(res).data
|
|
let videoU = app.urls.baseImgUrl + id
|
|
let item = {
|
|
id: id,
|
|
path: pathStr,
|
|
videoUrl: videoU
|
|
}
|
|
let tempList = _self.data.shopVideos.concat(item)
|
|
_self.setData({
|
|
shopVideos: tempList
|
|
})
|
|
})
|
|
.catch(err => {
|
|
wx.hideLoading({})
|
|
})
|
|
},
|
|
}) |