index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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)|退回(back)
  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 : ''
  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: that.data.order ? that.data.order.project_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. if(order.status_key == 'pass') actionType = 'back'
  67. }
  68. var changePrice = false
  69. this.setData({
  70. actionType,
  71. changePrice
  72. })
  73. },
  74. changePrice: function() {
  75. var order_device = this.data.order_device
  76. var price = this.data.device_price
  77. var that = this
  78. http({
  79. url: 'orders/changePrice',
  80. data: {
  81. id: order_device.pivot.id,
  82. price: price
  83. },
  84. success: function (res) {
  85. if (res.code == 0) {
  86. that.init()
  87. }
  88. }
  89. })
  90. },
  91. switchShowPrice: function(e) {
  92. var data = e.currentTarget.dataset
  93. var show = data.show
  94. var item = data.item
  95. if(show) {
  96. this.setData({
  97. order_device: item,
  98. device_price: item.pivot.price / 100
  99. })
  100. }
  101. this.setData({
  102. showPrice: e.currentTarget.dataset.show
  103. })
  104. },
  105. updateDeviceTotal: function () {
  106. var order = this.data.order
  107. var devices = order.inner_devices ? order.inner_devices : []
  108. var total = devices.length
  109. this.setData({
  110. device_total: total,
  111. devices: devices
  112. })
  113. },
  114. switchTab: function (e) {
  115. this.setData({
  116. tabIndex: e.currentTarget.dataset.index
  117. })
  118. },
  119. check: function(e) {
  120. var type = e.currentTarget.dataset.type
  121. var that = this
  122. var msg = '确认通过审核吗?'
  123. if(type == 'reject') msg = '确认驳回申请吗?'
  124. else if(type == 'confirm' || type == 're-submit') msg = '确认提交吗?'
  125. else if(type == 'back') msg = '确认归还吗?'
  126. Dialog.confirm({
  127. title: '提示',
  128. message: msg,
  129. })
  130. .then(() => {
  131. that.submitCheck(e)
  132. }).catch(()=>{
  133. Dialog.close()
  134. })
  135. },
  136. submitCheck: function (e) {
  137. var type = e.currentTarget.dataset.type
  138. var that = this
  139. http({
  140. url: 'orders/check',
  141. data: {
  142. id: this.data.id,
  143. type: type,
  144. remark: this.data.remark
  145. },
  146. success: function (res) {
  147. if (res.code == 0) {
  148. Dialog.close()
  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. })