123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- // 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: '',
- devices: [],
- // create/edit
- type: 'create',
- order_id: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- 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');
- if(order_id) {
- var that = this
- api.getByName(this, 'orders/detail', 'order', {id: order_id}, function(res) {
- that.initData()
- });
- wx.setNavigationBarTitle({
- title: '修订订单',
- })
- }
- },
- navigate: function(e) {
- wx.navigateTo({
- url: e.currentTarget.dataset.url,
- })
- },
-
- initData: function() {
- var order = this.data.order,
- work_points = this.data.work_points,
- pointIndex = this.data.pointIndex
- for(var i = 0; i < work_points.length; ++i) {
- if(work_points[i].id == order.work_point_id) {
- pointIndex = i;
- break;
- }
- }
- var devices = order.devices
- var local_devices = []
- for(var i = 0; i < devices.length; ++i) {
- var device = devices[i]
- local_devices.push({
- name: device.pivot.name,
- type_name: device.name,
- type_id: device.id,
- quantity: device.pivot.quantity,
- price: device.pivot.price / 100,
- start_date: device.pivot.start_date,
- end_date: device.pivot.end_date
- })
- }
- this.setData({
- pointIndex,
- remark: order.remark,
- devices: local_devices
- })
- },
- submit: function(e) {
- var type = e.currentTarget.dataset.type
- var is_draft = type == 'draft' ? 1 : 2
- var submit_type = this.data.type
- if(this.data.pointIndex < 0) {
- util.error('需求工点必填');
- return false;
- }
- if(this.data.devices.length <= 0) {
- util.error('请选择调用设备');
- return false;
- }
- var work_point = this.data.work_points[this.data.pointIndex]
- var url = submit_type == 'create' ? 'orders/createInner' : 'orders/updateInner'
- http({
- url: url,
- data: {
- id: this.data.order_id,
- project_id: this.data.id,
- work_point_id: work_point.id,
- remark: this.data.remark,
- devices: this.data.devices,
- is_draft: is_draft
- },
- success: function(res) {
- if(res.code == 0) {
- util.success('操作成功')
- }
- }
- })
- },
- switchTab: function(e) {
- this.setData({
- tabIndex: e.currentTarget.dataset.index
- })
- },
- onChange: function(e) {
- var name = e.currentTarget.dataset.name
- this.setData({
- [name]: e.detail.value
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- var devices = wx.getStorageSync('sg-added-devices')
- devices = devices ? devices : []
- this.setData({
- devices
- })
- },
- goAdd: function(e) {
- var devices = this.data.devices
- wx.setStorageSync('sg-added-devices', devices)
- this.navigate(e)
- },
- deleteDevice: function(e) {
- var index = e.currentTarget.dataset.index
- var devices = this.data.devices
- devices.splice(index, 1)
- this.setData({
- devices
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|