|
@@ -85,6 +85,13 @@ Page({
|
|
wx.setNavigationBarTitle({
|
|
wx.setNavigationBarTitle({
|
|
title: '产品新增'
|
|
title: '产品新增'
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ const response = await wx.getStorage({ key: app.globalData.businessGoodsEditsStorageKey })
|
|
|
|
+ if (response.errMsg === 'getStorage:ok' && /^{/.test(response.data)) {
|
|
|
|
+ this.setForm(JSON.parse(response.data))
|
|
|
|
+ }
|
|
|
|
+ } catch (err) {}
|
|
}
|
|
}
|
|
app.fetchSystemConfigCallback = () => {
|
|
app.fetchSystemConfigCallback = () => {
|
|
this.setUnitInColumns()
|
|
this.setUnitInColumns()
|
|
@@ -161,80 +168,10 @@ Page({
|
|
} catch (err) {}
|
|
} catch (err) {}
|
|
},
|
|
},
|
|
async fetchProductDetail() {
|
|
async fetchProductDetail() {
|
|
- let temp = {}
|
|
|
|
try {
|
|
try {
|
|
const { status, data, msg } = await getProductDetail(this.data.form.id)
|
|
const { status, data, msg } = await getProductDetail(this.data.form.id)
|
|
if (status) {
|
|
if (status) {
|
|
- for (let key in data) {
|
|
|
|
- let value = data[key]
|
|
|
|
- if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
|
|
|
|
-
|
|
|
|
- if (key === 'product_img_url') {
|
|
|
|
- value = [
|
|
|
|
- {
|
|
|
|
- 'formkey': key,
|
|
|
|
- 'url': value
|
|
|
|
- }
|
|
|
|
- ]
|
|
|
|
- }
|
|
|
|
- if (key === 'product_rotation_img_list' || key === 'product_detail_img_list') {
|
|
|
|
- value = JSON.parse(value).map(item => {
|
|
|
|
- return {
|
|
|
|
- 'formkey': key,
|
|
|
|
- 'url': item
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (key === 'product_category_id') {
|
|
|
|
- const category = this.data.categoryList.filter(item => item.id === value)
|
|
|
|
- if (category.length > 0) {
|
|
|
|
- value = category[0]
|
|
|
|
- temp['categoryInDefaultIndex'] = this.data.categoryList.findIndex(item => item.id === value)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (key === 'product_brand_id') {
|
|
|
|
- const brand = this.data.brandList.filter(item => item.id === value)
|
|
|
|
- if (brand.length > 0) {
|
|
|
|
- value = brand[0]
|
|
|
|
- temp['brandInDefaultIndex'] = this.data.brandList.findIndex(item => item.id === value)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (key === 'product_unit') {
|
|
|
|
- const unit = this.data.unitInColumns.filter(item => item === value)
|
|
|
|
- if (unit.length > 0) {
|
|
|
|
- temp['unitInDefaultIndex'] = this.data.unitInColumns.findIndex(item => item === value)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (key === 'product_all_price' || key === 'product_price') {
|
|
|
|
- value = fen2Yuan(value)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (key === 'product_sale_at') {
|
|
|
|
- if (value === 0) {
|
|
|
|
- value = '现货'
|
|
|
|
- } else {
|
|
|
|
- const { YYYY, MM, DD} = formatTs(value * 1000)
|
|
|
|
-
|
|
|
|
- temp['saleAtType'] = '1'
|
|
|
|
- temp['currentDate'] = value * 1000
|
|
|
|
- value = `${YYYY}年${MM}月${DD}日`
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (key === 'product_check_status') {
|
|
|
|
- temp['productCheckStatus'] = value
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (this.data.form.hasOwnProperty(key)) {
|
|
|
|
- temp[`form.${key}`] = value
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.setData(temp)
|
|
|
|
|
|
+ this.setForm(data)
|
|
} else {
|
|
} else {
|
|
wx.showToast({
|
|
wx.showToast({
|
|
title: msg,
|
|
title: msg,
|
|
@@ -245,6 +182,7 @@ Page({
|
|
},
|
|
},
|
|
...uploadJS,
|
|
...uploadJS,
|
|
uploadCallBack(res) {
|
|
uploadCallBack(res) {
|
|
|
|
+ const that = this
|
|
const temp = res.map(item => {
|
|
const temp = res.map(item => {
|
|
return {
|
|
return {
|
|
'url': item.url,
|
|
'url': item.url,
|
|
@@ -270,7 +208,9 @@ Page({
|
|
}
|
|
}
|
|
|
|
|
|
if (Object.keys(tempForm).length > 0) {
|
|
if (Object.keys(tempForm).length > 0) {
|
|
- this.setData(tempForm)
|
|
|
|
|
|
+ this.setData(tempForm, () => {
|
|
|
|
+ that.updateBusinessGoodsEditsDataOfStorage(formkey, that.data.form[formkey].map(item => item.url))
|
|
|
|
+ })
|
|
}
|
|
}
|
|
},
|
|
},
|
|
categoryShow() {
|
|
categoryShow() {
|
|
@@ -293,6 +233,8 @@ Page({
|
|
this.setData({
|
|
this.setData({
|
|
'form.product_category_id': value,
|
|
'form.product_category_id': value,
|
|
categoryInDefaultIndex: index
|
|
categoryInDefaultIndex: index
|
|
|
|
+ }, () => {
|
|
|
|
+ this.updateBusinessGoodsEditsDataOfStorage('product_category_id', value.id)
|
|
})
|
|
})
|
|
|
|
|
|
this.categoryHide()
|
|
this.categoryHide()
|
|
@@ -317,6 +259,8 @@ Page({
|
|
this.setData({
|
|
this.setData({
|
|
'form.product_brand_id': value,
|
|
'form.product_brand_id': value,
|
|
brandInDefaultIndex: index
|
|
brandInDefaultIndex: index
|
|
|
|
+ }, () => {
|
|
|
|
+ this.updateBusinessGoodsEditsDataOfStorage('product_brand_id', value.id)
|
|
})
|
|
})
|
|
|
|
|
|
this.brandHide()
|
|
this.brandHide()
|
|
@@ -341,6 +285,8 @@ Page({
|
|
this.setData({
|
|
this.setData({
|
|
'form.product_unit': value,
|
|
'form.product_unit': value,
|
|
unitInDefaultIndex: index
|
|
unitInDefaultIndex: index
|
|
|
|
+ }, () => {
|
|
|
|
+ this.updateBusinessGoodsEditsDataOfStorage('product_unit', value)
|
|
})
|
|
})
|
|
|
|
|
|
this.unitHide()
|
|
this.unitHide()
|
|
@@ -366,13 +312,8 @@ Page({
|
|
default:
|
|
default:
|
|
}
|
|
}
|
|
|
|
|
|
- this.setData(tempForm)
|
|
|
|
- },
|
|
|
|
- handleRadio(event) {
|
|
|
|
- const { formkey, item } = event.currentTarget.dataset
|
|
|
|
-
|
|
|
|
- this.setData({
|
|
|
|
- [`form.${formkey}`]: item.value
|
|
|
|
|
|
+ this.setData(tempForm, () => {
|
|
|
|
+ this.updateBusinessGoodsEditsDataOfStorage(formkey, this.data.form[formkey])
|
|
})
|
|
})
|
|
},
|
|
},
|
|
saleAtTypeShow() {
|
|
saleAtTypeShow() {
|
|
@@ -389,7 +330,9 @@ Page({
|
|
tempForm['booSaleAt'] = true
|
|
tempForm['booSaleAt'] = true
|
|
}
|
|
}
|
|
|
|
|
|
- this.setData(tempForm)
|
|
|
|
|
|
+ this.setData(tempForm, () => {
|
|
|
|
+ this.updateBusinessGoodsEditsDataOfStorage('product_sale_at', 0)
|
|
|
|
+ })
|
|
},
|
|
},
|
|
handleSaleAtType(e) {
|
|
handleSaleAtType(e) {
|
|
const { type } = e.currentTarget.dataset
|
|
const { type } = e.currentTarget.dataset
|
|
@@ -411,6 +354,8 @@ Page({
|
|
this.setData({
|
|
this.setData({
|
|
currentDate: event.detail,
|
|
currentDate: event.detail,
|
|
'form.product_sale_at': `${YYYY}年${MM}月${DD}日`
|
|
'form.product_sale_at': `${YYYY}年${MM}月${DD}日`
|
|
|
|
+ }, () => {
|
|
|
|
+ this.updateBusinessGoodsEditsDataOfStorage('product_sale_at', getTs(this.data.form.product_sale_at, 'YYYY年MM月DD日', 's'))
|
|
})
|
|
})
|
|
|
|
|
|
this.saleAtHide()
|
|
this.saleAtHide()
|
|
@@ -525,10 +470,10 @@ Page({
|
|
} else {
|
|
} else {
|
|
res = await postAddProduct(temp)
|
|
res = await postAddProduct(temp)
|
|
}
|
|
}
|
|
- const { status, data, msg } = res
|
|
|
|
|
|
+ const { status, msg } = res
|
|
if (status) {
|
|
if (status) {
|
|
- wx.redirectTo({
|
|
|
|
- url: '/pages/businessGoodsManage/businessGoodsManage'
|
|
|
|
|
|
+ wx.navigateBack({
|
|
|
|
+ delta: 1
|
|
})
|
|
})
|
|
} else {
|
|
} else {
|
|
wx.showToast({
|
|
wx.showToast({
|
|
@@ -544,5 +489,102 @@ Page({
|
|
this.setData({
|
|
this.setData({
|
|
unitInColumns: Array.isArray(product_unit_list) && product_unit_list.length > 0 ? product_unit_list : []
|
|
unitInColumns: Array.isArray(product_unit_list) && product_unit_list.length > 0 ? product_unit_list : []
|
|
})
|
|
})
|
|
|
|
+ },
|
|
|
|
+ setForm(data) {
|
|
|
|
+ let temp = {}
|
|
|
|
+ for (let key in data) {
|
|
|
|
+ let value = data[key]
|
|
|
|
+ if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
|
|
|
|
+ if (key === 'product_img_url') {
|
|
|
|
+ value = [
|
|
|
|
+ {
|
|
|
|
+ 'formkey': key,
|
|
|
|
+ 'url': Array.isArray(value) ? value.join('') : value
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ if (key === 'product_rotation_img_list' || key === 'product_detail_img_list') {
|
|
|
|
+ value = (Array.isArray(value) ? value : JSON.parse(value)).map(item => {
|
|
|
|
+ return {
|
|
|
|
+ 'formkey': key,
|
|
|
|
+ 'url': item
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (key === 'product_category_id') {
|
|
|
|
+ const category = this.data.categoryList.filter(item => item.id === value)
|
|
|
|
+ if (category.length > 0) {
|
|
|
|
+ value = category[0]
|
|
|
|
+ temp['categoryInDefaultIndex'] = this.data.categoryList.findIndex(item => item.id === value.id)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (key === 'product_brand_id') {
|
|
|
|
+ const brand = this.data.brandList.filter(item => item.id === value)
|
|
|
|
+ if (brand.length > 0) {
|
|
|
|
+ value = brand[0]
|
|
|
|
+ temp['brandInDefaultIndex'] = this.data.brandList.findIndex(item => item.id === value.id)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (key === 'product_unit') {
|
|
|
|
+ const unit = this.data.unitInColumns.filter(item => item === value)
|
|
|
|
+ if (unit.length > 0) {
|
|
|
|
+ temp['unitInDefaultIndex'] = this.data.unitInColumns.findIndex(item => item === value)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (key === 'product_all_price' || key === 'product_price') {
|
|
|
|
+ value = fen2Yuan(value)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (key === 'product_sale_at') {
|
|
|
|
+ if (value === 0) {
|
|
|
|
+ value = '现货'
|
|
|
|
+ } else {
|
|
|
|
+ const { YYYY, MM, DD } = formatTs(value * 1000)
|
|
|
|
+
|
|
|
|
+ temp['saleAtType'] = '1'
|
|
|
|
+ temp['currentDate'] = value * 1000
|
|
|
|
+ value = `${YYYY}年${MM}月${DD}日`
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (key === 'product_check_status') {
|
|
|
|
+ temp['productCheckStatus'] = value
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.data.form.hasOwnProperty(key)) {
|
|
|
|
+ temp[`form.${key}`] = value
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.setData(temp)
|
|
|
|
+ },
|
|
|
|
+ async updateBusinessGoodsEditsDataOfStorage(formKey, value) {
|
|
|
|
+ const key = app.globalData.businessGoodsEditsStorageKey
|
|
|
|
+ let temp = {}
|
|
|
|
+
|
|
|
|
+ if (this.data.form.id) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ const { data, errMsg } = await wx.getStorage({ key })
|
|
|
|
+ if (errMsg === 'getStorage:ok' && /^{/.test(data)) {
|
|
|
|
+ temp = JSON.parse(data)
|
|
|
|
+ }
|
|
|
|
+ } catch (e) {
|
|
|
|
+ temp = {}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ wx.setStorage({
|
|
|
|
+ key,
|
|
|
|
+ data: JSON.stringify({
|
|
|
|
+ ...temp,
|
|
|
|
+ [formKey]: value
|
|
|
|
+ })
|
|
|
|
+ })
|
|
}
|
|
}
|
|
})
|
|
})
|