<template>
  <style id="printGaiXianOrderStyle">
    #printGaiXianOrder td{
      height: 30px;
      text-align: center;
    }
    #printGaiXianOrder table{
      width: 100%;
      margin: 0;
      padding: 0;
      border: 1px solid black;
      border-collapse:collapse;
    }
    #printGaiXianOrder h1,
    #printGaiXianOrder h2,
    #printGaiXianOrder h3,
    #printGaiXianOrder h4,
    #printGaiXianOrder h5,
    #printGaiXianOrder h6 {
      text-align: center;
    }
    #printGaiXianOrder .merge-content {
      text-align: left;
      vertical-align: top;
      padding: 10px;
    }
    #printGaiXianOrder .sign {
      height: 80px;
    }
    #printGaiXianOrder .sign_img {
      width: 60px;
      transform: rotate(0deg);
    }
    #printGaiXianOrder .replace_img{
      width: 60px;
      transform: rotate(0deg);
    }
  </style>
  <div style="margin-bottom: 20px" class="form-group select-overspread">
    <label class="control-label-justify control-label col-sm-10">打印派工单</label>
    <div class="col-sm-2">
      <button class="button_search button_spacing" type="button" style="width: max-content;position: absolute"
              @click="openModal()">打印预览
      </button>
    </div>
  </div>
  <modal v-if="showModal" :show.sync="showModal" title="打印预览" v-ref:modal large backdrop="false">
    <header slot="modal-header" class="modal-header">
      <button type="button" class="close" @click="colseModal()"><span>&times;</span></button>
      <h4 class="modal-title">打印预览</h4>
    </header>
    <article slot="modal-body" class="modal-body">
      <div id="printGaiXianOrder">
        <h2><span style="letter-spacing: 0px">天然气用户拆除申请表</span></h2>
        <table>编号：{{ selectdata.f_apply_num }}</table>
        <table border="1" cellspacing="0" cellpadding="0">
          <tr>
            <td colspan="2">用户联系人</td>
            <td colspan="2">{{ selectdata.f_contact }}</td>
            <td colspan="2">单位</td>
            <td colspan="2">{{ selectdata.f_user_name }}</td>
            <td colspan="2">联系电话</td>
            <td colspan="2">{{ selectdata.f_phone }}</td>
          </tr>
          <tr>
            <td colspan="2">申请时间</td>
            <td colspan="2">{{ selectdata.f_apply_date }}</td>
            <td colspan="2">用户编号</td>
            <td colspan="2">{{ selectdata.f_userinfo_id }}</td>
            <td colspan="2">用气性质</td>
            <td colspan="2">{{ selectdata.f_apply_nature }}</td>
          </tr>
          <tr>
            <td colspan="2">详细地址</td>
            <td colspan="6">{{ selectdata.f_address }}</td>
            <td colspan="2" v-if="selectdata.f_meter_style">气表型号</td>
            <td colspan="2" v-if="selectdata.f_meter_style">{{ selectdata.f_meter_style }}</td>
          </tr>
          <tr>
            <td colspan="3">申请类别</td>
            <td colspan="3">{{ selectdata.f_user_classification }}</td>
            <td colspan="3">维修意见</td>
            <td colspan="3">{{ selectdata.f_prospecting_result }}</td>
          </tr>
          <tr>
            <td colspan="2">工程整改方案</td>
            <td colspan="10">
              <p style="margin: 0px 0px 30px 0px">{{ selectdata.f_modify_plan }}</p>
            </td>
          </tr>
          <tr>
            <td colspan="2">备注</td>
            <td colspan="10">
              <p style="margin: 0px 0px 30px 0px">{{ selectdata.f_apply_remarks}}</p>
            </td>
          </tr>
          <!--      <tr>-->
          <!--        <td colspan="6" class="merge-content">-->
          <!--          <p style="margin: 0px 0px 10px 0px">工程部审核意见：</p>-->
          <!--          <p style="margin: 0px 0px 30px 0px"></p>-->
          <!--        </td>-->
          <!--      </tr>-->
          <tr v-if="selectdata.f_due_money">
            <td colspan="2">整改收费</td>
            <td colspan="10">
              <p>金额小写：{{ selectdata.f_due_money}},金额大写：{{ selectdata.f_amount_words}}</p>
            </td>
          </tr>
          <tr>
            <td colspan="12"><h4>审批流程</h4></td>
          </tr>
          <tr>
            <td colspan="3">工程部意见</td>
            <td colspan="3">
              <p>&emsp;</p>
            </td>
            <td colspan="3">分管领导意见</td>
            <td colspan="3">
              <p>&emsp;</p>
            </td>
          </tr>
          <tr v-if="selectdata.f_due_money">
            <td colspan="3">用户管理部收费情况</td>
            <td colspan="3">
              <p>已收费</p>
              <p>{{ selectdata.f_charge_user }}</p>
              <p>{{ selectdata.f_charge_date }}</p>
            </td>
            <td colspan="3">开材料意见</td>
            <td colspan="3">
              <p>{{ selectdata.f_material_number }}</p>
              <p>{{ selectdata.pgname }}</p>
              <p>{{ selectdata.finishtime }}</p>
            </td>
          </tr>
          <tr>
            <td colspan="3">维修中心意见</td>
            <td colspan="3">
              <p>&emsp;</p>
            </td>
            <td colspan="3">省安一/二/三意见</td>
            <td colspan="3">
              <p>&emsp;</p>
            </td>
          </tr>
          <tr>
            <td colspan="3">用户确认签字</td>
            <td colspan="9">
              <p>&emsp;</p>
            </td>
          </tr>
        </table>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-primary" @click="print()">打印</button>
    </footer>
  </modal>

  <apply-print-element v-show="false" v-ref:print id='printGaiXianOrder' styleid='printGaiXianOrderStyle'
                 top='20' left='30' width='100%' height='100%'>
  </apply-print-element>
