addXnb.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. import moment from 'moment'
  6. Page({
  7. data: {
  8. startDate: '',
  9. endDate: '',
  10. max: 5,
  11. fileList: [],
  12. date: moment(new Date()).format('YYYY-MM'),
  13. currentDate: new Date().getTime(),
  14. minDate: new Date('2022-01-01').getTime(),
  15. pickerShow:false,
  16. type:'',
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. },
  23. goDetail() {
  24. wx.navigateTo({
  25. url: '/pages/upgrade/xnbInfo/xnbInfo',
  26. })
  27. },
  28. startPicker(){
  29. this.setData({
  30. pickerShow:true,
  31. type:'start'
  32. });
  33. },
  34. endPicker(){
  35. this.setData({
  36. pickerShow:true,
  37. type:'end'
  38. });
  39. },
  40. onCancel(){
  41. this.setData({
  42. pickerShow:false
  43. })
  44. },
  45. onConfirm(e){
  46. console.log(e);
  47. let date=moment(e.detail).format('YYYY-MM');
  48. if(this.data.type=='start'){
  49. this.setData({
  50. startDate:date,
  51. pickerShow:false
  52. });
  53. }else{
  54. this.setData({
  55. endDate:date,
  56. pickerShow:false
  57. });
  58. }
  59. },
  60. getDetail() {
  61. util.request(api.getDetail, {
  62. id: this.data.id
  63. }, 'GET').then(res => {
  64. if (res.errno === 0) {
  65. this.setData({
  66. isFinish: res.data.feedbackComment == '' ? false : true,
  67. feedbackInfo: res.data,
  68. content: res.data.feedbackComment
  69. });
  70. if (this.data.isFinish) {
  71. let imgs = res.data.feedbackImgs;
  72. if (imgs == '') {
  73. this.setData({
  74. uploadShow: false,
  75. });
  76. } else {
  77. let list = imgs.split(',');
  78. let current = [];
  79. list.forEach(item => {
  80. let obj = {
  81. url: item
  82. };
  83. current.push(obj);
  84. });
  85. this.setData({
  86. fileList: current,
  87. max: current.length,
  88. });
  89. }
  90. }
  91. }
  92. });
  93. },
  94. deleteImage(event) {
  95. const { fileList = [] } = this.data;
  96. fileList.splice(event.detail.index, 1)
  97. this.setData({
  98. fileList: fileList
  99. })
  100. let urls = [];
  101. fileList.forEach(function (e) {
  102. urls.push(e.url);
  103. })
  104. this.setData({
  105. "pictures": urls
  106. })
  107. },
  108. afterRead(event) {
  109. console.log(event);
  110. const { file } = event.detail
  111. let that = this;
  112. const uploadTask = wx.uploadFile({
  113. url: api.StorageUpload(),
  114. filePath: file.url,
  115. name: 'file',
  116. success: function (res) {
  117. console.log(res);
  118. var _res = JSON.parse(res.data);
  119. if (_res.errno === 0) {
  120. var url = _res.data.fileUrl;
  121. const { fileList = [] } = that.data;
  122. fileList.push({ ...file, url: url });
  123. that.setData({
  124. fileList: fileList
  125. })
  126. }
  127. },
  128. fail: function (e) {
  129. wx.showModal({
  130. title: '错误',
  131. content: '上传失败',
  132. showCancel: false
  133. })
  134. },
  135. })
  136. },
  137. submit() {
  138. if (this.data.fileList.length == 0) {
  139. wx.showToast({
  140. title: '请上传新农保照片',
  141. icon: 'none'
  142. });
  143. } else if (
  144. this.data.startDate == ''
  145. ) {
  146. wx.showToast({
  147. title: '请选择开始时间',
  148. icon: 'none'
  149. });
  150. } else if (
  151. this.data.endDate == ''
  152. ) {
  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. },
  216. onHide: function () {
  217. },
  218. onUnload: function () {
  219. },
  220. /**
  221. * 页面相关事件处理函数--监听用户下拉动作
  222. */
  223. onPullDownRefresh: function () {
  224. },
  225. /**
  226. * 页面上拉触底事件的处理函数
  227. */
  228. onReachBottom: function () {
  229. },
  230. /**
  231. * 用户点击右上角分享
  232. */
  233. onShareAppMessage: function () {
  234. },
  235. })