index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. tabs: ['维修记录填写', '维修配件添加'],
  11. tabIndex: 0,
  12. work_points: [],
  13. pointIndex: -1,
  14. id: -1,
  15. project: null,
  16. remark: '',
  17. inner_devices: [],
  18. deviceIndex: -1,
  19. parts: [],
  20. part_name: '',
  21. part_change: '',
  22. part_price: '',
  23. showAdd: false,
  24. order_id: '',
  25. // create/edit
  26. type: 'create',
  27. // create/edit
  28. dialog_type: 'create',
  29. default_dates: []
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. var id = options.id ? options.id : 1
  36. var type = options.type ? options.type : 'create'
  37. var order_id = options.order_id ? options.order_id : ''
  38. this.setData({
  39. id,
  40. type,
  41. order_id
  42. })
  43. api.getProject(this)
  44. api.getByName(this, 'work-points/get', 'work_points');
  45. api.getByName(this, 'inner-devices/get', 'inner_devices');
  46. },
  47. submit: function(e) {
  48. if(this.data.pointIndex < 0) {
  49. util.error('需求工点必填');
  50. return false;
  51. }
  52. if(this.data.deviceIndex < 0) {
  53. util.error('维修设备必填');
  54. return false;
  55. }
  56. var work_point = this.data.work_points[this.data.pointIndex]
  57. var device = this.data.inner_devices[this.data.deviceIndex]
  58. var url = 'repair-devices/create'
  59. http({
  60. url: url,
  61. data: {
  62. project_id: this.data.id,
  63. work_point_id: work_point.id,
  64. inner_device_id: device.id,
  65. money: this.data.money,
  66. reason: this.data.reason,
  67. day: this.data.day,
  68. remark: this.data.remark,
  69. parts: this.data.parts
  70. },
  71. success: function(res) {
  72. if(res.code == 0) {
  73. util.success('操作成功')
  74. }
  75. }
  76. })
  77. },
  78. switchTab: function(e) {
  79. this.setData({
  80. tabIndex: e.currentTarget.dataset.index
  81. })
  82. },
  83. delete: function(e) {
  84. var parts = this.data.parts
  85. var index = e.currentTarget.dataset.index
  86. parts.splice(index, 1)
  87. this.setData({
  88. parts
  89. })
  90. },
  91. add: function() {
  92. if(!this.data.part_name) {
  93. util.error('维修部位必填');
  94. return false;
  95. }
  96. if(!this.data.part_change) {
  97. util.error('更换配件必填');
  98. return false;
  99. }
  100. if(!this.data.part_price) {
  101. util.error('配件价格必填');
  102. return false;
  103. }
  104. var parts = this.data.parts
  105. var part = {
  106. name: this.data.part_name,
  107. change: this.data.part_change,
  108. price: this.data.part_price
  109. }
  110. parts.push(part)
  111. this.setData({
  112. parts
  113. })
  114. },
  115. onChange: function(e) {
  116. var name = e.currentTarget.dataset.name
  117. var val = e.detail.value
  118. this.setData({
  119. [name]: val
  120. })
  121. },
  122. switchShowAdd: function(e) {
  123. var show = e.currentTarget.dataset.show
  124. if(show) {
  125. this.setData({
  126. part_name: '',
  127. part_change: '',
  128. part_price: '',
  129. })
  130. }
  131. this.setData({
  132. showAdd: show,
  133. dialog_type: 'create'
  134. })
  135. },
  136. switchShowDate: function(e) {
  137. this.setData({
  138. showDate: e.currentTarget.dataset.show
  139. })
  140. },
  141. confirmDate: function(e) {
  142. this.switchShowDate(e)
  143. var [start_date, end_date] = e.detail;
  144. start_date = util.formatDate(start_date)
  145. end_date = util.formatDate(end_date)
  146. this.setData({
  147. start_date,
  148. end_date
  149. })
  150. },
  151. /**
  152. * 生命周期函数--监听页面初次渲染完成
  153. */
  154. onReady: function () {
  155. },
  156. /**
  157. * 生命周期函数--监听页面显示
  158. */
  159. onShow: function () {
  160. },
  161. /**
  162. * 生命周期函数--监听页面隐藏
  163. */
  164. onHide: function () {
  165. },
  166. /**
  167. * 生命周期函数--监听页面卸载
  168. */
  169. onUnload: function () {
  170. },
  171. /**
  172. * 页面相关事件处理函数--监听用户下拉动作
  173. */
  174. onPullDownRefresh: function () {
  175. },
  176. /**
  177. * 页面上拉触底事件的处理函数
  178. */
  179. onReachBottom: function () {
  180. },
  181. /**
  182. * 用户点击右上角分享
  183. */
  184. onShareAppMessage: function () {
  185. }
  186. })