<template>
  <div class="auto select-overspread" style="overflow-y: scroll;height: 100%">
    <validator name='v'>
      <form class="form-horizontal" novalidate>
        <ul class="nav nav-tabs">
          <li class="active"><a href="#">卡参数</a></li>
        </ul>
        <div  v-for="row in model.rows">
          <div class="col-sm-6">
<!--            <label class="font_normal_body" >{{row.modifiable}}:</label>-->
            <label class="font_normal_body" >{{row.name}}:</label>
            <input class="input_search" style="width:60%"  type="number" :disabled="row.modifiable==0 ?  true: false"
                   v-model="row.value">
          </div>
        </div>
      </form>
      <div style="text-align:right;height:auto;margin-top:6px;">
        <button :disabled='!$v.valid' @click="confirm()" class="button_search" >制卡</button>
      </div>
      <!--</div>-->
    </validator>
  </div>
</template>
<script>
  import Vue from "vue";



  export default {
    data() {
      return {

        model: {
          rows:[]
        },
        // 编辑控制
        isEdit: false,
        cardTool:{}

      }
    },
    props: ['typedata', 'config','toolcardname'],
    watch: {
      'typedata'(val) {
        if (val) {
          this.initGen()
        } else {
          this.initModel()
        }
      }
    },
    ready() {
      this.initGen()
    },
    methods: {
      initGen () {
        this.model.rows=[]
        if(this.typedata.parameter){
          this.typedata.parameter.forEach((item)=>{
            this.model.rows.push(item)

          })
        }
      },

    async confirm(){
      this.cardTool.parameter={}

      if(this.model.rows) {
        this.model.rows.forEach((item) => {
          this.cardTool.parameter[item.parameterName] = item.value

        })
      }
      this.cardTool.aliasName=this.typedata.aliasName
      this.cardTool.cardType=this.typedata.cardType
      var makecard_record={
        name:this.toolcardname,
        cardType:this.typedata.name,
        f_operator: this.$login.f.name,
        f_operatorid: this.$login.f.id,
        f_orgid: this.$login.f.orgid,
        f_orgname: this.$login.f.orgs,
        f_depid: this.$login.f.depids,
        f_depname: this.$login.f.deps


      }
      let res = await this.$showMessage(`您确定要制作卡吗？`, ['confirm', 'cancel'])
      if (res === 'confirm') {
        console.log("=====================================")
        console.log(this.cardTool)
        await Vue.resetpost('http://127.0.0.1:8003/MakeToolCard', makecard_record, {resolveMsg: "制卡成功", rejectMsg: '制卡失败！！'})
        this.$resetpost('rs/entity/t_toolcardmaking_record', makecard_record, {resolveMsg: null, rejectMsg: null})
      }
      this.initModel()

    },
      initModel() {
        this.model = {
          rows:[]
        }
      },
      close() {
        this.$dispatch('close')
      }


    }
  }
</script>
<style lang="less">
  #gas-price-form {
    .form-group {
      margin-left: 0px;
      margin-right: 0px;
    }
  }

</style>
