<template>
  <!-- 收费明细 -->
  <criteria-paged :model="model" v-ref:cp>
    <criteria
      partial="criteria"
      @condition-changed="$parent.searchCondition"
      v-ref:cri
    >
      <div
        class="form-horizontal select-overspread container-fluid auto"
        partial
      >
        <div class="row">
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>报建编号：</strong></label>
            <input
              type="text"
              class="input_search"
              style="width: 60%"
              v-model="model.f_apply_num"
              v-on:keyup.enter="$parent.$parent.search()"
              condition="a.f_apply_num like '%{}%'"
              placeholder="报建编号"
            />
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>用户名称：</strong></label>
            <input
              type="text"
              class="input_search"
              style="width: 60%"
              v-model="model.f_user_name"
              v-on:keyup.enter="$parent.$parent.search()"
              condition="a.f_user_name like '%{}%'"
              placeholder="用户名称"
            />
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>电&emsp;&emsp;话：</strong></label>
            <input
              type="text"
              class="input_search"
              style="width: 60%"
              v-model="model.f_phone"
              v-on:keyup.enter="$parent.$parent.search()"
              condition="a.f_phone like '%{}%'"
              placeholder="电话"
            />
          </div>
          <div class="form-group col-sm-3 button-range">
            <button
              class="button_search button_spacing"
              @click="$parent.$parent.updateshowStatus()"
              v-el:cx
            >
              {{ $parent.$parent.showStatus ? "已作废" : "正常" }}
            </button>
            <button
              class="button_search button_spacing"
              @click="$parent.$parent.search()"
              v-el:cx
            >
              查询
            </button>
            <button
              class="button_clear button_spacing"
              @click="$parent.$parent.clear()"
            >
              清空
            </button>
            <export-excel
              :data="$parent.$parent.getCondition"
              :field="$parent.$parent.getfield"
              sqlurl="rs/logic/applyExportfile"
              sql-name="getApplyCharge"
              template-name="收费记录信息导出"
              :choose-col="true"
            ></export-excel>
            <div
              :class="{
                button_shrink_top: $parent.$parent.criteriaShow,
                button_shrink_bottom: !$parent.$parent.criteriaShow,
              }"
              @click="
                $parent.$parent.criteriaShow = !$parent.$parent.criteriaShow
              "
              class="button_spacing"
              style="float: right"
            ></div>
          </div>
        </div>
        <div class="row" v-show="$parent.$parent.criteriaShow">
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>报建类型：</strong></label>
            <v-select
              v-model="model.f_apply_type"
              placeholder="请选择"
              condition="a.f_apply_type = '{}'"
              :value.sync="model.f_apply_type"
              :options="$parent.$parent.applytype"
              class="select select_list"
              :value-single="true"
              @change="$parent.$parent.applyTypeChange()"
              close-on-select
            ></v-select>
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>办理环节：</strong></label>
            <v-select
              v-model="model.defname"
              placeholder='办理环节'
              condition="act.defname like '%{}%'"
              :value.sync="model.defname"
              :options='$parent.$parent.defnames'
              class="select select_list"
              :value-single="true"
              close-on-select
              ></v-select>
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>票据类型：</strong></label>
            <v-select
              v-model="model.f_bill_style"
              placeholder="请选择"
              condition="cr.f_bill_style = '{}'"
              :value.sync="model.f_bill_style"
              :options="$parent.$parent.billStyles"
              class="select select_list"
              :value-single="true"
              close-on-select
            ></v-select>
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>收费人员：</strong></label>
            <input
              type="text"
              class="input_search"
              style="width: 60%"
              placeholder="收费人员"
              v-model="model.f_charge_collectors"
              v-on:keyup.enter="$parent.$parent.search()"
              condition="cr.f_charge_collectors like '%{}%'"
            />
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>收费金额：</strong></label>
            <input
              type="text"
              class="input_search"
              style="width: 60%"
              placeholder="收费金额"
              v-model="model.f_charge_money"
              v-on:keyup.enter="$parent.$parent.search()"
              condition="cr.f_charge_money = '{}'"
            />
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>流&ensp;水&ensp;号：</strong></label>
            <input
              type="text"
              class="input_search"
              style="width: 60%"
              placeholder="流水号"
              v-model="model.f_payer_number"
              v-on:keyup.enter="$parent.$parent.search()"
              condition="cr.f_payer_number like '%{}%'"
            />
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>付款方式：</strong></label>
            <v-select
              v-model="model.f_payment_method"
              placeholder="请选择"
              condition="cr.f_payment_method = '{}'"
              :value.sync="model.f_payment_method"
              :options="$parent.$parent.paymentMethod"
              class="select select_list"
              :value-single="true"
              close-on-select
            ></v-select>
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>缴费状态：</strong></label>
            <v-select
              v-model="model.f_charge_status"
              placeholder="请选择"
              condition="cr.f_charge_status = '{}'"
              :value.sync="model.f_charge_status"
              :options="$parent.$parent.chargingStatus"
              class="select select_list"
              :value-single="true"
              close-on-select
            ></v-select>
          </div>
          <div class="form-group col-sm-3">
            <label for="startDate" class="font_normal_body"><strong>开始时间：</strong></label>
            <datepicker
              id="startDate"
              placeholder="开始日期"
              style="width: 60% !important"
              v-model="model.startDate"
              :value.sync="model.startDate"
              :format="'yyyy-MM-dd 00:00:00'"
              :show-reset-button="true"
              condition="cr.f_charge_date >= '{}'"
            >
            </datepicker>
          </div>
          <div class="form-group col-sm-3">
            <label for="endDate" class="font_normal_body"><strong>结束时间：</strong></label>
            <datepicker
              id="endDate"
              placeholder="结束日期"
              style="width: 60% !important"
              v-model="model.endDate"
              :value.sync="model.endDate"
              :format="'yyyy-MM-dd 23:59:59'"
              :show-reset-button="true"
              condition="cr.f_charge_date <= '{}'"
            >
            </datepicker>
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>新旧报建：</strong></label>
            <v-select
              v-model="model.f_house_type"
              placeholder="保存状态"
              condition="a.f_house_type {}"
              :value.sync="model.f_house_type"
              :options="$parent.$parent.houseType"
              class="select select_list"
              :value-single="true"
              close-on-select
            >
            </v-select>
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>营业网点：</strong></label>
            <v-select
              v-model="model.f_depname"
              placeholder="请选择"
              condition="cr.f_depname = '{}'"
              :value.sync="model.f_depname"
              :options="$parent.$parent.Business"
              class="select select_list"
              :value-single="true"
              close-on-select
            ></v-select>
          </div>
          <div class="form-group col-sm-3">
            <label class="font_normal_body"><strong>地&ensp;址&ensp;：</strong></label>
            <input
              type="text"
              class="input_search"
              style="width: 60%"
              placeholder="地址"
              v-model="model.f_address"
              v-on:keyup.enter="$parent.$parent.search()"
              condition="a.f_address like '%{}%'"
            />
          </div>
        </div>
      </div>
    </criteria>
    <data-grid
      :model="model"
      partial="list"
      v-ref:grid
      style="overflow: auto"
      class="list_area table_sy"
    >
      <template partial="head">
        <tr>
          <th style="white-space: nowrap">序号</th>
          <th style="white-space: nowrap">报建编号</th>
          <th style="white-space: nowrap">办理环节</th>
          <th style="white-space: nowrap">用户名称</th>
          <th style="white-space: nowrap">用户地址</th>
          <th style="white-space: nowrap">电话</th>
          <th style="white-space: nowrap">合同编号</th>
          <th style="white-space: nowrap">报建类型</th>
          <th style="white-space: nowrap">报建性质</th>
          <th style="white-space: nowrap">收费金额</th>
          <th style="white-space: nowrap">户数</th>
          <th style="white-space: nowrap">付款方式</th>
          <th style="white-space: nowrap">收费人员</th>
          <th style="white-space: nowrap">收费日期</th>
          <th style="white-space: nowrap">缴费状态</th>
          <th
            style="white-space: nowrap"
            v-if="!$parent.$parent.$parent.showStatus"
          >
            作废人员
          </th>
          <th
            style="white-space: nowrap"
            v-if="!$parent.$parent.$parent.showStatus"
          >
            作废时间
          </th>
          <th
            style="white-space: nowrap"
            v-if="!$parent.$parent.$parent.showStatus"
          >
            作废原因
          </th>
          <th style="white-space: nowrap">票据类型</th>
          <th style="white-space: nowrap">发票代码</th>
          <th style="white-space: nowrap">发票号码</th>
          <th style="white-space: nowrap">票据状态</th>
          <th style="white-space: nowrap">操作</th>
          <th style="white-space: nowrap">流水号</th>
        </tr>
      </template>
      <template partial="body">
        <tr>
          <td style="text-align: center">
            <nobr
            ><font>{{ $index + 1 }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_apply_num }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.defname }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_user_name }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_address}}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_phone }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_contract_number }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_apply_type }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_apply_nature }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_charge_money }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_feecount }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_payment_method }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_charge_collectors }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_charge_date }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_charge_status }}</font></nobr
            >
          </td>
          <td
            style="text-align: center"
            v-if="!$parent.$parent.$parent.showStatus"
          >
            <nobr
            ><font>{{ row.f_void_staff }}</font></nobr
            >
          </td>
          <td
            style="text-align: center"
            v-if="!$parent.$parent.$parent.showStatus"
          >
            <nobr
            ><font>{{ row.f_void_date }}</font></nobr
            >
          </td>
          <td
            style="text-align: center"
            v-if="!$parent.$parent.$parent.showStatus"
          >
            <nobr
            ><font>{{ row.f_void_remarks }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_bill_style }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_bill_code }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_bill_number }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_bill_state }}</font></nobr
            >
          </td>
          <td style="text-align: center">
            <nobr v-if="row.f_charge_status !== '作废'">
              <button
                type="button"
                name="button"
                class="btn btn-link"
                v-if="row.f_bill_state !== '开票成功' &&  row.f_bill_state !== '冲红' && row.f_bill_state !== '冲正'"
                @click="$parent.$parent.$parent.openBill(row)"
              >
                开票
              </button>

              <button
                type="button"
                name="button"
                class="btn btn-link"
                v-else
                @click="$parent.$parent.$parent.showPrintModal(row)"
              >
                查看发票
              </button>
              <button
                type="button"
                name="button"
                class="btn btn-link"
                v-if="
                  $parent.$parent.$parent.getUserRolesname &&
                  row.f_charge_money > 0
                "
                @click="$parent.$parent.$parent.showChongZhengModal(row)"
              >
                作废
              </button>
            </nobr>
          </td>
          <td style="text-align: center">
            <nobr
            ><font>{{ row.f_payer_number }}</font></nobr
            >
          </td>
        </tr>
      </template>
    </data-grid>
  </criteria-paged>

  <modal
    v-if="showPrint"
    :show.sync="showPrint"
    v-ref:modal
    :large="true"
    :backdrop="false"
  >
    <header slot="modal-header" class="modal-header">
      <button type="button" class="close" @click="showPrint = !showPrint">
        <span>&times;</span>
      </button>
      <h4 class="modal-title">票据信息</h4>
    </header>
    <article slot="modal-body" class="modal-body clearfix">
      <iframe
        width="100%"
        height="500px"
        :src="charge.f_bill_link"
        v-if="charge.f_bill_link"
      ></iframe>
    </article>
    <footer slot="modal-footer" class="modal-footer"></footer>
  </modal>
  <modal
    v-if="showChongZheng"
    :show.sync="showChongZheng"
    v-ref:modal
    :large="true"
    :backdrop="false"
    style="overflow: auto"
  >
    <header slot="modal-header" class="modal-header">
      <button
        type="button"
        class="close"
        @click="showChongZheng = !showChongZheng"
      >
        <span>&times;</span>
      </button>
      <h4 class="modal-title">冲正信息</h4>
    </header>
    <article slot="modal-body" class="modal-body clearfix">
      <div class="form-group col-sm-5">
        <label class="col-sm-4 control-label">收费金额：</label>
        <div class="col-sm-8">
          <input
            type="text"
            class="form-control input_view"
            style="width: 100%"
            readonly
            v-model="charge.f_charge_money"
          />
        </div>
      </div>
      <div class="form-group col-sm-5">
        <label class="col-sm-4 control-label">金额大写：</label>
        <div class="col-sm-8">
          <input
            type="text"
            class="form-control input_view"
            style="width: 100%"
            readonly
            v-model="charge.f_amount_words"
          />
        </div>
      </div>
      <div class="form-group col-sm-5">
        <label class="col-sm-4 control-label">付款方式：</label>
        <div class="col-sm-8">
          <input
            type="text"
            class="form-control input_view"
            style="width: 100%"
            readonly
            v-model="charge.f_payment_method"
          />
        </div>
      </div>
      <div class="form-group col-sm-5">
        <label class="col-sm-4 control-label">收费人员：</label>
        <div class="col-sm-8">
          <input
            type="text"
            class="form-control input_view"
            style="width: 100%"
            readonly
            v-model="charge.f_charge_collectors"
          />
        </div>
      </div>
      <!--      <div class="form-group col-sm-5">
              <label class="col-sm-4 control-label">发票代码:</label>
              <div class="col-sm-8">
                <input
                  type="text"
                  class="form-control input_view"
                  style="width: 100%"
                  readonly
                  v-model="detail.fpdm"
                />
              </div>
            </div>
            <div class="form-group col-sm-5">
              <label class="col-sm-4 control-label">发票号码:</label>
              <div class="col-sm-8">
                <input
                  type="text"
                  class="form-control input_view"
                  style="width: 100%"
                  readonly
                  v-model="detail.fphm"
                />
              </div>
            </div>
            <div class="form-group col-sm-5">
              <label class="col-sm-4 control-label">购方单位名称:</label>
              <div class="col-sm-8">
                <input
                  type="text"
                  class="form-control input_view"
                  style="width: 100%"
                  readonly
                  v-model="detail.ghdwmc"
                />
              </div>
            </div>
            <div class="form-group col-sm-5">
              <label class="col-sm-4 control-label">开票人:</label>
              <div class="col-sm-8">
                <input
                  type="text"
                  class="form-control input_view"
                  style="width: 100%"
                  readonly
                  v-model="detail.kpr"
                />
              </div>
            </div>
            <div class="form-group col-sm-5">
              <label class="col-sm-4 control-label">开票日期:</label>
              <div class="col-sm-8">
                <input
                  type="text"
                  class="form-control input_view"
                  style="width: 100%"
                  readonly
                  v-model="detail.kprq"
                />
              </div>
            </div>
            <div class="form-group col-sm-5">
              <label class="col-sm-4 control-label">合计金额:</label>
              <div class="col-sm-8">
                <input
                  type="text"
                  class="form-control input_view"
                  style="width: 100%"
                  readonly
                  v-model="detail.hjje"
                />
              </div>
            </div>
            <div class="form-group col-sm-5">
              <label class="col-sm-4 control-label">合计税额:</label>
              <div class="col-sm-8">
                <input
                  type="text"
                  class="form-control input_view"
                  style="width: 100%"
                  readonly
                  v-model="detail.hjse"
                />
              </div>
            </div>
            <div class="form-group col-sm-5">
              <label class="col-sm-4 control-label">价税合计:</label>
              <div class="col-sm-8">
                <input
                  type="text"
                  class="form-control input_view"
                  style="width: 100%"
                  readonly
                  v-model="detail.jshj"
                />
              </div>
            </div>-->
      <div
        class="form-group col-sm-10"
        :class="charge.f_void_remarks ? '' : 'has-error'"
      >
        <label class="col-sm-2 control-label">作废原因：</label>
        <div class="col-sm-10">
          <input
            type="text"
            class="form-control input_view"
            style="width: 100%"
            v-model="charge.f_void_remarks"
          />
        </div>
      </div>
      <apply-upload
        :blodid="charge.f_process_id"
        :isupload="true"
        :isdelete="true"
        :isusetype="true"
        :isremark="true"
        :takeimg="false"
        :issearch="false"
        defname="冲正"
      >
      </apply-upload>
    </article>
    <footer slot="modal-footer" class="modal-footer">
      <button
        type="button"
        class="btn btn-primary"
        :disabled="!charge.f_void_remarks"
        @click="invalidApplyCharge()"
      >
        确认作废
      </button>
      <button
        type="button"
        class="btn btn-default"
        @click="showChongZheng = !showChongZheng"
      >
        取消
      </button>
    </footer>
  </modal>
