<template>
  <div class="goods-all">
    <!-- 选择商品类目 start -->
    <el-card class="good-all-type" v-if="!isShowGoodsDetails">
      <div slot="header" class="clearfix">
        <p class="card-header-title"><span class="blue-block-goods"></span>选择商品所属类目</p>
      </div>
      <div>
        <div>
          <p class="goods-type-tip">为商品设置正确的类目，能让商品快速的被搜索到</p>
        </div>
        <div class="goods-type-options">
<!--          <el-cascader-panel v-model="SSQList" :props='props' @change="SSQChange" ref="ssqCascader"></el-cascader-panel>-->
          <el-cascader-panel v-model="SSQList" :props='propsOptions' @change="SSQChange" ref="ssqCascader"></el-cascader-panel>
        </div>
        <el-button type="primary" class="next-step" :disabled="isNextStep" @click="nextStep">下一步</el-button>
      </div>
    </el-card>
    <!-- 选择商品类目  end  -->
    <!-- 添加商品 start -->
    <el-card class="box-card good-details-body" v-if="isShowGoodsDetails" v-loading="goodsLoading">
      <div class="floor-nav" id="floorNavList">
        <ul class="nav-list">
          <li class="nav-list-item" :class="{'floor-item-active': isFIActive === index}" v-for="(item, index) in floorNav" :key="item.id" @click="setFloorNavMountClick(index)">{{ item.name }}</li>
        </ul>
      </div>
      <div class="floor-cont" ref="scrollview">
        <!-- 商品信息 -->
        <div class="floor-item">
          <div class="floor-item-box">
            <p class="card-header-title floor-item-box-title"><span class="blue-block-goods blue-block-goods-title"></span>商品信息</p>
            <Goodsinfomation ref="goodsInfo" :goodsinfodata='goodsinfodata'/>
          </div>
        </div>
        <!--  商品规格  -->
        <div class="floor-item">
          <div class="floor-item-box">
            <p class="card-header-title floor-item-box-title"><span class="blue-block-goods blue-block-goods-title"></span>商品规格 
              <el-radio-group v-model="radioguide" @change="radiochange" style="padding-left:50px;">
                <el-radio :label="1">单规格</el-radio>
                <el-radio :label="2">多规格</el-radio>
              </el-radio-group>
             
                <el-link class="edit-type-span el-icon-search" type="primary" :underline="false" @click="viewPriceExp">查看各类价格说明
                </el-link>
                <span class="tip-span">所有商品价格均为含税价，必须开具发票</span>
            
            </p>
            <GoodsSpecifications v-show="radioguide==2" ref="goodsspecifications" :specificationsdata="specificationsdata" @calcSpeTable="calcSpeTable"/>
            <!--            <keep-alive>-->
            <GoodsParameter :key="keyvalue" ref="goodsparameter" :parameterdata="parameterdata" @ />
            <!--            </keep-alive>-->
          </div>
        </div>
        <!-- 商品详情 -->
        <div class="floor-item">
          <div class="floor-item-box">
            <p class="card-header-title floor-item-box-title"><span class="blue-block-goods blue-block-goods-title"></span>商品详情</p>
            <Goodsimg ref="goodsdetailsimg" :description="description"/>
          </div>
        </div>
        <!-- 售后及服务 -->
            <Goodsaftersale class="floor-item" style="box-shadow:none;"  ref="goodsaftersale" :goodsaftersale="goodsaftersale" />
           

            <div class="submit-type-con">
              <el-radio-group v-model="goodsAllData.submit" size="small">
                <el-radio :label="0" border>放入仓库</el-radio>
                <el-radio :label="1" border>立即上架</el-radio>
              </el-radio-group>
            </div>
        
      

      </div>
      <div class="submit-cont">
        <el-button type="primary" style="padding: 10px 30px;" @click="save" v-preventReClick>提 交</el-button>
      </div>
    </el-card>
    <!-- 添加商品  end  -->
     <!-- 查看各类价格说明 -->
     <el-dialog
     title="各类价格说明"
     :visible.sync="isViewPriceExp"
     width="40%"
     center
     append-to-body
   >
     <el-form ref="workOrderForm" size="small" label-width="150px">

       <el-form-item label="协议价：">
         <span>指您供货给下游的价格</span>
       </el-form-item>

       <el-form-item label="结算价：">
         <span>与云仓平台结算的价格，根据协议价自动计算</span>
       </el-form-item>

       <el-form-item label="指导售价：">
         <span>指导下游商户制定销售的价格</span>
       </el-form-item>

       <el-form-item label="市场价：">
         <span>市场售价，参考京东、天猫等平台的售价</span>
       </el-form-item>

       <el-form-item>
         <span class="pre-price-tip">商品价格均为含税价，必须开具发票。请准确填写并更新商品实际库存，超卖导致的虚假及延迟发货会引起用户投诉与平台判罚。</span>
       </el-form-item>


     </el-form>
     <span slot="footer" class="dialog-footer">
       <el-button @click="isViewPriceExp = false" size="mini">取 消</el-button>
     </span>
   </el-dialog>
  </div>
