<template>
	<section class="main">
    <div class="p_all_20">
      <div class="body_right">
       <div class="pwd_wrap">
            <div class="mainbox">
                <table class="table">
                <tr>
                    <td class="tdleft">商品库存预警数：</td>
                    <td>
                        <input id="txt_criticalvalue" class="membertxt" type="text" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" v-model="stock"/>
                    </td>
                </tr>
          <tr class="tr_tips">
                    <td class="tdleft"></td>
                    <td>
              <span class="tips_span">温馨提示：当某商品库存小于这个数值时，系统会自动提醒您设置库存。</span>
                    </td>
                </tr>
          <tr class="tr_input">
                    <td class="tdleft"></td>
                    <td>
              <label>
                <!-- <input type="checkbox" id="cbk_onlyspotgoods" v-model="check"/><span>子商城商品不作预警提示</span> -->
              </label>

                    </td>
                </tr>
                <tr>
                    <td colspan="2" class="msg">
                        <!-- <input type="button" value="保存" class="btnrefer" @click="save()"/> -->
                        <el-button type="primary" class="btnrefer" @click="save">保存</el-button>
                    </td>
                </tr>
                </table>
            </div>
        </div>
    </div>
    </div>
  </section>
</template>

<script>

  export default {
      name: 'saleStock',
      data() {
          return {
            lock: false,
            stock:0,
            check:false,
            id:"",
          }
      },
      components:{
      },
      mounted(){
        this.init()
      },
      methods: {
      init(){
        this.$axios.get('/stockwarn')
        .then(r => {
          // console.dir(r)
          if(r.data.code == 200){
            let data = r.data.data
            this.stock = data.criticalValue
            this.check = data.onlySpotGoods == 0?false:true
            // this.id = data.merId
          }
        }).catch(r => {console.log(r)})
      },
      save(){
        // console.dir(parseInt(this.stock))
        if(this.stock == ""){
            this.$message.error("预警数不能为空")
            return
        }else{
          this.$axios.post('/stockwarn',{
            criticalValue:parseInt(this.stock),
            onlySpotGoods:this.check,
            // merId:this.id
          }).then(r => {
              if(r.data.code == 200){
                this.$message.success(r.data.message)
                this.init()
              }
            }).catch(r => {console.log(r)})
          }

        }
      }
  }

</script>

<style scoped>
.pwd_wrap {
    display: block;
    background: #fff;
    padding: 6px 10px 200px;
}
.title_div {
    padding: 10px;
    border-bottom: 1px solid #000;
    font-size: 18px;
    background-color: #fff;
}
.mainbox {
    width: 600px;
    height: auto;
    margin: 50px auto 0;
}
.mainbox .table {
    /* width: 600px; */
    border-collapse: collapse;
    margin-top: 10px;
    color:#666;
}
tbody {
    display: table-row-group;
    vertical-align: middle;
    border-color: inherit;
}
tr {
    display: table-row;
    vertical-align: inherit;
    border-color: inherit;
}
.mainbox .table .tdleft {
    text-align: right;
    padding-right: 16px;
    font-size: 14px;
}
.mainbox .table td {
    height: 35px;
}
.mainbox .table .membertxt {
    height: 32px;
    line-height: 32px;
    border: 1px solid #dbdbdb;
    width: 250px;
    padding-left: 6px;
}
.mainbox .table .tr_tips td {
    height: 35px;
}

.mainbox .table .tdleft {
    text-align: right;
    padding-right: 16px;
    font-size: 14px;
}
.tips_span {
    color: #d23232;
    font-size: 14px;
}
.tr_input label {
    cursor: pointer;
}
.tr_input input {
    vertical-align: middle;
    cursor: pointer;
    margin-right:5px;
    width: 14px;
    height: 14px;
}
.tr_input span {
    display: inline-block;
    vertical-align: middle;
}
.mainbox .table .msg {
    text-align: center;
    font-weight: bold;
    font-size: 14px;
}
.mainbox .table .btnrefer {
    height: 34px;
    width: 120px;
    /* background-color: #409eff; */
    border: 0;
    /* color: White; */
    font-size: 14px;
    font-weight: bold;
    margin-top: 30px;
    cursor: pointer;
    border-radius: 4px;
    outline: none;
}
</style>
