index.js 4.7 KB

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