<template>
  <div class="auto">
    <form novalidate class="form-horizontal" style="margin-left: 25%; width: 50%;">
      <p class="text-center"><strong>中元卡次数修改</strong></p>
      <div class="row">
        <div class="col-sm-4">
          <label class=" font_normal_body">卡&emsp;&emsp;号</label>
          <input type="text" class="input_search" style="width: 60%" placeholder="卡号" v-model="model.CardID" disabled/>
        </div>

        <div class="col-sm-4">
          <label class=" font_normal_body">卡上气量</label>
          <input type="text" class="input_search" style="width: 60%"  placeholder="卡上气量" v-model="model.Gas" disabled/>
        </div>

        <div class="col-sm-4">
          <label class=" font_normal_body">卡上次数</label>
          <input type="text" class="input_search" style="width: 60%" placeholder="卡上次数" v-model="model.Times" disabled/>
        </div>

      </div>
      <div class="row">
        <div class="col-sm-4">
          <label class=" font_normal_body">新卡次数</label>
          <input type="text" class="input_search" style="width: 60%" placeholder="新卡次数" v-model="model.f_newtimes"/>
        </div>
      </div>
      <div style="text-align:right; height: 25%">
        <button class="button_search" type="button" @click="readCard()">读卡</button>
        <button class="button_search" type="button" @click="confirm()">写卡</button>
      </div>
    </form>

  </div>

</template>
<script>
  export default {
    title: '次数修改',
    data () {
      return {
        model: {
          Gas: '',
          Times: '',
          CardID: '',
          f_newtimes: ''
        }
      }
    },

    methods: {
      async readCard () {
        // 读卡
        let res = await this.$resetpost('http://127.0.0.1:8003/ReadCard', {}, {resolveMsg: null, rejectMsg: '读卡出错！！'})
        console.log('返回卡信息', res.data)
        if (res.data.Err || res.data.Exception) {
          this.$showAlert(`${res.data.Err}${res.data.Exception}`, 'danger', 2000)
        }
        this.model = Object.assign({}, this.model, res.data)
      },
      async confirm () {
        // 制卡
        // 验证是否读卡
        if (!this.model.CardID) {
          this.$showAlert('请先读卡！！', 'warning', 3000)
        }
        // 存记录 （将旧卡和新卡的信息存储）

        console.log('开始制卡', this.model)

        let params = {
          factory: this.model.Factory,                                // 气表厂家
          kh: this.model.CardID,                                         // 卡号
          yhh: this.model.Meterid,              // 用户号，档案中自己输
          kmm: 0,                            // 卡密码，写卡后返回新密码, 不论补卡还是先开户都没有密码
          bjql: 0,                              // 报警气量,t_gasbrand表中
          czsx: 0,                              // 充值上线，t_gasbrand表中
          tzed: 0,                            // 透支额度，t_gasbrand表中
          bkcs: 0,                          // 补卡次数，从补卡表里通过表编号获得
          ql: 0,                                  // 预购气量
          cs: this.model.f_newtimes,                         // 求购气次数，先开户为1
          money: 0,                            // 购气金额
          dqdm: 0,                                          // 精益工业地区代码
          klx: 0,
          csql: 0,
          lastmoney: 0,
          ccsql: 0,
          lastlastmoney: 0,
          ljgql: 0,
          ljyql: 0,
          yhh: 0,
          sxrq: 0,
          totalmoney: this.model.TotalMoney,
          stairversion: 0,
          pricedate: 0,
          pricetype: 0
        }
        await this.$resetpost('http://127.0.0.1:8003/WriteGasCard', params, {resolveMsg: '制卡成功', rejectMsg: '制卡失败'})
        this.model = {
          Gas: '',
          Times: '',
          CardID: '',
          f_newtimes: ''
        }
      }
    }
  }
</script>
