Browse Source

录入规格列表

afa 5 tháng trước cách đây
mục cha
commit
9e6873910b

+ 1 - 2
app/admin/controller/goods/ProductConfig.php

@@ -21,9 +21,8 @@ class ProductConfig extends Backend
         parent::_initialize();
         $this->model = new ProductConfigModel();
 
-        //
         $this->assign('varietyList', StockConfig::where('type_id', 'variety_name')->column('title','id'));
-        $this->assign('packingList', StockConfig::where('type_id', 'packing_box')->column('title','id'));
+     
      
     }
 

+ 40 - 69
app/admin/controller/shop/CustomerSpec.php

@@ -30,6 +30,7 @@ class CustomerSpec extends Backend
         parent::_initialize();
         $this->model = new CustomerSpecModel();
         $this->assign('typeList',  StockConfig::where('type_id', 'variety_name')->order('sort desc')->column('title','id'));
+        $this->assign('packingList', StockConfig::where('type_id', 'packing_box')->column('title','id'));
         $this->relationField=['customer'];
     }
 
@@ -46,93 +47,63 @@ class CustomerSpec extends Backend
     public function add()
     {
         if (false === $this->request->isPost()) {
+
+            $ids =$this->request->get('ids/d', 0);
+            $rows = $this->model->where('customer_id', $ids)->where('status', 1)->select();
+            $this->assign('ids', $ids);
+            $this->assign('row', $rows);
             return $this->fetch();
         }
-       
-        $customer_id =$this->request->post('customer_id/d', 0);
-        $type_box    =$this->request->post('type_box');
-        $type_list   =$this->request->post('type_list');
-        if(empty($customer_id) || empty($type_box) || empty($type_list)) return resp_json(0,'请填写完整信息');
-        //判断是否有发货价格
-        foreach ($type_box as $key => $item) {
-            if(!(isset($item['price']) && $item['price'] > 0)){
-                unset($type_box[$key]);
-            }
-        }
+    
+        $params = $this->request->post();
+        if(empty($params['ids']) || count($params['all_data']) == 0) return resp_json(0,'请填写完整信息');
+   
+        $result = 0;
+        Db::startTrans();
+        try {
+            //状态设置为0
+            $this->model->where('customer_id', $params['ids'])->save(['status'=>0]);
 
-        if(empty($type_box)) return resp_json(0, '请填写发货价格');
+            //然后根据选中的规格ID逐个判断是否存在,存在的更新状态、包装箱及发货价,不存在的则创建。 type_id
+            foreach ($params['all_data'] as $item) {
+                $row = $this->model->where('customer_id',$params['ids'])->where('type_id',$item['type_id'])->where('product_id',$item['value'])->findOrEmpty();
+                if($row->isEmpty()){
+                    $this->model->create([
+                        'customer_id' => $params['ids'],
+                        'type_id'     => $item['type_id'],
+                        'product_id'  => $item['value'],
+                        'box_id'      => $item['packet']??0,
+                        'price'       => $item['price']??0,
 
-        if($this->model->where('customer_id', $customer_id)->count()>0) return resp_json(0,'客户信息已存在');
+                    ]);
+                    $result++;
+                }else{
+                    $row->box_id = $item['packet']??0;
+                    $row->price  = $item['price']??0;
+                    $row->status  = 1;
+                    $row->save();
+                    $result++;
 
-        $result = false;
-        Db::startTrans();
-        try {
-            $result = $this->model->save([
-                'customer_id'=> $customer_id,
-                'variety'    => json_encode($type_list, JSON_UNESCAPED_UNICODE),
-                'specs'      => json_encode($type_box, JSON_UNESCAPED_UNICODE),
-            ]);
-            if($this->callback){
-                $callback=$this->callback;
-                $callback($this->model);
-            }
-            Db::commit();
-        } catch (\Exception $e) {
-            Db::rollback();
-            $this->error($e->getMessage());
-        }
-        if ($result === false) {
-            $this->error(__('没有新增任何数据'));
-        }
-        return resp_json(200,'操作成功');
-    }
+                }
 
-    /**
-     * 编辑
-     */
-    #[Route('GET,POST','edit')]
-    public function edit(mixed $row=null)
-    {   
-        if (false === $this->request->isPost()) {
-            $ids = $this->request->get('ids');
-            if(!$row || is_array($row)){
-                $row = $this->model->find($ids);
             }
-            if (!$row) {
-                $this->error(__('没有找到记录'));
-            }
-         
-            $this->assign('row', $row);
-            return $this->fetch();
-        }
-        $params = $this->request->post("");
-        if(empty($params['ids']) || empty($params['type_box']) || empty($params['type_list'])) return resp_json(0,'请填写完整信息');
-        //判断是否有发货价格
-        if(SpecService::getIsZeroSpecsPrice($params['type_box']) == false) return resp_json(0, '请填写发货价格');
-      
-        $result = false;
-        Db::startTrans();
-        try {
-         
-            $result = $this->model->where('id', $params['ids'])->save([
-                'variety'    => json_encode($params['type_list'], JSON_UNESCAPED_UNICODE),
-                'specs'      => json_encode($params['type_box'], JSON_UNESCAPED_UNICODE),
-            ]);
+
             if($this->callback){
                 $callback=$this->callback;
-                $callback($row);
+                $callback($this->model);
             }
             Db::commit();
         } catch (\Exception $e) {
             Db::rollback();
             $this->error($e->getMessage());
         }
-        if (false === $result) {
-            $this->error(__('没有数据被更新'));
-        }
+      
         return resp_json(200,'操作成功');
     }
 
+  
+
+
     //删除
     #[Route("GET,POST","del")]
     public function del()

+ 20 - 18
app/admin/controller/shop/ShopList.php

@@ -31,6 +31,9 @@ class ShopList extends Backend
         $this->assign('platformList', site_config('addonsd.platform_list'));
         $this->assign('userList', User::where('status',Customer::STATUS_NORMAL)->column('nickname','id'));
         $this->assign('fieldList', StockConfig::where('type_id', 'variety_name')->order('sort desc')->column('title','id'));
+
+        $this->assign('typeList',  StockConfig::where('type_id', 'variety_name')->order('sort desc')->column('title','id'));
+        $this->assign('packingList', StockConfig::where('type_id', 'packing_box')->column('title','id'));
         $this->relationField=['customer','staff'];
     }   
 
@@ -41,20 +44,17 @@ class ShopList extends Backend
         if($this->request->isAjax()){
             $ids = $this->request->post('ids/d', 0);
             $params = $this->request->post('');
-            if(empty($params['variety']) || empty($ids) || empty($params['type_box'])) return resp_json(0, '参数错误');
-         
+            if(empty($params['all_data']) || empty($ids)) return resp_json(0, '参数错误');
             $this->model->where('id', $ids)->save([
-                'variety'    => json_encode($params['variety'], JSON_UNESCAPED_UNICODE),
-                'type_spec'  => json_encode($params['type_box'], JSON_UNESCAPED_UNICODE),
+                'type_spec'  => json_encode($params['all_data'], JSON_UNESCAPED_UNICODE),
             ]);
             return resp_json(200,'操作成功');
         }else{
           
-            $ids = $this->request->get('ids/d', 0);
-            $rows = $this->model::find($ids);
-            $rows->variety = $rows->variety? json_decode($rows->variety, true) : [];
-            $rows->type_spec = $rows->type_spec? json_decode($rows->type_spec, true) : [];
-            $this->assign('row', $rows);
+            $ids =$this->request->get('ids/d', 0);
+            $rows = $this->model::where('id', $ids)->where('status', 1)->find();
+            $this->assign('ids', $ids);
+            $this->assign('row', $rows->type_spec??'');
             return $this->fetch();
         }
     }
