index.js 4.3 KB

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