</template>

<script>
import { PagedList } from "vue-client";
import { HttpResetClass } from "vue-client";
import { isEmpty } from "../../Util";
import Vue from "vue";
export default {
  title: "报建收费列表",
  data() {
    return {
      model: new PagedList("rs/sql/getApplyCharge", 30, null, {
        f_charge_money: 0,
      }),
      applytype: [
        { label: "全部", value: "" },
        ...this.$appdata.getParam("报建类型")?this.$appdata.getParam("报建类型"):[],
      ],
      paymentMethod: [
        { label: "全部", value: "" },
        ...this.$appdata.getParam("付款方式")?this.$appdata.getParam("付款方式"):[],
      ],
      billStyles: [
        { label: "全部", value: "" },
        { label: "电子票", value: "电子票" },
        { label: "专票", value: "专票" },
      ],
      chargingStatus: [
        { label: "全部", value: "" },
        { label: "有效", value: "有效" },
        { label: "作废", value: "作废" },
      ],
      Business: [
        { label: "微信", value: "微信" },
        { label: "各营业厅", value: "营业厅" },
      ],
      houseType: [
        { label: "全部", value: "" },
        { label: "旧报建", value: ` = '旧报导入'` },
        { label: "新报建", value: " is null" },
      ],
      criteriaShow: false,
      showStatus: true,
      getfield: {
        f_apply_num: "报建编号",
        defname: "办理环节",
        f_user_name: "用户名称",
        f_phone: "电话",
        f_contract_number: "合同编号",
        f_apply_type: "报建类型",
        f_apply_nature: "报建性质",
        f_charge_money: "收费金额",
        f_feecount: "收费户数",
        f_payment_method: "付款方式",
        f_charge_collectors: "收费人员",
        f_charge_date: "收费日期",
        f_charge_status: "缴费状态",
        f_bill_style: "票据类型",
        f_bill_code: "发票代码",
        f_bill_number: "发票号码",
        f_bill_state: "票据状态",
        f_outdoors_time: "户内出单日期",
        f_outdoors_receipt_time:"户内回单日期",
        f_courtyard_time:"庭院出单日期",
        f_courtyard_receipt_time:"庭院回单日期",
        f_address:"用户地址"
      },
      charge: null,
      showPrint: false,
      showChongZheng: false,
      detailShow: false,
      defnames: isEmpty(this.$appdata.getParam('办理环节')) ? [{label: '全部', value: ''}] : [{label: '全部', value: ''}, ...this.$appdata.getParam('办理环节')], // 流程节点
      detail: {
        title: "",
        confirmContent: "",
        type: "",
      },
    };
  },
  ready() {
    // 调用查询
    this.search();
  },
  methods: {
    async applyTypeChange () {
      if (!isEmpty(this.$refs.cp.$refs.cri.model.f_apply_type)) {
        let http = new HttpResetClass()
        let res = await http.load('POST', 'rs/logic/getDefnameByType', {
            f_apply_type: this.$refs.cp.$refs.cri.model.f_apply_type},
          {resolveMsg: null, rejectMsg: '流程标识获取失败！！！'}
        )
        this.defnames = [{label: '全部', value: ''}, ...res.data]
      } else {
        this.defnames = isEmpty(this.$appdata.getParam('办理环节')) ? [{label: '全部', value: ''}] : [{label: '全部', value: ''}, ...this.$appdata.getParam('办理环节')]
      }
    },
    clear() {
      Object.keys(this.$refs.cp.$refs.cri.model).forEach((key) => {
        this.$refs.cp.$refs.cri.model[key] = [];
      });
    },
    searchCondition(args) {
      if (this.showStatus) {
        args.condition = args.condition + ` and f_charge_status = '有效'`;
      } else {
        args.condition =
          args.condition +
          ` and (f_charge_status = '作废' or f_charge_money < 0)`;
      }
      console.log("args.condition", args.condition);
      this.model.search(args.condition, args.model);
    },
    // 查询
    search() {
      this.$refs.cp.$refs.cri.search();
    },
    updateshowStatus() {
      this.showStatus = !this.showStatus;
      this.search();
    },
    // 查看发票
    showPrintModal(row) {
      this.charge = row;
      if (!this.charge.f_bill_link && this.charge.f_filepath) {
        let date = new Date(this.charge.f_charge_date);
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let month2 = month <= 9 ? "0" + month : month;
        let day = date.getDate();
        let day2 = day <= 9 ? "0" + day : day;
        let chargedate = year + "-" + month2 + "-" + day2;
        this.charge.f_bill_link =
          `http://193.168.1.6:8082/eticket/` +
          chargedate +
          "/" +
          this.charge.f_filepath +
          ".pdf";
      } else if (!this.charge.f_bill_link) {
        this.charge.f_bill_link = this.charge.f_bill_url;
      }
      this.showPrint = true;
    },
    // 开票
    async openBill(charge) {
      this.$showMessage("请稍后查询，发票开具中.....")
      /*this.charge = charge;
      let data = null;
      let res = null;

      let http = new HttpResetClass();

      if (isEmpty(this.charge.f_bill_id)) {
        data = {
          id: this.charge.id,
          charge_type: "报装收费",
          f_user_name: this.charge.f_user_name,
        };
        if (this.charge.f_apply_type === "改线业务") {
          data.charge_type = "整改收费";
        }
        res = await http.load(
          "POST",
          "rs/logic/bjEticketCharge",
          { data: data },
          {
            resolveMsg: null,
            rejectMsg: "开票失败！！！",
          }
        );
        this.charge.f_bill_id = res.data;
      }

      if (this.charge.f_bill_style === "电子票") {
        data = {
          id: this.charge.f_bill_id,
          f_sell_id: this.charge.id,
        };
        try {
          res = await http.load(
            "POST",
            "rs/logic/bjOpenEticket",
            { data: data },
            {
              resolveMsg: null,
              rejectMsg: "开票失败！！！",
            }
          );

          // res.data.f_bill_url = 'https://dlj.51fapiao.cn/dlj/v7/de4c9b985021111ef1c722c2914e34d9273291'

          if (res.data.f_bill_state !== "开票成功") {
            throw "开票失败！！！";
          } else {
            let date = new Date();
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            let day = date.getDate();
            let month2 = month <= 9 ? "0" + month : month;
            let day2 = day <= 9 ? "0" + day : day;
            let chargedate = year + "-" + month2 + "-" + day2;
            this.charge.f_bill_link =
              `http://193.168.1.6:8082/eticket/` +
              chargedate +
              "/" +
              res.data.f_filepath +
              ".pdf";
            let pram = {
              f_bill_link: this.charge.f_bill_link,
              f_sell_id: this.charge.id,
            };
            await http.load(
              "POST",
              "rs/logic/updataChargeRecord",
              { data: pram },
              {
                resolveMsg: null,
                rejectMsg: null,
              }
            );
          }
          this.charge.f_bill_state = res.data.f_bill_state;
          this.charge.f_bill_url = res.data.f_bill_url;

          this.showPrint = true;
        } catch (e) {
          console.error(e);
          this.charge.f_bill_state = "开票失败";

          data = {
            f_bill_id: this.charge.f_bill_id,
            id: this.charge.id,
          };
          res = await http.load(
            "POST",
            "rs/logic/updateChargeBill",
            { data: data },
            {
              resolveMsg: null,
              rejectMsg: "收费信息更新失败！！！",
            }
          );

          throw e;
        }
      } else if (this.charge.f_bill_style === "专票") {
        data = {
          id: this.charge.f_bill_id,
        };
        res = await http.load(
          "POST",
          "rs/sql/getEticketData",
          { data: data },
          {
            resolveMsg: null,
            rejectMsg: "开票数据查询失败！！！",
          }
        );
        let openBillData = JSON.parse(res.data[0].f_bill_data);
        openBillData.kpzdbs = this.$login.f.taxnum;
        const nowDate = new Date();
        let year = nowDate.getFullYear();
        let mouth = nowDate.getMonth() + 1;
        let day = nowDate.getDate();
        openBillData.f_operate_date = year + "-" + mouth + "-" + day;
        openBillData.f_operator = this.$login.f.name;
        openBillData.outlets = this.$login.f.f_department_name;
        openBillData.hjse = "";
        openBillData.jshh = "";
        openBillData.tzdbh = "";
        openBillData.yfpdm = "";
        openBillData.yfphm = "";

        console.log("返回开票信息。。 ", openBillData);
        let billInfo = await this.$resetpost(
          "http://127.0.0.1:8003/Goldtax",
          openBillData,
          { resolveMsg: null, rejectMsg: "专用发票开具失败！" }
        );
        console.log("返回票据信息。。 ", JSON.parse(billInfo.data)); //保存发票明细
        if (!JSON.parse(billInfo.data).fphm) {
          this.charge.f_bill_state = "开票失败";
          data = {
            f_bill_id: this.charge.f_bill_id,
            id: this.charge.id,
          };
          res = await http.load(
            "POST",
            "rs/logic/updateChargeBill",
            { data: data },
            {
              resolveMsg: null,
              rejectMsg: "收费信息更新失败！！！",
            }
          );
          this.$showAlert("开票失败！！！", "warning", 3000);
          throw "开票失败！！";
        } else {
          data = {
            id: this.charge.f_bill_id,
            f_bill_number: JSON.parse(billInfo.data).fphm,
            f_bill_code: JSON.parse(billInfo.data).fpdm,
            f_filepath: JSON.parse(billInfo.data).dzpkex
              ? JSON.parse(billInfo.data).dzpkex
              : "",
            charge_id: this.charge.id,
          };
          res = await http.load(
            "POST",
            "rs/logic/updateEticketBill",
            { data: data },
            {
              resolveMsg: null,
              rejectMsg: "开票信息更新失败！！！",
            }
          );

          this.charge.f_bill_state = "开票成功";
          this.charge.f_bill_url = "";
        }
      }*/
    },
    showChongZhengModal(row) {
      this.charge = row;
      this.charge.f_bill_url = null
      this.charge.f_bill_state = "未开票"
      this.charge.f_bill_link = null
      if (this.$login.f.rolesnames.includes("营业厅报装") ||this.$login.f.name==='微信') {
        if(row.f_bill_style!='专票'){
          this.detailGen(this, "发票作废信息", "确认作废", "cancel");
        }else{
          this.showChongZheng=true
        }
      } else {
        this.showChongZheng = false;
        this.$showMessage(
          `您现在没有权限进行冲正，请联系管理员进行授权！`
        );
      }
    },
    async detailGen(self, title, content, type) {
      /*self.detail.title = title;
      self.detail.confirmContent = content;
      self.detail.type = type;

      let param = {
        f_bill_code: self.charge.f_bill_code,
        f_bill_number: self.charge.f_bill_number,
        // f_bill_code: '061002101311',
        // f_bill_number: '88682136'
      };
      let getDetail = await self.$resetpost(
        "rs/logic/queryEticket",
        { data: param },
        { resolveMsg: null, rejectMsg: "获取发票明细失败！！！" }
      );
      console.log("详情", getDetail);
      if (getDetail.data) {
        self.detail = Object.assign({}, self.detail, getDetail.data);
        console.log("获取票据明细信息", self.detail);
        self.showChongZheng = true;
      } else {
        self.$showAlert(
          "该发票号码和发票代码没有对应的收费详情,请确认发票信息",
          "warning",
          3000
        );
      }*/
      self.showChongZheng = true
    },
    confirmBill() {
      console.log("确认冲正");
      this.cancelBillGen(this);
    },
    async cancelBillGen(self) {
      try {
        let param = {
          type: "发票作废",
          fplxdm: "电子票",
          fpdm: self.charge.f_bill_code,
          fphm: self.charge.f_bill_number,
          zflx: "1",
          kpzdbs: self.$login.f.taxnum,
          zfr: self.$login.f.name,
        };
        console.log("发票作废参数，，", param);
        let res = await self.$resetpost(
          "http://127.0.0.1:8003/Goldtax",
          param,
          { resolveMsg: "发票作废成功", rejectMsg: "电子发票开具失败！！！" },
          0
        );
        console.log("发票冲正", res);
        self.detailShow = false;
      } catch (error) {
        self.$showAlert("发票作废失败", "danger", 0);
        self.detailShow = false;
      }
      this.$dispatch("breakControl", this.selectdata);
    },
    async invalidApplyCharge() {
      let http = new HttpResetClass();
      let data = {
        apply: this.charge,
        user: this.$login.f,
        charge: this.charge,
      };
      let res = await http.load(
        "POST",
        "rs/logic/invalidApplyCharge",
        { data: data },
        {
          resolveMsg: null,
          rejectMsg: "作废失败！！！",
        }
      );
      this.selectdata = res.data;
      this.showChongZheng = false
      this.$dispatch("breakControl", this.selectdata);
      this.search()
      // this.confirmBill();
    },
  },
  computed: {
    getCondition() {
      return {
        condition: this.$refs.cp.$refs.cri.condition,
        data: {
          orgid: this.$login.f.orgid,
        },
      };
    },
    getUserRolesname() {
      return this.$login.f.rolesnames.includes("营业厅报装") || this.$login.f.f_department_name.includes("微信");
    },
  },
};
</script>

<style scoped></style>