@@ -64,16 +64,18 @@ class ShopList extends Backend
     public function get_box()
     {
         if($this->request->isAjax()){
-            $result = [];
-            $customer_id = $this->request->get('customer_id/d', 0);
+            $ids = $this->request->get('ids/d', 0);
             $type_id = $this->request->get('type_id/d', 0);
-            if(empty($type_id) || empty($customer_id)) return resp_json(0, '参数错误');
-            $rows = CustomerSpecBack::where('customer_id', $customer_id)->order('sort desc')->find();
-            if($rows->specs){
-                $specs = json_decode($rows->specs, true);
-                $result = SpecService::getSpecsList($type_id, $specs);
-            }
-            return json($result, 200);
+            if(empty($ids) || empty($type_id)) return resp_json(0, '参数错误');
+            $customer_id = $this->model::where('id', $ids)->value('customer_id');
+            $rows = CustomerSpecBack::alias('a')
+                ->leftjoin('product_config b', 'a.product_id=b.id')
+                ->field('a.*,b.title')
+                ->where('a.type_id', $type_id)
+                ->where('a.customer_id', $customer_id)
+                ->where('a.status', CustomerSpecBack::NORMAL)
+                ->order('a.sort desc')->select();
+            return json($rows, 200);
         }
     }
  

+ 1 - 1
app/admin/view/goods/product_config/add.html

@@ -17,7 +17,7 @@
                 {field: 'title',title: __('名称'),edit:'text',rules:'required'},
                 {field: 'another_name',title: __('别名'),edit:'text',rules:'required'},
                 {field: 'weight',title: __('重量(斤)'),edit:'text',rules:'required'},
