index.js 4.8 KB

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