<template>
    <div class="goods">
      <div >
        
        <el-card class="boxcard" shadow="never" >
          <div slot="header" class="clearfix">
            <span>{{list[0].cn_name}}</span>
          </div>
          <r-formItem ref="itemData0" btnRight :itemData="list[0]" :btnList="btnList0" :formRule="formRule" :formItem="formItem0"></r-formItem>
        </el-card>
        <el-card class="boxcard" shadow="never" >
          <div slot="header" class="clearfix">
            <span>{{list[1].cn_name}}</span>
          </div>
          <r-formItem ref="itemData1" btnRight :itemData="list[1]" :btnList="btnList1" :formRule="formRule" :formItem="formItem1"></r-formItem>
        </el-card>
        <el-card class="boxcard" shadow="never" >
          <div slot="header" class="clearfix">
            <span>{{list[2].cn_name}}</span>
          </div>
          <r-formItem ref="itemData2" btnRight :itemData="list[2]" :btnList="btnList2" :formRule="formRule" :formItem="formItem2"></r-formItem>
        </el-card>
        
      </div>
      
    </div>
  </template>
  <script>
import index from '../../components/global/FormItem/index.vue';

  
  export default {
      data() {
          return {
            itemData0: {
              day_num: 3,
              active_time:'13:10',
              active_piece: 10,
              active_price: 0,
              user_id:1,
            },
            itemData1: {
              day_num: 3,
              active_time:'13:10',
              active_piece: 10,
              active_price: 0,
              user_id:1,
            },
            itemData2: {
              day_num: 3,
              active_time:'13:10',
              active_piece: 10,
              active_price: 0,
              user_id:1,
            },
            formItem0: [
              {labelWidth:'120',type: "time", label: "激活检查时间", prop: "active_time"},
              {labelWidth:'120',type: "select", label: "管理员推送", prop: "user_id",options:[]},
            ],
            formItem1: [
              {labelWidth:'120',type: "time", label: "激活检查时间", prop: "active_time"},
              {labelWidth:'120',type: "select", label: "管理员推送", prop: "user_id",options:[]},
            ],
            formItem2: [
              {labelWidth:'120',type: "time", label: "激活检查时间", prop: "active_time"},
              {labelWidth:'120',type: "select", label: "管理员推送", prop: "user_id",options:[]},
            ],
            formRule: {
              minutes: [{ required: true, message: "请输入时间区间/分钟", trigger: "blur" }],
              active_time: [{ required: true, message: "请选择激活检查时间", trigger: "blur" }],
              user_id: [{ required: true, message: "请选择管理员推送", trigger: "blur" }],
            },
            btnList0: [{label: "确定",type: "primary",icon: "el-icon-setting",handle: e => this.elFormSubmit0()}],
            btnList1: [{label: "确定",type: "primary",icon: "el-icon-setting",handle: e => this.elFormSubmit1()}],
            btnList2: [{label: "确定",type: "primary",icon: "el-icon-setting",handle: e => this.elFormSubmit2()}],
            width:500,
            height:500,
            contentHeight:500,
            list:[],
            data:[],
        }
      },
      mounted() {
        this.$http.post('/stockNoticeList').then(res=>{
          this.list=res.data.list
          // this.data=res.data.user
          this.formItem0[1].options=res.data.user
          this.formItem1[1].options=res.data.user
          this.formItem2[1].options=res.data.user
        })
      },
      methods: {
        getSavestockNotice(index=0){
          this.$http.post('/saveStockNotice',this.list[index]).then(res=>{
              if (res.code == 200) {
                this.$msg.success('修改成功！')
              }else{
                this.$msg.error('修改失败！')
              }
          })
        },
        elFormSubmit0(e) {
          console.log(e);
          this.$refs.itemData0.$refs.ruleForm.validate((valid) => {
            if (valid) {
              this.getSavestockNotice(0)
            }
          });
        },
        elFormSubmit1(e) {
          this.$refs.itemData1.$refs.ruleForm.validate((valid) => {
            if (valid) {
              this.getSavestockNotice(1)
            
            }
          });
        },
      elFormSubmit2(e) {
        this.$refs.itemData2.$refs.ruleForm.validate((valid) => {
          if (valid) {
            this.getSavestockNotice(2)
          }
        });
      },
    
      
    },
  };
  </script>