|
@@ -1,7 +1,7 @@
|
|
|
const uploadJS = require('../../mixin/upload.js')
|
|
|
-const { postAddProduct, postModifyProduct } = require('./api/index')
|
|
|
+const { postAddProduct, postModifyProduct, getProductDetail } = require('./api/index')
|
|
|
const { getProductCategoryList, getProductBrandList } = require('../../api/common')
|
|
|
-const { formatTs, yuan2Fen } = require('../../utils/util')
|
|
|
+const { formatTs, yuan2Fen, fen2Yuan } = require('../../utils/util')
|
|
|
const minDate = new Date().getTime()
|
|
|
const objMinDate = formatTs(minDate)
|
|
|
|
|
@@ -20,51 +20,24 @@ Page({
|
|
|
|
|
|
|
|
|
form: {
|
|
|
- 'product_img_url': [
|
|
|
- {
|
|
|
- 'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe57fa.jpg',
|
|
|
- 'formkey': 'product_rotation_img_list'
|
|
|
- }
|
|
|
- ],
|
|
|
- 'product_rotation_img_list': [
|
|
|
- {
|
|
|
- 'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe57fa.jpg',
|
|
|
- 'formkey': 'product_rotation_img_list'
|
|
|
- },
|
|
|
- {
|
|
|
- 'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe51c4.jpg',
|
|
|
- 'formkey': 'product_rotation_img_list'
|
|
|
- },
|
|
|
- {
|
|
|
- 'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffefa54.jpg',
|
|
|
- 'formkey': 'product_rotation_img_list'
|
|
|
- },
|
|
|
- {
|
|
|
- 'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi6323230067e26.png',
|
|
|
- 'formkey': 'product_rotation_img_list'
|
|
|
- }
|
|
|
- ],
|
|
|
- 'product_detail_img_list': [
|
|
|
- {
|
|
|
- 'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe57fa.jpg',
|
|
|
- 'formkey': 'product_rotation_img_list'
|
|
|
- }
|
|
|
- ],
|
|
|
- 'product_title': '商品标题',
|
|
|
- 'product_desc': '商品简介',
|
|
|
+ 'product_img_url': [],
|
|
|
+ 'product_rotation_img_list': [],
|
|
|
+ 'product_detail_img_list': [],
|
|
|
+ 'product_title': '',
|
|
|
+ 'product_desc': '',
|
|
|
'product_category_id': {
|
|
|
'category_name': '',
|
|
|
- 'id': '1'
|
|
|
+ 'id': ''
|
|
|
},
|
|
|
'product_brand_id': {
|
|
|
'brand_name': '',
|
|
|
- 'id': '1'
|
|
|
+ 'id': ''
|
|
|
},
|
|
|
- 'product_spec': '10个没件',
|
|
|
- 'product_unit': '个',
|
|
|
- 'product_all_price': '100',
|
|
|
- 'product_price': '88',
|
|
|
- 'product_count': '100',
|
|
|
+ 'product_spec': '',
|
|
|
+ 'product_unit': '',
|
|
|
+ 'product_all_price': '',
|
|
|
+ 'product_price': '',
|
|
|
+ 'product_count': '',
|
|
|
'product_sale_at': '预售'
|
|
|
},
|
|
|
product_img_url_max: 1,
|
|
@@ -99,7 +72,7 @@ Page({
|
|
|
this.setData({
|
|
|
'form.id': id
|
|
|
}, () => {
|
|
|
-
|
|
|
+ this.fetchProductDetail()
|
|
|
})
|
|
|
}
|
|
|
},
|
|
@@ -131,27 +104,7 @@ Page({
|
|
|
onUnload() {
|
|
|
|
|
|
},
|
|
|
-
|
|
|
-
|
|
|
- * 页面相关事件处理函数--监听用户下拉动作
|
|
|
- */
|
|
|
- onPullDownRefresh() {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- * 页面上拉触底事件的处理函数
|
|
|
- */
|
|
|
- onReachBottom() {
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
-
|
|
|
- * 用户点击右上角分享
|
|
|
- */
|
|
|
- onShareAppMessage() {
|
|
|
-
|
|
|
- },
|
|
|
+
|
|
|
async fetchProductCategoryList() {
|
|
|
try {
|
|
|
const { status, data, msg } = await getProductCategoryList()
|
|
@@ -172,23 +125,134 @@ Page({
|
|
|
}
|
|
|
} catch (err) {}
|
|
|
},
|
|
|
+
|
|
|
async fetchProductBrandList() {
|
|
|
- const { status, data, msg } = await getProductBrandList()
|
|
|
- if (status) {
|
|
|
- this.setData({
|
|
|
- brandList: data.map(item => {
|
|
|
- return {
|
|
|
- ...item,
|
|
|
- text: item.brand_name
|
|
|
+ try {
|
|
|
+ const { status, data, msg } = await getProductBrandList()
|
|
|
+ if (status) {
|
|
|
+ this.setData({
|
|
|
+ brandList: data.map(item => {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ text: item.brand_name
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (err) {}
|
|
|
+ },
|
|
|
+ async fetchProductDetail() {
|
|
|
+ let temp = {}
|
|
|
+ try {
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ 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 => {
|
|
|
+ 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)
|
|
|
+ } else {
|
|
|
+ value = {
|
|
|
+ 'category_name': '',
|
|
|
+ '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)
|
|
|
+ } else {
|
|
|
+ value = {
|
|
|
+ 'brand_name': '',
|
|
|
+ '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) {
|
|
|
+ temp['saleAtType'] = '0'
|
|
|
+ } else {
|
|
|
+ temp['currentDate'] = value
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.data.form.hasOwnProperty(key)) {
|
|
|
+ temp[`form.${key}`] = value
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData(temp)
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'none'
|
|
|
})
|
|
|
- })
|
|
|
- } else {
|
|
|
- wx.showToast({
|
|
|
- title: msg,
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- }
|
|
|
+ }
|
|
|
+ } catch (err) {}
|
|
|
},
|
|
|
...uploadJS,
|
|
|
uploadCallBack(res) {
|
|
@@ -206,11 +270,12 @@ Page({
|
|
|
|
|
|
switch (formkey) {
|
|
|
case 'product_img_url':
|
|
|
- tempForm[`form.${formkey}`] = temp
|
|
|
+ tempForm[`form.${formkey}[0]`] = temp[0]
|
|
|
break
|
|
|
case 'product_rotation_img_list':
|
|
|
case 'product_detail_img_list':
|
|
|
- tempForm[`form.${formkey}`] = this.data.form[formkey].concat(...temp)
|
|
|
+ const formkeyData = this.data.form[formkey]
|
|
|
+ tempForm[`form.${formkey}`] = formkeyData.concat(...temp)
|
|
|
break
|
|
|
default:
|
|
|
}
|
|
@@ -387,7 +452,6 @@ Page({
|
|
|
product_sale_at: product_sale_at === '预售' ? 0 : this.data.currentDate
|
|
|
}
|
|
|
},
|
|
|
- setForm() {},
|
|
|
verify() {
|
|
|
let errorList = []
|
|
|
const {
|
|
@@ -407,10 +471,10 @@ Page({
|
|
|
if (!product_img_url) {
|
|
|
errorList.push('请上传商品主图')
|
|
|
}
|
|
|
- if (!product_rotation_img_list.length) {
|
|
|
+ if (!product_rotation_img_list) {
|
|
|
errorList.push('请上传商品轮播图')
|
|
|
}
|
|
|
- if (!product_detail_img_list.length) {
|
|
|
+ if (!product_detail_img_list) {
|
|
|
errorList.push('请上传商品详情图')
|
|
|
}
|
|
|
if (!product_title) {
|
|
@@ -463,6 +527,16 @@ Page({
|
|
|
res = await postModifyProduct({ ...temp, id: this.data.form.id })
|
|
|
}
|
|
|
const { status, data, msg } = res
|
|
|
+ if (status) {
|
|
|
+ wx.redirectTo({
|
|
|
+ url: '/pages/businessGoodsManage/businessGoodsManage'
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
} catch (err) {}
|
|
|
}
|
|
|
})
|