123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- // StepPage/pages/third/third.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- phoneIndex:null,
- showCamera:false,
- imgList:[],
- set_status:'',
- cameraSet:'back'
- },
- handleDelPic(e){
- let imgList = this.data.imgList;
- imgList[e.currentTarget.dataset.index].src = '';
- this.setData({
- imgList:imgList
- })
- },
- handleOpenCamera(row){
- if(this.data.imgList[row.currentTarget.dataset.index].src){
- wx.previewImage({
- urls:[this.data.imgList[row.currentTarget.dataset.index].src]
- })
- return
- }
- if(this.data.set_status==='is_detail'){
- return
- }
- this.setData({
- showCamera:true,
- phoneIndex:row.currentTarget.dataset.index,
- })
- },
- takePhoto() {
- const ctx = wx.createCameraContext()
- ctx.takePhoto({
- quality: 'high',
- success: (res) => {
- this.upRecord(res.tempImagePath);
- }
- })
- },
- upRecord(video){
- var that =this;
- let app = getApp();
- let openid = app.globalData.openID;
- let formData = {
- openid
- };
- wx.uploadFile({
- url: `${app.globalData.url}wx/uploadConstructionFile`,//这是你自己后台的连接
- filePath: video,
- name:"file",//后台要绑定的名称
- header: {
- "Content-Type": "multipart/form-data"
- },
- //参数绑定
- formData: formData,// HTTP 请求中其他额外的 form data
- success:function(ress){
- wx.showToast({
- title: '上传成功',
- })
- let src = JSON.parse(ress.data).data.url;
- that.data.imgList[that.data.phoneIndex].src = `${app.globalData.url}${src}`;
- if(that.data.set_status){
- that.data.imgList[that.data.phoneIndex].show_url = `${app.globalData.url}${src}`;
- }
- app.globalData.img.forEach(v=>{
- if(v.type== that.data.imgList[that.data.phoneIndex]){
- v.src = `${app.globalData.url}${src}`;
- if(that.data.set_status){
- v.show_url = `${app.globalData.url}${src}`;
- }
- }
- })
- that.setData({
- imgList:that.data.imgList,
- showCamera:false
- })
- console.log(that.data.imgList)
- },
- fail: function(ress){
-
- wx.showToast({
- title: '上传失败',
- })
- that.setData({
- showCamera:false
- })
- }
- })
- },
- error(e) {
- console.log(e.detail)
- },
- handleNext(){
- let app = getApp();
- if(this.data.set_status){
- wx.redirectTo({
- url: '../writeVIN/writeVIN',
- })
- }else{
- let openid = app.globalData.openID;
- app.globalData.stepData = app.globalData.stepData.filter(v=>v.sort!=3);
- app.globalData.stepData.push({
- sort:3,
- data:{
- imgList:this.data.imgList
- }
- })
- wx.p.request({
- url: `${app.globalData.url}wx/saveWxConstructionData`,
- method:'POST',
- data:{
- openid,
- type:1,
- data:JSON.stringify(app.globalData)
- }
- }).then(res=>{
- if(res.data.code==200){
- wx.redirectTo({
- url: '../writeVIN/writeVIN',
- })
- }
-
- })
- }
- },
- handleExpand(){
- if(this.data.cameraSet=='back'){
- this.setData({
- cameraSet:'front'
- })
- }else{
- this.setData({
- cameraSet:'back'
- })
- }
- },
- handleReturn(){
- let app = getApp();
- let openid = app.globalData.openID;
- if(this.data.set_status){
- wx.redirectTo({
- url: '../second/second',
- })
- }else{
- app.globalData.stepData.forEach((v,index)=>{
- if(v.sort == '3'){
- app.globalData.stepData.splice(index,1);
- }
- })
- wx.p.request({
- url: `${app.globalData.url}wx/saveWxConstructionData`,
- method:'POST',
- data:{
- openid,
- type:1,
- data:JSON.stringify(app.globalData)
- }
- }).then(res=>{
- if(res.data.code==200){
- wx.redirectTo({
- url: '../second/second',
- })
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- let app = getApp();
- let imgList = [];
- imgList = app.globalData.img?app.globalData.img.filter(v=>['1','2','3'].indexOf(v.type)==-1):[];
- if(app.globalData.set_status){
- if(app.globalData.basic_type_item_id == app.globalData.detailData.basic_type_item_id){
- imgList.forEach(c=>{
-
- c.src = app.globalData.detailData.img.find(v=>v.type==c.type).src?`${app.globalData.url}${app.globalData.detailData.img.find(v=>v.type==c.type).src}`:''
- c.show_url = app.globalData.detailData.img.find(v=>v.type==c.type).show_url?app.globalData.detailData.img.find(v=>v.type==c.type).show_url:''
-
- })
- }
- this.setData({
- imgList:imgList,
- set_status:app.globalData.set_status
- })
- }else{
- if(app.globalData.stepData.length==0){
- wx.redirectTo({
- url: '../second/second',
- })
- }
- this.setData({
- imgList:imgList,
- set_status:''
- })
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|