report.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. Page({
  6. data: {
  7. servant: {
  8. gohome: '0',
  9. walk: '1',
  10. walkDate: '', //可接单时间
  11. address: '',
  12. goHomeDate: '', //返乡时间
  13. goBackDate: '', //返程时间
  14. date: [{
  15. date: '1月18日',
  16. lunar: '廿七',
  17. type: [{
  18. title: '全天',
  19. checked: true
  20. }, {
  21. title: '白班',
  22. checked: false
  23. }, {
  24. title: '休息',
  25. checked: false
  26. }]
  27. }, {
  28. date: '1月19日',
  29. lunar: '廿八',
  30. type: [{
  31. title: '全天',
  32. checked: true
  33. }, {
  34. title: '白班',
  35. checked: false
  36. }, {
  37. title: '休息',
  38. checked: false
  39. }]
  40. }, {
  41. date: '1月20日',
  42. lunar: '廿九',
  43. type: [{
  44. title: '全天',
  45. checked: true
  46. }, {
  47. title: '白班',
  48. checked: false
  49. }, {
  50. title: '休息',
  51. checked: false
  52. }]
  53. }, {
  54. date: '1月21日',
  55. lunar: '除夕',
  56. type: [{
  57. title: '全天',
  58. checked: true
  59. }, {
  60. title: '白班',
  61. checked: false
  62. }, {
  63. title: '休息',
  64. checked: false
  65. }]
  66. }, {
  67. date: '1月22日',
  68. lunar: '春节',
  69. type: [{
  70. title: '全天',
  71. checked: true
  72. }, {
  73. title: '白班',
  74. checked: false
  75. }, {
  76. title: '休息',
  77. checked: false
  78. }]
  79. }, {
  80. date: '1月23日',
  81. lunar: '初二',
  82. type: [{
  83. title: '全天',
  84. checked: true
  85. }, {
  86. title: '白班',
  87. checked: false
  88. }, {
  89. title: '休息',
  90. checked: false
  91. }]
  92. }, {
  93. date: '1月24日',
  94. lunar: '初三',
  95. type: [{
  96. title: '全天',
  97. checked: true
  98. }, {
  99. title: '白班',
  100. checked: false
  101. }, {
  102. title: '休息',
  103. checked: false
  104. }]
  105. }, {
  106. date: '1月25日',
  107. lunar: '初四',
  108. type: [{
  109. title: '全天',
  110. checked: true
  111. }, {
  112. title: '白班',
  113. checked: false
  114. }, {
  115. title: '休息',
  116. checked: false
  117. }]
  118. }, {
  119. date: '1月26日',
  120. lunar: '初五',
  121. type: [{
  122. title: '全天',
  123. checked: true
  124. }, {
  125. title: '白班',
  126. checked: false
  127. }, {
  128. title: '休息',
  129. checked: false
  130. }]
  131. }, {
  132. date: '1月27日',
  133. lunar: '初六',
  134. type: [{
  135. title: '全天',
  136. checked: true
  137. }, {
  138. title: '白班',
  139. checked: false
  140. }, {
  141. title: '休息',
  142. checked: false
  143. }]
  144. }, {
  145. date: '1月28日',
  146. lunar: '初七',
  147. type: [{
  148. title: '全天',
  149. checked: true
  150. }, {
  151. title: '白班',
  152. checked: false
  153. }, {
  154. title: '休息',
  155. checked: false
  156. }]
  157. }],
  158. }
  159. },
  160. /**
  161. * 生命周期函数--监听页面加载
  162. */
  163. onLoad: function (options) {
  164. let userInfo = wx.getStorageSync('userInfo');
  165. if (userInfo) {} else {
  166. wx.navigateTo({
  167. url: '/pages/index/index',
  168. })
  169. }
  170. },
  171. saveNewYearReport() {
  172. let that = this;
  173. if (this.valid() == false) return;
  174. console.info(that.data.servant)
  175. wx.showModal({
  176. title: '提示',
  177. content: '请核对提交内容,确定提交吗?提交后无法修改',
  178. success: function (sm) {
  179. if (sm.confirm) {
  180. wx.showLoading({
  181. title: '提交中',
  182. });
  183. util.request(api.NewYearReport, that.data.servant, "POST").then(res => {
  184. wx.hideLoading();
  185. wx.showToast({
  186. title: '报备成功',
  187. duration: 2000
  188. });
  189. setTimeout(
  190. function () {
  191. wx.switchTab({
  192. url: '/pages/upgrade/my/my',
  193. })
  194. }, 3000
  195. );
  196. }).catch(res => {
  197. wx.hideLoading();
  198. wx.showToast({
  199. title: res.data.data,
  200. duration: 3000
  201. });
  202. })
  203. }
  204. }
  205. });
  206. },
  207. valid() {
  208. if (this.data.servant.gohome == '1' && (this.data.servant.address == '' || this.data.servant.goHomeDate == '' || this.data.servant.goBackDate == '' || this.data.servant.walkDate == "")) {
  209. wx.showToast({
  210. title: '请填写返乡居住地及时间',
  211. duration: 3000
  212. });
  213. return false;
  214. }
  215. if (this.data.servant.gohome == '1' && this.data.servant.goBackDate < this.data.servant.goHomeDate) {
  216. wx.showToast({
  217. title: '【返城】时间不能小于【返乡】时间',
  218. duration: 3000
  219. });
  220. return false;
  221. }
  222. return true;
  223. },
  224. radioChangeGoHome(e) {
  225. this.setData({
  226. 'servant.gohome': e.detail.value
  227. })
  228. if (e.detail.value) {
  229. this.setData({
  230. 'servant.walk': 1
  231. })
  232. }
  233. console.info(this.data.servant)
  234. },
  235. radioChangeWalk(e) {
  236. this.setData({
  237. 'servant.walk': e.detail.value
  238. })
  239. console.info(this.data.servant)
  240. },
  241. bindAddress(e) {
  242. this.setData({
  243. 'servant.address': e.detail.value
  244. })
  245. },
  246. bindGoHomeChange(e) {
  247. this.setData({
  248. 'servant.goHomeDate': e.detail.value
  249. })
  250. },
  251. bindGoBackChange(e) {
  252. this.setData({
  253. 'servant.goBackDate': e.detail.value
  254. })
  255. },
  256. bindWalkDateChange(e) {
  257. this.setData({
  258. 'servant.walkDate': e.detail.value
  259. })
  260. //小于选择的接单日期,全部设置为休息
  261. // var dates = this.data.servant.date;
  262. // var selected = this.data.servant.walkDate.substring(5).replace("-", "月") + "日";
  263. // if (selected.substring(0, 1) == "0")
  264. // selected = selected.substring(1, 5);
  265. // //console.info(selected)
  266. // dates.forEach(item => {
  267. // if (item.date <= selected)
  268. // item.type[2].checked = true;
  269. // })
  270. // this.setData({
  271. // 'servant.date': dates
  272. // });
  273. },
  274. radioDateChange(e) {
  275. let date = e.currentTarget.dataset.id;
  276. let title = e.detail.value;
  277. var dates = this.data.servant.date;
  278. dates.forEach(item => {
  279. if (item.date == date) {
  280. item.type.forEach(t => {
  281. t.checked = (t.title == title);
  282. })
  283. }
  284. });
  285. this.setData({
  286. 'servant.date': dates
  287. })
  288. },
  289. /**
  290. * 生命周期函数--监听页面初次渲染完成
  291. */
  292. onReady: function () {
  293. },
  294. /**
  295. * 生命周期函数--监听页面显示
  296. */
  297. onShow: function () {},
  298. /**
  299. * 生命周期函数--监听页面隐藏
  300. */
  301. onHide: function () {
  302. },
  303. /**
  304. * 生命周期函数--监听页面卸载
  305. */
  306. onUnload: function () {
  307. },
  308. /**
  309. * 页面相关事件处理函数--监听用户下拉动作
  310. */
  311. onPullDownRefresh: function () {
  312. },
  313. /**
  314. * 页面上拉触底事件的处理函数
  315. */
  316. onReachBottom: function () {
  317. },
  318. /**
  319. * 用户点击右上角分享
  320. */
  321. onShareAppMessage: function () {
  322. }
  323. })