<template>
  <div class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">客户名称</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_user_name" placeholder='客户名称'
                     condition="f_user_name like '%{}%'">
            </div>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">用户编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_userinfo_code"
                     placeholder='用户编号'
                     condition="f_userinfo_code like '%{}%'">
            </div>

            <div class="span" style="float:right;">
              <button class="button_search" @click="$parent.$parent.search()" v-el:cx>查询</button>
              <button class="button_clear button_spacing" @click="clear">清空</button>
              <export-excel
                :data="{condition: $parent.$parent.condition}"
                :field="$parent.$parent.getfield"
                sqlurl="rs/logic/saleExport" progress="saleGetExportProgress" sql-name="showPrintList" template-name='打印数据导出'
                :choose-col="true">
              </export-excel>
              <button class="button_export button_spacing" @click="$parent.$parent.batchPrint()">批量打印</button>

              <div style="float: right" class="button_spacing"
                   :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                   @click="$parent.$parent.hidden()"></div>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">
            <res-select-group :style="$parent.$parent.styles" :initres="$parent.$parent.initres" @re-res="$parent.$parent.getorg" :show-component="['company','department','operator']"></res-select-group>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">打印类型</label>
              <v-select :value.sync="model.f_print_dh"
                        v-model="model.f_print_dh"
                        :disabled="false"
                        :value-single="true"
                        condition="f_print_dh like '%{}%'"
                        :options='$parent.$parent.dhoptions' placeholder='打印类型'
                        close-on-select></v-select>
            </div>

            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">打印状态</label>
              <v-select :value.sync="model.f_print_state"
                        v-model="model.f_print_state"
                        :disabled="false"
                        :value-single="true"
                        condition="f_print_state = '{}'"
                        :options='$parent.$parent.dhoptionss' placeholder='打印状态'
                        close-on-select></v-select>
            </div>

            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">地址信息</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_address"
                     placeholder='地址信息'
                     condition="f_address like '%{}%'">
            </div>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">打印编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_print_id_number"
                     placeholder='打印编号'
                     condition="f_print_id_number like '%{}%'">
            </div>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">用户类型</label>
              <v-select :value.sync="model.f_user_type"
                        :options='$parent.$parent.usertypes' placeholder='请选择'
                        v-model="model.f_user_type"
                        condition="f_user_type = '{}'"
                        close-on-select></v-select>
            </div>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">客户状态</label>
              <v-select :options='$parent.$parent.userstates' :value.sync="model.f_user_state"
                        close-on-select condition="f_user_state='{}'"
                        placeholder='客户状态' v-model="model.f_user_state"></v-select>
            </div>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">开始日期</label>
              <datepicker id="startDate" placeholder=""
                          v-model="model.f_start_date"
                          :value.sync="model.f_start_date"
                          :disabled-days-of-Week="[]"
                          style="width: 60%"
                          :format="'yyyy-MM-dd 00:00:00'"
                          condition="f_operate_date >= '{}'">
              </datepicker>
            </div>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">结束日期</label>
              <datepicker id="endDate" placeholder=""
                          v-model="model.f_end_date"
                          :value.sync="model.f_end_date"
                          style="width: 60%"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd 23:59:59'"
                          condition="f_operate_date <= '{}'">
              </datepicker>
            </div>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">预约状态</label>
              <v-select :options='$parent.$parent.orderState' :value.sync="model.f_order_state"
                        close-on-select condition="f_order_state='{}'"
                        placeholder='预约状态' v-model="model.f_order_state"></v-select>
            </div>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">预约时间</label>
              <datepicker id="startDate" placeholder=""
                          v-model="model.f_start_date1"
                          :value.sync="model.f_start_date1"
                          :disabled-days-of-Week="[]"
                          style="width: 60%"
                          :format="'yyyy-MM-dd 00:00:00'"
                          condition="f_order_date >= '{}'">
              </datepicker>
            </div>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">结束时间</label>
              <datepicker id="endDate" placeholder=""
                          v-model="model.f_end_date1"
                          :value.sync="model.f_end_date1"
                          style="width: 60%"
                          :disabled-days-of-Week="[]"
                          :format="'yyyy-MM-dd 23:59:59'"
                          condition="f_order_date <= '{}'">
              </datepicker>
            </div>
            <div :class="$parent.$parent.styles">
              <label class="font_normal_body">记录状态</label>
              <v-select :value.sync="model.f_state" :value-single="true"
                        :options='$parent.$parent.states' placeholder='请选择'
                        v-model="model.f_state"
                        condition="f_state = '{}'"
                        close-on-select></v-select>
            </div>
          </div>
        </div>

      </criteria>
      <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
        <template partial='head'>
          <tr>
            <th style="text-align:center" v-if="$parent.$parent.$parent.canCheckAll">
              <nobr>全选</nobr>
              <input @keyup.enter="search" style="width:60%" type="checkbox" v-model='checked1'
                     @click="$parent.$parent.$parent.checkedALL()">
            </th>
            <th>
              <nobr>序号</nobr>
            </th>
            <th>
              <nobr>查看</nobr>
            </th>
            <th>
              <nobr>打印编号</nobr>
            </th>
            <th>
              <nobr>打印次数</nobr>
            </th>
            <th>
              <nobr>客户编号</nobr>
            </th>
            <th>
              <nobr>客户名称</nobr>
            </th>
            <th>
              <nobr>客户电话</nobr>
            </th>
            <th v-if="!$parent.$parent.$parent.isOper">
              <nobr>地址信息</nobr>
            </th>
            <th>
              <nobr>用户类型</nobr>
            </th>
            <th>
              <nobr>用户状态</nobr>
            </th>
            <th>
              <nobr>房屋类型</nobr>
            </th>
            <th>
              <nobr>打印时间</nobr>
            </th>
            <th>
              <nobr>转单时间</nobr>
            </th>
            <th>
              <nobr>打印类型</nobr>
            </th>
            <th>
              <nobr>打印状态</nobr>
            </th>
            <th>
              <nobr>审核状态</nobr>
            </th>
            <th>
              <nobr>预约状态</nobr>
            </th>
            <th>
              <nobr>预约时间</nobr>
            </th>
            <th>
              <nobr>审核员</nobr>
            </th>
            <th>
              <nobr>审核时间</nobr>
            </th>
            <th>
              <nobr>通气人</nobr>
            </th>
            <th>
              <nobr>通气时间</nobr>
            </th>
            <th>
              <nobr>记录状态</nobr>
            </th>
            <th>
              <nobr>公司</nobr>
            </th>
            <th>
              <nobr>部门</nobr>
            </th>
            <th>
              <nobr>操作员</nobr>
            </th>
            <th>
              <nobr>备注</nobr>
            </th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;" v-if="$parent.$parent.$parent.canCheckAll">
          <input @keyup.enter="search" style="width:60%" type="checkbox" name="opertioninput" v-if="row.f_order_state==='已预约'&& row.f_state === '有效'&&row.f_print_num<$parent.$parent.$parent.max_print"
                 @click="$parent.$parent.$parent.checked(row)">
          </td>
          <td style="text-align: center;">{{$index + 1}}</td>
          <td style="text-align: center;">
            <button class="btn button_export" style="border:none;background:rgba(0,0,0,0)"
                    @click="$parent.$parent.$parent.getPrintDetail(row)"
            >查看
            </button>
          </td>
          <td style="text-align: center;">{{row.f_print_id_number}}</td>
          <td style="text-align: center;">{{row.f_print_num}}</td>
          <td style="text-align: center;">{{row.f_userinfo_code}}</td>
          <td style="text-align: center;">{{row.f_user_name}}</td>
          <td style="text-align: center;">{{row.f_user_phone}}</td>
          <td style="text-align: center;" v-if="!$parent.$parent.$parent.isOper"><nobr>{{row.f_address_detail ? row.f_address
            + row.f_address_detail : row.f_address}}
            </nobr></td>
          <td style="text-align: center;">{{row.f_user_type}}</td>
          <td style="text-align: center;">{{row.f_user_state}}</td>
          <td style="text-align: center;">{{row.f_house_type}}</td>
          <td style="text-align: center;"><nobr>{{row.f_printdate}}</nobr></td>
          <td style="text-align: center;"><nobr>{{row.f_operate_date}}</nobr></td>
          <td style="text-align: center;">
            <button v-show="row.f_print_dh ==='点火单' && row.f_order_state == '已预约' && row.f_state == '有效' && row.f_print_num<$parent.$parent.$parent.max_print" class="button_search"
                    @click="$parent.$parent.$parent.downFiles(1,row)"
                    v-if="this.$login.r.includes('通知单打印')">点火单打印
            </button>
            <button v-show="row.f_print_dh ==='流程单' && row.f_order_state == '已预约' && row.f_state == '有效'&& row.f_print_num<$parent.$parent.$parent.max_print" class="button_search"
                     @click="$parent.$parent.$parent.downFiles(0,row)"
                    v-if="this.$login.r.includes('流程表打印')">流程表打印
            </button>
            <button v-show="row.f_print_dh ==='改装单' && row.f_order_state == '已预约' && row.f_state == '有效'&& row.f_print_num<$parent.$parent.$parent.max_print" class="button_search"
                     @click="$parent.$parent.$parent.downFiles(2,row)"
                    v-if="$login.r.includes('改装单打印')">改装单打印
            </button>
            <button v-show="row.f_print_dh ==='燃气使用证打印' && row.f_user_state == '正常' && row.f_print_num<$parent.$parent.$parent.max_print" class="button_search"
                    @click="$parent.$parent.$parent.downFiles(3,row)"
                    v-if="$login.r.includes('燃气使用证打印')">燃气使用证打印
            </button>
            <button disabled v-show="row.f_print_dh ===null" class="button_search"
                    style="border:none;background:rgba(0,0,0,0)">未绑定打印单
            </button>
          </td>
          <td style="text-align: center;">
            {{row.f_print_state}}
          </td>
          <td style="text-align: center;" v-show="row.f_verify_state ==='未审核' && row.f_order_state == '已预约'&& row.f_state == '有效'">
            <button  class="button_search"
                    @click="$parent.$parent.$parent.setVerify(row)"
                   >审核
            </button>
          </td>
          <td style="text-align: center;" v-show="!(row.f_verify_state ==='未审核' && row.f_order_state == '已预约'&& row.f_state == '有效')">
            {{row.f_verify_state}}
          </td>
          <td style="text-align: center;">
            {{row.f_order_state?row.f_order_state:'未预约'}}
          </td>
          <td style="text-align: center;" v-if="row.f_order_state!=='已预约'">
            <button class="button_search" style="width: max-content" @click="$parent.$parent.$parent.showOrderDate(row)">预约</button>
          </td>
          <td style="text-align: center;"  v-if="row.f_order_state=='已预约'"><nobr>
            {{row.f_order_date}}</nobr>
          </td>
          <td style="text-align: center;">
            {{row.f_verify_person}}
          </td>
          <td style="text-align: center;">
            <nobr>{{row.f_verify_date}}</nobr>
          </td>
          <td style="text-align: center;">
            {{row.f_gas_person}}
          </td>
          <td style="text-align: center;">
            <nobr>{{row.f_gas_date}}</nobr>
          </td>
          <td style="text-align: center;">
            {{row.f_state}}
          </td>
          <td style="text-align: center;">
            {{row.f_orgname}}
          </td>
          <td style="text-align: center;">
            {{row.f_depname}}
          </td>
          <td style="text-align: center;">
            {{row.f_operator}}
          </td>
          <td style="text-align: center;">
            {{row.f_comments}}
          </td>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
    <user-flow-sheet :show="printflag" :disprint="disprint" :bill-config='configs' :bill-data='billData' :data='newdata' v-on:toggle="close"
                     @printok="printok" v-ref:printbill></user-flow-sheet>
  </div>
  <modal :show.sync="showVerify"  v-ref:modal large backdrop="false">
    <header slot="modal-header" class="modal-header">
      <h3 style="color:black" class="modal-title">审核</h3>
    </header>
    <article slot="modal-body" class="modal-body">
      <form class="form-horizontal  select-overspread">

          <div class="row">
            <div  class="col-sm-6">
              <label class="font_normal_body" >通气人&emsp;</label>
              <input type="text" class="input_search" style="width:60%" v-model="row.f_gas_person"
                     placeholder='通气人'
                    >
            </div>
            <div  class="col-sm-6">
              <label class="font_normal_body" >通气时间</label>
              <datepicker :format="'yyyy-MM-dd HH:mm:ss'"
                          :value.sync="row.f_gas_date"
                          placeholder="通气时间"
                          v-model="row.f_gas_date" style="width: 80%">
              </datepicker>
            </div>
          </div>
         <div class="row">
           <div  class="col-sm-12">
             <label class="font_normal_body" >备注&emsp;&emsp;</label>
             <textarea type="" class="input_search" style="width:90%" v-model="row.f_comments"
                       placeholder='备注' rows="3"></textarea>
           </div>
         </div>
      </form>
    </article>
    <footer slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-success"  @click='verifySuccess()'>确认</button>
      <button type="button" class="btn btn-default"  @click='cancel()' >取消</button>
    </footer>
  </modal>
  <modal :show.sync="showOrder"  v-ref:modal2 large backdrop="false">
    <header slot="modal-header" class="modal-header">
    </header>
    <article slot="modal-body" class="modal-body">
      <form class="form-horizontal  select-overspread">
        <div class="row">
          <div  class="col-sm-6">
            <label class="font_normal_body" >预约时间</label>
            <datepicker :format="'yyyy-MM-dd HH:mm:ss'"
                        :value.sync="selectrow.f_order_date"
                        placeholder="预约时间"
                        v-model="selectrow.f_order_date" style="width: 80%">
            </datepicker>
          </div>
        </div>

      </form>
    </article>
    <footer slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-success"  @click='Order()'>确认</button>
      <button type="button" class="btn btn-default"  @click='closeOrder()' >取消</button>
    </footer>
  </modal>
