pointapply.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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:'',
  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.getDept()//获取公司部门列表
  42. },
  43. bindPickerChange: function (e) {
  44. var that = this
  45. console.log('picker发送选择改变,携带值为', e.detail)
  46. var categoryId = that.data.Cotegory[e.detail.value].categoryId
  47. if (categoryId){
  48. wx.navigateTo({
  49. url: '../selectnorm/selectnorm' + '?getcategoryId=' + categoryId + '&getAddType=' + true,
  50. })
  51. }
  52. },
  53. getDept:function(){
  54. var that = this
  55. var data = { parentId:0}
  56. var url = baseUrl + BASEURL.getUrl.getDept
  57. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  58. }, function (res) {
  59. wx.showToast({
  60. title: '加载数据失败',
  61. icon: 'none',
  62. duration: 2000
  63. })
  64. })
  65. },
  66. getCotegory:function(){
  67. var that = this
  68. var data = { parentId: 0 }
  69. var url = baseUrl + BASEURL.getUrl.getCotegory
  70. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  71. if(res.data.success && res.data.data){
  72. that.setData({
  73. Cotegory:res.data.data
  74. })
  75. var array = []
  76. for (var i = 0; i < res.data.data.length; i++){
  77. array[i] = res.data.data[i].categoryName
  78. if (i == res.data.data.length-1){
  79. console.log('array', array)
  80. that.setData({
  81. CotegoryArray:array
  82. })
  83. }
  84. }
  85. }
  86. }, function (res) {
  87. wx.showToast({
  88. title: '加载数据失败',
  89. icon: 'none',
  90. duration: 2000
  91. })
  92. })
  93. },
  94. initView: function (itemdata){
  95. var that = this;
  96. var isDetails = that.data.isDetails
  97. var title
  98. if (isDetails) {
  99. title = '加分申请详情'
  100. if (itemdata && itemdata.invoicesId){
  101. var invoicesStatus = itemdata.invoicesStatus
  102. var applyStatus
  103. if (invoicesStatus == 0){
  104. applyStatus = '待审批'
  105. } else if (invoicesStatus == 1){
  106. applyStatus = '已审批'
  107. }else{
  108. applyStatus = '未通过'
  109. }
  110. that.setData({
  111. applyStatus: applyStatus,
  112. invoicesStatus: invoicesStatus,
  113. })
  114. that.initDetailsView(itemdata.invoicesId)
  115. }
  116. } else {
  117. that.getCotegory()//获得分类列表
  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. applyJob: res.data.data.fillStation
  201. })
  202. }
  203. }, function (res) {
  204. wx.showToast({
  205. title: '加载数据失败',
  206. icon: 'none',
  207. duration: 2000
  208. })
  209. })
  210. },
  211. /**
  212. * 撤回 : 目前做的是删除单据操作
  213. */
  214. cancelApply:function(){
  215. var that = this
  216. var data = { invoicesId: that.data.detailsData.invoicesId }
  217. var url = baseUrl + BASEURL.getUrl.withdrawInvoices
  218. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  219. if(res.data.success && res.data.data){
  220. that.comToast(res.data.data)
  221. setTimeout(function () {
  222. wx.navigateBack({
  223. })
  224. }, 1000)
  225. }
  226. }, function (res) {
  227. wx.showToast({
  228. title: '加载数据失败',
  229. icon: 'none',
  230. duration: 2000
  231. })
  232. })
  233. },
  234. /**
  235. * 生命周期函数--监听页面初次渲染完成
  236. */
  237. onReady: function () {
  238. },
  239. /**
  240. * 生命周期函数--监听页面显示
  241. */
  242. onShow: function () {
  243. var that = this
  244. that.setData({
  245. applyNorm:that.data.itemNorm.normItem
  246. })
  247. },
  248. /**
  249. * 生命周期函数--监听页面隐藏
  250. */
  251. onHide: function () {
  252. },
  253. /**
  254. * 生命周期函数--监听页面卸载
  255. */
  256. onUnload: function () {
  257. },
  258. /**
  259. * 页面相关事件处理函数--监听用户下拉动作
  260. */
  261. onPullDownRefresh: function () {
  262. },
  263. /**
  264. * 页面上拉触底事件的处理函数
  265. */
  266. onReachBottom: function () {
  267. },
  268. /**
  269. * 用户点击右上角分享
  270. */
  271. onShareAppMessage: function () {
  272. }
  273. })