xuxy
2024-06-28 b07d5f16634fc4a695fa8e6f6b18c33806f2b05a
sub_pages/supplier/flower-manage/flower-add.vue
文件名从 sub_pages/farmer/flower-manage/flower-add.vue 修改
@@ -3,29 +3,38 @@
      <view>
         <view class="form-item">
            <view class="label required">商品分类</view>
            <view class="m-l-a m-r-0 flex " :class="[!dto.category?'desc-gray':'']" @click="()=>{
            <!--             <view class="m-l-a m-r-0 flex " :class="[!dto.category?'desc-gray':'']" @click="()=>{
               // show_select_category=true
               $refs.picker_category.showPicker()
            }">
               <view>{{dto.categoryStr||dto.category || '请选择'}}</view>
               <u-icon class="m-l-a" name="arrow-right"></u-icon>
            </view> -->
            <view class="m-l-a m-r-0 flex " :class="[!dto['category']?'desc-gray':'']">
               <uni-data-picker @change="(e)=>{PickCategory(dto,e)}" placeholder="" @search="updateSearch"
                  :localdata="columns_categorys_picker">
                  {{dto.categoryStr||dto.category || '请选择'}}
               </uni-data-picker>
               <u-icon class="m-l-a" name="arrow-right"></u-icon>
            </view>
         </view>
         <view class="form-item before-line">
            <view class="label required">商品名称</view>
            <view class="m-l-a m-r-0 flex">
               <input v-model="dto.name" placeholder="请输入商品名称" style="margin-top: 16px;text-align: right;"></input>
               <input v-model="dto.name" placeholder="请选择分类" disabled
                  style="margin-top: 16px;text-align: right;"></input>
            </view>
         </view>
         <view class="form-item before-line">
            <view class="label required">商品单位</view>
            <view class="m-l-a m-r-0 flex">
               <input v-model="dto.unit" placeholder="请输入商品单位" style="margin-top: 16px;text-align: right;"></input>
               <input v-model="dto.unit" placeholder="请选择分类" disabled
                  style="margin-top: 16px;text-align: right;"></input>
            </view>
         </view>
         <view class="form-item before-line">
            <view class="label required">商品颜色</view>
            <!--    <view class="m-l-a m-r-0 flex " :class="[!dto.color?'desc-gray':'']" @click="()=>{
@@ -35,7 +44,7 @@
               <u-icon class="m-l-a" name="arrow-right"></u-icon>
            </view> -->
            <view class="m-l-a m-r-0 flex">
               <input v-model="dto.color" placeholder="请输入商品颜色"
               <input v-model="dto.color" placeholder="请选择分类" disabled
                  style="margin-top: 16px;text-align: right;"></input>
            </view>
         </view>
@@ -202,8 +211,8 @@
            id: '',
            dto: {
               id: '',
               name: '',
               category: '',
               name: '',
               unit: '',
               color: '',
               cover: '',
@@ -217,6 +226,9 @@
            show_select_category: false,
            show_select_level: false,
            columns_categorys: [],
            columns_categorys_picker: [],
            columns_categorys_dict: {},
            columns_categorys_search: '',
            columns_levels: [],
            //    columns_params: [], //弹窗选择具体的值
            // cancel: {
@@ -232,13 +244,16 @@
            // ]
         }
      },
      async onLoad(options) {
         //tree
         this.$http.request('get', '/api/flower/category/tree', {}).then(res => {
            var data = res.data
            this.columns_categorys = data || []
            console.log('columns_categorys', this.columns_categorys)
            // console.log('columns_categorys', this.columns_categorys)
            //递归mao
            this.mapCategoryTree(this.columns_categorys_picker, this.columns_categorys)
            // console.log('columns_categorys_picker', this.columns_categorys_picker)
            // this.columns_categorys = [data || []]
            // this.columns_categorys[0].unshift({
            //    label: '全部',
@@ -288,6 +303,79 @@
      },
      methods: {
         async updateSearch(search) {
            this.columns_categorys_search = search || ''
            this.columns_categorys_picker = []
            this.mapCategoryTree(this.columns_categorys_picker, this.columns_categorys)
            console.log('change updateSearch', search, this.columns_categorys_picker)
         },
         async PickCategory(item, e) {
            console.log('PickCategory', item, e)
            if (e.detail.value) {
               if (this.dto.category) {
                  await this.$message.confirm('修改分类将清空商品参数,确定修改吗')
               } {
                  var currentnode = this.columns_categorys_dict['@' + e.detail.value[e.detail.value.length - 1]
                     .value]
                  // console.log('currentnode',currentnode,this.columns_categorys_dict,'@'+e.detail.value[e.detail.value.length - 1].value)
                  this.dto.categoryStr = currentnode.name
                  this.dto.category = currentnode.id
                  this.dto.name = currentnode.name
                  this.dto.unit = currentnode.unit
                  this.dto.color = currentnode.color
                  //递归获取category的其他数据,用来做map?
                  this.$message.showLoading()
                  await this.refresh_category()
                  this.$message.hideLoading()
               }
            }
         },
         mapCategoryTree(node, arr) {
            var has = true
            if (arr) {
               var hasTrue = false
               if(!this.columns_categorys_search){
                  hasTrue = true
               }
               for (var item of arr) {
                  has = true
                  if (this.columns_categorys_search) {
                     has = false
                  }
                  var tmp = {
                     ...item,
                     name: item.name,
                     text: item.name,
                     label: item.name,
                     value: item.id,
                     children: undefined
                  }
                  if (item.name == this.columns_categorys_search) {
                     has = true
                  }
                  this.columns_categorys_dict['@' + item.id] = item
                  if (item.children && item.children.length > 0) {
                     tmp.children = []
                     var childrenhas = this.mapCategoryTree(tmp.children, item.children)
                     if (childrenhas) {
                        has = true
                        hasTrue = true
                     }
                  } else {
                     tmp.children = undefined
                  }
                  if (hasTrue || has) {
                     console.log('has ',tmp)
                     node.push(tmp)
                  } else {
                     console.log('not has ',tmp)
                  }
               }
            }
            return hasTrue
         },
         async confirmPickerCategory(picker) {
            console.log('confirmPickerCategory', picker)
            var id = picker.value
@@ -298,6 +386,10 @@
               }
               this.dto.categoryStr = name
               this.dto.category = id
               // name: '',
               // unit: '',
               // color: '',
               //递归获取category的其他数据,用来做map?
               this.$message.showLoading()
               await this.refresh_category()
               this.$message.hideLoading()