|
@@ -1,4 +1,5 @@
|
|
|
const uploadJS = require('../../mixin/upload.js')
|
|
|
+const { getProductCategoryList, getProductBrandList } = require('./api/index')
|
|
|
|
|
|
Page({
|
|
|
|
|
@@ -55,7 +56,13 @@ Page({
|
|
|
product_img_url_max: 1,
|
|
|
product_rotation_img_list_max: 5,
|
|
|
product_detail_img_list_max: 5,
|
|
|
- unitShow: false,
|
|
|
+ booCategory: false,
|
|
|
+ categoryInDefaultIndex: 0,
|
|
|
+ categoryList: [],
|
|
|
+ booBrand: false,
|
|
|
+ brandInDefaultIndex: 0,
|
|
|
+ brandList: [],
|
|
|
+ booUnit: false,
|
|
|
unitInDefaultIndex: 0,
|
|
|
unitInColumns: ['件', '个']
|
|
|
},
|
|
@@ -63,8 +70,9 @@ Page({
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
- onLoad(options) {
|
|
|
-
|
|
|
+ async onLoad(options) {
|
|
|
+ await this.fetchProductCategoryList()
|
|
|
+ await this.fetchProductBrandList()
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -114,6 +122,44 @@ Page({
|
|
|
*/
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
+ },
|
|
|
+ async fetchProductCategoryList() {
|
|
|
+ try {
|
|
|
+ const { status, data, msg } = await getProductCategoryList()
|
|
|
+ if (status) {
|
|
|
+ this.setData({
|
|
|
+ categoryList: data.map(item => {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ text: item.category_name
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ wx.showToast({
|
|
|
+ title: msg,
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } catch (err) {}
|
|
|
+ },
|
|
|
+ async fetchProductBrandList() {
|
|
|
+ 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'
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
...uploadJS,
|
|
|
uploadCallBack(res) {
|
|
@@ -140,22 +186,70 @@ Page({
|
|
|
default:
|
|
|
}
|
|
|
|
|
|
- console.log(tempForm)
|
|
|
-
|
|
|
if (Object.keys(tempForm).length > 0) {
|
|
|
this.setData(tempForm)
|
|
|
}
|
|
|
},
|
|
|
+ categoryShow() {
|
|
|
+ this.setData({
|
|
|
+ booCategory: true
|
|
|
+ })
|
|
|
+ },
|
|
|
+ categoryHide() {
|
|
|
+ if (this.data.categoryList.length > 0) {
|
|
|
+ this.selectComponent('#picker-category').setIndexes([this.data.categoryInDefaultIndex])
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ booCategory: false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ categoryConfirm(event) {
|
|
|
+ const { value, index } = event.detail
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ 'form.product_category_id': value,
|
|
|
+ categoryInDefaultIndex: index
|
|
|
+ })
|
|
|
+
|
|
|
+ this.categoryHide()
|
|
|
+ },
|
|
|
+ brandShow() {
|
|
|
+ this.setData({
|
|
|
+ booBrand: true
|
|
|
+ })
|
|
|
+ },
|
|
|
+ brandHide() {
|
|
|
+ if (this.data.brandList.length > 0) {
|
|
|
+ this.selectComponent('#picker-brand').setIndexes([this.data.brandInDefaultIndex])
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ booBrand: false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ brandConfirm(event) {
|
|
|
+ const { value, index } = event.detail
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ 'form.product_brand_id': value,
|
|
|
+ brandInDefaultIndex: index
|
|
|
+ })
|
|
|
+
|
|
|
+ this.brandHide()
|
|
|
+ },
|
|
|
unitShow() {
|
|
|
this.setData({
|
|
|
- unitShow: true
|
|
|
+ booUnit: true
|
|
|
})
|
|
|
},
|
|
|
unitHide() {
|
|
|
- this.selectComponent('#picker-unit').setIndexes([this.data.unitInDefaultIndex])
|
|
|
+ if (this.data.unitInColumns.length > 0) {
|
|
|
+ this.selectComponent('#picker-unit').setIndexes([this.data.unitInDefaultIndex])
|
|
|
+ }
|
|
|
|
|
|
this.setData({
|
|
|
- unitShow: false
|
|
|
+ booUnit: false
|
|
|
})
|
|
|
},
|
|
|
unitConfirm(event) {
|