-                {field: 'box_id',title: __('包装箱'),edit:'radio',rules:'required', searchList: Yunqi.data.packingList},
+                //{field: 'box_id',title: __('包装箱'),edit:'radio',rules:'required', searchList: Yunqi.data.packingList},
                 {field: 'sort',title: __('排序'),edit:'text'},
                 {field: 'status', title: __('状态'), edit:'switch',searchList: {1: __('正常'),2: __('隐藏')}},
             ]

+ 1 - 1
app/admin/view/goods/product_config/index.html

@@ -38,7 +38,7 @@
                 {field: 'title',title: __('标题'),operate: '='},
                 {field: 'another_name', title: __('别名'),operate:'LIKE'},
                 {field: 'weight', title: __('重量(斤)'),operate: false},
-                {field: 'type_box', title: __('包装箱'),operate: false, searchList: Yunqi.data.packingList},
+                //{field: 'type_box', title: __('包装箱'),operate: false, searchList: Yunqi.data.packingList},
                 {field: 'status', title: __('状态'),width:120,searchList: {1: __('正常'),2: __('停用')},formatter:Yunqi.formatter.switch},
                 {field: 'sort', title: __('排序'), operate:false,sortable: true},
                 {field: 'createtime', title: __('创建时间'), width:160,formatter: Yunqi.formatter.datetime,operate:false,sortable: true},

+ 1 - 1
app/admin/view/shop/customer/index.html

