index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. // pages/create-order/index.js
  2. import http from '../../utils/http'
  3. import util from '../../utils/util'
  4. import api from '../../utils/api'
  5. import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. tabs: ['设备租赁订单', '租赁设备添加'],
  12. tabIndex: 0,
  13. id: -1,
  14. order: null,
  15. device_total: 0,
  16. role: null,
  17. // 审核(check)|确认(pass)|重新提交(re-submit)
  18. actionType: null,
  19. changePrice: false,
  20. remark: '',
  21. order_device: {},
  22. showPrice: false,
  23. device_quantity: '',
  24. right: null
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. var id = options.id ? options.id : 49
  31. this.setData({
  32. id
  33. })
  34. this.init()
  35. },
  36. onChange: function(e) {
  37. var name = e.currentTarget.dataset.name
  38. this.setData({
  39. [name]: e.detail.value
  40. })
  41. },
  42. init() {
  43. var that = this
  44. var id = this.data.id
  45. api.getByName(this, 'orders/detail', 'order', {
  46. id: id
  47. }, function () {
  48. that.setData({
  49. remark: that.data.order.remark
  50. })
  51. that.updateDeviceTotal()
  52. api.getByName(that, 'orders/getRole', 'role', {
  53. id: that.data.order ? that.data.order.project_id : ''
  54. }, function() {
  55. that.updateActionType()
  56. });
  57. });
  58. },
  59. updateActionType: function () {
  60. var actionType = ''
  61. var role = this.data.role
  62. var order = this.data.order
  63. var changePrice = false
  64. if (order.level == role.level) {
  65. if(['checking', 'checked'].indexOf(order.status_key) != -1 && role && role.rights && role.rights.rentCheck) actionType = 'check';
  66. else if(order.status_key == 'checked' && role.key == 'work') actionType = 'pass'
  67. else if(order.status_key == 'reject' && role.key == 'work') actionType = 're-submit'
  68. changePrice = role && role.rights && role.rights.rentMoneyChange
  69. }
  70. this.setData({
  71. actionType,
  72. changePrice
  73. })
  74. },
  75. changePrice: function() {
  76. var order_device = this.data.order_device
  77. var quantity = this.data.device_quantity
  78. var that = this
  79. http({
  80. url: 'orders/change',
  81. data: {
  82. id: order_device.id,
  83. quantity: quantity
  84. },
  85. success: function (res) {
  86. if (res.code == 0) {
  87. that.init()
  88. }
  89. }
  90. })
  91. },
  92. switchShowPrice: function(e) {
  93. var data = e.currentTarget.dataset
  94. var show = data.show
  95. var item = data.item
  96. if(show) {
  97. this.setData({
  98. order_device: item,
  99. device_quantity: item.price / 100
  100. })
  101. }
  102. this.setData({
  103. showPrice: e.currentTarget.dataset.show
  104. })
  105. },
  106. updateDeviceTotal: function () {
  107. var order = this.data.order
  108. var devices = order.order_devices ? order.order_devices : []
  109. var total = devices.length
  110. this.setData({
  111. device_total: total,
  112. devices: devices
  113. })
  114. },
  115. switchTab: function (e) {
  116. this.setData({
  117. tabIndex: e.currentTarget.dataset.index
  118. })
  119. },
  120. check: function(e) {
  121. var type = e.currentTarget.dataset.type
  122. var that = this
  123. var msg = '确认通过审核吗?'
  124. if(type == 'reject') msg = '确认驳回申请吗?'
  125. else if(type == 'pass' || type == 're-submit') msg = '确认提交吗?'
  126. Dialog.confirm({
  127. title: '提示',
  128. message: msg,
  129. })
  130. .then(() => {
  131. that.submitCheck(e)
  132. })
  133. },
  134. submitCheck: function (e) {
  135. var type = e.currentTarget.dataset.type
  136. var that = this
  137. http({
  138. url: 'orders/check',
  139. data: {
  140. id: this.data.id,
  141. type: type,
  142. remark: this.data.remark
  143. },
  144. success: function (res) {
  145. if (res.code == 0) {
  146. util.success('操作成功')
  147. setTimeout(function() {
  148. that.init()
  149. }, 1000)
  150. }
  151. }
  152. })
  153. },
  154. /**
  155. * 生命周期函数--监听页面初次渲染完成
  156. */
  157. onReady: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面显示
  161. */
  162. onShow: function () {
  163. },
  164. /**
  165. * 生命周期函数--监听页面隐藏
  166. */
  167. onHide: function () {
  168. },
  169. /**
  170. * 生命周期函数--监听页面卸载
  171. */
  172. onUnload: function () {
  173. },
  174. /**
  175. * 页面相关事件处理函数--监听用户下拉动作
  176. */
  177. onPullDownRefresh: function () {
  178. },
  179. /**
  180. * 页面上拉触底事件的处理函数
  181. */
  182. onReachBottom: function () {
  183. },
  184. /**
  185. * 用户点击右上角分享
  186. */
  187. onShareAppMessage: function () {
  188. }
  189. })