产品规格生成图表

image

tableData格式:
关键: generateTable()函数,通过goodsSpecList生成下图的格式
image

<product-spec 
                  v-for="(s, i) in form.goodsSpecList" 
                  :key="s.specName" 
                  :spec="s" 
                  :index="i"
                  @specValue="handleSpecValue"
                  @closeSpec="handleCloseSpec"
                  ></product-spec>
                <Button class="bt-spec" @click="handleAddSpec">添加规格项目</Button>

 handleSpecValue() {
        this.tableData = this.generateTable();
      },
<el-table
                :data="tableData"
                border
                style="width: 100%">
                  <el-table-column
                    :prop="c.specName"
                    :label="c.specName"
                    width="180"
                    v-for="c in form.goodsSpecList">
                  </el-table-column>
                  <el-table-column
                    prop="prcie"
                    label="价格">
                    <template slot-scope="{row}">
                      <el-input 
                        v-model="row.price"
                        @input="handlePriceInput"
                        oninput="value=value.replace(/^0|[^0-9.]/g, '')"
                        style="width: 223px;"></el-input>
                    </template>
                  </el-table-column>
                </el-table>

data() {
      return {
form: {goodsSpecList: [
            {
              specName: '',
              specValueList: [
                {
                  specValue: '',
                  imgUrl: ''
                }
              ]
            }
          ],}
}

generateTable()  {
        let specs = this.form.goodsSpecList
        let tt = [{}]
        specs.forEach(s => {
          tt = tt.flatMap(t => {
            return s.specValueList.map(v  => {
              console.log({...t});
              return {
                ...t,
                [s.specName]: v.specValue
              }
            })
          })
        })
        return tt;
      },
posted @ 2024-01-24 17:24  躺尸的大笨鸟  阅读(5)  评论(0编辑  收藏  举报