@@ -61,7 +61,7 @@
         methods: {
             spec:function (row){
                 Yunqi.api.open({
-                    url:'shop/customer_spec/add',
+                    url:'shop/customer_spec/add?ids='+row.id,
                     width:1000,
                     title:__('关联规格'),
                     icon:'fa fa-list'

+ 171 - 111
app/admin/view/shop/customer_spec/add.html

@@ -1,138 +1,198 @@
 <template>
 
-    <el-card shadow="never">
-        <el-tabs v-model="activeName" @tab-click="handleClick">
-            <el-tab-pane label="用户管理" name="first">
-                <template>
-                    <el-table :data="tableData" style="width: 100%">
-                    <el-table-column prop="date" label="日期" width="180"></el-table-column>
-                    <el-table-column prop="name" label="姓名" width="180"></el-table-column>
-                    <el-table-column prop="address" label="地址"></el-table-column>
-                    </el-table>
-                </template>
 
+    <el-card shadow="never" style="min-height: 500px;">
+
+        <el-tabs tab-position="left" style="height: 400px;" v-model="tabValue" @tab-click="handleClick">
+            <el-tab-pane v-for="(item,index) in tabData" :label="item.label" :name="item.value">
             </el-tab-pane>
-            <el-tab-pane label="配置管理" name="second">配置管理2</el-tab-pane>
-            <el-tab-pane label="角色管理" name="third">角色管理</el-tab-pane>
-            <el-tab-pane label="定时任务补偿" name="fourth">定时任务补偿</el-tab-pane>
+            <el-form ref="form" :model="form" label-width="0" stripe>
+                <el-form-item>
+
+                    <el-table :data="tableData" style="width: 100%" border :ref="'multipleTable_' + tabValue" stripe
+                        @selection-change="handleSelectionChange">
+                        <el-table-column type="selection" width="55">
+                        </el-table-column>
+                        <el-table-column prop="name" label="规格" align="center">
+                        </el-table-column>
+                        <el-table-column prop="packet" label="包装箱" align="center">
+                            <template #default="{row}">
+                                <el-select v-model="row.packet" placeholder="请选择">
+                                    <el-option v-for="item in options" :key="item.value" :label="item.label"
+                                        :value="item.value">
+                                    </el-option>
+                                </el-select>
+                            </template>
+                        </el-table-column>
+                        <el-table-column prop="price" label="发货价" align="center">
+                            <template #default="{row}">
+                                <el-input v-model="row.price"></el-input>
+                            </template>
+                        </el-table-column>
+                    </el-table>
+
+                </el-form-item>
+                <el-form-item style="padding-top: 20px;">
+                    <el-button type="primary" @click="onSubmit">立即创建</el-button>
+                    <el-button>取消</el-button>
+                </el-form-item>
+            </el-form>
         </el-tabs>
     </el-card>
-    <!-- <el-card shadow="never">
-        <el-form ref="form" :model="form" label-width="0"  stripe>
-            <el-form-item>
-                <yun-table :columns="columns" :common-search="false" :pagination="false" tabs="type" toolbar=""
-                    :common-search="false" :search-form-visible="false" :extend="extend">
-                </yun-table>
-            </el-form-item>
-           
-
-            <el-form-item>
-                <el-button type="primary" @click="onSubmit">立即创建</el-button>
-                <el-button>取消</el-button>
-            </el-form-item>
-        </el-form>
-    </el-card> -->
 </template>
 <script>
     import table from "@components/Table.js";
+
     export default {
         components: { 'YunTable': table },
-        data() {
-            return {
-                activeName: 'first',
-                tableData: [{
-                    date: '2016-05-02',
-                    name: '王小虎',
-                    address: '上海市普陀区金沙江路 1518 弄'
-                }, {
-                    date: '2016-05-04',
-                    name: '王小虎',
-                    address: '上海市普陀区金沙江路 1517 弄'
-                }, {
-                    date: '2016-05-01',
-                    name: '王小虎',
-                    address: '上海市普陀区金沙江路 1519 弄'
-                }, {
-                    date: '2016-05-03',
-                    name: '王小虎',
-                    address: '上海市普陀区金沙江路 1516 弄'
-                }]
-            };
-        },
-        /*data: {
+        data: {
             extend: {
                 index_url: 'general/category/index',
             },
-            columns: [
-                { checkbox: true },
-                { field: 'type', title: __('规格'), width: 120, searchList: Yunqi.data.typeList},
-                { field: 'nickname', title: __('包装箱'), formatter: Yunqi.formatter.select },
-
-                {
-                    field: 'weigh', title: __('价格'), width: 220, formatter: function (data) {
-                        let html = Yunqi.formatter.html;
-                        html.value = `<input class="input" value='' />`;
-                        return html;
-                    }
-                },
-
-
-            ],
             row: Yunqi.data.row,
-            tableData: [
-                {
-                    "name": "哈密",
-                    "num": "3940.00"
-                },
-                {
-                    "name": "紫薯",
-                    "num": "8915.00"
-                }
-            ],
+            tabData: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value })),
+            tableData: [],
             value: "",
             form: {
                 nameValue: null,
             },
-            options: [],//品种
-        },*/
+            options: Object.entries(Yunqi.data.packingList).map(([value, label]) => ({ label, value: value.toString() })),//品种
+            tabValue: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value }))[0].value, //选中的品种 获取到品种数据后要给他默认赋值第一个
+
+            chooseSpec: [], // 当前分类选中的规格  
+
+            allData: {},
+            type: 1, // 1编辑 0新增
+        },
         methods: {
-            handleClick(tab, event) {
-                console.log(tab, event);
-            }
+            onSubmit() {
+                if (this.allData == "") return;
+                let arr = Object.values(this.allData).flat(Infinity)
+                console.log(JSON.stringify(arr), "所有数据")
+                //
+                Yunqi.ajax.post('shop/customer_spec/add', { ids: Yunqi.data.ids, all_data: arr }, false, false, true).then(res => {
+                    if (res.code == 200) {
+                        this.$message.success(__('设置成功'));
+                        Yunqi.api.closelayer(Yunqi.app.window.id, true);
+                    } else {
+                        Yunqi.alert(__('请填写发货价格'), __('温馨提示'), { type: 'error' });
+                    }
+                });
 
-        }
-    }
-</script>
-<style>
-    .input {
-        border: none;
-        width: 100%;
-        box-shadow: 0 0 0 1px #dcdfe6 inset;
-        line-height: 24px;
-        min-height: 31px;
-        caret-color: #999;
-        box-sizing: border-box;
-        padding: 0 10px;
-        border-radius: 4px;
-    }
+            },
+            handleSelectionChange(e) {
+                if (e.length > 0) {
+                    this.allData[this.tabValue] = e || []
+                }
+            },
+            handleClick(data, row) {
+                // 品种切换事件 可以在这里请求规格接口
 
-    .input:active {
-        border: none !important;
-        border-color: #fff !important;
+                this.tabValue = data.props.name
+                // this.chooseSpec = this.allData[this.tabValue]
+                console.log(this.allData[this.tabValue], "this.allData[this.tabValue]")
+                this.tabName = data.props.label
+                this.tableData = [];
+                this.getSpecData()
+            },
+            getSpecData() {
 
-    }
+                //获取规格
+                Yunqi.ajax.get('shop/customer_spec/get_box', { type_id: this.tabValue }, false, false, true).then(res => {
+                    //编辑数据
+                    if (res.length > 0) {
+                        console.log("res", res)
+                        for (var key in Object(res)) {
+                            let index = this.tableData.findIndex(item => item.value == res[key]['id']);
+                            if (index != -1) {
+                                this.tableData.splice(index, 1)
+                            } else {
+                                this.tableData.push({ name: res[key]['title'], value: res[key]['id'], price: res[key]['price'], type_id: this.tabValue });
+                            }
+                        }
+                        this.$nextTick(() => {
+                            const tableRef = this.$refs['multipleTable_' + this.tabValue];
+                            if (this.type == 0 && this.allData[this.tabValue]?.length > 0 && tableRef) {
+                                this.tableData.forEach((item, index) => {
+                                    const matched = this.allData[this.tabValue].find(row => {
+                                        return row.value == item.value
+                                    });
 
-    .input:focus {
-        outline: none;
-        border: none !important;
-        border-color: #fff !important;
-        border: 1px solid #fff !important;
-    }
+                                    if (matched) {
+                                        this.tableData[index] = matched
+                                    }
+                                })
+                                this.allData[this.tabValue].forEach(selected => {
+                                    const matched = this.tableData.find(row => row.value === selected.value);
+                                    if (matched) {
+                                        this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
+                                    }
+                                });
+                            }
+                            else if (this.type == 1 && this.allData[Number(this.tabValue)]) {
+                                this.tableData.forEach((item, index) => {
+                                    const matched = this.allData[Number(this.tabValue)].find(row => {
+                                        if (row.product_id) {
+                                            return row.product_id == item.value
+                                        } else {
+                                            return row.value == item.value
+                                        }
 
-    .button {
-        display: flex;
-        align-items: center;
-        justify-content: flex-end;
-        padding-top: 15px;
+                                    });
+                                    console.log(matched, "type2matched");
+                                    if (matched) {
+                                        // this.tableData[index] = { name: 'kam', value: 3, price: '111', type_id: '4', packet: '3' }
+                                        if (matched.product_id) {
+                                            this.tableData[index].price = matched.price
+                                            this.tableData[index].packet = matched.box_id != 0 ? matched?.box_id.toString() : ""
+                                        } else {
+                                            this.tableData[index] = matched
+                                        }
+                                    }
+                                })
+                                this.allData[Number(this.tabValue)].forEach(selected => {
+                                    const matched = this.tableData.find(row => {
+                                        if (selected.product_id) {
+                                            return selected.product_id == row.value
+                                        } else {
+                                            return row.value === selected.value
+                                        }
+                                    });
+                                    if (matched) {
+                                        this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
+                                    }
+                                });
+                                // this.type = 0
+                            }
+                        });
+                    }
+                });
+            }
+
+        },
+        onLoad: function (query) {
+            let row = Yunqi.data.row;
+            if (row.length > 0) {
+                this.type = 1
+            } else {
+                this.type = 0
+            }
+            console.log(this.type)
+            const grouped = row.reduce((acc, item) => {
+                const key = item.type_id;
+                if (!acc[key]) {
+                    acc[key] = [];
+                }
+                console.log(item)
+                item.value = item.product_id
+                item.packet = item.box_id
+                acc[key].push(item);
+                return acc;
+            }, {});
+            this.allData = JSON.parse(JSON.stringify(grouped))
+            this.getSpecData()
+        },
     }
