123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- // 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: [],
- showAdd: false,
- device_types: [],
- typeIndex: -1,
- device_name: '',
- device_quantity: '',
- device_price: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var id = options.id ? options.id : 1
- this.setData({
- id
- })
- api.getProject(this)
- api.getByName(this, 'work-points/get', 'work_points');
- api.getByName(this, 'devices/get', 'device_types');
- },
- submit: function(e) {
- var type = e.currentTarget.dataset.type
- var is_draft = type == 'draft' ? 1 : 2
- 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]
- http({
- url: 'orders/create',
- data: {
- 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
- })
- },
- deleteDevice: function(e) {
- var devices = this.data.devices
- var index = e.currentTarget.dataset.index
- devices.splice(index, 1)
- this.setData({
- devices
- })
- },
- addDevice: function() {
- if(!this.data.device_name) {
- util.error('设备名称必填');
- return false;
- }
- if(!this.data.typeIndex < 0) {
- util.error('设备类型必填')
- return false
- }
- if(!this.data.device_quantity) {
- util.error('设备数量必填')
- return false
- }
- if(!this.data.device_price) {
- util.error('设备单价必填')
- return false
- }
- var devices = this.data.devices
- var type = this.data.device_types[this.data.typeIndex]
- devices.push({
- name: this.data.device_name,
- type_name: type.name,
- type_id: type.id,
- quantity: this.data.device_quantity,
- price: this.data.device_price
- })
- this.setData({
- devices
- })
- },
- onChange: function(e) {
- var name = e.currentTarget.dataset.name
- this.setData({
- [name]: e.detail.value
- })
- },
- switchShowAdd: function(e) {
- this.setData({
- showAdd: e.currentTarget.dataset.show
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|