index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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: 1,
  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. showDevice: false
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. var id = options.id ? options.id : 1
  37. var type = options.type ? options.type : 'create'
  38. var order_id = options.order_id ? options.order_id : ''
  39. this.setData({
  40. id,
  41. type,
  42. order_id
  43. })
  44. api.getProject(this)
  45. api.getByName(this, 'work-points/get', 'work_points');
  46. api.getByName(this, 'inner-devices/get', 'inner_devices', { project_id: id, status: 'using' });
  47. },
  48. switchChecked(e) {
  49. var name = e.currentTarget.dataset.name
  50. var items = this.data[name]
  51. console.log(items)
  52. var index = e.currentTarget.dataset.index
  53. for (var i = 0; i < items.length; ++i) {
  54. items[i].checked = false;
  55. }
  56. items[index].checked = true;
  57. this.setData({
  58. [name]: items,
  59. deviceIndex: index
  60. })
  61. },
  62. submit: function (e) {
  63. // if(this.data.pointIndex < 0) {
  64. // util.error('需求工点必填');
  65. // return false;
  66. // }
  67. if (this.data.deviceIndex < 0) {
  68. util.error('维修设备必填');
  69. return false;
  70. }
  71. // var work_point = this.data.work_points[this.data.pointIndex]
  72. var device = this.data.inner_devices[this.data.deviceIndex]
  73. var url = 'repair-devices/create'
  74. http({
  75. url: url,
  76. data: {
  77. project_id: this.data.id,
  78. // work_point_id: work_point.id,
  79. inner_device_id: device.id,
  80. money: this.data.money,
  81. reason: this.data.reason,
  82. day: this.data.day,
  83. remark: this.data.remark,
  84. parts: this.data.parts
  85. },
  86. success: function (res) {
  87. if (res.code == 0) {
  88. util.success('操作成功')
  89. setTimeout(function () {
  90. wx.navigateBack({
  91. delta: 0,
  92. })
  93. }, 1000)
  94. }
  95. }
  96. })
  97. },
  98. switchTab: function (e) {
  99. this.setData({
  100. tabIndex: e.currentTarget.dataset.index
  101. })
  102. },
  103. delete: function (e) {
  104. var parts = this.data.parts
  105. var index = e.currentTarget.dataset.index
  106. parts.splice(index, 1)
  107. this.setData({
  108. parts
  109. })
  110. },
  111. add: function () {
  112. if (!this.data.part_name) {
  113. util.error('维修部位必填');
  114. return false;
  115. }
  116. if (!this.data.part_change) {
  117. util.error('更换配件必填');
  118. return false;
  119. }
  120. if (!this.data.part_price) {
  121. util.error('配件价格必填');
  122. return false;
  123. }
  124. var parts = this.data.parts
  125. var part = {
  126. name: this.data.part_name,
  127. change: this.data.part_change,
  128. price: this.data.part_price
  129. }
  130. parts.push(part)
  131. this.setData({
  132. parts
  133. })
  134. },
  135. onChange: function (e) {
  136. var name = e.currentTarget.dataset.name
  137. var val = e.detail.value
  138. this.setData({
  139. [name]: val
  140. })
  141. if (name == 'part_price') {
  142. let price
  143. if (/^(\d?)+(\.\d{0,2})?$/.test(val)) { //正则验证,提现金额小数点后不能大于两位数字
  144. price = val;
  145. } else {
  146. price = val.substring(0, val.length - 1);
  147. }
  148. this.setData({
  149. part_price: price
  150. })
  151. }
  152. if (name == 'pointIndex') {
  153. var work_point = this.data.work_points[val]
  154. var work_point_id = work_point ? work_point.id : ''
  155. var that = this
  156. api.getByName(this, 'inner-devices/get', 'inner_devices', {
  157. work_point_id: work_point_id
  158. }, function () {
  159. that.setData({
  160. deviceIndex: -1
  161. })
  162. });
  163. }
  164. },
  165. switchShow(e) {
  166. var name = e.currentTarget.dataset.name
  167. var val = !this.data[name]
  168. this.setData({
  169. [name]: val
  170. })
  171. },
  172. switchShowAdd: function (e) {
  173. var show = e.currentTarget.dataset.show
  174. if (show) {
  175. this.setData({
  176. part_name: '',
  177. part_change: '',
  178. part_price: '',
  179. })
  180. }
  181. this.setData({
  182. showAdd: show,
  183. dialog_type: 'create'
  184. })
  185. },
  186. switchShowDate: function (e) {
  187. this.setData({
  188. showDate: e.currentTarget.dataset.show
  189. })
  190. },
  191. confirmDate: function (e) {
  192. this.switchShowDate(e)
  193. var [start_date, end_date] = e.detail;
  194. start_date = util.formatDate(start_date)
  195. end_date = util.formatDate(end_date)
  196. this.setData({
  197. start_date,
  198. end_date
  199. })
  200. },
  201. /**
  202. * 生命周期函数--监听页面初次渲染完成
  203. */
  204. onReady: function () {
  205. },
  206. /**
  207. * 生命周期函数--监听页面显示
  208. */
  209. onShow: function () {
  210. },
  211. /**
  212. * 生命周期函数--监听页面隐藏
  213. */
  214. onHide: function () {
  215. },
  216. /**
  217. * 生命周期函数--监听页面卸载
  218. */
  219. onUnload: function () {
  220. },
  221. /**
  222. * 页面相关事件处理函数--监听用户下拉动作
  223. */
  224. onPullDownRefresh: function () {
  225. },
  226. /**
  227. * 页面上拉触底事件的处理函数
  228. */
  229. onReachBottom: function () {
  230. },
  231. /**
  232. * 用户点击右上角分享
  233. */
  234. onShareAppMessage: function () {
  235. }
  236. })