</template>

<script>
  import { NewGetCategory,NewGetCategoryData,addGoods,getGoodsNew,updateGoodsNew } from '@/api/module/goods';
  import Goodsinfomation from './components/goodsinfomation';
  import GoodsSpecifications from './components/goodsspecifications';
  import GoodsParameter from './components/goodsparameter';
  import Goodsimg from './components/goodsimg2';
  import Goodsaftersale from './components/goodsaftersale';

  export default {
    name: 'Index',
    // props: {
    //   option: {
    //     type: Number,
    //     required: true
    //   }
    // },
    components: {
      Goodsinfomation,
      GoodsSpecifications,
      GoodsParameter,
      Goodsimg,
      Goodsaftersale,
    },
    data() {
      return {
        isViewPriceExp:false,
        radioguide:1,
        keyvalue:1,
        goodsLoading: false,
        SSQList: [], // 省市区
        SSQStr: '', // 省市区 拼接
        propsOptions: {
          expandTrigger: 'click',
          lazy: true,
          lazyLoad: this.lazyLoad,
          value: "id",
          label: 'title',
          leaf: 'leaf'
        },
        isNextStep: true,
        isShowGoodsDetails: false,
        isFIActive: 0,
        /**/
        floorNav: [
          { id: 1, name: '商品信息' },
          { id: 2, name: '商品规格' },
          { id: 3, name: '商品详情' },
          { id: 4, name: '商品参数' },
          { id: 5, name: '售后及服务' },
          { id: 6, name: '其他设置' }
        ],
        /* 商品信息 */
        goodsinfodata: {
          // orgGoodsInfoForm: {},
          categoryList: [],
          categoryStr: ''
        },
        /* 商品规格 */
        specificationsdata: [],
        /* 商品售价 */
        parameterdata: {
          isradioguide:this.radioguide,
          singleSpecTable: []
        },
        /* 商品详情 */
        // imgdata: {
        //   description: ''
        // },
        description: '',
        /* 售后及服务 */
        goodsaftersale: {
          params:[
            {
              'title':'',
              'value':''
            }
          ],//参数
          stags: [],
          freight_id: 310,
          delay_compensate: 24,
          aftersale_time: 7,
          goods_des:'',//关键词
          producing_area:'',//产地
          deliver_area:'',//发货地
          unit:'',//单位
          web_url:'',//外部市场链接
          out_goods_id:''//商品编码
        },
        goodsAllData: {
          submit: 0,
        }, // 商品所有数据
        TIMER: null,
        hehe: 0,
        option: 0
      } // return end
    },

    created() {
// option 商品的id
      //debugger
      this.option = Number(this.$route.query.goods_id)
      if( this.option && this.option !== 0 ) {
        let data = { goodsId: this.option};
        getGoodsNew(data).then(res => {
          if(res.data) {
            this.isShowGoodsDetails = true;
            // 商品信息
            this.goodsinfodata = {
              goods_id: res.data.goods_id,
              categoryStr: '',     // 商品分类 地址拼接
              categoryList: [],    // 商品分类 id集合的数组
              // goods_des: res.data.goods_des,       // 关键词
              goods_name: res.data.goods_name,      // 商品标题
              category_id: res.data.category_id,
              // producing_area: res.data.producing_area,   // 产地
              // deliver_area: res.data.deliver_area,     // 发货地
              // unit: res.data.unit,             // 单位
              goods_brand: res.data.goods_brand,      // 品牌
              brand_id: res.data.brand_id,      // 品牌
              // web_url: res.data.web_url,          // 外部链接
              // out_goods_id: (res.data.out_goods_id == 0) ? '' : res.data.out_goods_id ,     // 商品编码
              imgs: res.data.imgs,              // 商品图片
              video:res.data.video    
            }
            this.goodsinfodata.categoryStr = res.data.category_first_name + '/' + res.data.category_first_name + '/' + res.data.category_three_name;

            let arr = [];
            arr[0] = res.data.category_first_id;
            arr[1] = res.data.category_second_id;
            arr[2] = res.data.category_three_id;
            this.goodsinfodata.categoryList = arr;

            // 商品规格,  售价由规格决定
            if(res.data.specs && res.data.specs.length > 0) {
              this.specificationsdata = res.data.specs;
              this.radioguide = 2
              this.parameterdata.isradioguide = 2
            }else{
              this.parameterdata['specs']=[]
              this.radioguide = 1
              this.parameterdata.isradioguide = 1
            }

            // 商品售价
            if(res.data.specs_group && res.data.specs_group.length > 0) {
              //this.parameterdata
             let specs_group = res.data.specs_group
              res.data.specs_group.forEach((item)=> {
                item.js_price = item.js_price / 100;
                item.sl_price = item.js_price / 100;
                item.price = item.price / 100;
                item.sc_price = item.sc_price / 100;
              })
              
              let goodsParametersList = this.cartesian(this.processData(res.data.specs));
                for (let index = 0; index < goodsParametersList.length; index++) {
                for (let i = 0; i < res.data.specs.length; i++) {
                  if(res.data.specs.length>1){
                    specs_group[index][res.data.specs[i].spec_name] = goodsParametersList[index][i];
                  
                  }
                  if(res.data.specs.length==1){
                    specs_group[index][res.data.specs[0].spec_name] = goodsParametersList[index];
                  }
                }
              }
              this.parameterdata['specs_group'] = specs_group
              // debugger
              this.parameterdata['specs'] = res.data.specs;
              this.parameterdata['shopTypes'] = goodsParametersList
            
            }else {
              this.parameterdata.pamTableList = [];
              let singleSpecObj = {
                js_price:'',
                sl_price:'',
                price:'',
                sc_price:'',
                stock:'',
                weight:'',
              }
              this.parameterdata.singleSpecTable = [];
              singleSpecObj.js_price = res.data.js_price / 100;
              singleSpecObj.sl_price = res.data.js_price / 100;
              singleSpecObj.price = res.data.price / 100;
              singleSpecObj.sc_price = res.data.sc_price / 100;
              singleSpecObj.stock = res.data.stock;
              singleSpecObj.weight = res.data.weight;
              this.parameterdata.singleSpecTable.push(singleSpecObj);
            }

            // 商品详情
            this.description = res.data.description;

            // 商品参数 售后服务 其他设置
            this.goodsaftersale.params = res.data.params?res.data.params:[{'title':'','value':''}]//参数
            this.goodsaftersale.goods_des = res.data.goods_des//关键词
            this.goodsaftersale.producing_area = res.data.producing_area // 产地
            this.goodsaftersale.deliver_area = res.data.deliver_area  // 发货地
            this.goodsaftersale.unit = res.data.unit           // 单位
            this.goodsaftersale.web_url = res.data.web_url        // 外部链接
            this.goodsaftersale.out_goods_id = (res.data.out_goods_id == 0) ? '' : res.data.out_goods_id //商品编码
            this.goodsaftersale.freight_id = res.data.freight_id;
            this.goodsaftersale.delay_compensate = res.data.delay_compensate;
            this.goodsaftersale.aftersale_time = res.data.aftersale_time;
            let stagArr = [];
           
            // 后台返回数据格式 ‘2,3’或者‘[]’都是字符串，处理兼容一下
            //debugger
            if( res.data.stags && !Array.isArray(res.data.stags)) {
              if( res.data.stags.indexOf(',') > -1 ) {
                stagArr = res.data.stags.split(',');
                stagArr.forEach(item => {
                  if (item) {
                    if(Number(item)) {
                      this.goodsaftersale.stags.push(Number(item));
                    }
                  }
                })
              }else {
                if(Number(res.data.stags)) {
                  this.goodsaftersale.stags.push( Number(res.data.stags) )
                }else {
                  this.goodsaftersale.stags = [];
                }
              }
            }else {
              this.goodsaftersale.stags = [];
            }
          }
        });
        console.log(this.goodsaftersale)
      }else {
        this.isShowGoodsDetails = false;
      }
    },
    mounted() {
    },
    methods: {
      radiochange(val){
        this.parameterdata.isradioguide = val
        this.$refs.goodsparameter.parentMsg(val)
      },
        // 查看各类价格说明
    viewPriceExp() {
      this.isViewPriceExp = true;
    },
      // 规格子组件，传给父组件的数据
      calcSpeTable(data) {
       this.keyvalue++
        this.parameterdata = data;
        // debugger

      },
      // 只有点击完最后一级，才会有值
      SSQChange() {
        if(this.SSQList && this.SSQList.length > 0) {
          this.isNextStep = false
        }else {
          this.SSQList = []
          this.isNextStep = true
        }
      },
      lazyLoad(node, resolve) {
        this.SSQList = [];
        this.SSQStr = '';
        this.getArea(node, resolve);
        if(this.SSQList && this.SSQList.length > 0) {
          this.isNextStep = false
        }else {
          this.isNextStep = true
        }
      },
      getArea(node, resolve) {
        const level = node.level;
        let limboNode = {};
        if(level === 0) {
          limboNode = {parent_id: 0}
        }
        if(level === 1) {
          limboNode = { parent_id: node.value };
        }
        if(level === 2) {
          limboNode = { parent_id: node.value };
        }

        NewGetCategoryData(limboNode).then(res => {
          let result = {};
          result = res.data
          if (level === 0) {
            result.forEach(item => {
              item.value = item.id;
              item.label = item.label;
              item.children = [];
              item.leaf = 0;  // 可以控制 是否有下级   值为true都不行，必须等于0
            })
          }

          if (level === 1) {
            for(let i = 0; i < res.data.length; i++) {
              if( limboNode.id === res.data[i].id ) {
                result = res.data[i].children;
                break;
              }
            }
            result.forEach(item => {
              item.value = item.id;
              item.label = item.label
              item.children=[];
              //这句代码表示当点击最后一级的时候 label后面不会转圈圈 并把相关值赋值到选择器上
              item.leaf = 0
            })
          }

          if (level === 2) {
            for(let i = 0; i < res.data.length; i++) {
              if( limboNode.id === res.data[i].id ) {
                result = res.data[i].children;
                break;
              }
            }

            result.forEach(item => {
              item.value = item.id;
              item.label = item.label
              item.leaf = 1;
            })
          }

          resolve(result)

        });
      },
      // 添加商品后，下一步 操作
      nextStep() {
        // 注意数据格式 [1,2,3] 数组，且里面是数字类型
        let ssqLabelList = this.$refs['ssqCascader'].getCheckedNodes()[0].pathLabels;
        this.goodsinfodata.categoryList = this.SSQList;
        this.goodsinfodata.categoryStr = ssqLabelList[0] + '/' + ssqLabelList[1] + '/' + ssqLabelList[2];
        this.isShowGoodsDetails = true;
      },

      // 保存/提交
      save() {
        // 此处变量 有顺序 校验时，电梯至某处

        // 商品信息 是否填写完整
        let isGoodsInfoMsg = this.$refs['goodsInfo'].validateGoodsInfoForm();
        // 商品规格 无需校验
        let spggRef = this.$refs.goodsspecifications;
        let spggData = spggRef.speData;
        spggRef.upDateDom();
        // return;
        // 商品售价，通过获取的数据，分别进行判断
        let isGoodsPrice = true;
        let goodsPriceMsg = '';
        let spsjData1 = JSON.parse(JSON.stringify(this.$refs.goodsparameter.singleSpecTable));
        let spsjData2 = JSON.parse(JSON.stringify(this.$refs.goodsparameter.parameterdata));

        // 如果有，则说明有规格组合数据
        if ( this.radioguide==2&&spsjData2.specs_group && spsjData2.specs_group.length > 0 ) {
          // debugger
          for(let i = 0; i < spsjData2.specs_group.length; i++) {
            let itemObj = spsjData2.specs_group[i][0];
            for (let itemKey in itemObj) {
              // 有多余字段，可能为空，需要对有效字段单独判断
              // Number后，有三中情况：0，正数，负数，NaN
              if( !Number(itemObj['js_price']) ||  Number(itemObj['js_price']) <0 ) {
                goodsPriceMsg = '[ 商品售价 ]中，协议价不能为空，并且只能填大于0的数值'
                isGoodsPrice = false;
                break
              } else if ( !Number(itemObj['price']) ||  Number(itemObj['price']) <0 ) {
                goodsPriceMsg = '[ 商品售价 ]中，指导价不能为空，并且只能填大于0的数值'
                isGoodsPrice = false;
                break
              } else if( !Number(itemObj['sc_price']) ||  Number(itemObj['sc_price']) <0 ) {
                goodsPriceMsg = '[ 商品售价 ]中，市场价不能为空，并且只能填大于0的数值'
                isGoodsPrice = false;
              } else if ( !Number(itemObj['stock']) ||  Number(itemObj['stock']) <0 ) {
                goodsPriceMsg = '[ 商品售价 ]中，库存量不能为空，并且只能填大于0的整数'
                isGoodsPrice = false;
              } else {
                goodsPriceMsg = '';
                isGoodsPrice = true;
              }
            }
            if (!isGoodsPrice) {
              break
            }
          }
        }else {
          // 无规格组合数据
          let slingleSpeObj = spsjData1[0];
          if ( !Number(slingleSpeObj['js_price']) ||  Number(slingleSpeObj['js_price']) <0 ) {
            goodsPriceMsg = '[ 商品售价 ]中，协议价不能为空，并且只能填大于0的数值'
            isGoodsPrice = false;
          } else if ( !Number(slingleSpeObj['price']) ||  Number(slingleSpeObj['price']) <0 ) {
            goodsPriceMsg = '[ 商品售价 ]中，指导价不能为空，并且只能填大于0的数值'
            isGoodsPrice = false;
          } else if ( !Number(slingleSpeObj['sc_price']) ||  Number(slingleSpeObj['sc_price']) <0 ) {
            goodsPriceMsg = '[ 商品售价 ]中，市场价不能为空，并且只能填大于0的数值'
            isGoodsPrice = false;
          } else if ( !Number(slingleSpeObj['stock']) ||  Number(slingleSpeObj['stock']) <0 ) {
            goodsPriceMsg = '[ 商品售价 ]中，库存量不能为空，并且只能填大于0的整数'
            isGoodsPrice = false;
          } else {
            goodsPriceMsg = ''
            isGoodsPrice = true;
          }
        }

        // 商品详情 是否填写完整
        // let isGoodsDetailsImgMsg = (this.$refs.goodsdetailsimg.goodsDeForm.description.indexOf('img') > -1) ? true : false;
        let isGoodsDetailsImgMsg = (this.$refs.goodsdetailsimg.editor.txt.html()) ? true : false

        // 售后服务 是否填写完整
        let isGoodsAfterSaleMsg = this.$refs['goodsaftersale'].validateGoodsAfterSaleForm();

        if(!isGoodsInfoMsg) {
          this.$message({type:'error',message:'商品信息未填写完整'});
          this.setFloorNavMountClick(0);
          return
        }

        if(!isGoodsPrice) {
          if ( goodsPriceMsg ) {
            this.$message({type:'error',message: goodsPriceMsg });
            this.setFloorNavMountClick(2);
            return
          }
        }
        if(!isGoodsDetailsImgMsg) {
          this.$message({type:'error',message:'商品详情未填写完整'});
          this.setFloorNavMountClick(3);
          return
        }

        if(!isGoodsAfterSaleMsg) {
          if(sessionStorage.getItem('clickbtm')==1){
            this.$message({type:'error',message:'其他设置未填写完整'});
          this.setFloorNavMountClick(5);
          }else  if(sessionStorage.getItem('clickbtm')==2){
            this.$message({type:'error',message:'售后及服务未填写完整'});
          this.setFloorNavMountClick(4);
          }
         
          return
        }

        // 所有校验通过，整理数据
        // 获取 商品信息数据
        let spxxData = this.$refs.goodsInfo.goodsInfoForm;
        
        // 品牌处理  goods_brand
        let brandOptions = this.$refs.goodsInfo.brandOptions;
        // debugger
        // goods_brand
        if (Array.isArray(brandOptions) && brandOptions.length > 0) {
          for(let bi = 0; bi < brandOptions.length; bi++) {
            if( Number(spxxData.brand_id) === Number(brandOptions[bi].id) ) {
              spxxData.goods_brand = brandOptions[bi].brand_cn;
              break;
            }
          }
        }


       
        // console.log(500,spxxData);
        if( spxxData.imgs.length > 7 ) {
          this.$message({ type: 'warning',message: '商品信息中，商品图片最大数量为7张，请检查' });
          this.setFloorNavMountClick(0);
          return;
        }

        // 商品规格
        // let spggData = this.$refs.goodsspecifications.speData;
        //
        // 商品售价，上面已经获取，
        let spsjData = {};
        if(this.radioguide==2 && spsjData2.specs_group && spsjData2.specs_group.length > 0 ) {
          this.goodsAllData['specs_group'] = spsjData2.specs_group
          this.goodsAllData['specs'] =spsjData2.specs
        }else {
          spsjData = spsjData1[0];
          this.goodsAllData['specs_group'] = []
          this.goodsAllData['specs'] = []
        }

        // 商品详情 数据
        // let spxqData = this.$refs.goodsdetailsimg.goodsDeForm;
        let spxqData =  String(this.$refs.goodsdetailsimg.editor.txt.html())

        // 售后服务 数据
        let ssffData = this.$refs.goodsaftersale.goodsAfterSaleForm;
         // 产地数据处理
         let areaOptions = this.$refs.goodsaftersale.areaOptions;
        for(let ai = 0; ai < areaOptions.length; ai++) {
          if ( Number(ssffData.producing_area) === Number(areaOptions[ai].id) ) {
            ssffData.producing_area = areaOptions[ai].name;
            break;
          }
        }

        // 发货地数据处理
        for(let ai = 0; ai < areaOptions.length; ai++) {
          if ( Number(ssffData.deliver_area) === Number(areaOptions[ai].id) ) {
            ssffData.deliver_area = areaOptions[ai].name;
            break;
          }
        }
        console.log(569,ssffData);

        if (ssffData.delay_compensate == 72) {
          this.$message({ type: 'warning',message: '发货时长不能超过48小时，请重新编辑' });
          return
        }
        // return

        // 所有数据合并
        Object.assign( this.goodsAllData, spxxData, spsjData, ssffData);
        this.goodsAllData.description = spxqData

        // 经营类目，服务标签，需要单独处理数据格式
        this.goodsAllData.category_id = spxxData.categoryList.slice(-1)[0] ? spxxData.categoryList.slice(-1)[0] : '';
        if(this.goodsAllData.stags) {
          this.goodsAllData.stags = this.goodsAllData.stags.toString();
        }

        // 价格数字需要 乘以100
        if(this.goodsAllData.specs_group && this.goodsAllData.specs_group.length > 0) {
          this.goodsAllData.specs_group.forEach((item)=> {
            item.js_price = (Number(item.js_price) * 1000)/10;
            item.price = (Number(item.price) * 1000)/10;
            item.sc_price = (Number(item.sc_price) * 1000)/10;
            item.sl_price = (Number(item.sl_price) * 1000)/10;
            item.stock = Number(item.stock);
          })
          delete this.goodsAllData.js_price;
          delete this.goodsAllData.price;
          delete this.goodsAllData.sc_price;
          delete this.goodsAllData.sl_price;
          delete this.goodsAllData.stock;
          delete this.goodsAllData.weight;
        }else {
          this.goodsAllData.js_price = (Number(this.goodsAllData.js_price) * 1000)/10
          this.goodsAllData.price = (Number(this.goodsAllData.price) * 1000)/10
          this.goodsAllData.sc_price = (Number(this.goodsAllData.sc_price) * 1000)/10
          this.goodsAllData.sl_price = (Number(this.goodsAllData.sl_price) * 1000)/10
          this.goodsAllData.stock = Number(this.goodsAllData.stock);
          delete this.goodsAllData.specs;
          delete this.goodsAllData.specs_group;
        }

        // 修改  商品id不为 0
        if( this.goodsAllData.goods_id ) {
          // 商品id 为 0 是新增
          let goodsStatus = 1;
          if ( this.goodsAllData.submit === 0 ) {
            goodsStatus = 2;
          }else if(this.goodsAllData.submit === 1) {
            goodsStatus = 3;
          }
          updateGoodsNew(this.goodsAllData).then(res=> {
            //debugger
            if( res.code === 1 ) {
              this.$message({type: 'success', message:'编辑成功'});
              this.initAllGoodsInfo();
              //console.log(600,this.$store.state.tagsView.visitedViews);
              // 编辑成功，关闭当前路由
              this.$store.state.tagsView.visitedViews.splice(this.$store.state.tagsView.visitedViews.findIndex(item => item.path === this.$route.path), 1)
              this.$router.push({
                path: '/system/goods/management',
                query: { goodsStatus: goodsStatus }
              });
            } else {
              // 如果保存失败，将价格还原,仅处理 多规格数据
              this.$refs.goodsparameter.priceReduce()
              let msg = res.message ? res.message : '编辑失败'
              this.$message({type: 'error', message: msg});
            }
          });
        }else {
          //debugger
          // 新增  商品id 为 0
          let goodsStatus = 1;
          if ( this.goodsAllData.submit === 0 ) {
            goodsStatus = 2;
          }else if(this.goodsAllData.submit === 1) {
            goodsStatus = 3;
          }
          addGoods( this.goodsAllData ).then( res=> {
            if( res.code === 1 ) {
              this.$message({type: 'success', message:'新增成功'});
              this.initAllGoodsInfo();
              // 编辑成功，关闭当前路由
              this.$store.state.tagsView.visitedViews.splice(this.$store.state.tagsView.visitedViews.findIndex(item => item.path === this.$route.path), 1)
              this.$router.push({
                path: '/system/goods/management',
                query: { goodsStatus: goodsStatus }
              });
            }else {
              // 如果保存失败，将价格还原,仅处理 多规格数据
              this.$refs.goodsparameter.priceReduce()
              let msg = res.message ? res.message : '新增失败'
              this.$message({type: 'error', message: msg});
            }
          });
        }

      },

      // 初始化 商品所有数据
      initAllGoodsInfo() {
        // 初始化 商品信息 数据
        this.$refs.goodsInfo.initInfo();
        // 初始化 商品规格 数据
        this.$refs.goodsspecifications.initInfo();
        // 初始化 商品售价 数据
        this.$refs.goodsparameter.initInfo();
        // 初始化 商品详情 数据
        this.$refs.goodsdetailsimg.initInfo();
        // 初始化 商品售后 数据
        this.$refs.goodsaftersale.initInfo();
      },

      /*  添加商品详细 */
      /* 设置楼层导航事件驱动方法* @params Number index  楼层下标 */
      setFloorNavMountClick(index) {
        let _this = this
        _this.isFIActive = index;
        clearInterval(_this.TIMER);

        // 可以通过 floor-cont的父元素，高度减去上下两个div的高度，来准确计算出来了，需要wtach监听,暂时用初步高来计算，一般问题不大
        let floor_cont = document.getElementsByClassName('floor-cont')[0];
        let floor_item,floor_offsetTop 
        if(index==1||index==2||index==0){
         floor_item = document.getElementsByClassName('floor-item')
         floor_offsetTop = floor_item[index].offsetTop - floor_item[0].offsetTop
        }
        if(index==3){
           floor_item = this.$refs.goodsaftersale.$refs.paramsvalue.$el
          console.log(floor_item)
          floor_offsetTop =floor_item.offsetTop - 90
        }
        if(index==4){
           floor_item = this.$refs.goodsaftersale.$refs.salesvalue.$el
          
          floor_offsetTop = floor_item.offsetTop - 90
        }
        if(index==5){
          floor_item = this.$refs.goodsaftersale.$refs.outhervalue.$el
          
          floor_offsetTop = floor_item.offsetTop - 90
        }
          // 每次点击，对应dom需要滚动的高度
       
        let window_scrollTop = _this.$refs.scrollview.scrollTop
          // 基本滚动动画配置
        let timer = { step: 60, times: 15, FLOOR_OFFSETTOP: 0 };

        // floor_cont 可是窗口的 高
        let hxz = 0;
        let resList = [];
        let list = [];
       
        for(let i = 0; i < 6; i++) {
          if(i==0||i==1||i==2){
           let floor_item = document.getElementsByClassName('floor-item')
           list.push(Number(floor_item[i].offsetHeight));
        }
        if(i==3){
          list.push(Number(this.$refs.goodsaftersale.$refs.paramsvalue.$el.offsetHeight));
        }
        if(i==4){
          list.push(Number(this.$refs.goodsaftersale.$refs.salesvalue.$el.offsetHeight));
        }
        if(i==5){
          list.push(Number(this.$refs.goodsaftersale.$refs.outhervalue.$el.offsetHeight));
        }
        }
       
     
      resList = list.slice(index)
        for(let j = 0; j < resList.length; j++) {
          hxz += resList[j]
        }

        if( hxz > floor_cont.offsetHeight) {
          timer.FLOOR_OFFSETTOP = floor_offsetTop;
        }else {
          timer.FLOOR_OFFSETTOP = floor_cont.scrollHeight - floor_cont.offsetHeight
        }

        if (window_scrollTop > floor_offsetTop) {
          _this.setFloorScrollArrowUp(timer)
        } else if (window_scrollTop === floor_offsetTop) {
          return false
        } else {
          _this.setFloorScrollArrowDown(timer)
        }
      },

      /* 设置楼层向上滚动* @params Object timer 定时器配置 */
      setFloorScrollArrowUp(timer) {
        let _this = this
        clearInterval(_this.TIMER)
        _this.TIMER = setInterval(() => {
          const window_scrollTop = _this.$refs.scrollview.scrollTop
          if (window_scrollTop <= timer.FLOOR_OFFSETTOP) {
            _this.$refs.scrollview.scrollTop = timer.FLOOR_OFFSETTOP
            clearInterval(_this.TIMER)
          } else {
            _this.$refs.scrollview.scrollTop = window_scrollTop - timer.step
          }
        }, timer.times)
      },

      /* 设置楼层向下滚动@params Object timer 定时器配置 */
      setFloorScrollArrowDown(timer) {
        let _this = this
        clearInterval(_this.TIMER)
        _this.TIMER = setInterval(() => {
          const window_scrollTop = _this.$refs.scrollview.scrollTop
          if (window_scrollTop >= timer.FLOOR_OFFSETTOP) {
            _this.$refs.scrollview.scrollTop = timer.FLOOR_OFFSETTOP
            clearInterval(_this.TIMER)
          } else {
            _this.$refs.scrollview.scrollTop = window_scrollTop + timer.step
          }
        }, timer.times)
      },
        /** 数据处理为,二维数组，供笛卡尔积算法方法使用,对空数据进行过滤 */
    processData(list) {
      let result = [];
      if (list && list.length > 0) {
        for (let i = 0; i < list.length; i++) {
          let childList = [];

          if(list[i].spec_name) {
            for(let j = 0; j < list[i].spec_value.length; j++) {
              if(list[i].spec_value[j].value) {
                childList.push(list[i].spec_value[j].value);
              }
            }
          }

          if(childList.length > 0) {
            result.push(childList);
          }

        }
      }
      return result;
    },
        /** 笛卡尔积算法 */
    cartesian(arr) {
      if(arr.length < 2) {
        return arr[0] || [];
      }else {
        return [].reduce.call(arr, function(col, set) {
          let res = [];
          col.forEach( c => {
            set.forEach(s => {
              let t = [].concat(Array.isArray(c) ? c : [c]);
              t.push(s);
              res.push(t);
            });
          });
     
          return res
        });
      }
    }
    }, // methods end
    destroyed() {
      clearInterval(this.TIMER);
      this.TIMER = null;
    } // destroyed end
  }
