123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- // pages/create-order/index.js
- import http from '../../utils/http'
- import util from '../../utils/util'
- import api from '../../utils/api'
- import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- tabs: ['设备租赁订单', '租赁设备添加'],
- tabIndex: 0,
- id: -1,
- order: null,
- device_total: 0,
- role: null,
- // 审核(check)|确认(pass)|重新提交(re-submit)
- actionType: null,
- changePrice: false,
- remark: '',
- order_device: {},
- showPrice: false,
- device_quantity: '',
- right: null
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var id = options.id ? options.id : 49
- this.setData({
- id
- })
- this.init()
- },
- onChange: function(e) {
- var name = e.currentTarget.dataset.name
- this.setData({
- [name]: e.detail.value
- })
- },
- init() {
- var that = this
- var id = this.data.id
- api.getByName(this, 'orders/detail', 'order', {
- id: id
- }, function () {
- that.setData({
- remark: that.data.order.remark
- })
- that.updateDeviceTotal()
- api.getByName(that, 'orders/getRole', 'role', {
- id: that.data.order ? that.data.order.project_id : ''
- }, function() {
- that.updateActionType()
- });
-
- });
- },
- updateActionType: function () {
- var actionType = ''
- var role = this.data.role
- var order = this.data.order
- var changePrice = false
- if (order.level == role.level) {
- if(['checking', 'checked'].indexOf(order.status_key) != -1 && role && role.rights && role.rights.rentCheck) actionType = 'check';
- else if(order.status_key == 'checked' && role.key == 'work') actionType = 'pass'
- else if(order.status_key == 'reject' && role.key == 'work') actionType = 're-submit'
- changePrice = role && role.rights && role.rights.rentMoneyChange
- }
- this.setData({
- actionType,
- changePrice
- })
- },
- changePrice: function() {
- var order_device = this.data.order_device
- var quantity = this.data.device_quantity
- var that = this
- http({
- url: 'orders/change',
- data: {
- id: order_device.id,
- quantity: quantity
- },
- success: function (res) {
- if (res.code == 0) {
- that.init()
- }
- }
- })
- },
- switchShowPrice: function(e) {
- var data = e.currentTarget.dataset
- var show = data.show
- var item = data.item
- if(show) {
- this.setData({
- order_device: item,
- device_quantity: item.price / 100
- })
- }
- this.setData({
- showPrice: e.currentTarget.dataset.show
- })
- },
- updateDeviceTotal: function () {
- var total = 0
- var order = this.data.order
- var devices = order.order_devices ? order.order_devices : []
- for (var i = 0; i < devices.length; ++i) {
- total = total + devices[i].quantity
- }
- this.setData({
- device_total: total,
- devices: devices
- })
- },
- switchTab: function (e) {
- this.setData({
- tabIndex: e.currentTarget.dataset.index
- })
- },
- check: function(e) {
- var type = e.currentTarget.dataset.type
- var that = this
- var msg = '确认通过审核吗?'
- if(type == 'reject') msg = '确认驳回申请吗?'
- else if(type == 'pass' || type == 're-submit') msg = '确认提交吗?'
- Dialog.confirm({
- title: '提示',
- message: msg,
- })
- .then(() => {
- that.submitCheck(e)
- })
- },
- submitCheck: function (e) {
- var type = e.currentTarget.dataset.type
- var that = this
- http({
- url: 'orders/check',
- data: {
- id: this.data.id,
- type: type,
- remark: this.data.remark
- },
- success: function (res) {
- if (res.code == 0) {
- util.success('操作成功')
- setTimeout(function() {
- that.init()
- }, 1000)
- }
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|