pointapply.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. addPoints:'',
  18. itemNorm: { normItem: '请选择', normScore:'' },//所选规则数据
  19. applyReason:'',
  20. CotegoryArray:[],
  21. Cotegory:[],
  22. invoicesStatus: 1,//单据状态1:待审批,2:已审批,3:不同意?
  23. isDetails: false, //加分申请详情时状态
  24. applyNorm:'',
  25. detailsData:{} ,
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. var that = this
  32. var isDetails = options.getisDetails
  33. var itemdata
  34. if (options.getItemdata){
  35. itemdata = JSON.parse(options.getItemdata)
  36. that.setData({
  37. isDetails: isDetails
  38. })
  39. }
  40. console.log('itemdata', itemdata)
  41. that.initView(itemdata) //修改标题
  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 == 1){
  105. applyStatus = '待审批'
  106. } else if (invoicesStatus == 2){
  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. that.getCotegory()//获得分类列表
  119. title = '积分申请'
  120. that.setData({
  121. applyJob: myInfoData.station,
  122. applyName: myInfoData.empName
  123. })
  124. }
  125. that.setData({
  126. mername: title
  127. })
  128. wx.setNavigationBarTitle({
  129. title: that.data.mername
  130. })
  131. var nowTime = dateutil.getComDate(new Date,'yy-mm-dd')
  132. that.setData({
  133. applyTime: nowTime
  134. })
  135. // console.log('nowTime', nowTime)
  136. },
  137. /**
  138. * 提交申请
  139. */
  140. applySubmit: function (event) {
  141. var that = this
  142. var object = event.detail.value
  143. console.log(object)
  144. var applyName = object.applyName
  145. var applyJob = object.applyJob
  146. var itemNorm = that.data.itemNorm
  147. var applyReason = object.applyReason
  148. var applyName = object.applyName
  149. if (!itemNorm.normId) {
  150. that.comToast('请选择申请标准')
  151. return
  152. }
  153. if (!applyReason){
  154. that.comToast('请输入申请事由')
  155. return
  156. }
  157. var data = {
  158. openid: wx.getStorageSync('openid'),
  159. reasons: applyReason,
  160. normId: itemNorm.normId
  161. }
  162. var url = baseUrl + BASEURL.getUrl.saveAddInvoices
  163. netUtil.requestLoading(url, data, '正在加载数据...', 'POST', function (res) {
  164. if(res.data.success){
  165. that.comToast("提交成功")
  166. setTimeout(function(){
  167. wx.navigateBack({
  168. })
  169. },1000)
  170. }
  171. }, function (res) {
  172. wx.showToast({
  173. title: '加载数据失败',
  174. icon: 'none',
  175. duration: 2000
  176. })
  177. })
  178. },
  179. comToast: function (title) {
  180. wx.showToast({
  181. title: title,
  182. icon: 'none',
  183. duration: 2000
  184. })
  185. },
  186. /**
  187. * 根据invoicesId 获取加分单据详情数据
  188. */
  189. initDetailsView: function (invoicesId){
  190. var that =this
  191. var data = { invoicesId: invoicesId}
  192. var url = baseUrl + BASEURL.getUrl.getInvoices
  193. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  194. if (res.data.success && res.data.data){
  195. that.setData({
  196. detailsData: res.data.data,
  197. applyTime: res.data.data.invoicesDate,
  198. applyName: res.data.data.fillName,
  199. applyNorm: res.data.data.normName,
  200. applyReason: res.data.data.reasons,
  201. applyJob: res.data.data.fillStation,
  202. addPoints: res.data.data.score
  203. })
  204. }
  205. }, function (res) {
  206. wx.showToast({
  207. title: '加载数据失败',
  208. icon: 'none',
  209. duration: 2000
  210. })
  211. })
  212. },
  213. /**
  214. * 撤回 : 目前做的是删除单据操作
  215. */
  216. cancelApply:function(){
  217. var that = this
  218. var data = { invoicesId: that.data.detailsData.invoicesId }
  219. var url = baseUrl + BASEURL.getUrl.withdrawInvoices
  220. netUtil.requestLoading(url, data, '正在加载数据...', 'GET', function (res) {
  221. if(res.data.success && res.data.data){
  222. that.comToast(res.data.data)
  223. setTimeout(function () {
  224. wx.navigateBack({
  225. })
  226. }, 1000)
  227. }
  228. }, function (res) {
  229. wx.showToast({
  230. title: '加载数据失败',
  231. icon: 'none',
  232. duration: 2000
  233. })
  234. })
  235. },
  236. /**
  237. * 生命周期函数--监听页面初次渲染完成
  238. */
  239. onReady: function () {
  240. },
  241. /**
  242. * 生命周期函数--监听页面显示
  243. */
  244. onShow: function () {
  245. var that = this
  246. that.setData({
  247. applyNorm:that.data.itemNorm.normItem,
  248. addPoints: that.data.itemNorm.normScore
  249. })
  250. },
  251. /**
  252. * 生命周期函数--监听页面隐藏
  253. */
  254. onHide: function () {
  255. },
  256. /**
  257. * 生命周期函数--监听页面卸载
  258. */
  259. onUnload: function () {
  260. },
  261. /**
  262. * 页面相关事件处理函数--监听用户下拉动作
  263. */
  264. onPullDownRefresh: function () {
  265. },
  266. /**
  267. * 页面上拉触底事件的处理函数
  268. */
  269. onReachBottom: function () {
  270. },
  271. /**
  272. * 用户点击右上角分享
  273. */
  274. onShareAppMessage: function () {
  275. }
  276. })