</script>

<style scoped lang="scss" type="text/css">

  .goods-all {
    height: 100%;
    padding: 20px;
  }

  .goods-all .good-all-type {
    height: 100%;
    overflow: auto;
  }

  /deep/.goods-all .el-card .el-card__body{
    height:100%;
    overflow: auto;
  }

  p {
    margin: 0;
    padding: 0;
  }
  /* el-card title hxz 样式统一 */
  .card-header-title {
    display: flex;
    flex-direction: row;
    justify-content: start;
    align-items: center;
    font-size: 16px;
    color: #333;
    font-weight: 400;
    height: 24px;
  }
  .blue-block-goods {
    width: 5px;
    height: 24px;
    /*background: #3A84FF;*/
    /*margin: 0 7px 0 0;*/
    /*border-radius: 2px;*/
  }
  /* el-card title hxz 样式统一 end */
  .goods-type-tip {
    width: 100%;
    background: #F1F7FD;
    border: 1px solid #3A84FF;
    font-size: 14px;
    font-weight: 400;
    color: #3A84FF;
    line-height: 1em;
    padding: 14px 15px;
  }
  .goods-type-options {
    margin: 25px 0;
  }
  /*------------ 联级面板样式重置  start ------------*/
  /deep/.el-cascader-panel.is-bordered {
    border: none;
  }
  /deep/.el-cascader-menu {
    min-width: 280px;
    border: none;
    box-shadow: 0px 4px 9px 1px rgba(51, 51, 51, 0.09);
    border-radius: 2px;
    overflow: hidden;
  }
  /deep/.el-cascader-menu__wrap {
    width: 280px;
    height: 500px;
    overflow: auto;
    margin: 5px 0!important;
  }
  /* 很重要,不要问我为什么 */
  /deep/.el-scrollbar:hover>.el-scrollbar__bar, /deep/.el-scrollbar:active>.el-scrollbar__bar, /deep/.el-scrollbar:focus>.el-scrollbar__bar {
    opacity: 0;
  }
  /*------------ 联级面板样式重置  end ---------------*/
  .next-step {
    padding: 10px 25px;
    margin: 0 auto;
    display: block;
  }

  /* 电梯效果 样式 */
  .floor-nav {
    width: 100%;
  }
  .floor-nav .nav-list {
    padding: 0;
    margin:0;
    display: flex;
    justify-content: start;
    flex-direction: row;
    border-bottom:1px solid #eee;
  }
  .floor-nav .nav-list .nav-list-item {
    font-size: 16px;
    font-weight: 400;
    color: #333333;
    padding: 0 25px 15px;
    list-style: none;
    vertical-align: middle;
    align-self: center;
    border-bottom: 2px solid #fff;
    cursor: pointer;
  }
  .floor-nav .nav-list .floor-item-active,
  .floor-nav .nav-list .nav-list-item:hover {
    color: #3A84FF;
    font-weight: bold;
    border-bottom: 2px solid #3A84FF;
  }

  .floor-item-box-title {
    background: #F1F1F6;
    height: 45px;
  }
  .blue-block-goods-title {
    margin: 0 20px 0 0;
  }
  .good-details-body {
    height: 100%;
  }
  /deep/.good-details-body .el-card__body  {
    height: 100%;
    padding: 15px 20px 0px 20px;
    overflow: hidden;
  }

  .floor-cont{
    height: calc(100% - 98px);
    overflow: auto;
  }

  .floor-item {
    padding: 0;
    margin: 20px;
    color: #333;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0 ,0.1);
  }
  .submit-type-con {
    width: 236px;
    margin: 0 auto 20px;
    padding: 0 0 20px;
  }
  .submit-cont {
    width: calc(100% + 40px);
    padding: 12px 0 8px;
    margin-left: -20px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    /*align-content: center;*/
    box-shadow: 0 -8px 9px 1px rgba(51, 51, 51, 0.06);
  }
  .edit-type-span {
    display: inline-block;
    cursor: pointer;
    margin: 0 20px;
  }
  .tip-span {
    color: #909399;
    font-size: 12px;
  }
</style>
