|
|
|
@ -1,5 +1,13 @@ |
|
|
|
// pages/goods/create/index.js
|
|
|
|
import { paperCategoryList, getProductInfo, createProductInfo, updateProductInfo, getWaterRate, getDopantRate, getBiddingInterval } from "../../api/ztb" |
|
|
|
import { |
|
|
|
paperCategoryList, |
|
|
|
getProductInfo, |
|
|
|
createProductInfo, |
|
|
|
updateProductInfo, |
|
|
|
getWaterRate, |
|
|
|
getDopantRate, |
|
|
|
getBiddingInterval |
|
|
|
} from "../../api/ztb" |
|
|
|
import regions from '../../../utils/region' |
|
|
|
const math = require('../../../utils/math') |
|
|
|
const util = require('../../../utils/util') |
|
|
|
@ -60,29 +68,49 @@ Page({ |
|
|
|
}) |
|
|
|
this.cascaderView = this.cascaderView || this.selectComponent('#wux-cascader') |
|
|
|
this.pickerView = this.pickerView || this.selectComponent('#picker-view') |
|
|
|
wx.showLoading({ title: '加载中', mask: true }) |
|
|
|
wx.showLoading({ |
|
|
|
title: '加载中', |
|
|
|
mask: true |
|
|
|
}) |
|
|
|
getDopantRate().then(result => { |
|
|
|
var list = [] |
|
|
|
result.data.forEach((item) => { |
|
|
|
list.push({ text: item.name, value: item.id }) |
|
|
|
list.push({ |
|
|
|
text: item.name, |
|
|
|
value: item.id |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
dopantList: list |
|
|
|
}) |
|
|
|
this.setData({ dopantList: list }) |
|
|
|
}) |
|
|
|
getWaterRate().then(result => { |
|
|
|
var list = [] |
|
|
|
result.data.forEach((item) => { |
|
|
|
list.push({ text: item.name, value: item.id }) |
|
|
|
list.push({ |
|
|
|
text: item.name, |
|
|
|
value: item.id |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
waterList: list |
|
|
|
}) |
|
|
|
this.setData({ waterList: list }) |
|
|
|
}) |
|
|
|
getBiddingInterval().then(result => { |
|
|
|
var list = [] |
|
|
|
result.data.forEach((item) => { |
|
|
|
list.push({ text: item.name, value: item.id }) |
|
|
|
list.push({ |
|
|
|
text: item.name, |
|
|
|
value: item.id |
|
|
|
}) |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
intervalList: list |
|
|
|
}) |
|
|
|
this.setData({ intervalList: list }) |
|
|
|
}) |
|
|
|
paperCategoryList({ type: 1 }).then(result => { |
|
|
|
paperCategoryList({ |
|
|
|
type: 1 |
|
|
|
}).then(result => { |
|
|
|
var cateList = [] |
|
|
|
result.data.forEach((item) => { |
|
|
|
cateList.push({ |
|
|
|
@ -108,15 +136,21 @@ Page({ |
|
|
|
var fileList = [] |
|
|
|
if (result.data.imgList && result.data.imgList.length) { |
|
|
|
result.data.imgList.forEach(element => { |
|
|
|
fileList.push({ url: element, status: 8 }) |
|
|
|
fileList.push({ |
|
|
|
url: element, |
|
|
|
status: 8 |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
var videoList = [] |
|
|
|
if (result.data.videoUrl) { |
|
|
|
videoList.push({ videoUrl: result.data.videoUrl, status: 8 }) |
|
|
|
videoList.push({ |
|
|
|
videoUrl: result.data.videoUrl, |
|
|
|
status: 8 |
|
|
|
}) |
|
|
|
} |
|
|
|
var region = [] |
|
|
|
if(result.data.locDistrictId){ |
|
|
|
if (result.data.locDistrictId) { |
|
|
|
region[0] = parseInt(result.data.locDistrictId / 10000) * 10000 |
|
|
|
region[1] = parseInt(result.data.locDistrictId / 100) * 100 |
|
|
|
region[2] = parseInt(result.data.locDistrictId) |
|
|
|
@ -143,15 +177,15 @@ Page({ |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
if(result.data.unitPrice){ |
|
|
|
if (result.data.unitPrice) { |
|
|
|
var unitPrice = app.globalData.kg ? result.data.unitPrice : math.times(result.data.unitPrice, 1000) |
|
|
|
}else{ |
|
|
|
var unitPrice='' |
|
|
|
} else { |
|
|
|
var unitPrice = '' |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var stock = app.globalData.kg ? result.data.stock : math.divide(result.data.stock, 1000) |
|
|
|
var lowestNum = '' |
|
|
|
if(!util.isEmpty(result.data.lowestNum)){ |
|
|
|
if (!util.isEmpty(result.data.lowestNum)) { |
|
|
|
lowestNum = app.globalData.kg ? result.data.lowestNum : math.divide(result.data.lowestNum, 1000) |
|
|
|
} |
|
|
|
this.setData({ |
|
|
|
@ -170,7 +204,7 @@ Page({ |
|
|
|
imgLength: fileList.length, |
|
|
|
intervalName: this.data.intervalName |
|
|
|
}) |
|
|
|
if(util.isEmpty(this.data.form.areaStr)){ |
|
|
|
if (util.isEmpty(this.data.form.areaStr)) { |
|
|
|
this.cascaderView.getCurrentOptions(region, true) |
|
|
|
} |
|
|
|
this.sumAmount(null) |
|
|
|
@ -184,13 +218,24 @@ Page({ |
|
|
|
} |
|
|
|
}, |
|
|
|
InputFocus(e) { |
|
|
|
this.setData({ focus: true, toView: 'textarea', keyboard: e.detail.height }) |
|
|
|
this.setData({ |
|
|
|
focus: true, |
|
|
|
toView: 'textarea', |
|
|
|
keyboard: e.detail.height |
|
|
|
}) |
|
|
|
}, |
|
|
|
InputBlur(e) { |
|
|
|
this.setData({ keyboard: 0, focus: false, toView: null }) |
|
|
|
this.setData({ |
|
|
|
keyboard: 0, |
|
|
|
focus: false, |
|
|
|
toView: null |
|
|
|
}) |
|
|
|
}, |
|
|
|
textareaFocus: function(e){ |
|
|
|
this.setData({ focus: true, toView: 'textarea' }) |
|
|
|
textareaFocus: function (e) { |
|
|
|
this.setData({ |
|
|
|
focus: true, |
|
|
|
toView: 'textarea' |
|
|
|
}) |
|
|
|
}, |
|
|
|
onVideoChange: function (e) { |
|
|
|
if (e.detail && e.detail.length) { |
|
|
|
@ -212,30 +257,45 @@ Page({ |
|
|
|
} |
|
|
|
}, |
|
|
|
bindInput: function (e) { |
|
|
|
if(e.target.id == 'description'){ |
|
|
|
this.setData({['form.' + e.target.id] : e.detail.value}) |
|
|
|
if (e.target.id == 'description') { |
|
|
|
this.setData({ |
|
|
|
['form.' + e.target.id]: e.detail.value |
|
|
|
}) |
|
|
|
} else { |
|
|
|
this.data.form[e.target.id] = e.detail.value |
|
|
|
} |
|
|
|
}, |
|
|
|
onLoadOptions: function (e) { |
|
|
|
// /paperCategoryList 获取纸品列表
|
|
|
|
const { value } = e.detail |
|
|
|
const { |
|
|
|
value |
|
|
|
} = e.detail |
|
|
|
const options = [...this.data.cateList] |
|
|
|
var typeId = parseInt(value[value.length - 1]) |
|
|
|
wx.showLoading({ title: '加载中', mask: true }) |
|
|
|
paperCategoryList({ type: 2, firstCategoryId: typeId}).then(result => { |
|
|
|
wx.showLoading({ |
|
|
|
title: '加载中', |
|
|
|
mask: true |
|
|
|
}) |
|
|
|
paperCategoryList({ |
|
|
|
type: 2, |
|
|
|
firstCategoryId: typeId |
|
|
|
}).then(result => { |
|
|
|
//成功回调
|
|
|
|
var list = [] |
|
|
|
result.data.forEach((item) => { |
|
|
|
list.push({ label: item.name, value: item.id }) |
|
|
|
list.push({ |
|
|
|
label: item.name, |
|
|
|
value: item.id |
|
|
|
}) |
|
|
|
}) |
|
|
|
options.forEach((element) => { |
|
|
|
if (parseInt(element.value) === typeId) { |
|
|
|
element.children = list |
|
|
|
} |
|
|
|
}) |
|
|
|
this.setData({ cateList: options }) |
|
|
|
this.setData({ |
|
|
|
cateList: options |
|
|
|
}) |
|
|
|
wx.hideLoading() |
|
|
|
}).catch(err => { |
|
|
|
//异常回调
|
|
|
|
@ -247,7 +307,9 @@ Page({ |
|
|
|
return |
|
|
|
} |
|
|
|
this.cascaderView.showPicker(this.data.region) |
|
|
|
this.setData({ picking: true }) |
|
|
|
this.setData({ |
|
|
|
picking: true |
|
|
|
}) |
|
|
|
}, |
|
|
|
onRegionInit: function (e) { |
|
|
|
if (this.data.form.locDistrictId && e.detail.length == 3) { |
|
|
|
@ -269,13 +331,22 @@ Page({ |
|
|
|
this.data.form['locDistrictId'] = e.detail.value[2] |
|
|
|
this.data.form['locDistrictName'] = e.detail.options[2].label |
|
|
|
} |
|
|
|
this.setData({ picking: false }) |
|
|
|
this.setData({ |
|
|
|
picking: false |
|
|
|
}) |
|
|
|
}, |
|
|
|
showPaperPicker: function (e) { |
|
|
|
this.setData({ visible: true, picking: true }) |
|
|
|
this.setData({ |
|
|
|
visible: true, |
|
|
|
picking: true |
|
|
|
}) |
|
|
|
var list = [this.data.cateList[0].value] |
|
|
|
if(!this.data.cateList[0].children){ |
|
|
|
this.onLoadOptions({detail: { value: list}}) |
|
|
|
if (!this.data.cateList[0].children) { |
|
|
|
this.onLoadOptions({ |
|
|
|
detail: { |
|
|
|
value: list |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
onCategory: function (e) { |
|
|
|
@ -351,33 +422,37 @@ Page({ |
|
|
|
util.showToast('请选择废纸品类') |
|
|
|
return |
|
|
|
} |
|
|
|
// if (util.isEmpty(this.data.form.unitPrice)) {
|
|
|
|
// if (this.data.form.bidType == 1) {
|
|
|
|
// util.showToast('请输入商品单价')
|
|
|
|
// } else {
|
|
|
|
// util.showToast('请输入起拍单价')
|
|
|
|
// }
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// if(app.globalData.kg){
|
|
|
|
// if(parseFloat(this.data.form.unitPrice) > 100){
|
|
|
|
// if (this.data.form.bidType == 1) {
|
|
|
|
// util.showToast('请检查您输入的商品单价是否合理')
|
|
|
|
// } else {
|
|
|
|
// util.showToast('请检查您输入的起拍单价是否合理')
|
|
|
|
// }
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// } else {
|
|
|
|
// if(parseFloat(this.data.form.unitPrice) < 100){
|
|
|
|
// if (this.data.form.bidType == 1) {
|
|
|
|
// util.showToast('请检查您输入的商品单价是否合理')
|
|
|
|
// } else {
|
|
|
|
// util.showToast('请检查您输入的起拍单价是否合理')
|
|
|
|
// }
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
if (this.data.form.bidType == 2) { |
|
|
|
if (util.isEmpty(this.data.form.unitPrice)) { |
|
|
|
if (this.data.form.bidType == 1) { |
|
|
|
util.showToast('请输入商品单价') |
|
|
|
} else { |
|
|
|
util.showToast('请输入起拍单价') |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
if (app.globalData.kg) { |
|
|
|
if (parseFloat(this.data.form.unitPrice) > 100) { |
|
|
|
if (this.data.form.bidType == 1) { |
|
|
|
util.showToast('请检查您输入的商品单价是否合理') |
|
|
|
} else { |
|
|
|
util.showToast('请检查您输入的起拍单价是否合理') |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (parseFloat(this.data.form.unitPrice) < 100) { |
|
|
|
if (this.data.form.bidType == 1) { |
|
|
|
util.showToast('请检查您输入的商品单价是否合理') |
|
|
|
} else { |
|
|
|
util.showToast('请检查您输入的起拍单价是否合理') |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (util.isEmpty(this.data.form.stock)) { |
|
|
|
util.showToast('请输入库存') |
|
|
|
return |
|
|
|
@ -411,16 +486,21 @@ Page({ |
|
|
|
util.showToast('请输入商品描述') |
|
|
|
return |
|
|
|
} |
|
|
|
this.setData({ requesting: true }) |
|
|
|
wx.showLoading({ title: '加载中', mask: true }) |
|
|
|
if(!app.globalData.kg){ |
|
|
|
if(this.data.form.unitPrice>0){ |
|
|
|
this.setData({ |
|
|
|
requesting: true |
|
|
|
}) |
|
|
|
wx.showLoading({ |
|
|
|
title: '加载中', |
|
|
|
mask: true |
|
|
|
}) |
|
|
|
if (!app.globalData.kg) { |
|
|
|
if (this.data.form.unitPrice > 0) { |
|
|
|
this.data.form.unitPrice = math.divide(this.data.form.unitPrice, 1000) |
|
|
|
|
|
|
|
}else{ |
|
|
|
this.data.form.unitPrice='' |
|
|
|
|
|
|
|
} else { |
|
|
|
this.data.form.unitPrice = '' |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.data.form.stock = math.times(this.data.form.stock, 1000) |
|
|
|
if (!util.isEmpty(this.data.form.lowestNum)) { |
|
|
|
this.data.form.lowestNum = math.times(this.data.form.lowestNum, 1000) |
|
|
|
@ -429,12 +509,17 @@ Page({ |
|
|
|
if (this.data.form.productId) { |
|
|
|
updateProductInfo(this.data.form).then(result => { |
|
|
|
wx.hideLoading() |
|
|
|
event.emit('EventMessage', { what: 102, desc: 'GoodsCreate' }) |
|
|
|
event.emit('EventMessage', { |
|
|
|
what: 102, |
|
|
|
desc: 'GoodsCreate' |
|
|
|
}) |
|
|
|
util.showBackToast('商品发布成功!') |
|
|
|
}).catch(err => { |
|
|
|
//异常回调
|
|
|
|
wx.hideLoading() |
|
|
|
this.setData({ requesting: false }) |
|
|
|
this.setData({ |
|
|
|
requesting: false |
|
|
|
}) |
|
|
|
util.showToast(err) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
@ -443,7 +528,9 @@ Page({ |
|
|
|
util.showBackToast('商品创建成功!') |
|
|
|
}).catch(err => { |
|
|
|
wx.hideLoading() |
|
|
|
this.setData({ requesting: false }) |
|
|
|
this.setData({ |
|
|
|
requesting: false |
|
|
|
}) |
|
|
|
util.showToast(err) |
|
|
|
}) |
|
|
|
} |
|
|
|
|