third.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // StepPage/pages/third/third.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. phoneIndex:null,
  8. showCamera:false,
  9. imgList:[],
  10. set_status:'',
  11. cameraSet:'back'
  12. },
  13. handleDelPic(e){
  14. let imgList = this.data.imgList;
  15. imgList[e.currentTarget.dataset.index].src = '';
  16. this.setData({
  17. imgList:imgList
  18. })
  19. },
  20. handleOpenCamera(row){
  21. if(this.data.imgList[row.currentTarget.dataset.index].src){
  22. wx.previewImage({
  23. urls:[this.data.imgList[row.currentTarget.dataset.index].src]
  24. })
  25. return
  26. }
  27. if(this.data.set_status==='is_detail'){
  28. return
  29. }
  30. this.setData({
  31. showCamera:true,
  32. phoneIndex:row.currentTarget.dataset.index,
  33. })
  34. },
  35. takePhoto() {
  36. const ctx = wx.createCameraContext()
  37. ctx.takePhoto({
  38. quality: 'high',
  39. success: (res) => {
  40. this.upRecord(res.tempImagePath);
  41. }
  42. })
  43. },
  44. upRecord(video){
  45. var that =this;
  46. let app = getApp();
  47. let openid = app.globalData.openID;
  48. let formData = {
  49. openid
  50. };
  51. wx.uploadFile({
  52. url: `${app.globalData.url}wx/uploadConstructionFile`,//这是你自己后台的连接
  53. filePath: video,
  54. name:"file",//后台要绑定的名称
  55. header: {
  56. "Content-Type": "multipart/form-data"
  57. },
  58. //参数绑定
  59. formData: formData,// HTTP 请求中其他额外的 form data
  60. success:function(ress){
  61. wx.showToast({
  62. title: '上传成功',
  63. })
  64. let src = JSON.parse(ress.data).data.url;
  65. that.data.imgList[that.data.phoneIndex].src = `${app.globalData.url}${src}`;
  66. if(that.data.set_status){
  67. that.data.imgList[that.data.phoneIndex].show_url = `${app.globalData.url}${src}`;
  68. }
  69. app.globalData.img.forEach(v=>{
  70. if(v.type== that.data.imgList[that.data.phoneIndex]){
  71. v.src = `${app.globalData.url}${src}`;
  72. if(that.data.set_status){
  73. v.show_url = `${app.globalData.url}${src}`;
  74. }
  75. }
  76. })
  77. that.setData({
  78. imgList:that.data.imgList,
  79. showCamera:false
  80. })
  81. console.log(that.data.imgList)
  82. },
  83. fail: function(ress){
  84. wx.showToast({
  85. title: '上传失败',
  86. })
  87. that.setData({
  88. showCamera:false
  89. })
  90. }
  91. })
  92. },
  93. error(e) {
  94. console.log(e.detail)
  95. },
  96. handleNext(){
  97. let app = getApp();
  98. if(this.data.set_status){
  99. wx.redirectTo({
  100. url: '../writeVIN/writeVIN',
  101. })
  102. }else{
  103. let openid = app.globalData.openID;
  104. app.globalData.stepData = app.globalData.stepData.filter(v=>v.sort!=3);
  105. app.globalData.stepData.push({
  106. sort:3,
  107. data:{
  108. imgList:this.data.imgList
  109. }
  110. })
  111. wx.p.request({
  112. url: `${app.globalData.url}wx/saveWxConstructionData`,
  113. method:'POST',
  114. data:{
  115. openid,
  116. type:1,
  117. data:JSON.stringify(app.globalData)
  118. }
  119. }).then(res=>{
  120. if(res.data.code==200){
  121. wx.redirectTo({
  122. url: '../writeVIN/writeVIN',
  123. })
  124. }
  125. })
  126. }
  127. },
  128. handleExpand(){
  129. if(this.data.cameraSet=='back'){
  130. this.setData({
  131. cameraSet:'front'
  132. })
  133. }else{
  134. this.setData({
  135. cameraSet:'back'
  136. })
  137. }
  138. },
  139. handleReturn(){
  140. let app = getApp();
  141. let openid = app.globalData.openID;
  142. if(this.data.set_status){
  143. wx.redirectTo({
  144. url: '../second/second',
  145. })
  146. }else{
  147. app.globalData.stepData.forEach((v,index)=>{
  148. if(v.sort == '3'){
  149. app.globalData.stepData.splice(index,1);
  150. }
  151. })
  152. wx.p.request({
  153. url: `${app.globalData.url}wx/saveWxConstructionData`,
  154. method:'POST',
  155. data:{
  156. openid,
  157. type:1,
  158. data:JSON.stringify(app.globalData)
  159. }
  160. }).then(res=>{
  161. if(res.data.code==200){
  162. wx.redirectTo({
  163. url: '../second/second',
  164. })
  165. }
  166. })
  167. }
  168. },
  169. /**
  170. * 生命周期函数--监听页面加载
  171. */
  172. onLoad(options) {
  173. let app = getApp();
  174. let imgList = [];
  175. imgList = app.globalData.img?app.globalData.img.filter(v=>['1','2','3'].indexOf(v.type)==-1):[];
  176. if(app.globalData.set_status){
  177. if(app.globalData.basic_type_item_id == app.globalData.detailData.basic_type_item_id){
  178. imgList.forEach(c=>{
  179. 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}`:''
  180. 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:''
  181. })
  182. }
  183. this.setData({
  184. imgList:imgList,
  185. set_status:app.globalData.set_status
  186. })
  187. }else{
  188. if(app.globalData.stepData.length==0){
  189. wx.redirectTo({
  190. url: '../second/second',
  191. })
  192. }
  193. this.setData({
  194. imgList:imgList,
  195. set_status:''
  196. })
  197. }
  198. },
  199. /**
  200. * 生命周期函数--监听页面初次渲染完成
  201. */
  202. onReady() {
  203. },
  204. /**
  205. * 生命周期函数--监听页面显示
  206. */
  207. onShow() {
  208. },
  209. /**
  210. * 生命周期函数--监听页面隐藏
  211. */
  212. onHide() {
  213. },
  214. /**
  215. * 生命周期函数--监听页面卸载
  216. */
  217. onUnload() {
  218. },
  219. /**
  220. * 页面相关事件处理函数--监听用户下拉动作
  221. */
  222. onPullDownRefresh() {
  223. },
  224. /**
  225. * 页面上拉触底事件的处理函数
  226. */
  227. onReachBottom() {
  228. },
  229. /**
  230. * 用户点击右上角分享
  231. */
  232. onShareAppMessage() {
  233. }
  234. })