<template>
  <el-dialog title="商品链接" :visible.sync="modalData.show" width="450px" @close="cancel()">
    <div class="dialog-body">
      <el-table :data="goodsSkuList" :span-method="objectSpanMethod" border>
        <el-table-column width="140px" v-for="(i, k) in skuCols" :label="i" :key="k" :class-name="k == skuCols.length - 1 ? 'pad-l-20' : 'right-border'">
          <template slot-scope="scope">{{ JSON.parse(scope.row.giftPropValues)[k].valueName }}</template>
        </el-table-column>
        <el-table-column label="当前商品库存" width="130px">
          <template slot-scope="scope">
            {{ scope.row.stock || '--' }}
          </template>
        </el-table-column>
        <el-table-column label="活动库存">
          <template slot-scope="scope">
            <el-select v-model="scope.row.stockType" style="width:100px" @change="changeSingleStock(scope.row.giftSkuId, scope.row.stageStock, scope.row.stockType)">
              <el-option label="增加" :value="1"></el-option>
              <el-option label="减少" :value="0"></el-option>
            </el-select>
            <el-input-number v-model="scope.row.stageStock" width="140" style="margin-left:-2px;" controls-position="right" @blur="changeSingleStock(scope.row.giftSkuId, scope.row.stageStock, scope.row.stockType)" precision="0" :min="0" :max="999999"></el-input-number>
          </template>
        </el-table-column>
      </el-table>
      <div style="margin-top: 20px;text-align:right">
        <el-button type="default" @click="cancel">取消</el-button>
        <el-button type="primary" @click="submit">确认</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
// import request from '../service/request';
import copy from '../utils/clone.js';
export default {
  props: {
    skuStockData: {
      type: Object
    }
  },
  data() {
    return {
      dialogVisible: false,
      skuCols: [],
      goodsSkuList: []
      // forceIntegralMallProId: '',
      // forceType: ''
    };
  },
  // watch: {
  //   integralMallProId: function(value) {
  //     this.forceIntegralMallProId = value;
  //   },
  //   saleType: function(value) {
  //     this.forceType = value;
  //   }
  // },
  created() {
    this.dialogVisible = true;
    let giftProStandardJsonCopy = copy(this.skuStockData.giftProStandardJson);
    this.goodsSkuList = copy(this.skuStockData.skuJson);
    this.goodsSkuList = JSON.parse(this.goodsSkuList);
    this.handelSkuData(giftProStandardJsonCopy);
  },
  methods: {
    handelSkuData(value) {
      // let arr = [];
      this.skuCols = [];
      /** ****组合sku的数据*****/
      for (let item of value) {
        this.skuCols.push(item.standardName);
      }
    },
    combine(arr) {
      arr.reverse();
      let r = [];

      (function f(t, a, n) {
        if (n == 0) return r.push(t);
        for (let i = 0; i < a[n - 1].length; i++) {
          f(t.concat(a[n - 1][i]), a, n - 1);
        }
      })([], arr, arr.length);
      // var t = r;
      return r; // r是排列组合后的数据与
    },
    cancel() {
      this.dialogVisible = false;
      setInterval(() => {
        this.$emit('closeSkuStock');
      }, 10);
    }
  }
};
</script>
<style scoped>
.wechat-img-box {
  margin: 0 auto;
  text-align: center;
}
.wechat-img {
  width: 200px;
  height: 200px;
}
.wechat-force {
  margin: 30px auto 50px;
  text-align: center;
}
/* .force-button {
  background: #1890ff;
  color: #fff;
  border-color: #1890ff;
  font-size: 14px;
  line-height: 14px;
  padding: 8px 15px;
} */
</style>
