index.js 4.5 KB

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