contract.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // pages/invoice/contract/contract.js
  2. const app = getApp();
  3. const api = app.api;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. invoiceId:"",
  10. invoiceOrderId:"",
  11. upFileInfo:null,
  12. formData:{
  13. contractFileId:"",
  14. id:"",
  15. },
  16. isSubmit:false,
  17. isShowFileChoose:false
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. if(options.invoiceOrderId){
  24. this.setData({
  25. invoiceId:options.invoiceId||'',
  26. invoiceOrderId:options.invoiceOrderId||''
  27. },()=>{
  28. this.getData();
  29. })
  30. }
  31. wx.hideShareMenu();
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow: function () {
  42. },
  43. /**已提交获取数据**/
  44. getData(){
  45. const invoiceInfo=wx.getStorageSync('invoiceInfo');
  46. if(invoiceInfo){
  47. this.setData({
  48. upFileInfo:invoiceInfo.contractFileInfo,
  49. formData:{
  50. contractFileId:invoiceInfo.contractId,
  51. id:invoiceInfo.invoiceOrderId,
  52. }
  53. },()=>{
  54. wx.removeStorageSync('invoiceInfo')
  55. });
  56. }
  57. /*const {invoiceId,invoiceOrderId}=this.data;
  58. app.post(api.queryOrderInvoiceInfo,{
  59. id:invoiceId,
  60. invoiceOrderId
  61. }).then(res=>{
  62. const {data}=res;
  63. this.setData({
  64. upFileInfo:data.contractFileInfo,
  65. formData:{
  66. contractFileId:data.contractId,
  67. id:invoiceOrderId,
  68. }
  69. })
  70. })*/
  71. },
  72. saveData(){
  73. const{formData,invoiceId,isSubmit}=this.data;
  74. if(isSubmit){
  75. return
  76. }
  77. if(!formData.contractFileId){
  78. wx.showToast({
  79. title: '请上传合同文件',
  80. icon: 'none',
  81. duration: 2000
  82. })
  83. return
  84. }
  85. this.setData({
  86. isSubmit:true
  87. });
  88. app.post(api.uploadArtistUserInvoice,formData).then(res=>{
  89. console.log(res);
  90. const {invoiceOrderId}=res.data
  91. //记录id 回退记录
  92. this.setData({
  93. 'formData.id':invoiceOrderId,
  94. })
  95. wx.navigateTo({
  96. url:`/pages/invoice/editInvoice/editInvoice?id=${res.data.invoiceOrderId}&invoiceId=${invoiceId}`
  97. })
  98. this.setData({
  99. isSubmit:false,
  100. });
  101. }).catch(()=>{
  102. this.setData({
  103. isSubmit:false
  104. })
  105. })
  106. },
  107. chooseFileMsg(){
  108. app.uploadFileMsg({
  109. extension:['pdf']
  110. }).then(res=>{
  111. this.upFileFormatter(res)
  112. }).catch(error=>{
  113. console.log(error)
  114. });
  115. },
  116. chooseFile(){
  117. app.uploadFile({
  118. extension:['pdf']
  119. }).then(res=>{
  120. this.upFileFormatter(res);
  121. }).catch(error=>{
  122. console.log(error)
  123. });
  124. },
  125. upFileFormatter(res){
  126. const data=JSON.parse(res.data);
  127. this.setData({
  128. upFileInfo:data,
  129. isShowFileChoose:false,
  130. 'formData.contractFileId':data.id
  131. })
  132. },
  133. removeFile(){
  134. this.setData({
  135. upFileInfo:null,
  136. 'formData.contractFileId':''
  137. })
  138. },
  139. /**预览pdf文件**/
  140. prevFile() {
  141. const {upFileInfo}=this.data;
  142. if(upFileInfo.contentType.indexOf('image')!=-1){
  143. app.previewImg([upFileInfo.url]);
  144. }else{
  145. app.openDocument(upFileInfo.url)
  146. }
  147. },
  148. /** 显示文件上传方式 **/
  149. showFileChoose(){
  150. this.setData({
  151. isShowFileChoose:true
  152. })
  153. },
  154. /** 隐藏文件上传方式 **/
  155. hideFileChoose(){
  156. this.setData({
  157. isShowFileChoose:false
  158. })
  159. },
  160. /**
  161. * 生命周期函数--监听页面隐藏
  162. */
  163. onHide: function () {
  164. },
  165. /**
  166. * 生命周期函数--监听页面卸载
  167. */
  168. onUnload: function () {
  169. },
  170. /**
  171. * 页面相关事件处理函数--监听用户下拉动作
  172. */
  173. onPullDownRefresh: function () {
  174. },
  175. /**
  176. * 页面上拉触底事件的处理函数
  177. */
  178. onReachBottom: function () {
  179. },
  180. /**
  181. * 用户点击右上角分享
  182. */
  183. onShareAppMessage: function () {
  184. }
  185. })