</template>

<script>
import {isEmpty} from '../../../Util'
import {HttpResetClass} from "vue-client";

Date.prototype.Format = function (fmt) {
  var o = {
    'M+': this.getMonth() + 1, // 月份
    'd+': this.getDate(), // 日
    'H+': this.getHours(), // 小时
    'm+': this.getMinutes(), // 分
    's+': this.getSeconds(), // 秒
    'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
    'S': this.getMilliseconds() // 毫秒
  }
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
  for (var k in o)
    if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
  return fmt
}
export default {
  title: '打印派工单',
  props: ['selectdata'],
  data () {
    return {
      showModal: false,
      device: null
    }
  },
  ready () {
    this.getGaiXianData(this.selectdata.f_process_id)
  },
  methods: {
    openModal () {
      if (this.selectdata.f_due_money >= 0 ) {
        this.smalltoBIG(this.selectdata.f_due_money)
      }
      this.showModal = true
    },
    colseModal () {
      this.showModal = false
    },
    print () {
      this.showInput = false
      setTimeout(() => {
        this.$refs.print.PrintTable()
      }, 10)
    },
    // 金额转大写
    smalltoBIG (n) {
      let fraction = ['角', '分']
      let digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
      let unit = [['元', '万', '亿'], ['', '拾', '佰', '仟']]
      let head = n < 0 ? '欠' : ''
      n = Math.abs(n)

      let s = ''

      for (var i = 0; i < fraction.length; i++) {
        s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '')
      }
      s = s || '整'
      n = Math.floor(n)

      for (var i = 0; i < unit[0].length && n > 0; i++) {
        let p = ''
        for (var j = 0; j < unit[1].length && n > 0; j++) {
          p = digit[n % 10] + unit[1][j] + p
          n = Math.floor(n / 10)
        }
        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s
      }
      let result = head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整')
      console.log('当前大写', result)
      this.selectdata.f_amount_words = result
    },
    async getGaiXianData(index) {
      let data = {
        condition: `1=1`,
        f_process_id: index
      }
      let http = new HttpResetClass()
      let res = await http.load(
        'POST',
        `rs/sql/applyGetGaixian`,
        {data: data},
        {resolveMsg: null, rejectMsg: '改线数据查询失败！！！'}
      )
      this.selectdata.f_charge_user = res.data[0].jfname
      this.selectdata.f_charge_date = res.data[0].finishtime
      this.selectdata.pgname = res.data[0].pgname
      this.selectdata.user_dep = res.data[0].departmentname
    }
  },
  computed: {
    orgs () {
      return this.$login.f.f_fengongsi
    },
    src () {
      // return require(`./img/${this.$login.f.number}.png`)
    }
  }
}
</script>

<style scoped>

</style>
