| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 | 
							- // pages/create-order/index.js
 
- import http from '../../utils/http'
 
- import util from '../../utils/util'
 
- import api from '../../utils/api'
 
- Page({
 
-   /**
 
-    * 页面的初始数据
 
-    */
 
-   data: {
 
-     tabs: ['维修记录填写', '维修配件添加'],
 
-     tabIndex: 0,
 
-     work_points: [],
 
-     pointIndex: -1,
 
-     id: -1,
 
-     project: null,
 
-     remark: '',
 
-     inner_devices: [],
 
-     deviceIndex: -1,
 
-     parts: [],
 
-     part_name: '',
 
-     part_change: '',
 
-     part_price: '',
 
-     showAdd: false,
 
-     order_id: '',
 
-     // create/edit
 
-     type: 'create',
 
-     // create/edit
 
-     dialog_type: 'create',
 
-     default_dates: []
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面加载
 
-    */
 
-   onLoad: function (options) {
 
-     var id = options.id ? options.id : 1
 
-     var type = options.type ? options.type : 'create'
 
-     var order_id = options.order_id ? options.order_id : ''
 
-     this.setData({
 
-       id,
 
-       type,
 
-       order_id
 
-     })
 
-     api.getProject(this)
 
-     api.getByName(this, 'work-points/get', 'work_points');
 
-     api.getByName(this, 'inner-devices/get', 'inner_devices');
 
-   },
 
-   submit: function(e) {
 
-     if(this.data.pointIndex < 0) {
 
-       util.error('需求工点必填');
 
-       return false;
 
-     }
 
-     if(this.data.deviceIndex < 0) {
 
-       util.error('维修设备必填');
 
-       return false;
 
-     }
 
-     var work_point = this.data.work_points[this.data.pointIndex]
 
-     var device = this.data.inner_devices[this.data.deviceIndex]
 
-     var url = 'repair-devices/create'
 
-     http({
 
-       url: url,
 
-       data: {
 
-         project_id: this.data.id,
 
-         work_point_id: work_point.id,
 
-         inner_device_id: device.id,
 
-         money: this.data.money,
 
-         reason: this.data.reason,
 
-         day: this.data.day,
 
-         remark: this.data.remark,
 
-         parts: this.data.parts
 
-       },
 
-       success: function(res) {
 
-         if(res.code == 0) {
 
-           util.success('操作成功')
 
-         }
 
-       }
 
-     })
 
-   },
 
-   switchTab: function(e) {
 
-     this.setData({
 
-       tabIndex: e.currentTarget.dataset.index
 
-     })
 
-   },
 
-   delete: function(e) {
 
-     var parts = this.data.parts
 
-     var index = e.currentTarget.dataset.index
 
-     parts.splice(index, 1)
 
-     this.setData({
 
-       parts
 
-     })
 
-   },
 
-   add: function() {
 
-     if(!this.data.part_name) {
 
-       util.error('维修部位必填');
 
-       return false;
 
-     }
 
-     if(!this.data.part_change) {
 
-       util.error('更换配件必填');
 
-       return false;
 
-     }
 
-     if(!this.data.part_price) {
 
-       util.error('配件价格必填');
 
-       return false;
 
-     }
 
-     var parts = this.data.parts
 
-     var part = {
 
-       name: this.data.part_name,
 
-       change: this.data.part_change,
 
-       price: this.data.part_price
 
-     }
 
-     parts.push(part)
 
-     this.setData({
 
-       parts
 
-     })
 
-   },
 
-   onChange: function(e) {
 
-     var name = e.currentTarget.dataset.name
 
-     var val = e.detail.value
 
-     
 
-     this.setData({
 
-       [name]: val
 
-     })
 
-   },
 
-   switchShowAdd: function(e) {
 
-     var show = e.currentTarget.dataset.show
 
-     if(show) {
 
-       this.setData({
 
-         part_name: '',
 
-         part_change: '',
 
-         part_price: '',
 
-       })
 
-     }
 
-     this.setData({
 
-       showAdd: show,
 
-       dialog_type: 'create'
 
-     })
 
-   },
 
-   switchShowDate: function(e) {
 
-     this.setData({
 
-       showDate: e.currentTarget.dataset.show
 
-     })
 
-   },
 
-   confirmDate: function(e) {
 
-     this.switchShowDate(e)
 
-     var [start_date, end_date] = e.detail;
 
-     start_date = util.formatDate(start_date)
 
-     end_date = util.formatDate(end_date)
 
-     this.setData({
 
-       start_date,
 
-       end_date
 
-     })
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面初次渲染完成
 
-    */
 
-   onReady: function () {
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面显示
 
-    */
 
-   onShow: function () {
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面隐藏
 
-    */
 
-   onHide: function () {
 
-   },
 
-   /**
 
-    * 生命周期函数--监听页面卸载
 
-    */
 
-   onUnload: function () {
 
-   },
 
-   /**
 
-    * 页面相关事件处理函数--监听用户下拉动作
 
-    */
 
-   onPullDownRefresh: function () {
 
-   },
 
-   /**
 
-    * 页面上拉触底事件的处理函数
 
-    */
 
-   onReachBottom: function () {
 
-   },
 
-   /**
 
-    * 用户点击右上角分享
 
-    */
 
-   onShareAppMessage: function () {
 
-   }
 
- })
 
 
  |