index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 total = 0
  108. var order = this.data.order
  109. var devices = order.order_devices ? order.order_devices : []
  110. for (var i = 0; i < devices.length; ++i) {
  111. total = total + devices[i].quantity
  112. }
  113. this.setData({
  114. device_total: total,
  115. devices: devices
  116. })
  117. },
  118. switchTab: function (e) {
  119. this.setData({
  120. tabIndex: e.currentTarget.dataset.index
  121. })
  122. },
  123. check: function(e) {
  124. var type = e.currentTarget.dataset.type
  125. var that = this
  126. var msg = '确认通过审核吗?'
  127. if(type == 'reject') msg = '确认驳回申请吗?'
  128. else if(type == 'pass' || type == 're-submit') msg = '确认提交吗?'
  129. Dialog.confirm({
  130. title: '提示',
  131. message: msg,
  132. })
  133. .then(() => {
  134. that.submitCheck(e)
  135. })
  136. },
  137. submitCheck: function (e) {
  138. var type = e.currentTarget.dataset.type
  139. var that = this
  140. http({
  141. url: 'orders/check',
  142. data: {
  143. id: this.data.id,
  144. type: type,
  145. remark: this.data.remark
  146. },
  147. success: function (res) {
  148. if (res.code == 0) {
  149. util.success('操作成功')
  150. setTimeout(function() {
  151. that.init()
  152. }, 1000)
  153. }
  154. }
  155. })
  156. },
  157. /**
  158. * 生命周期函数--监听页面初次渲染完成
  159. */
  160. onReady: function () {
  161. },
  162. /**
  163. * 生命周期函数--监听页面显示
  164. */
  165. onShow: function () {
  166. },
  167. /**
  168. * 生命周期函数--监听页面隐藏
  169. */
  170. onHide: function () {
  171. },
  172. /**
  173. * 生命周期函数--监听页面卸载
  174. */
  175. onUnload: function () {
  176. },
  177. /**
  178. * 页面相关事件处理函数--监听用户下拉动作
  179. */
  180. onPullDownRefresh: function () {
  181. },
  182. /**
  183. * 页面上拉触底事件的处理函数
  184. */
  185. onReachBottom: function () {
  186. },
  187. /**
  188. * 用户点击右上角分享
  189. */
  190. onShareAppMessage: function () {
  191. }
  192. })