addXnb.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. const app = getApp()
  2. const util = require("../../../utils/util");
  3. const api = require('../../../api/api.js');
  4. const user = require('../../../utils/user.js');
  5. const formatDate=require("../../../utils/util")
  6. import moment from 'moment'
  7. Page({
  8. data: {
  9. startDate: '',
  10. endDate: '',
  11. max: 5,
  12. fileList: [],
  13. date: moment(new Date()).format('YYYY-MM'),
  14. currentDate: new Date().getTime(),
  15. minDate: new Date('2022-01-01').getTime(),
  16. pickerShow:false,
  17. type:'',
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. },
  24. goDetail() {
  25. wx.navigateTo({
  26. url: '/pages/upgrade/xnbInfo/xnbInfo',
  27. })
  28. },
  29. /* startPicker(){
  30. this.setData({
  31. pickerShow:true,
  32. type:'start'
  33. });
  34. }, */
  35. /* endPicker(){
  36. this.setData({
  37. pickerShow:true,
  38. type:'end'
  39. });
  40. }, */
  41. /* onCancel(){
  42. this.setData({
  43. pickerShow:false
  44. })
  45. }, */
  46. /* onConfirm(e){
  47. console.log(e);
  48. let date=moment(e.detail).format('YYYY-MM');
  49. if(this.data.type=='start'){
  50. this.setData({
  51. startDate:date,
  52. pickerShow:false
  53. });
  54. }else{
  55. this.setData({
  56. endDate:date,
  57. pickerShow:false
  58. });
  59. }
  60. }, */
  61. getDate(){
  62. let today=new Date()
  63. // console.log(formatDate.formatDate(today));
  64. let startTime=formatDate.formatDate(today)
  65. const year=today.getFullYear()
  66. // console.log(year);
  67. let endTime=`${year}-12-31`
  68. // console.log(endTime);
  69. this.setData({
  70. startDate:startTime,
  71. endDate:endTime
  72. })
  73. },
  74. getDetail() {
  75. util.request(api.getDetail, {
  76. id: this.data.id
  77. }, 'GET').then(res => {
  78. if (res.errno === 0) {
  79. this.setData({
  80. isFinish: res.data.feedbackComment == '' ? false : true,
  81. feedbackInfo: res.data,
  82. content: res.data.feedbackComment
  83. });
  84. if (this.data.isFinish) {
  85. let imgs = res.data.feedbackImgs;
  86. if (imgs == '') {
  87. this.setData({
  88. uploadShow: false,
  89. });
  90. } else {
  91. let list = imgs.split(',');
  92. let current = [];
  93. list.forEach(item => {
  94. let obj = {
  95. url: item
  96. };
  97. current.push(obj);
  98. });
  99. this.setData({
  100. fileList: current,
  101. max: current.length,
  102. });
  103. }
  104. }
  105. }
  106. });
  107. },
  108. deleteImage(event) {
  109. const { fileList = [] } = this.data;
  110. fileList.splice(event.detail.index, 1)
  111. this.setData({
  112. fileList: fileList
  113. })
  114. let urls = [];
  115. fileList.forEach(function (e) {
  116. urls.push(e.url);
  117. })
  118. this.setData({
  119. "pictures": urls
  120. })
  121. },
  122. afterRead(event) {
  123. console.log(event);
  124. const { file } = event.detail
  125. let that = this;
  126. const uploadTask = wx.uploadFile({
  127. url: api.StorageUpload(),
  128. filePath: file.url,
  129. name: 'file',
  130. success: function (res) {
  131. console.log(res);
  132. var _res = JSON.parse(res.data);
  133. if (_res.errno === 0) {
  134. var url = _res.data.fileUrl;
  135. const { fileList = [] } = that.data;
  136. fileList.push({ ...file, url: url });
  137. that.setData({
  138. fileList: fileList
  139. })
  140. }
  141. },
  142. fail: function (e) {
  143. wx.showModal({
  144. title: '错误',
  145. content: '上传失败',
  146. showCancel: false
  147. })
  148. },
  149. })
  150. },
  151. submit() {
  152. if (this.data.fileList.length == 0) {
  153. wx.showToast({
  154. title: '请上传新农保照片',
  155. icon: 'none'
  156. });
  157. } else {
  158. let imgs = [];
  159. this.data.fileList.forEach(item => {
  160. imgs.push(item.url)
  161. });
  162. util.request(api.uploadNewFarmer, {
  163. effectStartMonth:this.data.startDate,
  164. effectEndMonth:this.data.endDate,
  165. newFarmerList:imgs
  166. }, 'POST').then(res => {
  167. if (res.errno === 0) {
  168. // wx.showToast({
  169. // title: '提交成功',
  170. // icon:'none'
  171. // });
  172. wx.showModal({
  173. title: '提醒',
  174. content: '提交成功',
  175. showCancel: false, //是否显示取消按钮
  176. success: function (res) {
  177. wx.navigateBack({
  178. delta: 1,
  179. });
  180. }
  181. })
  182. }else{
  183. wx.showToast({
  184. title: res.errmsg,
  185. icon:'none'
  186. })
  187. }
  188. });
  189. }
  190. },
  191. onReachBottom() {
  192. // if (this.data.totalPages > this.data.page) {
  193. // this.setData({
  194. // page: this.data.page + 1
  195. // });
  196. // this.getGoodsList();
  197. // } else {
  198. // wx.showToast({
  199. // title: '没有更多商品了',
  200. // icon: 'none',
  201. // duration: 2000
  202. // });
  203. // return false;
  204. // }
  205. },
  206. /**
  207. * 生命周期函数--监听页面初次渲染完成
  208. */
  209. onReady: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面显示
  213. */
  214. onShow: function () {
  215. this.getDate()
  216. },
  217. onHide: function () {
  218. },
  219. onUnload: function () {
  220. },
  221. /**
  222. * 页面相关事件处理函数--监听用户下拉动作
  223. */
  224. onPullDownRefresh: function () {
  225. },
  226. /**
  227. * 页面上拉触底事件的处理函数
  228. */
  229. onReachBottom: function () {
  230. },
  231. /**
  232. * 用户点击右上角分享
  233. */
  234. onShareAppMessage: function () {
  235. },
  236. })