+</script>
+<style>
 </style>

+ 148 - 88
app/admin/view/shop/shop_list/specs.html

@@ -1,85 +1,59 @@
 <template>
-    <el-card shadow="never" style="border: 0;">
+    <el-card shadow="never" style="min-height: 500px;">
+        <el-tabs tab-position="left" style="height: 400px;" v-model="tabValue" @tab-click="handleClick">
+            <el-tab-pane v-for="(item,index) in tabData" :label="item.label" :name="item.value">
+            </el-tab-pane>
+            <el-form ref="form" :model="form" label-width="0" stripe>
+                <el-form-item>
 
-        <el-form ref="form" :model="form" label-width="80px" border stripe>
-            <el-form-item label="品种">
-                <el-checkbox-group v-model="form.nameValue">
-                    <el-checkbox :label="item.label" :value="JSON.stringify(item)" v-for="(item, index) in options"
-                        :key="index" @change="changeType">
-                    </el-checkbox>
-                </el-checkbox-group>
-            </el-form-item>
+                    <el-table :data="tableData" style="width: 100%" border :ref="'multipleTable_' + tabValue" stripe
+                        @selection-change="handleSelectionChange">
+                        <el-table-column type="selection" width="55">
+                        </el-table-column>
+                        <el-table-column prop="name" label="规格" align="center">
+                        </el-table-column>
+                    </el-table>
 
