绿满眶商城微信小程序-uniapp
zhanghua
2025-06-09 7ee6309073fdc9fd38979accabb733cee42cefaa
pages/goods-manager/addGoods/addGoods.vue
@@ -4,9 +4,9 @@
         <u-form :border-bottom="false" :model="form" ref="uForm" :error-type="['toast']" :rule="rules">
            <u-form-item label="商品分类" label-width="130" prop="">
               <div @click="showPicker">
                  {{ form.___path || '请选择所在地区' }}
               </div>
               <picker @change="bindCategoryChange" :value="index" :range="categoryArray">
                  <view class="uni-input">{{categoryArray[index]}}</view>
               </picker>
            </u-form-item>
            <u-form-item class="border" label="商品名称" label-width="130" prop="name">
@@ -24,13 +24,13 @@
            </u-form-item>
            <u-form-item label="商品品牌" label-width="130" prop="">
               <div @click="showPicker">
                  {{ form.___path || '请选择所在地区' }}
               <div @click="showBrands">
                  {{ form.___path || '请选择品牌' }}
               </div>
            </u-form-item>
            <u-form-item label="计量单位" label-width="130" prop="___path">
               <div @click="showPicker">
               <div @click="showUnit">
                  {{ form.___path || '请选择所在地区' }}
               </div>
            </u-form-item>
@@ -64,16 +64,19 @@
import UCheckboxGroup from '@/uview-components/uview-ui/components/u-checkbox-group/u-checkbox-group.vue';
import UCheckbox from '@/uview-components/uview-ui/components/u-checkbox/u-checkbox.vue';
import UIcon from '@/uview-components/uview-ui/components/u-icon/u-icon.vue';
import UActionSheet from '@/uview-components/uview-ui/components/u-action-sheet/u-action-sheet.vue';
import storage from "@/utils/storage.js";
import * as API_GOODS from "@/api/goods.js";
export default {
   components: { UForm, UFormItem, UInput, UUpload, UCheckboxGroup, UCheckbox, UIcon, UActionSheet },
   components: { UForm, UFormItem, UInput, UUpload, UCheckboxGroup, UCheckbox, UIcon },
   data() {
      return {
         storage,
         form: {}
         form: {},
         categoryArray:[],
         brandsArray:[],
         unitArray:[]
      }
   },
   methods: {
@@ -86,17 +89,44 @@
         });
         this.form.images = images;
      },
      bindCategoryChange(){},
      bindBrandsChange(){},
      bindUnitChange(){},
      initCategory(){
         API_GOODS.getStoreGoodsCategory().then((res) => {
            const params = res.data.result;
            this.categoryArray = params
            if(params.length>0){
               this.initBrands(params[0].id)
            }
         });
      },
      initBrands(categoryId){
         API_GOODS.getStoreGoodsBrands(categoryId).then((res) => {
            const params = res.data.result;
            this.brandsArray = params
         });
      },
      initGoods(){
         API_GOODS.getgoodsUnit().then((res) => {
            const params = res.data.result;
            this.unitArray = params
         });
      },
   },
   onShow() {
      this.initGoods()
      this.initCategory()
   },
   onLoad(option) {
      uni.showLoading({
         title: "加载中",
      });
      this.routerVal = option;
      console.log(option);
      if (option.id) {
         getGoodsDetail(option.id).then((res) => {
         API_GOODS.getStoreGoodsInfo(option.id).then((res) => {
            const params = res.data.result;
            params.___path = params.consigneegoodsPath;
            this.$set(this, "form", params);