<template>
  <div>
    <el-dialog title="设置库存" :visible.sync="objProps.dialogVisibleStock" :before-close="handleDialogClose">
      <el-table :data="objProps.gridData">
        <el-table-column property="brandName" label="SPU型号" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.model}}
          </template>
        </el-table-column>
        <el-table-column property="specName" label="SKU规格" align="center" show-overflow-tooltip></el-table-column>
        <el-table-column property="supplyPrice" label="供货价" align="center"></el-table-column>
        <el-table-column property="stock" label="库存数量">
          <template slot-scope="scope">
            <!-- :class="{resTip:objProps.gridDataSave.stock < objProps.gridDataSave.warnStock?true:false}"  -->
            <el-input
              maxlength="6"
              show-word-limit
            v-model="objProps.gridDataSave.stock"
            placeholder="请输入库存"
            oninput="value=value.replace(/[^\d]/g, '')"></el-input>
          </template>
        </el-table-column>
        <!-- <el-table-column property="warnStock" label="预警库存">
          <template slot-scope="scope">
            <el-input type="number" v-model.number="objProps.gridDataSave.warnStock" placeholder="请输入预警库存" oninput="value=value.replace(/[^\d]/g, '')"></el-input>
          </template>
        </el-table-column> -->
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelForm(objProps.dialogVisibleStock)">取 消</el-button>
        <el-button type="primary" @click="setSkuStock(objProps.dialogVisibleStock)">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
// import { _delivery } from "@/utils/utils";
export default {
  name: "setStockDialog",
  data() {
    return {
  //     form: {
  //       logisticsMerchantsName: "",
  //       invoiceNo: "",
  //       deliverQty: ""
  //     },
  //     ids:[],
  //     rulesSend: {
  //       logisticsMerchantsName: [{ required: true, message: "名称不能为空" }],
  //       invoiceNo: [{ required: true, message: "单号不能为空" }],
  //       deliverQty: []
  //     }
    };
  },
  props: ["objProps"],
  filters: {
    delivery: function(type) {
      return _delivery(type);
    }
  },
  methods: {
    setSkuStock(val){

      this.$axios
      .post("/products/updateSkuStock", this.objProps.gridDataSave)
      .then(res => {
         let {code,data,msg} =res.data;
         if(code ==200){
            this.$message.success(msg);
            this.cancelForm(val);
            this.changeProfile();
         }else{
             this.$message.error(msg);
         }

        // this.getList();
        // this.removeDialog()

      })
      .catch(res => {
        this.dialogVisibleStock = false;
      });
    },
    cancelForm(val) {
      const data = {
        state: !val
      };
      this.objProps.gridData =[];
      this.objProps.gridDataSave ={};
      this.$emit("resData", data);
      //   location.reload()
    },
    //重新页面加载数据
    changeProfile() {
      this.$emit("okSend");
    },
    handleDialogClose(){
      this.cancelForm(this.objProps.dialogVisibleStock);
    },
  },
  mounted(){
  }
};
</script>
<style lang="scss" scoped>
</style>
