|
@@ -1,5 +1,5 @@
|
|
|
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 { formatTs, yuan2Fen, fen2Yuan } = require('../../utils/util')
|
|
|
const minDate = new Date().getTime()
|
|
@@ -38,8 +38,8 @@ Page({
|
|
|
'product_all_price': '', // 批发价
|
|
|
'product_price': '', // 零售价
|
|
|
'product_count': '', // 库存
|
|
|
- 'product_sale_at': '预售', // 预售时间(0代表预售)
|
|
|
- ...mockData
|
|
|
+ 'product_status': 0, // 状态
|
|
|
+ 'product_sale_at': '预售' // 预售时间(0代表预售)
|
|
|
},
|
|
|
product_img_url_max: 1,
|
|
|
product_rotation_img_list_max: 5,
|
|
@@ -65,16 +65,23 @@ Page({
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
async onLoad(options) {
|
|
|
- const { id } = options
|
|
|
+ const { product_id } = options
|
|
|
|
|
|
await this.fetchProductCategoryList()
|
|
|
await this.fetchProductBrandList()
|
|
|
- if (id) {
|
|
|
+ if (product_id) {
|
|
|
this.setData({
|
|
|
- 'form.id': id
|
|
|
+ 'form.id': product_id
|
|
|
}, () => {
|
|
|
this.fetchProductDetail()
|
|
|
})
|
|
|
+ wx.setNavigationBarTitle({
|
|
|
+ title: '产品编辑'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.setNavigationBarTitle({
|
|
|
+ title: '产品新增'
|
|
|
+ })
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -150,45 +157,22 @@ Page({
|
|
|
async fetchProductDetail() {
|
|
|
let temp = {}
|
|
|
try {
|
|
|
- // const { status, data, msg } = await getProductDetail(this.data.form.id)
|
|
|
- const { status, data, msg } = {
|
|
|
- 'status': true,
|
|
|
- 'data': {
|
|
|
- 'id': 2, //商品ID
|
|
|
- 'shop_id': 1,
|
|
|
- 'product_img_url': 'sdsd', //商品主图
|
|
|
- 'product_rotation_img_list': '["sdsjdsd"]', //商品轮播图(json数组)
|
|
|
- 'product_detail_img_list': '["sdsndish"]', //商品详情图(json数据)
|
|
|
- 'product_title': '测试商品', //商品名称
|
|
|
- 'product_category_id': null, //商品分类ID
|
|
|
- 'product_category_name': '', //商品分类
|
|
|
- 'product_brand_id': 1, //商品品牌ID
|
|
|
- '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, //预售(0代表非预售 时间戳代表预售时间)
|
|
|
- 'product_status': 1, //状态(0下架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, //是否精选(0否1是)
|
|
|
- 'product_desc': ''
|
|
|
- }, //返回数据
|
|
|
- 'code': 200, //授权码
|
|
|
- 'msg': '', //返回文字描述
|
|
|
- 'url': ''
|
|
|
- }
|
|
|
+ const { status, data, msg } = await getProductDetail(this.data.form.id)
|
|
|
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' || key === 'product_rotation_img_list' || key === 'product_detail_img_list') {
|
|
|
- value = value.map(item => {
|
|
|
+ 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
|
|
@@ -201,11 +185,6 @@ Page({
|
|
|
if (category.length > 0) {
|
|
|
value = category[0]
|
|
|
temp['categoryInDefaultIndex'] = this.data.categoryList.findIndex(item => item.id === value)
|
|
|
- } else {
|
|
|
- value = {
|
|
|
- 'category_name': '',
|
|
|
- 'id': ''
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
if (key === 'product_brand_id') {
|
|
@@ -213,11 +192,6 @@ Page({
|
|
|
if (brand.length > 0) {
|
|
|
value = brand[0]
|
|
|
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 (value === 0) {
|
|
|
- temp['saleAtType'] = '0'
|
|
|
+ value = '预售'
|
|
|
} else {
|
|
|
+ const { YYYY, MM, DD, HH, mm } = formatTs(value)
|
|
|
+
|
|
|
+ value = `${YYYY}年${MM}月${DD}日 ${HH}:${mm}`
|
|
|
+ temp['saleAtType'] = '1'
|
|
|
temp['currentDate'] = value
|
|
|
}
|
|
|
}
|