<template>
  <div class="auto">
    <validator name='v'>
      <form novalidate class="form-horizontal">
        <p class="bg-info text-center" style="padding: 8px;">线下写卡</p>
        <div class="row">
          <div class="form-group form-input-group col-sm-4">
            <label for="f_paytype" class=" col-sm-2 control-label">付款方式:</label>
            <input type="text" class="form-control col-sm-2" v-model="model.f_payment" disabled/>
          </div>
          <div class="form-group form-input-group col-sm-4">
            <label for="f_pregas" class=" col-sm-2 control-label">预购气量:</label>
            <input type="number" class="form-control col-sm-2" v-model="model.f_pregas" disabled>
          </div>

          <div class="form-group form-input-group col-sm-4">
            <label for="f_preamount" class=" col-sm-2 control-label">预购金额:</label>
            <input type="number" class="form-control col-sm-2" v-model="model.f_preamount" disabled>
          </div>
        </div>
        <div class="row" style="margin-top:6px;">
          <div class="form-group form-input-group col-sm-4">
            <label for="f_print" class="control-label col-sm-2">收款人:</label>
            <input type="text" class="form-control col-sm-2" v-model="model.f_operator" disabled>
          </div>
          <div class="form-group form-input-group col-sm-4">
            <label for="f_print" class="control-label col-sm-2">网点:</label>
            <input type="text" class="form-control col-sm-2" v-model="model.f_outlets" disabled>
          </div>
          <div class="form-group form-input-group col-sm-4">
            <label for="f_print" class="control-label col-sm-2">收费时间:</label>
            <input type="text" class="form-control col-sm-2" v-model="model.f_delivery_date" disabled>
          </div>
        </div>
      </form>
      <print-bill :show="print" :bill-manager='config.hasBillManage' v-ref:printbill :bill-url='billUrl' v-on:toggle="close" @printok="printok" :data='row'></print-bill>
      <div style="text-align:right;margin-top:80px;margin-right:50px;">
        <button class="btn btn-success" @click="confirm()" :disabled='clickConfirm'>写卡</button>
        <button class="btn btn-default" @click="clean()">取消</button>
      </div>
    </validator>
  </div>
</template>
<script>
  /**
   *综合业务
   *卡表收费组件
   */

  // 执行保存逻辑
  let sellgasGen = async function (self) {
    try {
      await self.$CardService.offlineWrite(self.row)
      // 开始打票
      self.clickConfirm = false
      self.$dispatch('success')
    } catch (error) {
      self.$showAlert(error, 'danger', 0)
      self.$dispatch('refresh')
      self.clickConfirm = false
    }
  }

  export default {
    title: '线下写卡',
    data() {
      return {
        model: {},
        clickConfirm: false
      }
    },
    props: ['row'],
    ready() {
      this.model = this.row.unWriteSell[0]
    },
    methods: {
      confirm() {
        this.clickConfirm = true
        this.$showMessage(`对用户${this.row.f_user_name}进行写卡操作。该操作只做写卡操作。确定要进行该操作吗？`, ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            sellgasGen(this)
          }
        })
      },
      clean() {
        this.$dispatch('refresh', this.row)
      }
    }
  }
</script>

<style>
</style>