-            <el-form-item label="规格">
-                <el-table :data="tableData" style="border: 1px solid rgb(235, 235, 235); border-radius: 6px">
-                    <el-table-column prop="name" label="规格" width="200">
-                    </el-table-column>
-
-                    <el-table-column  label="操作" header-align="right">
-                        <template  #default="scope">
-                            <el-button @click.native.prevent="deleteRow(scope.$index, tableData)" type="text"
-                                size="small">
-                                移除
-                            </el-button>
-                        </template>
-                    </el-table-column>
-
-                </el-table>
-            </el-form-item>
-            <el-form-item>
-                <el-button type="primary" @click="onSubmit">立即创建</el-button>
-                <el-button>取消</el-button>
-            </el-form-item>
-        </el-form>
+                </el-form-item>
+                <el-form-item style="padding-top: 20px;">
+                    <el-button type="primary" @click="onSubmit">立即创建</el-button>
+                    <el-button>取消</el-button>
+                </el-form-item>
+            </el-form>
+        </el-tabs>
     </el-card>
 </template>
 <script>
-    import form from "@components/Form.js";
-    var typeList = [], boxList = [];
+    import table from "@components/Table.js";
+
     export default {
-        components: { 'YunForm': form },
-        data() {
-            return {
-                row: Yunqi.data.row,
-                tableData: Yunqi.data.row.type_spec,
-                value: 0,
-                form: {
-                    nameValue: Yunqi.data.row.variety,
-                },
-                options: typeList,//品种
-            }
+        components: { 'YunTable': table },
+        data: {
+            extend: {
+                index_url: 'general/category/index',
+            },
+            row: Yunqi.data.row,
+            tabData: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value })),
+            tableData: [],
+            value: "",
+            form: {
+                nameValue: null,
+            },
+            options: Object.entries(Yunqi.data.packingList).map(([value, label]) => ({ label, value: value.toString() })),//品种
+            tabValue: Object.entries(Yunqi.data.typeList).map(([value, label]) => ({ label, value }))[0].value, //选中的品种 获取到品种数据后要给他默认赋值第一个
+
+            chooseSpec: [], // 当前分类选中的规格  
+
+            allData: {},
+            type: 1, // 1编辑 0新增
         },
         methods: {
-            changeType: function (data, row) {
-                
-                //获取规格
-                let obj = JSON.parse(row.target.value);
-                let idx = boxList.findIndex(item => item.value == obj.value);
-                if (idx != -1) {
-                    boxList.splice(idx, 1)
-                }else{
-                    boxList.push({ label: obj.label, value: obj.value });
-                }
-                Yunqi.ajax.get('shop/shop_list/get_box', {customer_id:Yunqi.data.row.customer_id, type_id: obj.value }, false, false, true).then(res => {
-                    //编辑数据
-                    console.log(res, "========")
-                    if (res.length > 0) {
-                          for (var key in Object(res)) {
-                              let index = this.tableData.findIndex(item => item.value == res[key]['value']);
-                              if (index != -1 ) {
-                                  this.tableData.splice(index, 1)
-                              }else {
-                                this.tableData.push({ name: res[key]['name'], value: res[key]['value'], price: res[key]['price'], type_id:obj.value, type_name: obj.label });
-                              }
-                          }
-                    }
-                });
-            },
             onSubmit() {
-                //获取规格
-              
-                if (this.tableData == "" || boxList.length == 0) return
-                Yunqi.ajax.post('shop/shop_list/specs', { ids: Yunqi.data.row.id,  variety: boxList, type_box: this.tableData }, false, false, true).then(res => {
+                
+                if (this.allData == "") return;
+                let arr = Object.values(this.allData).flat(Infinity)
+             
+                Yunqi.ajax.post('shop/shop_list/specs', { ids: Yunqi.data.ids, all_data: arr }, false, false, true).then(res => {
                     if (res.code == 200) {
                         this.$message.success(__('设置成功'));
                         Yunqi.api.closelayer(Yunqi.app.window.id, true);
@@ -89,28 +63,114 @@
                 });
 
             },
+            handleSelectionChange(e) {
+                //console.log(e,"选中的数据")
+                if (e.length > 0) {
+                    this.allData[this.tabValue] = e || []
+                }
+            },
+            handleClick(data, row) {
+                // 品种切换事件 可以在这里请求规格接口
+                this.tabValue = data.props.name
+                this.tabName = data.props.label
+                this.tableData = [];
+                this.getSpecData()
+            },
+            getSpecData() {
 
-            deleteRow(index, rows) {
-                rows.splice(index, 1);
-            }
-        },
-        onLoad: function () {
+                //获取规格 ;
+                Yunqi.ajax.get('shop/shop_list/get_box', {ids:Yunqi.data.ids, type_id: this.tabValue }, false, false, true).then(res => {
+                    //编辑数据
+                    if (res.length > 0) {
+                        for (var key in Object(res)) {
+                            let index = this.tableData.findIndex(item => item.value == res[key]['id']);
+                            if (index != -1) {
+                                this.tableData.splice(index, 1)
+                            } else {
+                                this.tableData.push({ name: res[key]['title'], value: res[key]['product_id'], price: res[key]['price'], box_id: res[key]['box_id'], type_id: this.tabValue });
+                            }
+                        }
+                        this.$nextTick(() => {
+                            const tableRef = this.$refs['multipleTable_' + this.tabValue];
+                            if (this.type == 0 && this.allData[this.tabValue]?.length > 0 && tableRef) {
+                                this.tableData.forEach((item, index) => {
+                                    const matched = this.allData[this.tabValue].find(row => {
+                                        return row.value == item.value
+                                    });
 
-            for (let index = 0; index < this.form.nameValue.length; index++) {
-                this.form.nameValue[index] = JSON.stringify(this.form.nameValue[index]);
-            }
-            //全部品种
-            let type = Yunqi.data.fieldList;
-            for (var key in Object(type)) {
-                typeList.push({ label: type[key], value: key });
+                                    if (matched) {
+                                        this.tableData[index] = matched
+                                    }
+                                })
+                                this.allData[this.tabValue].forEach(selected => {
+                                    const matched = this.tableData.find(row => row.value === selected.value);
+                                    if (matched) {
+                                        this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
+                                    }
+                                });
+                            }
+                            else if (this.type == 1 && this.allData[Number(this.tabValue)]) {
+                                this.tableData.forEach((item, index) => {
+                                    const matched = this.allData[Number(this.tabValue)].find(row => {
+                                        if (row.product_id) {
+                                            return row.product_id == item.value
+                                        } else {
+                                            return row.value == item.value
+                                        }
+
+                                    });
+                                   
+                                    if (matched) {
+                                        // this.tableData[index] = { name: 'kam', value: 3, price: '111', type_id: '4', packet: '3' }
+                                        if (matched.product_id) {
+                                            this.tableData[index].price = matched.price
+                                            this.tableData[index].packet = matched.box_id != 0 ? matched?.box_id.toString() : ""
+                                        } else {
+                                            this.tableData[index] = matched
+                                        }
+                                    }
+                                })
+                                this.allData[Number(this.tabValue)].forEach(selected => {
+                                    const matched = this.tableData.find(row => {
+                                        if (selected.product_id) {
+                                            return selected.product_id == row.value
+                                        } else {
+                                            return row.value === selected.value
+                                        }
+                                    });
+                                    if (matched) {
+                                        this.$refs['multipleTable_' + this.tabValue].toggleRowSelection(matched, true); // 勾选
+                                    }
+                                });
+                                // this.type = 0
+                            }
+                        });
+                    }
+                });
             }
-            //品种
-            for (var key in Object(Yunqi.data.row.variety)) {
-                boxList[key] = JSON.parse(Yunqi.data.row.variety[key]);
+
+        },
+        onLoad: function (query) {
+            let row =  Yunqi.data.row;
+            if (row) {
+                this.type = 1
+                const grouped = JSON.parse(row).reduce((acc, item) => {
+                const key = item.type_id;
+                if (!acc[key]) {
+                    acc[key] = [];
+                }
+                
+                acc[key].push(item);
+                return acc;
+            }, {});
+            this.allData = JSON.parse(JSON.stringify(grouped))
+            } else {
+                this.type = 0
             }
+            //你只需要保存规格是吧, 是你末尾加了个row
+            this.getSpecData()
         },
     }
 </script>
 <style>
-
 </style>

+ 0 - 1
app/admin/view/user/index/index.html

@@ -43,7 +43,6 @@
                 {field: 'mobile',title: __('手机'),operate: '='},
                 {field: 'role', title: __('角色'),sortable: true,operate:'selects', formatter(value, row, index) {
                     var role = "";
-                    console.log(value, "====")
                     if(value.indexOf("1") > -1)  role =role+"录入员";
                     if(value.indexOf("2") > -1)  role =role+"-库管";
                     if(value.indexOf("3") > -1)  role =role+"-记账";

+ 1 - 0
app/api/controller/Index.php

@@ -91,6 +91,7 @@ class Index extends Base
             }
             $spec = $shopList->where('id', $shop_id)->value('type_spec');
             $shopList = $spec?json_decode($spec, true): [];
+            
             return $this->success('ok', $shopList);  
       }
 

+ 26 - 19
app/api/service/SpecService.php

@@ -7,6 +7,7 @@ use app\common\model\StockConfig;
 use app\common\model\ProductConfig;
 use app\common\model\StockDetail;
 use app\common\model\ShopDelivery;
+use app\common\model\CustomerSpecBack;
 /**
  * 录入发货
  */
@@ -50,10 +51,10 @@ class SpecService{
             //结算周期
             $settlement_data = SpecService::getDeliverySettlement($customer, $data['ship_date']);
             foreach ($data['variety'] as $item) {
-                  if(count($item) != 6 || empty(floatval($item['num'])))  throw new \Exception('参数有误!');
-                  $specs = ProductConfig::where('id', $item['spec_id'])->field('weight,box_id')->find();
-                  if(!$specs)  throw new \Exception('参数有误!');
-                  $weight = bcmul((string)$specs->weight, $item['num'], 2);
+                  if(count($item) != 5 || empty(floatval($item['num'])))  throw new \Exception('参数有误!');
+                  $specsWeight = ProductConfig::where('id', $item['spec_id'])->value('weight');
+                  //if(!$specs)  throw new \Exception('参数有误!');
+                  $weight = bcmul((string)$specsWeight, $item['num'], 2);
                   $result[] = [
                         'user_id'         => $uid, 
                         'customer_id'     => $customer->id,
@@ -81,16 +82,20 @@ class SpecService{
                         'remark'          => '录入出库'
                   ];
                   //根据规格扣除包装箱
-                  $boxNum = StockDetail::setStockConfigNum($specs->box_id, (string)-$item['num'], StockConfig::PackingBox);
-                  $stockData[] = [
-                        'user_id'         => $uid, 
-                        'type_id'         => StockConfig::PackingBox,
-                        'type'            => 1,
-                        'variety_id'      => $specs['box_id'],
-                        'change'          => -$item['num'],
-                        'after'           => $boxNum,
-                        'remark'          => '录入出库'
-                  ];
+                  $box_id = CustomerSpecBack::where('customer_id', $customer->id)->where('type_id', $item['variety_id'])->where('product_id', $item['spec_id'])->value('box_id');
+                  if($box_id){
+                        $boxNum = StockDetail::setStockConfigNum($box_id, (string)-$item['num'], StockConfig::PackingBox);
+                        $stockData[] = [
+                              'user_id'         => $uid, 
+                              'type_id'         => StockConfig::PackingBox,
+                              'type'            => 1,
+                              'variety_id'      => $box_id,
+                              'change'          => -$item['num'],
+                              'after'           => $boxNum,
+                              'remark'          => '录入出库'
+                        ];
+                  }
+                
             }
             return [$result, $stockData];
       }
@@ -105,18 +110,20 @@ class SpecService{
            if(substr($delivery->createtime, 0, 10) != date('Y-m-d')) throw new \Exception('只能修改当日发货记录!');
     
             //修改库存
-            $specs = ProductConfig::where('id', $delivery->spec_id)->field('weight,box_id')->find();
-            if(!$specs)  throw new \Exception('参数有误!');
+            $specs = ProductConfig::where('id', $delivery->spec_id)->value('weight');
+            if(!$specs) throw new \Exception('参数有误!');
          
             //根据品种扣除库存
-            $weight = bcmul((string)$specs->weight, $data['num'], 2); //总重
+            $weight = bcmul((string)$specs, $data['num'], 2); //总重
            
             //扣除品种
             StockDetail::setStockConfigNum($delivery->variety_id, bcsub($delivery->weigh, $weight, 2), StockConfig::VarietyName);
 
             //根据规格扣除包装箱
-            StockDetail::setStockConfigNum($specs->box_id, bcsub((string)$delivery->num, $data['num'], 2), StockConfig::PackingBox);
-               
+            $box_id = CustomerSpecBack::where('customer_id', $delivery->customer_id)->where('type_id', $delivery['variety_id'])->where('product_id', $delivery->spec_id)->value('box_id');
+            if($box_id){
+                  StockDetail::setStockConfigNum($box_id, bcsub((string)$delivery->num, $data['num'], 2), StockConfig::PackingBox);
+            }
             //修改数量
             $price  = bcdiv($delivery->total_price, (string)$delivery->num, 2); //单价
             $delivery->weigh = $weight; //总重

+ 2 - 1
app/common/model/CustomerSpecBack.php

@@ -7,8 +7,9 @@ use think\Model;
 
 class CustomerSpecBack Extends Model
 {
+      const NORMAL = 1;
+      const DELETE = 0;
 
-      //customer_spec spec_back
       //customer
       public function customer()
       {

+ 1 - 1
public/assets/js/components/Table.js

@@ -187,7 +187,7 @@ export default {
         isShowtotal:{
             type:Boolean,
             default:false
-        }
+        },
     },
     mounted:function(){
         this.table_.searchFormVisible=this.searchFormVisible;