|
@@ -1,5 +1,5 @@
|
|
const uploadJS = require('../../mixin/upload.js')
|
|
const uploadJS = require('../../mixin/upload.js')
|
|
-const { postAddProduct, postModifyProduct, getProductDetail, mockData } = require('./api/index')
|
|
+const { postAddProduct, postModifyProduct, getProductDetail } = require('./api/index')
|
|
const { getProductCategoryList, getProductBrandList } = require('../../api/common')
|
|
const { getProductCategoryList, getProductBrandList } = require('../../api/common')
|
|
const { formatTs, yuan2Fen, fen2Yuan } = require('../../utils/util')
|
|
const { formatTs, yuan2Fen, fen2Yuan } = require('../../utils/util')
|
|
const minDate = new Date().getTime()
|
|
const minDate = new Date().getTime()
|
|
@@ -38,8 +38,8 @@ Page({
|
|
'product_all_price': '',
|
|
'product_all_price': '',
|
|
'product_price': '',
|
|
'product_price': '',
|
|
'product_count': '',
|
|
'product_count': '',
|
|
- 'product_sale_at': '预售',
|
|
+ 'product_status': 0,
|
|
- ...mockData
|
|
+ 'product_sale_at': '预售'
|
|
},
|
|
},
|
|
product_img_url_max: 1,
|
|
product_img_url_max: 1,
|
|
product_rotation_img_list_max: 5,
|
|
product_rotation_img_list_max: 5,
|
|
@@ -65,16 +65,23 @@ Page({
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
async onLoad(options) {
|
|
async onLoad(options) {
|
|
- const { id } = options
|
|
+ const { product_id } = options
|
|
|
|
|
|
await this.fetchProductCategoryList()
|
|
await this.fetchProductCategoryList()
|
|
await this.fetchProductBrandList()
|
|
await this.fetchProductBrandList()
|
|
- if (id) {
|
|
+ if (product_id) {
|
|
this.setData({
|
|
this.setData({
|
|
- 'form.id': id
|
|
+ 'form.id': product_id
|
|
}, () => {
|
|
}, () => {
|
|
this.fetchProductDetail()
|
|
this.fetchProductDetail()
|
|
})
|
|
})
|
|
|
|
+ wx.setNavigationBarTitle({
|
|
|
|
+ title: '产品编辑'
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ wx.setNavigationBarTitle({
|
|
|
|
+ title: '产品新增'
|
|
|
|
+ })
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
@@ -150,45 +157,22 @@ Page({
|
|
async fetchProductDetail() {
|
|
async fetchProductDetail() {
|
|
let temp = {}
|
|
let temp = {}
|
|
try {
|
|
try {
|
|
-
|
|
+ const { status, data, msg } = await getProductDetail(this.data.form.id)
|
|
- const { status, data, msg } = {
|
|
|
|
- 'status': true,
|
|
|
|
- 'data': {
|
|
|
|
- 'id': 2,
|
|
|
|
- 'shop_id': 1,
|
|
|
|
- 'product_img_url': 'sdsd',
|
|
|
|
- 'product_rotation_img_list': '["sdsjdsd"]',
|
|
|
|
- 'product_detail_img_list': '["sdsndish"]',
|
|
|
|
- 'product_title': '测试商品',
|
|
|
|
- 'product_category_id': null,
|
|
|
|
- 'product_category_name': '',
|
|
|
|
- 'product_brand_id': 1,
|
|
|
|
- 'product_brand_name': '大众',
|
|
|
|
- 'product_spec': 'xl',
|
|
|
|
- 'product_unit': '个',
|
|
|
|
- 'product_code': '1-1-1663145154',
|
|
|
|
- 'product_all_price': 10000,
|
|
|
|
- 'product_price': 9000,
|
|
|
|
- 'product_count': 1000,
|
|
|
|
- 'product_sale_at': 0,
|
|
|
|
- 'product_status': 1,
|
|
|
|
- 'created_at': '2022-09-14 16:45:54',
|
|
|
|
- 'updated_at': '2022-09-14 16:45:54',
|
|
|
|
- 'product_market_price': 0,
|
|
|
|
- 'product_is_select': 0,
|
|
|
|
- 'product_desc': ''
|
|
|
|
- },
|
|
|
|
- 'code': 200,
|
|
|
|
- 'msg': '',
|
|
|
|
- 'url': ''
|
|
|
|
- }
|
|
|
|
if (status) {
|
|
if (status) {
|
|
for (let key in data) {
|
|
for (let key in data) {
|
|
let value = data[key]
|
|
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 ((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' || key === 'product_rotation_img_list' || key === 'product_detail_img_list') {
|
|
+ if (key === 'product_img_url') {
|
|
- value = value.map(item => {
|
|
+ value = [
|
|
|
|
+ {
|
|
|
|
+ 'formkey': key,
|
|
|
|
+ 'url': value
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ if (key === 'product_rotation_img_list' || key === 'product_detail_img_list') {
|
|
|
|
+ value = JSON.parse(value).map(item => {
|
|
return {
|
|
return {
|
|
'formkey': key,
|
|
'formkey': key,
|
|
'url': item
|
|
'url': item
|
|
@@ -201,11 +185,6 @@ Page({
|
|
if (category.length > 0) {
|
|
if (category.length > 0) {
|
|
value = category[0]
|
|
value = category[0]
|
|
temp['categoryInDefaultIndex'] = this.data.categoryList.findIndex(item => item.id === value)
|
|
temp['categoryInDefaultIndex'] = this.data.categoryList.findIndex(item => item.id === value)
|
|
- } else {
|
|
|
|
- value = {
|
|
|
|
- 'category_name': '',
|
|
|
|
- 'id': ''
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (key === 'product_brand_id') {
|
|
if (key === 'product_brand_id') {
|
|
@@ -213,11 +192,6 @@ Page({
|
|
if (brand.length > 0) {
|
|
if (brand.length > 0) {
|
|
value = brand[0]
|
|
value = brand[0]
|
|
temp['brandInDefaultIndex'] = this.data.brandList.findIndex(item => item.id === value)
|
|
temp['brandInDefaultIndex'] = this.data.brandList.findIndex(item => item.id === value)
|
|
- } else {
|
|
|
|
- value = {
|
|
|
|
- 'brand_name': '',
|
|
|
|
- 'id': ''
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -234,8 +208,12 @@ Page({
|
|
|
|
|
|
if (key === 'product_sale_at') {
|
|
if (key === 'product_sale_at') {
|
|
if (value === 0) {
|
|
if (value === 0) {
|
|
- temp['saleAtType'] = '0'
|
|
+ value = '预售'
|
|
} else {
|
|
} else {
|
|
|
|
+ const { YYYY, MM, DD, HH, mm } = formatTs(value)
|
|
|
|
+
|
|
|
|
+ value = `${YYYY}年${MM}月${DD}日 ${HH}:${mm}`
|
|
|
|
+ temp['saleAtType'] = '1'
|
|
temp['currentDate'] = value
|
|
temp['currentDate'] = value
|
|
}
|
|
}
|
|
}
|
|
}
|