pointapply.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. // pages/pointapply/pointapply.js
  2. var BASEURL = require('../../utils/wxconstant.js')
  3. var baseUrl = BASEURL.BaseUrl()
  4. var baseutils = require('../../utils/baseUtils.js')
  5. var netUtil = require('../../utils/network.js')
  6. var dateutil = require('../../utils/DateTime.js')
  7. var myInfoData = wx.getStorageSync('myInfoData')
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. applyJob:'',
  14. applyName:'',
  15. applyStatus:'待审批',
  16. applyTime:'2018-09-20',
  17. itemNorm: { normItem: '请选择' },//所选规则数据
  18. applyReason:'',
  19. CotegoryArray:[],
  20. Cotegory:[],
  21. invoicesStatus: 0,//单据状态1:待审批,2:已审批,3:不同意?
  22. isDetails: false, //加分申请详情时状态
  23. applyNorm:'',
  24. detailsData:{} ,
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. var that = this
  31. var isDetails = options.getisDetails
  32. var itemdata
  33. if (options.getItemdata){
  34. itemdata = JSON.parse(options.getItemdata)
  35. that.setData({
  36. isDetails: isDetails
  37. })
  38. }
  39. console.log('itemdata', itemdata)
  40. that.initView(itemdata) //修改标题
  41. that.getCotegory()//获得分类列表
  42. // that.getDept()//获取公司部门列表
  43. },
  44. bindPickerChange: function (e) {
  45. var that = this
  46. console.log('picker发送选择改变,携带值为', e.detail)
  47. var categoryId = that.data.Cotegory[e.detail.value].categoryId
  48. if (categoryId){
  49. wx.navigateTo({
  50. url: '../selectnorm/selectnorm' + '?getcategoryId=' + categoryId + '&getAddType=' + true,
  51. })
  52. }
  53. },
  54. getDept:function(){
  55. var that = this
  56. var data = { parentId:0}
  57. var url = baseUrl + BASEURL.getUrl.getDept
  58. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  59. }, function (res) {
  60. wx.showToast({
  61. title: '加载数据失败',
  62. icon: 'none',
  63. duration: 2000
  64. })
  65. })
  66. },
  67. getCotegory:function(){
  68. var that = this
  69. var data = { parentId: 0 }
  70. var url = baseUrl + BASEURL.getUrl.getCotegory
  71. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  72. if(res.data.success && res.data.data){
  73. that.setData({
  74. Cotegory:res.data.data
  75. })
  76. var array = []
  77. for (var i = 0; i < res.data.data.length; i++){
  78. array[i] = res.data.data[i].categoryName
  79. if (i == res.data.data.length-1){
  80. console.log('array', array)
  81. that.setData({
  82. CotegoryArray:array
  83. })
  84. }
  85. }
  86. }
  87. }, function (res) {
  88. wx.showToast({
  89. title: '加载数据失败',
  90. icon: 'none',
  91. duration: 2000
  92. })
  93. })
  94. },
  95. initView: function (itemdata){
  96. var that = this;
  97. var isDetails = that.data.isDetails
  98. var title
  99. if (isDetails) {
  100. title = '加分申请详情'
  101. if (itemdata && itemdata.invoicesId){
  102. var invoicesStatus = itemdata.invoicesStatus
  103. var applyStatus
  104. if (invoicesStatus == 0){
  105. applyStatus = '待审批'
  106. } else if (invoicesStatus == 1){
  107. applyStatus = '已审批'
  108. }else{
  109. applyStatus = '未通过'
  110. }
  111. that.setData({
  112. applyStatus: applyStatus,
  113. invoicesStatus: invoicesStatus,
  114. })
  115. that.initDetailsView(itemdata.invoicesId)
  116. }
  117. } else {
  118. title = '积分申请'
  119. that.setData({
  120. applyJob: myInfoData.station,
  121. applyName: myInfoData.empName
  122. })
  123. }
  124. that.setData({
  125. mername: title
  126. })
  127. wx.setNavigationBarTitle({
  128. title: that.data.mername
  129. })
  130. var nowTime = dateutil.getComDate(new Date,'yy-mm-dd')
  131. that.setData({
  132. applyTime: nowTime
  133. })
  134. // console.log('nowTime', nowTime)
  135. },
  136. /**
  137. * 提交申请
  138. */
  139. applySubmit: function (event) {
  140. var that = this
  141. var object = event.detail.value
  142. console.log(object)
  143. var applyName = object.applyName
  144. var applyJob = object.applyJob
  145. var itemNorm = that.data.itemNorm
  146. var applyReason = object.applyReason
  147. var applyName = object.applyName
  148. if (!itemNorm.normId) {
  149. that.comToast('请选择申请标准')
  150. return
  151. }
  152. if (!applyReason){
  153. that.comToast('请输入申请事由')
  154. return
  155. }
  156. var data = {
  157. openid: wx.getStorageSync('openid'),
  158. reasons: applyReason,
  159. normId: itemNorm.normId
  160. }
  161. var url = baseUrl + BASEURL.getUrl.saveAddInvoices
  162. netUtil.requestLoading(url, data, '正在加载数据...', 'POST', function (res) {
  163. if(res.data.success){
  164. that.comToast("提交成功")
  165. setTimeout(function(){
  166. wx.navigateBack({
  167. })
  168. },1000)
  169. }
  170. }, function (res) {
  171. wx.showToast({
  172. title: '加载数据失败',
  173. icon: 'none',
  174. duration: 2000
  175. })
  176. })
  177. },
  178. comToast: function (title) {
  179. wx.showToast({
  180. title: title,
  181. icon: 'none',
  182. duration: 2000
  183. })
  184. },
  185. /**
  186. * 根据invoicesId 获取加分单据详情数据
  187. */
  188. initDetailsView: function (invoicesId){
  189. var that =this
  190. var data = { invoicesId: invoicesId}
  191. var url = baseUrl + BASEURL.getUrl.getInvoices
  192. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  193. if (res.data.success && res.data.data){
  194. that.setData({
  195. detailsData: res.data.data,
  196. applyTime: res.data.data.invoicesDate,
  197. applyName: res.data.data.fillName,
  198. applyNorm: res.data.data.normName,
  199. applyReason: res.data.data.reasons,
  200. })
  201. }
  202. }, function (res) {
  203. wx.showToast({
  204. title: '加载数据失败',
  205. icon: 'none',
  206. duration: 2000
  207. })
  208. })
  209. },
  210. /**
  211. * 撤回 : 目前做的是删除单据操作
  212. */
  213. cancelApply:function(){
  214. var that = this
  215. var data = { invoicesId: that.data.detailsData.invoicesId }
  216. var url = baseUrl + BASEURL.getUrl.withdrawInvoices
  217. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  218. if(res.data.success && res.data.data){
  219. that.comToast(res.data.data)
  220. setTimeout(function () {
  221. wx.navigateBack({
  222. })
  223. }, 1000)
  224. }
  225. }, function (res) {
  226. wx.showToast({
  227. title: '加载数据失败',
  228. icon: 'none',
  229. duration: 2000
  230. })
  231. })
  232. },
  233. /**
  234. * 生命周期函数--监听页面初次渲染完成
  235. */
  236. onReady: function () {
  237. },
  238. /**
  239. * 生命周期函数--监听页面显示
  240. */
  241. onShow: function () {
  242. var that = this
  243. that.setData({
  244. applyNorm:that.data.itemNorm.normItem
  245. })
  246. },
  247. /**
  248. * 生命周期函数--监听页面隐藏
  249. */
  250. onHide: function () {
  251. },
  252. /**
  253. * 生命周期函数--监听页面卸载
  254. */
  255. onUnload: function () {
  256. },
  257. /**
  258. * 页面相关事件处理函数--监听用户下拉动作
  259. */
  260. onPullDownRefresh: function () {
  261. },
  262. /**
  263. * 页面上拉触底事件的处理函数
  264. */
  265. onReachBottom: function () {
  266. },
  267. /**
  268. * 用户点击右上角分享
  269. */
  270. onShareAppMessage: function () {
  271. }
  272. })