123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- import * as util from '../../../../utils/util.js'
- let app = getApp();
- let host = app.globalData.servsers;
- Page({
-
- data: {
- dataPositionObj: {
- top: '156rpx',
- left: '286rpx',
- width: '',
- height: '',
-
- },
- propSize: {
- top: '8cm',
- right: '8cm',
- bottom: '8cm',
- left: '8cm',
- },
- host:null,
- obverseImgObject: {
- '1': '/customized/images/customized/cup_black_big.png',
- '2': '/customized/images/customized/cup_black_side.png',
- '3': '/customized/images/customized/cup_black_handle.png',
- '4': '/customized/images/customized/cup_black_bottom.png',
- },
- fontContent: '可定制区域',
- madeImg: null,
- madeStatic: false,
- animationData: {},
- imageArray:[],
- imageId: null,
- imageSrc:null,
- touch:{
- isActive: '1',
- src: null,
- x:0,
- y:0,
- clientX:0,
- clientY:0,
- width:null,
- height:null,
- scale:1,
- angle: 0,
- }
- },
-
- onLoad: function (options) {
- let that = this
- that.animation = wx.createAnimation({
- timingFunction: 'step-start',
- })
- if('id' in options){
- let cupNum = util.changeCup(options.id);
- let madeTouchImg = wx.getStorageSync('madeCupImgData' + options.id);
- if (madeTouchImg){
- that.animation.rotate(madeTouchImg.angle).step();
- that.setData({
- touch: madeTouchImg,
- animationData: this.animation.export(),
- dataPositionObj: cupNum.dataPositionObj,
- propSize: cupNum.propSize,
- madeStatic:true,
- });
- }else {
- that.setData({
- 'touch.isActive': options.id,
- dataPositionObj: cupNum.dataPositionObj,
- propSize: cupNum.propSize
- });
- }
-
-
- }
- },
-
- onReady: function () {
- let that = this;
- that.setData({
- host:host,
- })
-
- },
-
- onShow: function () {
- this.getImgList();
- },
-
- onHide: function () {
- },
-
- onUnload: function () {
- },
-
- onPullDownRefresh: function () {
- },
-
- onReachBottom: function () {
- },
-
- onShareAppMessage: function () {
- },
-
- fontTouchstart(e) {
-
- this.setData({
- "touch.clientX": e.touches[0].clientX - this.data.touch.x,
- "touch.clientY": e.touches[0].clientY - this.data.touch.y
- });
- console.log(this.data.touch, "touch")
- },
- fontTouchmove(e) {
-
- this.setData({
- "touch.x": e.changedTouches[0].clientX - this.data.touch.clientX,
- "touch.y": e.changedTouches[0].clientY - this.data.touch.clientY
- });
-
- },
- imgDelete(){
- let that = this;
- that.setData({
- 'touch.src': null,
- madeStatic: false,
- })
- },
- imgEnlarge(e){
- let that = this;
- console.log(e.detail.value,'eee')
- that.setData({
- 'touch.width': e.detail.value,
- 'touch.height': e.detail.value/that.data.touch.scale
- })
- },
- imgRotate(e) {
- this.animation.rotate(e.detail.value).step();
- this.setData({
- animationData: this.animation.export(),
- 'touch.angle': e.detail.value
- })
- },
- getImgList(){
-
- let that = this
- wx.request({
- url: host+'/queryCustomGoodsUserListByUserId',
- data:{
- userId: app.globalData.user_id,
- },
- type:'get',
- success(res){
- console.log(res,'图片列表请求结束')
- that.setData({
- imageArray:res.data
- })
- }
- })
-
- },
- uploadImg(){
- console.log('点击上传图片');
- let that = this;
- wx.chooseImage({
- success(res) {
- const tempFilePaths = res.tempFilePaths
- wx.uploadFile({
- url: host + '/fileUpload',
- filePath: tempFilePaths[0],
- name: 'file',
- formData: {
- file: tempFilePaths[0],
- userId: app.globalData.user_id,
- },
- success(res) {
- console.log(res,'我上传完了')
- that.getImgList()
- }
- })
- }
- })
- },
- selectImgBtn(e){
- console.log('选中图片', e.currentTarget.dataset.id);
- this.setData({
- imageId: e.currentTarget.dataset.id,
- imageSrc: e.currentTarget.dataset.src
- })
-
-
-
- },
- getScale(that,src){
- wx.getImageInfo({
- src: src,
- success: function (res) {
- console.log(res, "fff")
- that.setData({
- 'touch.width': res.width,
- 'touch.height': res.height,
- 'touch.scale': res.width / res.height,
- })
- console.log(that.data.touch)
- }
- })
- },
- addImg(){
- let that = this;
- if (that.data.imageSrc){
- that.setData({
- 'touch.src': that.data.imageSrc,
- madeStatic: true,
- })
- that.getScale(that, that.data.imageSrc)
- } else {
- wx.showToast({
- title: '您还没有选中图片',
- icon: 'none'
- })
- }
- },
- madeConfirm(){
-
- if (this.data.madeStatic){
- wx.setStorageSync('madeCupImgData'+this.data.touch.isActive, this.data.touch);
- wx.navigateBack()
-
-
-
- } else {
- wx.showToast({
- title: '您还没有选择图片进行设计',
- icon:'none'
- })
- }
- }
- })
|