</template>

<script>
import {HttpResetClass, PagedList} from 'vue-client'
  export default {
    data () {
      return {
        model: new PagedList('rs/sql/showPrintList', 30, {orderitem: '"f_userinfo_id DESC"'}),
        show: false,
        // 公司下拉
        initres: {
          org: [this.$login.f.orgid],
          dep: [],
          user: []
        },
        orgCondtionStr: '',
        row: {},
        f_orgid: '',
        condition: '',
        criteriaShow: false,
        billData: {
          url: 'rs/report/userignition',
          bill: ''
        },
        configs: {
          hasPrint: false,  // 默认打票
          hasBillManage: false  // 默认不启用发票管理
        },
        showOrder:false,//预约弹框
        showVerify:false,//审核弹框
        selectrow:null,
        disprint: false,
        printflag: false,
        batch: false,
        canCheckAll: true,
        checked1: false, // 是否全选
        selectPrint: [], // 选择的需要打印的数据
        getfield: {},
        newdata: {},
        userstates: this.$appdata.getParam('客户状态') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('客户状态')] : [],
        orderState: [{label: '全部', value: ''}, {label: '已预约', value: " ='已预约'"}, {label: '未预约', value: " <>'已预约'"}],
        dhoptions: [{label: '全部', value: ''}, {label: '点火单', value: '点火单'}, {label: '流程单', value: '流程单'}, {label: '改装单', value: '改装单'}],
        dhoptionss: [{label: '全部', value: ''}, {label: '未打印', value: '未打印'}, {label: '已打印', value: '已打印'}],
        states: [{label: '全部', value: ''}, {label: '有效', value: '有效'}, {label: '无效', value: '无效'}],
        usertypes: this.$appdata.getParam('用户类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')] : [],
        f_order_date:null,
        max_print: this.$appdata.getSingleValue('最多打印次数') ? this.$appdata.getSingleValue('最多打印次数') : 1,
        config: {
          excelHeaders: {
            'f_print_id_number': '打印编号',
            'f_print_num':'打印次数',
            'f_userinfo_code': '客户编号',
            'f_user_name': '客户名称',
            'f_user_phone': '客户电话',
            'f_address': '地址信息',
            'f_user_type': '用户类型',
            'f_user_state': '用户状态',
            'f_house_type': '房屋类型',
            'f_print_dh': '打印类型',
            'f_print_state': '打印状态',
            'f_order_state':'预约状态',
            'f_order_date':'预约时间',
            'f_state': '记录状态',
            'f_depname': '部门',
            'f_operator': '操作员',
            'f_printdate' : '打印时间',
            'f_operate_date' : '转单时间'
          }
        }
      }
    },
    props: {
      styles: {
        type:String,
        default:'col-sm-2 form-grop',
      },
      orderitem: {
        type: String,
        default: 'id desc'
      },
      row: {},
      // config: {},
      ispartial: false,

      f_filialeid: {
        type: String
      }
    },
    ready () {
      this.getfield = this.config.excelHeaders
      this.$refs.paged.$refs.cri.model.f_state = '有效'
      this.search()
    },
    methods: {
      showOrderDate(row){
        this.showOrder=true
        this.selectrow=row
      },
      closeOrder(){
        this.showOrder=false
        this.selectrow=null
      },
      async verifySuccess(){
        console.log("-----------------,",this.row)
        var param={
          f_print_id:this.row.id,
          f_gas_person:this.row.f_gas_person,
          f_gas_date:this.row.f_gas_date,
          f_comments:this.row.f_comments,
          f_verify_state:'已审核'
        }
        var param1={
          f_userfiles_id:this.row.f_userfiles_id,
          f_gas_person:this.row.f_gas_person,
          f_gas_date:this.row.f_gas_date,
          version:this.row.fileversion
        }
        let http = new HttpResetClass()
        await http.load('POST', 'rs/entity/t_print_sheet',
          param,
          {resolveMsg: null, rejectMsg: null})
        await http.load('POST', 'rs/entity/t_userfiles',
          param1,
          {resolveMsg: "审核成功", rejectMsg: "审核失败"})
        this.showVerify=false
        await this.search()

      },
      cancel(){
        this.showVerify=false
      },
      async setVerify(row){
        this.showVerify=true
        this.row=row
      },
      async Order(){

        var param={
          f_print_id:this.selectrow.id,
          f_order_date:this.selectrow.f_order_date,
          f_order_state:'已预约'
        }
        let http = new HttpResetClass()
        await http.load('POST', 'rs/entity/t_print_sheet',
           param,
          {resolveMsg: "预约成功", rejectMsg: "预约失败"})
        this.showOrder=false
        this.selectrow=null
        await this.search()
      },
      async close () {
        this.printflag = false
        if (this.disprint) {
          this.disprint = false
        } else {
          this.disprint = true
          if (!this.batch) {
            await this.search()
          }
        }
      },
      async downFiles (index, row) {
        if (!row.f_user_type) {
          this.$showMessage('当前用户无用户类型,信息不完整，无法继续下载，请完善数据！')
          return
        }
        // 如果有流程单id则直接使用，如果没有则重新获取
        if (!row.f_print_id) {
          let param = {
            id: row.id,
            f_user_type: row.f_user_type,
            f_print_dh: row.f_print_dh,
            f_userinfo_id: row.f_userinfo_id
          }
          var res = await this.$resetpost('rs/logic/getDectirNum', {data: param}, {rejectMsg: '获取流程编号失败'}).then((res) => {
            if (res) {
              if (res.data != '') {
                row.f_print_id = res.data
              } else {
                this.$showAlert('获取流程编号失败，请检查用户数据是否完整！', 'warning', 2000)
                this.close()
              }
            }
          })
        }
        let url = ''

        // 下载不同文件
        if (index == 0) {
          if (row.f_user_type == '民用') {
            url = 'rs/report/userinstall'
          } else {
            url = 'rs/report/fuserinstall'
          }
          this.billData.url = url
        } else if (index == 1) {
          url = 'rs/report/userignition'
          this.billData.url = url
        } else if (index == 2) {
          url = 'rs/report/gasModified'
          this.billData.url = url
        } else if (index == 3) {
          url = 'rs/report/userPrintBill'
          this.billData.url = url
        }
        row.f_name = this.$login.f.name
        this.newdata = row
        this.printflag = true
        this.disprint = false
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      async downDispatcher (row) {
        var link = document.createElement('a')
        var param = {'condition': 'id=' + row.id, 'orderitem': 'id'}
        var res = await this.$resetpost('rs/sql/getDispatchInfo', {data: param}, {
          rejectMsg: '查询出错'
        })
        console.log(res)
        let path = res.data[0].f_dispathch_path
        console.log(path)
        let filepath = {'filepath': path}
        var rses = await this.$resetpost('rs/logic/getDispatcherFile', {data: filepath}, {
          rejectMsg: '获取失败'
        })
        console.log(rses)
        let downfilepath = rses.data
      // webapps这个是在服务器上导出用的
        let pathName = 'http://' + location.host + '/webapps' + downfilepath.split('webapps')[1]
        // word这个是在本地导出用的
        //   let pathName = "http://" + "localhost:8080" + "/word" + downfilepath.split('word')[1]
        console.log(pathName)
        window.location.href = pathName

      // link.href = pathName;
      // link.download = path.split('excel/')[1];
      //   link.dispatchEvent(new MouseEvent('click'));
      },
      showhistory (row) {
        this.show = true
        this.row = row
      },
      operate (id, pricename) {
        this.$parent.usershow = true
        this.$parent.priceid = id
        this.$parent.pricename = pricename
      },
      async search () {
        await this.$refs.paged.$refs.cri.search()
        this.$dispatch('search')
      },
      getorg (val) {
        this.orgCondtionStr = val
      },
      async selfSearch (args) {
        console.log('--------selfSearch')
        this.$refs.paged.$refs.grid.$el.scrollTop = 0
        if (!this.orgCondtionStr) {
          args.condition = `${args.condition}` + ' and f_orgid = ' + this.$login.f.orgid
        } else {
          args.condition = `${args.condition}` + this.orgCondtionStr
        }
        this.condition = args.condition
        await this.model.search(args.condition, args.model)
      },
      add () {
        this.$dispatch('add')
      },
      async printok (name, val) {
        await this.confirmprintState(val)
        console.log("-----------------------val",val)
        this.$refs.printbill.printControl('打印完成')
      },
      async confirmprintState (row) {
        console.log('===>' + JSON.stringify(row))
        let temp = {
          id: row.id,
          f_print_state: row.f_print_state,
          f_type: row.f_type,
          f_userinfo_id: row.f_userinfo_id,
          f_print_date: this.$login.toStandardTimeString(),
          f_state: '打印'
        }
        if (row.f_print_state == '否') {
          temp.f_state = '撤销'
        }
        if (row.f_print_state == '重置') {
          temp.f_state = '重置'
        }
        let res = await this.$resetpost('rs/logic/updatePrintSheet', {data: temp},
          {resolveMsg: null, rejectMsg: null})
        if (res.data && res.data.state) {
          if (res.data.state == 200) {
            this.$showAlert(res.data.msg, 'success', 2000)
          } else if (res.data.state == 500) {
            this.$showAlert(res.data.msg, 'warning', 2000)
          }
          if (!this.batch) {
            await this.close()
          }
        }
        await this.search()
      },
      async getPrintDetail (row) {
        await this.showPrintDetail(row)
        this.newdata.f_name = this.$login.f.name
        this.printflag = true
        this.disprint = true
      },
      async showPrintDetail (row) {
        row.f_name = this.$login.f.name
        let index = null
        switch (row.f_print_dh) {
          case '点火单':
            index = 1
            break
          case '流程单':
            index = 0
            break
          case '改装单':
            index = 2
            break
        }
        if (index !== null) {
          if (!row.f_print_id) {
            let param = {
              id: row.id,
              f_user_type: row.f_user_type,
              f_print_dh: row.f_print_dh,
              f_userinfo_id: row.f_userinfo_id
            }
            await this.$resetpost('rs/logic/getDectirNum', {data: param}, {rejectMsg: '获取流程编号失败'}).then((res) => {
              if (res) {
                if (res.data != '') {
                  row.f_print_id = res.data
                } else {
                  this.$showAlert('获取流程编号失败，请检查用户数据是否完整！', 'warning', 2000)
                  this.close()
                }
              }
            })
          }
          let url = ''
          // 下载不同文件
          if (index == 0) {
            if (row.f_user_type == '民用') {
              url = 'rs/report/userinstall'
            } else {
              url = 'rs/report/fuserinstall'
            }
            this.billData.url = url
          } else if (index == 1) {
            url = 'rs/report/userignition'
            this.billData.url = url
          } else if (index == 2) {
            url = 'rs/report/gasModified'
            this.billData.url = url
          }
          this.newdata = row
        }
      },

      async batchPrint () {
        this.batch = true
        console.log('打印抄表单')
        if (this.selectPrint.length > 0) {
          let res = await this.$showMessage(`当前数据条数: ${this.selectPrint.length}, 条数过大时打印时间可能会过长, 是否确认打印?`)
          if (res == 'confirm') {
            for (let row of this.selectPrint) {
              this.newdata = row
              await this.showPrintDetail(row)
              var p = {
                condition: this.newdata,
                staticData: {f_user_name: this.newdata.f_user_name}
              }
              this.$refs.printbill.batch = true
              await this.$refs.printbill.printChecked(p)
            }
            var msg = `打印完毕`
            this.$showMessage(msg)
            await this.search()
          }
        } else {
          this.$showAlert('请选择要打印的单子', 'warning', 3000)
        }
      },
      unCheckAll () {
        let box = document.getElementsByName('opertioninput')
        for (var i = 0; i < box.length; i++) {
          box[i].checked = false
        }
        this.checked1 = false
        this.selectPrint = []
        this.newdata = {}
      },
      checkedALL () {
        this.checked1 = !this.checked1
        let box = document.getElementsByName('opertioninput')
        for (var i = 0; i < box.length; i++) {
          box[i].checked = this.checked1
        }
      },
      checked (val) {
        var hasId = false
        for (let i = 0; i < this.selectPrint.length; i++) {
          if (this.selectPrint[i].id === val.id && row.f_order_state == '已预约' && val.f_state == '有效' &&val.f_print_num<this.max_print) {
            hasId = true
            console.log('这个f_print_id已经选过了')
            this.selectPrint.splice(i, 1)
            console.log('this.selectPrint：', this.selectPrint)
          }
        }
        if (!hasId) {
          this.selectPrint.push(val)
        }
      }
    },
    watch: {
      'model.rows': {
        async handler (val, oldVal) {
          if (val.length > 0) {
            var i = false
            this.model.rows.forEach((item) => {
              if (item.f_print_num < this.max_print && item.f_state === '有效' && item.f_order_state === '已预约') {
                i = true
              }
            })
            if (i) {
              this.canCheckAll = true
            } else {
              this.canCheckAll = false
            }
          } else {
            this.canCheckAll = false
          }
          this.unCheckAll()
          this.batch = false
        },
        deep: true
      },
      'checked1' (val) {
        if (val) {
          this.model.rows.forEach((item) => {
            if (item.f_print_num < this.max_print && item.f_state === '有效' && item.f_order_state === '已预约') {
              this.selectPrint.push(item)
            }
          })
        } else {
          this.selectPrint = []
        }
      }
    }
  }
</script>
<style scoped>
  .p1 {
    color: #28dc1f;
    font-weight: bold
  }

  .p {
    color: #5f37ff;
  }
</style>
