From 89de2bbaf2e81ab3fa7a8c2aad3b76bc81033d3d Mon Sep 17 00:00:00 2001 From: xuxueyang <xuxy@fengyuntec.com> Date: 星期二, 23 七月 2024 18:44:27 +0800 Subject: [PATCH] update 订单功能(花店端) --- mixin/mixin.js | 928 +++++++++++++++++++++++++++++---------------------------- 1 files changed, 469 insertions(+), 459 deletions(-) diff --git a/mixin/mixin.js b/mixin/mixin.js index a2ac9ad..f197668 100644 --- a/mixin/mixin.js +++ b/mixin/mixin.js @@ -1,496 +1,506 @@ import { - mapState + mapState } from 'vuex' import store from "../store"; import environments from '@/environments' const mixinsCommon = { - computed: { - ...mapState({ - hasLogin: state => { - // console.log('computed hasLogin',state.hasLogin,state) - return state.hasLogin || false - }, - selftype: state => { - return (state.currentInfo || {}).type || '' - }, - currentInfo: state => { - return state.currentInfo || {} - }, - cache_address: state => { - return state.cache_address || {} - }, - cache_user: state => { - return state.currentInfo || {} - }, - sign: state => { - return state.sign || {} - }, - // currentEnId: state=>{ - // // console.log('currentEnId',state.currentInfo.enId,state.currentInfo) - // return state.currentInfo.enId || '' - // } - }), - }, - data() { - return { - list: [], - query: {}, - page: { - size: 10, - current: 1, - total: 0, - }, - style: { - 'color': '#fff' - }, - listApi: '', - regUserName: '用户-' + this.getRandomName(Math.floor(Math.random() * (6 - 2) + 3)), - regAvatarUrl: 'https://youzhen123.oss-cn-huhehaote.aliyuncs.com/WechatOwnerProperty/images/mrtx.png', + computed: { + ...mapState({ + hasLogin: state => { + // console.log('computed hasLogin',state.hasLogin,state) + return state.hasLogin || false + }, + selftype: state => { + return (state.currentInfo || {}).type || '' + }, + currentInfo: state => { + return state.currentInfo || {} + }, + cache_address: state => { + return state.cache_address || {} + }, + cache_user: state => { + return state.currentInfo || {} + }, + sign: state => { + return state.sign || {} + }, + // currentEnId: state=>{ + // // console.log('currentEnId',state.currentInfo.enId,state.currentInfo) + // return state.currentInfo.enId || '' + // } + }), + }, + data() { + return { + list: [], + query: {}, + page: { + size: 10, + current: 1, + total: 0, + }, + style: { + 'color': '#fff' + }, + listApi: '', + regUserName: '用户-' + this.getRandomName(Math.floor(Math.random() * (6 - 2) + 3)), + regAvatarUrl: 'https://youzhen123.oss-cn-huhehaote.aliyuncs.com/WechatOwnerProperty/images/mrtx.png', - } - }, - methods: { - onChooseavatar(e) { - let self = this; - let { - avatarUrl - } = e.detail; - this.regAvatarUrl = avatarUrl - console.log('avatarUrl', this.regAvatarUrl) - }, - onBindblur(e) { - this.regUserName = e.detail.value; // 获取微信昵称 - }, - onBindinput(e) { - this.regUserName = e.detail.value; // 获取微信昵称 - }, - randomAccess(min, max) { - return Math.floor(Math.random() * (min - max) + max) - }, - getRandomName(NameLength) { - let name = "" - for (let i = 0; i < NameLength; i++) { - let unicodeNum = "" - unicodeNum = this.randomAccess(0x4e00, 0x9fa5).toString(16) - name += this.decodeUnicode(unicodeNum) - } - return name - }, - decodeUnicode(str) { - //Unicode显示方式是\u4e00 - str = "\\u" + str - str = str.replace(/\\/g, "%"); - //转换中文 - str = unescape(str); - //将其他受影响的转换回原来 - str = str.replace(/%/g, "\\"); - return str; - }, - async onWxCheckSubmit() { - if (this.regUserName == '微信用户') { - this.$message.showToast('昵称不合规,不可以叫做:微信用户哈~') - return - } - //保存一下 - //先上传图片 - if (this.regAvatarUrl === - 'https://youzhen123.oss-cn-huhehaote.aliyuncs.com/WechatOwnerProperty/images/mrtx.png') { - var picture = this.regAvatarUrl - //更新接口 - this.$message.showLoading() - const { - code - } = await this.$http.request('post', "/api/current/user/update", { - data: { - ...this.dto, - nickName: this.regUserName, - picture: picture - } - }) + } + }, + methods: { + onChooseavatar(e) { + let self = this; + let { + avatarUrl + } = e.detail; + this.regAvatarUrl = avatarUrl + console.log('avatarUrl', this.regAvatarUrl) + }, + onBindblur(e) { + this.regUserName = e.detail.value; // 获取微信昵称 + }, + onBindinput(e) { + this.regUserName = e.detail.value; // 获取微信昵称 + }, + randomAccess(min, max) { + return Math.floor(Math.random() * (min - max) + max) + }, + getRandomName(NameLength) { + let name = "" + for (let i = 0; i < NameLength; i++) { + let unicodeNum = "" + unicodeNum = this.randomAccess(0x4e00, 0x9fa5).toString(16) + name += this.decodeUnicode(unicodeNum) + } + return name + }, + decodeUnicode(str) { + //Unicode显示方式是\u4e00 + str = "\\u" + str + str = str.replace(/\\/g, "%"); + //转换中文 + str = unescape(str); + //将其他受影响的转换回原来 + str = str.replace(/%/g, "\\"); + return str; + }, + async onWxCheckSubmit() { + if (this.regUserName == '微信用户') { + this.$message.showToast('昵称不合规,不可以叫做:微信用户哈~') + return + } + //保存一下 + //先上传图片 + if (this.regAvatarUrl === + 'https://youzhen123.oss-cn-huhehaote.aliyuncs.com/WechatOwnerProperty/images/mrtx.png') { + var picture = this.regAvatarUrl + //更新接口 + this.$message.showLoading() + const { + code + } = await this.$http.request('post', "/api/current/user/update", { + data: { + ...this.dto, + nickName: this.regUserName, + picture: picture + } + }) - this.$message.hideLoading() - this.$forceUpdate() - if (code == 0) { - this.$refs.popup_info.close() - this.$message.showToast('设置成功') - this.currentInfo.picture = picture - this.currentInfo.nickName = this.regUserName - } else { + this.$message.hideLoading() + this.$forceUpdate() + if (code == 0) { + this.$refs.popup_info.close() + this.$message.showToast('设置成功') + this.currentInfo.picture = picture + this.currentInfo.nickName = this.regUserName + } else { - } - } else { - this.$http.upload(this.regAvatarUrl).then(async res => { - var picture = res.data && res.data.length > 0 && res.data[0].url || '' - //更新接口 - this.$message.showLoading() - const { - code - } = await this.$http.request('post', "/api/current/user/update", { - data: { - ...this.currentInfo, - nickName: this.regUserName, - picture: picture - } - }) + } + } else { + this.$http.upload(this.regAvatarUrl).then(async res => { + var picture = res.data && res.data.length > 0 && res.data[0].url || '' + //更新接口 + this.$message.showLoading() + const { + code + } = await this.$http.request('post', "/api/current/user/update", { + data: { + ...this.currentInfo, + nickName: this.regUserName, + picture: picture + } + }) - this.$message.hideLoading() - this.$forceUpdate() - if (code == 0) { - this.$refs.popup_info.close() - this.$message.showToast('设置成功') - this.currentInfo.picture = picture - this.currentInfo.nickName = this.regUserName - } else { + this.$message.hideLoading() + this.$forceUpdate() + if (code == 0) { + this.$refs.popup_info.close() + this.$message.showToast('设置成功') + this.currentInfo.picture = picture + this.currentInfo.nickName = this.regUserName + } else { - } - }) - } - }, + } + }) + } + }, - async getUserProfile(e) { - this.$message.showLoading() - const res = await wx.getUserProfile({ - desc: '用于完善会员资料', - }); - console.log(res); - this.$message.hideLoading() - this.login_Wx(res.userInfo.avatarUrl, res.userInfo.nickName) - }, - login_Wx(imgurl, nickname) { - //获取openId - // /wx/jscode2session - let inviter = this.$storage.getItem('inviter') || '' - let inviterName = this.$storage.getItem('inviterName') || '' - //有效24小时 - if (inviter) { - var inviterTime = this.$storage.getItem('inviterTime') - if (new Date().getTime() > parseInt(inviterTime) + 1000 * 3600 * 24) { - inviter = '' - inviterName = '' - this.$storage.removeItem('inviter') - this.$storage.removeItem('inviterTime') - this.$storage.removeItem('inviterName') - } - } + async getUserProfile(e) { + this.$message.showLoading() + const res = await wx.getUserProfile({ + desc: '用于完善会员资料', + }); + console.log(res); + this.$message.hideLoading() + this.login_Wx(res.userInfo.avatarUrl, res.userInfo.nickName) + }, + login_Wx(imgurl, nickname) { + //获取openId + // /wx/jscode2session + let inviter = this.$storage.getItem('inviter') || '' + let inviterName = this.$storage.getItem('inviterName') || '' + //有效24小时 + if (inviter) { + var inviterTime = this.$storage.getItem('inviterTime') + if (new Date().getTime() > parseInt(inviterTime) + 1000 * 3600 * 24) { + inviter = '' + inviterName = '' + this.$storage.removeItem('inviter') + this.$storage.removeItem('inviterTime') + this.$storage.removeItem('inviterName') + } + } - const tmp = this; - this.$message.showLoading() - this.openid = this.$storage.getItem('openid'); - this.tel = this.$storage.getItem('tel'); - console.log('info,info,info,info,info,info', this.openid, this.tel); - if (!!this.openid && !!this.tel) { - // this.login = true; - } else { - // this.login = false; - console.log('wx.login'); - wx.login({ - success: async res => { - if (res.code) { - //微信登录成功 已拿到code - // tmp.login = true; - // tmp.jsCode = res.code; //保存获取到的code - console.log('abcd', res.code); - // this.$http.request('post',`/api/login/wechat`,{data:{code:tmp.jsCode}}) - this.$storage.setItem('jsCode', res.code); - const res2 = await wx.getUserInfo(); - console.log('res', res2); - this.tcode = res.code || '' - // if (nickname == '微信用户' || true) { - // //跳出弹出框,获取具体用户信息 - // tmp.$message.hideLoading() + const tmp = this; + this.$message.showLoading() + this.openid = this.$storage.getItem('openid'); + this.tel = this.$storage.getItem('tel'); + console.log('info,info,info,info,info,info', this.openid, this.tel); + if (!!this.openid && !!this.tel) { + // this.login = true; + } else { + // this.login = false; + console.log('wx.login'); + wx.login({ + success: async res => { + if (res.code) { + //微信登录成功 已拿到code + // tmp.login = true; + // tmp.jsCode = res.code; //保存获取到的code + console.log('abcd', res.code); + // this.$http.request('post',`/api/login/wechat`,{data:{code:tmp.jsCode}}) + this.$storage.setItem('jsCode', res.code); + const res2 = await wx.getUserInfo(); + console.log('res', res2); + this.tcode = res.code || '' + // if (nickname == '微信用户' || true) { + // //跳出弹出框,获取具体用户信息 + // tmp.$message.hideLoading() - // this.$refs.popup_info.open() + // this.$refs.popup_info.open() - // } else { - await this.$store.dispatch('loginwx', { - code: res.code, - imgurl: imgurl, - nickname: nickname, - inviter: inviter - }); - tmp.$message.hideLoading() - this.$forceUpdate() - //延迟,如果用户昵称是微信用户的话? - - setTimeout(() => { - if (tmp.currentInfo && tmp.currentInfo.id) { - if (tmp.currentInfo.nickName == '微信用户') { - tmp.$refs.popup_info && tmp.$refs.popup_info.open() - } - } - }, 500) - // } + // } else { + await this.$store.dispatch('loginwx', { + code: res.code, + imgurl: imgurl, + nickname: nickname, + inviter: inviter + }); + tmp.$message.hideLoading() + this.$forceUpdate() + //延迟,如果用户昵称是微信用户的话? - } else { - tmp.$message.hideLoading() - tmp.$message.showToast('微信登录失败'); + setTimeout(() => { + if (tmp.currentInfo && tmp.currentInfo.id) { + if (tmp.currentInfo.nickName == '微信用户') { + tmp.$refs.popup_info && tmp.$refs.popup_info.open() + } + } + }, 500) + // } - } - }, - error: res => { - console.log('wx.login error', res); - tmp.$message.hideLoading() + } else { + tmp.$message.hideLoading() + tmp.$message.showToast('微信登录失败'); - tmp.$message.showToast('微信授权失败'); - } - }); - } - }, + } + }, + error: res => { + console.log('wx.login error', res); + tmp.$message.hideLoading() - previewImg(url) { - if (url) { - uni.previewImage({ - urls: [url] - }) - } - }, - checkFormValues(dto, keys) { - if (keys) { - for (var key of keys) { - if (!dto[key]) { - return false - } - } - } - return true - }, - async refreshList(){ - this.page.current = 1 - await this.getList() - }, - async getList(type='get') { - if (this.listApi) { - this.$message.showLoading() - const { - data - } = await this.$http.request(type, this.listApi, { - params: { - ...this.query, - ...this.page - }, - data:{ - ...this.query, - ...this.page - } - }) - if (data) { - if (this.page.current == 1) { - this.list = data.records || [] - } else { - //根据id去重正常 - var ids = [] - for (var item of this.list) { - ids.push(item.id) - } - for (var item of data.records) { - if (ids.indexOf(item.id) < 0) { - this.list.push(item) - } - } + tmp.$message.showToast('微信授权失败'); + } + }); + } + }, - } - this.page.total = data.total || 0 - } - this.$message.hideLoading() - } + previewImg(url) { + if (url) { + uni.previewImage({ + urls: [url] + }) + } + }, + checkFormValues(dto, keys) { + if (keys) { + for (var key of keys) { + if (!dto[key]) { + return false + } + } + } + return true + }, + async refreshList() { + this.page.current = 1 + await this.getList() + }, + async getList(type = 'get') { + if (this.listApi) { + this.$message.showLoading() + const { + data + } = await this.$http.request(type, this.listApi, { + params: { + ...this.query, + ...this.page + }, + data: { + ...this.query, + ...this.page + } + }) + if (data) { + if (this.page.current == 1) { + this.list = data.records || [] + } else { + //根据id去重正常 + var ids = [] + for (var item of this.list) { + ids.push(item.id) + } + for (var item of data.records) { + if (ids.indexOf(item.id) < 0) { + this.list.push(item) + } + } - }, - async getMore(type='get') { - if (this.page.total > this.page.current * this.page.size) { - this.page.current += 1 - await this.getList(type) - } - }, - backHome() { - uni.reLaunch({ - url: '/pages/home/home' - }) - }, - goto(url, check = false) { - if (check) { - console.log('currentInfo', this.currentInfo) - if (!this.currentInfo.id) { - this.$message.showToast('请先登陆') - return - } + } + this.page.total = data.total || 0 + } + this.$message.hideLoading() + } - } - uni.navigateTo({ - url - }) - }, - backpage() { - // this.$router.go(-1) - uni.navigateBack() - } - // #ifdef APP || H5 - , - async appdownload(url, name = '') { - await this.$message.confirm('确定下载此文件吗') - let _this = this - if (url) { - // var url2 = environments.httpBaseUri + `/api/download/file?fileName=${name}&filePath=` + url - // uni.downloadFile({ - // url: url2, - // success: (res) => { - // if (res.statusCode === 200) { - // _this.$message.showToast('下载成功') - // } else { - // console.log(res) - // _this.$message.showToast('下载失败') - // } - // }, - // fail: (res) => { - // console.log(res) - // _this.$message.showToast('下载失败') - // } - // }); - _this.$message.showLoading() + }, + async getMore(type = 'get') { + if (this.page.total > this.page.current * this.page.size) { + this.page.current += 1 + await this.getList(type) + } + }, + backHome() { + uni.reLaunch({ + url: '/pages/home/home' + }) + }, + goto(url, check = false) { + if (check) { + console.log('currentInfo', this.currentInfo) + if (!this.currentInfo.id) { + this.$message.showToast('请先登陆') + return + } - uni.downloadFile({ - url: url, //下载地址接口返回 - success: (data) => { - _this.$message.hideLoading() - console.log('success', data) - if (data.statusCode === 200) { - //文件保存到本地 - uni.saveFile({ - tempFilePath: data.tempFilePath, //临时路径 - success: function(res) { - uni.showToast({ - icon: 'none', - mask: true, - title: '文件已保存:' + res - .savedFilePath, //保存路径 - duration: 2000, - }); - setTimeout(() => { - //打开文档查看 - uni.openDocument({ - filePath: res.savedFilePath, - success: function(res) { - // console.log('打开文档成功'); - } - }); - }, 2000) - }, - fail: (err) => { + } + uni.navigateTo({ + url + }) + }, + backpage() { + // this.$router.go(-1) + uni.navigateBack() + } + // #ifdef APP || H5 + , + async appdownload(url, name = '') { + await this.$message.confirm('确定下载此文件吗') + let _this = this + if (url) { + // var url2 = environments.httpBaseUri + `/api/download/file?fileName=${name}&filePath=` + url + // uni.downloadFile({ + // url: url2, + // success: (res) => { + // if (res.statusCode === 200) { + // _this.$message.showToast('下载成功') + // } else { + // console.log(res) + // _this.$message.showToast('下载失败') + // } + // }, + // fail: (res) => { + // console.log(res) + // _this.$message.showToast('下载失败') + // } + // }); + _this.$message.showLoading() - console.log(err); - uni.showToast({ - icon: 'none', - mask: true, - title: '下载成功保存失败', - }); - }, - }); - } - }, - fail: (err) => { - _this.$message.hideLoading() + uni.downloadFile({ + url: url, //下载地址接口返回 + success: (data) => { + _this.$message.hideLoading() + console.log('success', data) + if (data.statusCode === 200) { + //文件保存到本地 + uni.saveFile({ + tempFilePath: data.tempFilePath, //临时路径 + success: function (res) { + uni.showToast({ + icon: 'none', + mask: true, + title: '文件已保存:' + res + .savedFilePath, //保存路径 + duration: 2000, + }); + setTimeout(() => { + //打开文档查看 + uni.openDocument({ + filePath: res.savedFilePath, + success: function (res) { + // console.log('打开文档成功'); + } + }); + }, 2000) + }, + fail: (err) => { - console.log(err); - uni.showToast({ - icon: 'none', - mask: true, - title: '失败请重新下载', - }); - }, - }); - } - } - // #endif - // #ifdef MP - , - async wxdownload(url, name = '') { - await this.$message.confirm('是否要下载此文件') - var url2 = environments.httpBaseUri + `/api/download/file?fileName=${name}&filePath=` + url + console.log(err); + uni.showToast({ + icon: 'none', + mask: true, + title: '下载成功保存失败', + }); + }, + }); + } + }, + fail: (err) => { + _this.$message.hideLoading() - let that = this - that.$message.showLoading() - // wx.sa - // wx.downloadFile({ - // url: url2, - // success: res => { - // that.$message.showToast('下载成功') + console.log(err); + uni.showToast({ + icon: 'none', + mask: true, + title: '失败请重新下载', + }); + }, + }); + } + } + // #endif + // #ifdef MP + , + async wxdownload(url, name = '') { + await this.$message.confirm('是否要下载此文件') + var url2 = environments.httpBaseUri + `/api/download/file?fileName=${name}&filePath=` + url - // }, - // fail: res => { - // that.$message.showToast('下载失败') + let that = this + that.$message.showLoading() + // wx.sa + // wx.downloadFile({ + // url: url2, + // success: res => { + // that.$message.showToast('下载成功') - // }, - // complete: res => { - // that.$message.hideLoading() - // } - // }) - wx.downloadFile({ - url: url, - timeout: 120000, - success(res) { - that.$message.hideLoading() - console.log('res', res) - if (res.statusCode === 200) { - const filePath = res.tempFilePath - if (filePath.endsWith('.jpg') || - filePath.endsWith('.jpeg') || - filePath.endsWith('.png') || - filePath.endsWith('.jpg')) { - wx.saveImageToPhotosAlbum({ - filePath: filePath, - success: function(res) { - that.$message.showToast('保存图片成功') - }, - fail: function(res) { - that.$message.showToast('打开文档失败,非支持的类型') - } - }) + // }, + // fail: res => { + // that.$message.showToast('下载失败') - } else if (filePath.endsWith('.mp4') || - filePath.endsWith('.flv') || - filePath.endsWith('.avi') || - filePath.endsWith('.wmv') || - filePath.endsWith('.mpeg')) { - wx.saveVideoToPhotosAlbum({ - filePath: filePath, - success: function(res) { - that.$message.showToast('保存视频成功') - }, - fail: function(res) { - that.$message.showToast('打开文档失败,非支持的类型') - } - }) + // }, + // complete: res => { + // that.$message.hideLoading() + // } + // }) + wx.downloadFile({ + url: url, + timeout: 120000, + success(res) { + that.$message.hideLoading() + console.log('res', res) + if (res.statusCode === 200) { + const filePath = res.tempFilePath + if (filePath.endsWith('.jpg') || + filePath.endsWith('.jpeg') || + filePath.endsWith('.png') || + filePath.endsWith('.jpg')) { + wx.saveImageToPhotosAlbum({ + filePath: filePath, + success: function (res) { + that.$message.showToast('保存图片成功') + }, + fail: function (res) { + that.$message.showToast('打开文档失败,非支持的类型') + } + }) - } else { - wx.openDocument({ - filePath: filePath, - showMenu: true, //关键点 - success: function(res) { - console.log('打开文档成功') - }, - fail: function(res) { - that.$message.showToast('打开文档失败,非支持的类型') - } - }) - } - } else { - that.$message.showToast('下载失败,服务器内部错误') + } else if (filePath.endsWith('.mp4') || + filePath.endsWith('.flv') || + filePath.endsWith('.avi') || + filePath.endsWith('.wmv') || + filePath.endsWith('.mpeg')) { + wx.saveVideoToPhotosAlbum({ + filePath: filePath, + success: function (res) { + that.$message.showToast('保存视频成功') + }, + fail: function (res) { + that.$message.showToast('打开文档失败,非支持的类型') + } + }) - } - }, - fail: res => { - that.$message.hideLoading() - that.$message.showToast('下载失败') - }, - complete: res => { + } else { + wx.openDocument({ + filePath: filePath, + showMenu: true, //关键点 + success: function (res) { + console.log('打开文档成功') + }, + fail: function (res) { + that.$message.showToast('打开文档失败,非支持的类型') + } + }) + } + } else { + that.$message.showToast('下载失败,服务器内部错误') - } - }) - } - // #endif - } + } + }, + fail: res => { + that.$message.hideLoading() + that.$message.showToast('下载失败') + }, + complete: res => { + + } + }) + } + // #endif + + // #ifdef PUB_CUSTOMER + , + async submitShopping(dto) { + //提交到购物车中 + this.$message.showLoading() + await this.$store.dispatch('submitShopping',dto); + this.$message.hideLoading() + } + // #endif + } } export default mixinsCommon \ No newline at end of file -- Gitblit v1.9.3