You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.5 KiB
113 lines
3.5 KiB
// pages/setting/paper-detial/index.js
|
|
import Scene from '../../index/scene'
|
|
import Dialog from '../../../components/dialog/dialog'
|
|
import { getPaperInfo, getCategoryList, savePaperPrice, editPaperPrice, delePaperPrice } from "../../../api/saas"
|
|
const event = require('../../../utils/event')
|
|
const util = require('../../../utils/util')
|
|
|
|
Scene({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
paperList: null,
|
|
form: {},
|
|
visible: false,
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if(options.id){
|
|
wx.showLoading({ title: '正在获取', mask: true })
|
|
getCategoryList().then(result => {
|
|
this.setData({ paperList: result.data })
|
|
}).catch(err => {
|
|
util.showToast(err)
|
|
})
|
|
getPaperInfo(options.id).then(result => {
|
|
wx.hideLoading()
|
|
this.setData({ form: result.data })
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
} else {
|
|
wx.showLoading({ title: '正在获取', mask: true })
|
|
getCategoryList().then(result => {
|
|
this.setData({ paperList: result.data })
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
},
|
|
chooseMethod: function(e){
|
|
this.setData({ visible: true })
|
|
},
|
|
onConfirm: function(e){
|
|
this.data.cIndex = e.currentTarget.dataset.index
|
|
var nowItem = this.data.paperList[this.data.cIndex]
|
|
this.data.form.categoryId = nowItem.categoryId
|
|
this.data.form.categoryName = nowItem.name
|
|
this.setData({ visible: false, ['form.productName']: nowItem.name, ['form.categoryName']: nowItem.categoryName, cIndex: this.data.cIndex })
|
|
},
|
|
onHide: function(){
|
|
this.setData({ visible: false })
|
|
},
|
|
bindInput: function(e){
|
|
this.data.form[e.currentTarget.id] = e.detail
|
|
},
|
|
deleteForm: function(e){
|
|
Dialog.confirm({ title: '温馨提示', message: '确定删除该纸品?' }).then(() => {
|
|
wx.showLoading({ title: '正在处理', mask: true })
|
|
delePaperPrice(this.data.form.id).then(result => {
|
|
wx.hideLoading()
|
|
util.showBackToast('删除成功')
|
|
event.emit('OrderMessage', { what: 201 })
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}).catch(err => {
|
|
})
|
|
},
|
|
submitForm: function(e){
|
|
if(util.isEmpty(this.data.form.categoryId)){
|
|
util.showToast('请选择一个纸品名称')
|
|
return
|
|
}
|
|
if(util.isEmpty(this.data.form.defaultUnitPrice) || Number(this.data.form.defaultUnitPrice) <= 0){
|
|
util.showToast('请输入纸品价格')
|
|
return
|
|
}
|
|
if(!util.isEmpty(this.data.form.highestUnitPrice)){
|
|
if(Number(this.data.form.defaultUnitPrice) >= Number(this.data.form.highestUnitPrice)){
|
|
util.showToast('最高收货价格必须高于一般收货价格')
|
|
return
|
|
}
|
|
}
|
|
wx.showLoading({ title: '正在处理', mask: true })
|
|
if(util.isEmpty(this.data.form.id)){
|
|
savePaperPrice(this.data.form).then(result => {
|
|
wx.hideLoading()
|
|
util.showBackToast('添加成功')
|
|
event.emit('OrderMessage', { what: 201 })
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
} else {
|
|
editPaperPrice(this.data.form).then(result => {
|
|
wx.hideLoading()
|
|
util.showBackToast('修改成功')
|
|
event.emit('OrderMessage', { what: 202, detail: this.data.form })
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
}
|
|
|
|
})
|