report.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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: '2月6日',
  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: '2月7日',
  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: '2月8日',
  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: '2月9日',
  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: '2月10日',
  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: '2月11日',
  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: '2月12日',
  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: '2月13日',
  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: '2月14日',
  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: '2月15日',
  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: '2月16日',
  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. */
  164. onLoad: function (options) {
  165. let userInfo = wx.getStorageSync('userInfo');
  166. if (userInfo) {} else {
  167. wx.navigateTo({
  168. url: '/pages/index/index',
  169. })
  170. }
  171. },
  172. saveNewYearReport() {
  173. let that = this;
  174. if (this.valid() == false) return;
  175. console.info(that.data.servant)
  176. wx.showModal({
  177. title: '提示',
  178. content: '请核对提交内容,确定提交吗?提交后无法修改',
  179. success: function (sm) {
  180. if (sm.confirm) {
  181. wx.showLoading({
  182. title: '提交中',
  183. });
  184. util.request(api.NewYearReport, that.data.servant, "POST").then(res => {
  185. wx.hideLoading();
  186. wx.showToast({
  187. title: '报备成功',
  188. duration: 2000
  189. });
  190. setTimeout(
  191. function () {
  192. wx.switchTab({
  193. url: '/pages/upgrade/my/my',
  194. })
  195. }, 3000
  196. );
  197. }).catch(res => {
  198. wx.hideLoading();
  199. wx.showToast({
  200. title: res.data.data,
  201. duration: 3000
  202. });
  203. })
  204. }
  205. }
  206. });
  207. },
  208. valid() {
  209. if (this.data.servant.gohome == '1' && (this.data.servant.address == '' || this.data.servant.goHomeDate == '' || this.data.servant.goBackDate == '' || this.data.servant.walkDate == "")) {
  210. wx.showToast({
  211. title: '请填写返乡居住地及时间',
  212. duration: 3000
  213. });
  214. return false;
  215. }
  216. if (this.data.servant.gohome == '1' && this.data.servant.goBackDate < this.data.servant.goHomeDate) {
  217. wx.showToast({
  218. title: '【返城】时间不能小于【返乡】时间',
  219. duration: 3000
  220. });
  221. return false;
  222. }
  223. return true;
  224. },
  225. radioChangeGoHome(e) {
  226. this.setData({
  227. 'servant.gohome': e.detail.value
  228. })
  229. if (e.detail.value) {
  230. this.setData({
  231. 'servant.walk': 1
  232. })
  233. }
  234. console.info(this.data.servant)
  235. },
  236. radioChangeWalk(e) {
  237. this.setData({
  238. 'servant.walk': e.detail.value
  239. })
  240. console.info(this.data.servant)
  241. },
  242. bindAddress(e) {
  243. this.setData({
  244. 'servant.address': e.detail.value
  245. })
  246. },
  247. bindGoHomeChange(e) {
  248. this.setData({
  249. 'servant.goHomeDate': e.detail.value
  250. })
  251. },
  252. bindGoBackChange(e) {
  253. this.setData({
  254. 'servant.goBackDate': e.detail.value
  255. })
  256. },
  257. bindWalkDateChange(e) {
  258. this.setData({
  259. 'servant.walkDate': e.detail.value
  260. })
  261. //小于选择的接单日期,全部设置为休息
  262. // var dates = this.data.servant.date;
  263. // var selected = this.data.servant.walkDate.substring(5).replace("-", "月") + "日";
  264. // if (selected.substring(0, 1) == "0")
  265. // selected = selected.substring(1, 5);
  266. // //console.info(selected)
  267. // dates.forEach(item => {
  268. // if (item.date <= selected)
  269. // item.type[2].checked = true;
  270. // })
  271. // this.setData({
  272. // 'servant.date': dates
  273. // });
  274. },
  275. radioDateChange(e) {
  276. let date = e.currentTarget.dataset.id;
  277. let title = e.detail.value;
  278. var dates = this.data.servant.date;
  279. dates.forEach(item => {
  280. if (item.date == date) {
  281. item.type.forEach(t => {
  282. t.checked = (t.title == title);
  283. })
  284. }
  285. });
  286. this.setData({
  287. 'servant.date': dates
  288. })
  289. },
  290. /**
  291. * 生命周期函数--监听页面初次渲染完成
  292. */
  293. onReady: function () {
  294. },
  295. /**
  296. * 生命周期函数--监听页面显示
  297. */
  298. onShow: function () {},
  299. /**
  300. * 生命周期函数--监听页面隐藏
  301. */
  302. onHide: function () {
  303. },
  304. /**
  305. * 生命周期函数--监听页面卸载
  306. */
  307. onUnload: function () {
  308. },
  309. /**
  310. * 页面相关事件处理函数--监听用户下拉动作
  311. */
  312. onPullDownRefresh: function () {
  313. },
  314. /**
  315. * 页面上拉触底事件的处理函数
  316. */
  317. onReachBottom: function () {
  318. },
  319. /**
  320. * 用户点击右上角分享
  321. */
  322. onShareAppMessage: function () {
  323. }
  324. })