leavepost.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. const app = getApp()
  2. const util = require("../../../utils/util");
  3. const mallapi = require('../../../api/mall.js');
  4. var dateTimePicker = require('../../../utils/dateTimePicker.js')
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. leaveTypeList: [],
  11. subTypeList: [],
  12. arrnameA: ['请选择'],
  13. arrnameB: [],
  14. chooseLeaveTypeIndex: 0,
  15. chooseLeaveTypeValue: null,
  16. chooseLeaveSubIndex: 0,
  17. chooseLeaveSubValue: null,
  18. leaveStartTime: null,
  19. leaveEndTime: null,
  20. leaveReason: null,
  21. dateTimeKS: '', //插件日期
  22. dateTimeJS: '', //插件日期
  23. dateTimeArray: '', //插件日期
  24. // startT: '',
  25. picUrls: [],
  26. files: [],
  27. },
  28. bindPickerChange: function (e) {
  29. console.log('picker发送选择改变,携带值为', e.detail.value)
  30. let index = e.detail.value - 1;
  31. if (index == -1) {
  32. return;
  33. }
  34. let temparr = this.data.leaveTypeList[index].subList;
  35. let tempB = [];
  36. temparr.forEach(c => {
  37. tempB.push(c.typeName);
  38. })
  39. this.setData({
  40. chooseLeaveTypeValue: this.data.leaveTypeList[index].id,
  41. chooseLeaveTypeIndex: index + 1,
  42. subTypeList: temparr,
  43. arrnameB: tempB,
  44. chooseLeaveSubValue: temparr[0].id,
  45. })
  46. },
  47. bindPickerChangeB: function (e) {
  48. console.log('pickerB发送选择改变,携带值为', e.detail.value)
  49. this.setData({
  50. chooseLeaveSubValue: this.data.subTypeList[e.detail.value].id,
  51. chooseLeaveSubIndex:e.detail.value
  52. })
  53. },
  54. changeDateTime(e) {
  55. //获取时间日期
  56. console.log(e.detail.value);
  57. let leaveStartTime = dateTimePicker.formatPickerDateTime(this.data.dateTimeArray, e.detail.value)
  58. this.setData({
  59. dateTimeKS:e.detail.value,
  60. leaveStartTime: leaveStartTime,
  61. })
  62. },
  63. changeDateTimeEnd(e) {
  64. //获取时间日期
  65. console.log(e.detail.value);
  66. let leaveEndTime = dateTimePicker.formatPickerDateTime(this.data.dateTimeArray, e.detail.value)
  67. this.setData({
  68. dateTimeJS:e.detail.value,
  69. leaveEndTime: leaveEndTime,
  70. })
  71. },
  72. bindleaveReason(e){
  73. this.setData({
  74. leaveReason: e.detail.value,
  75. })
  76. },
  77. previewImage: function (e) {
  78. wx.previewImage({
  79. current: e.currentTarget.id, // 当前显示图片的http链接
  80. urls: this.data.files // 需要预览的图片http链接列表
  81. })
  82. },
  83. chooseImage: function (e) {
  84. if (this.data.files.length >= 4) {
  85. util.showErrorToast('只能上传四张图片')
  86. return false;
  87. }
  88. var that = this;
  89. wx.chooseImage({
  90. count: 1,
  91. sizeType: ['original', 'compressed'],
  92. sourceType: ['album', 'camera'],
  93. success: function (res) {
  94. that.setData({
  95. files: that.data.files.concat(res.tempFilePaths)
  96. });
  97. console.info(res.tempFilePaths[0])
  98. that.upload(res)
  99. }
  100. })
  101. },
  102. upload: function (res) {
  103. var that = this;
  104. const uploadTask = wx.uploadFile({
  105. url: mallapi.StorageUpload(),
  106. filePath: res.tempFilePaths[0],
  107. name: 'file',
  108. formData:{'X-JZ-Token':wx.getStorageSync('token')},
  109. success: function (res) {
  110. var _res = JSON.parse(res.data);
  111. if (_res.errno === 0) {
  112. var url = _res.data.fileUrl
  113. var pics = that.data.picUrls;
  114. pics.push(url);
  115. that.setData({
  116. hasPicture: true,
  117. picUrls: pics
  118. })
  119. }
  120. },
  121. fail: function (e) {
  122. wx.showModal({
  123. title: '错误',
  124. content: '上传失败',
  125. showCancel: false
  126. })
  127. },
  128. })
  129. // uploadTask.onProgressUpdate((res) => {
  130. // console.log('上传进度', res.progress)
  131. // console.log('已经上传的数据长度', res.totalBytesSent)
  132. // console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)
  133. // })
  134. },
  135. commitLeave() {
  136. if (this.data.chooseLeaveSubValue == null || this.data.chooseLeaveSubValue == '') {
  137. this.myshowtost("请选择请假子类型")
  138. return;
  139. }
  140. if (this.data.leaveReason == null || this.data.leaveReason == '') {
  141. this.myshowtost("请输入请假原因")
  142. return;
  143. }
  144. let req = {
  145. "leaveTypeId": this.data.chooseLeaveSubValue,
  146. // "workerNo":"s0000464",
  147. "leaveStartTime": this.data.leaveStartTime,
  148. "leaveEndTime": this.data.leaveEndTime,
  149. "leaveReason": this.data.leaveReason,
  150. "leaveImages": this.data.picUrls.join(',')
  151. }
  152. console.log(req);
  153. let that=this;
  154. util.request(mallapi.SubmitLeave,req,"POST").then(function (res) {
  155. if (res.errno === 0) {
  156. that.myshowtost("提交成功")
  157. wx.navigateBack({ });
  158. }else{
  159. that.myshowtost(res.errmsg)
  160. }
  161. });
  162. },
  163. /**
  164. * 生命周期函数--监听页面加载
  165. */
  166. onLoad: function (options) {
  167. this.getLeaveTypeList();
  168. var start =util.formatDate(new Date())+" 00:00"; //'2022-08-27 00:00:00'
  169. var obj = dateTimePicker.dateTimePicker(2022, 2030, start);
  170. this.setData({
  171. dateTimeKS: obj.dateTime,
  172. dateTimeJS: obj.dateTime,
  173. dateTimeArray: obj.dateTimeArray
  174. });
  175. var leaveStartTime = dateTimePicker.formatPickerDateTime(this.data.dateTimeArray, this.data.dateTimeKS)
  176. this.setData({
  177. leaveStartTime: leaveStartTime,
  178. leaveEndTime: leaveStartTime,
  179. })
  180. },
  181. getLeaveTypeList() {
  182. let that = this;
  183. util.request(mallapi.GetLeaveAllType, {}, 'GET').then(function (res) {
  184. if (res.errno === 0) {
  185. let arrname = ['请选择'];
  186. res.data.forEach(c => {
  187. arrname.push(c.typeName);
  188. })
  189. that.setData({
  190. leaveTypeList: res.data,
  191. arrnameA: arrname
  192. });
  193. }
  194. });
  195. },
  196. /**
  197. * 生命周期函数--监听页面初次渲染完成
  198. */
  199. onReady: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面显示
  203. */
  204. onShow: function () {
  205. },
  206. /**
  207. * 生命周期函数--监听页面隐藏
  208. */
  209. onHide: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面卸载
  213. */
  214. onUnload: function () {
  215. },
  216. /**
  217. * 页面上拉触底事件的处理函数
  218. */
  219. onReachBottom: function () {
  220. },
  221. myshowtost: function (v) {
  222. wx.showToast({
  223. title: v,
  224. icon: 'none',
  225. duration: 2000
  226. })
  227. },
  228. })