<template>
  <div @keyup.enter="search">
    <partial-view v-ref:pv>
      <criteria-paged :model="model" :pager="false" v-ref:paged>
        <criteria @condition-changed='$parent.$parent.selfSearch' partial='criteria' v-ref:cri>
          <div class="form-horizontal" novalidate partial>
            <div class="row">
              <div class="form-group col-sm-4">
                <!-- <label>用户编号:</label> -->
                <input class="input_search" condition="f_userinfo_code = '{}'" placeholder='客户编号' style="width: 80%"
                       type="text"
                       v-model="model.f_userinfo_code">
              </div>
              <div class="form-group  col-sm-4" style="flex: 1;width: max-content">
                <!-- <label>操作类型:</label> -->
                <v-select :options='$parent.$parent.$parent.operationtypes'

                          :value.sync="model.f_operat_type"
                          :width="'100%'"
                          close-on-select
                          condition="f_operat_type = '{}'"
                          id="f_paytype"
                          placeholder='操作类型'
                          style="width: 100%"
                          v-model="model.f_operat_type"></v-select>
              </div>
              <div class="form-group col-sm-2 button-range" style="padding-right: 10px">
                <button @click="search()" class="button_search">查询</button>
                <div
                  :class="{'button_shrink_top':$parent.$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.$parent.criteriaShow}"
                  @click="$parent.$parent.$parent.criteriaShow=!$parent.$parent.$parent.criteriaShow" class="button_spacing" style="float: right"></div>
              </div>
              <div class="form-group col-sm-5" v-show="$parent.$parent.$parent.criteriaShow">
                <!-- <label>用户编号:</label> -->
                <input class="input_search" condition="r.f_operator like '%{}%'" placeholder='操作员' style="width: 80%"
                       type="text"
                       v-model="model.f_operator">
              </div>
            </div>
            <!-- <partial name="cardcriteria"></partial> -->
            <!-- <div class="form-group">
              <partial name="cardcriteria"></partial>
            </div> -->
          </div>
        </criteria>
        <div partial="list" style="overflow-y: scroll;height: 90%">
          <accordion :one-at-atime="true" type="info"  >
            <panel :is-click="false" :is-open="true" type="info" v-for="row in model.rows" >
            <span @click="$parent.$parent.$parent.selected(row)" class="panel-title row" slot="header"
                  style="cursor: pointer;">
              <div class="col-sm-11">
<!--                <div class="row"  v-if="row.f_state==='冲正' " style="color: red">-->
<!--                  <strong :title="row.f_userinfo_code" class="col-sm-4" show-overflow-tooltip="true">{{row.f_userinfo_code.length>9?''+row.f_userinfo_code.substring(0,9)+'...':row.f_userinfo_code}}</strong>-->
<!--                  <span class="col-sm-4">{{$parent.$parent.$parent.dateDes(row.f_operate_date)}}</span>-->
<!--                  <span class="col-sm-4">{{row.type}}</span>-->
<!--                </div>-->
                <div class="row">
                  <strong :title="row.f_userinfo_code" class="col-sm-4" show-overflow-tooltip="true">{{row.f_userinfo_code.length>9?''+row.f_userinfo_code.substring(0,9)+'...':row.f_userinfo_code}}</strong>
                  <span class="col-sm-4">{{$parent.$parent.$parent.dateDes(row.f_operate_date)}}</span>
                  <span class="col-sm-4">{{row.type}}</span>
                </div>
              </div>
              <div class="col-sm-1" v-if="$parent.$parent.$parent.isOperate" title="涉及权限:冲正权限">
                <dropdown class="auto"
                          v-if="(row.type ==='机表收费撤销' || row.type ==='卡表收费撤销' || row.type ==='物联网收费撤销' || row.type ==='其他收费撤销'
                          || row.type ==='气损收费撤销' || row.type ==='预存缴费' || row.type === '补卡' || row.type === '物联网收费' ||
                          row.type === '用户退费' || row.type === '机表收费' || row.type === '数码表收费' ||
                          row.type === '卡表收费' || row.type === '超用收费' || row.type === '发卡售气' || row.type === '其他收费' ||
                          row.type === '换表' || row.state === 1 || row.type==='调价补费' || row.type==='卡表赠气' ||
                          row.type==='物联网赠气'|| row.type==='物联网赠费'|| row.type==='卡表赠费'|| row.type==='卡表赠气'||
                          row.type==='卡表收费撤销'||row.type==='物联网补费' || row.type==='物联网扣费'||row.type==='机表补费'||
                          row.type==='机表扣费'||row.type==='物联网补气'||row.type==='物联网扣气'||row.type==='气损收费' ||
                          row.type === '气表清零' || row.type === '掉气补气' || row.type === '其他补气'  || row.type === '清零补气' ||
                          row.type === '换表补气' || row.type === '过户'|| row.type ==='价格补差' || row.type ==='价格补差撤销') && row.type!=='新增户档案' && row.type!=='转气转出' && row.type!=='转气转入'">
                  <button data-toggle="dropdown" style="border: 0px;background: none;" type="button"
                          v-if="row.f_user_state==='正常'||row.f_user_state==='预备'||row.type==='气损收费' ">
                    <span class="glyphicon glyphicon-th-list"></span>
                  </button>
                  <ul class="dropdown-menu dropdown-menu-right" slot="dropdown-menu" style=" min-width: 60px;" v-if="row.f_user_state==='正常'||row.f_user_state==='预备'||row.type==='气损收费' ">
<!--                    <li-->
<!--                      v-if="row.type === '换新表' || row.type === '气表清零' || row.type === '掉气补气' || row.type === '其他补气'  || row.type === '清零补气' || row.type === '换表补气'-->
<!--                      || row.type === '补卡' || row.type === '物联网开户' || row.type === '物联网收费' || row.type === '用户退费' || row.type === '机表收费' ||  row.type === '数码表收费' || row.type === '卡表收费' || row.type === '超用收费' || row.type === '发卡售气' || row.type === '其他收费' || row.type === '换表' || row.type === '过户'|| row.type==='预存缴费'|| row.type==='退费'|| row.type==='调价补费'  ||row.type==='卡表收费撤销'||row.type==='物联网补费' || row.type==='物联网扣费'||row.type==='机表补费'||row.type==='机表扣费'||row.type==='物联网补气'||row.type==='物联网扣气'||row.type==='气损收费' ">-->
<!--                      <a @click.stop="$parent.$parent.$parent.operate('票据补打', row)" href="#">票据补打</a>-->
<!--                    </li>-->
<!--                    <li-->
<!--                      v-if="row.state === 1 && (row.type === '其他收费欠费登记' || row.type === '迁表' || row.type === '调价预存' || row.type === '拆表' || row.type === '物联网开户' || row.type === '物联网收费'|| row.type === '卡表收费' || row.type === '其他收费'|| row.type === '气费减免'||row.type === '维修收费' || row.type === '过户' || row.type === '换新表' || row.type === '气表清零' || row.type === '机表收费' || row.type === '超用收费' || row.type === '其他收费' || row.type === '补卡'|| row.type === '调价补费'|| row.type=='预存缴费' || row.type==='卡表赠气'|| row.type==='物联网赠费'|| row.type==='卡表赠费'|| row.type==='物联网赠气')">-->
<!--                      <a @click.stop="$parent.$parent.$parent.operate('撤销', row)" href="#">撤销</a>-->
<!--                    </li>-->
                    <li>
                      <a @click.stop="$parent.$parent.$parent.operate('票据补打', row)" href="#">票据补打</a>
                    </li>
                    <li>
                      <a @click.stop="$parent.$parent.$parent.operate('撤销', row)" href="#">撤销</a>
                    </li>
                  </ul>
                </dropdown>
              </div>

            </span>
              <div class="panel-body" v-if="$parent.$parent.$parent.isSelected(row)">
                <salecardgas-detail :data="row" v-if="row.type === '发卡售气'"></salecardgas-detail>
                <movemeter-detail :data="row" v-if="row.type === '迁表'"></movemeter-detail>
                <salecardgas-detail :data="row" v-if="row.type === '换表发卡'"></salecardgas-detail>
                <cardmetercenter-detail :data="row" v-if="row.type === '卡表收费'||row.type === '数码表收费' "></cardmetercenter-detail>
                <movegas-detail :data="row" v-if="row.type === '转气转出'"></movegas-detail>
                <movegas-detail :data="row" v-if="row.type === '转气转入'"></movegas-detail>
                <machinemetercenter-detail :data="row" v-if="row.type === '机表收费'"></machinemetercenter-detail>
                <autoaccounts-detail :data="row" v-if="row.type === '自动下账'"></autoaccounts-detail>
                <bankdk-detail :data="row" v-if="row.type === '银行代扣'"></bankdk-detail>
                <bank-pay :data="row" v-if="row.type === '银行支付'"></bank-pay>
                <wechat-pay :data="row" v-if="row.type === '微信支付'"></wechat-pay>
                <disablemanage-detail :data="row" v-if="row.type === '停用'"></disablemanage-detail>
                <enablemanage-detail :data="row" v-if="row.type === '启用'"></enablemanage-detail>
                <replacecardmanage-detail :data="row" v-if="row.type === '补卡'"></replacecardmanage-detail>
                <machinecard-detail :data="row" v-if="row.type === '机表补卡'"></machinecard-detail>
                <transfermanage-detail :data="row" v-if="row.type === '过户'"></transfermanage-detail>
                <othercharge-detail :data="row" v-if="row.type === '其他收费欠费登记'||row.type === '其他收费'||row.type === '维修收费'"></othercharge-detail>
                <inputtorchange-detail :data="row" v-if="row.type === '抄表员变更'"></inputtorchange-detail>
                <offgasaddgas-detail :data="row" v-if=" row.type === '换表补气' ||row.type === '其他补气' || row.type === '清零补气' || row.type === '掉气补气'||row.type==='物联网补费'||row.type==='物联网扣费'||row.type==='机表补费'||row.type==='机表扣费'||row.type==='物联网补气'||row.type==='物联网扣气' " ></offgasaddgas-detail>
                <iotopen-detail :data="row" v-if="row.type === '开通'"></iotopen-detail>
                <iotmetercenter-detail :data="row" v-if="row.type === '物联网收费' || row.type === '物联网开户' || row.type === '调价退费' || row.type === '调价补费'||row.type === '退押金'  "></iotmetercenter-detail>
                <overuserchange-detail :data="row" v-if="row.type === '超用收费'"></overuserchange-detail>
                <adduser-detail :data="row" v-if="row.type === '新增户档案'"></adduser-detail>
                <gaspricechange-detail :data="row" v-if="row.type === '气价变更'"></gaspricechange-detail>
                <userchange-detail :data="row" v-if="row.type === '档案变更'"></userchange-detail>
                <changemeter-detail :data="row" v-if="row.type === '换新表' || row.type === '气表清零'"></changemeter-detail>
                <changeflowmeter-detail :data="row" v-if="row.type === '换卡控流量计'"></changeflowmeter-detail>
                <cardoveruser-detail :data="row" v-if="row.type === '卡表超用'||row.type === '超用'"></cardoveruser-detail>
                <cancellation-detail :data="row" v-if="row.type === '销户'"></cancellation-detail>
                <refund-detail :data="row" v-if="row.type === '退费' || row.type == '卡表退费'"></refund-detail>

                <change-meter-cancel :data="row" v-if="row.type === '换表撤销'"></change-meter-cancel>
                <autoaccounts-cancel-detail :data="row" v-if="row.type === '自动下账撤销'"></autoaccounts-cancel-detail>
                <transfermanage-cancel-detail :data="row" v-if="row.type === '过户撤销'"></transfermanage-cancel-detail>
                <cardmetercenter-cancel-detail :data="row" v-if="row.type === '卡表收费撤销'"></cardmetercenter-cancel-detail>
                <machinemetercenter-cancel-detail :data="row" v-if="row.type === '机表收费撤销'"></machinemetercenter-cancel-detail>
                <machinemetercenter-cancel-detail :data="row" v-if="row.type == '预存缴费撤销'"></machinemetercenter-cancel-detail>
                <othercharge-cancel-detail :data="row" v-if="row.type === '其他收费撤销'"></othercharge-cancel-detail>
                <replacecardmanage-cancel-detail :data="row" v-if="row.type === '补卡撤销'"></replacecardmanage-cancel-detail>
                <iotmetercenter-cancel-detail :data="row" v-if="row.type === '物联网收费撤销'"></iotmetercenter-cancel-detail>
                <feededuction-detail :data="row" v-if="row.type === '补费' ||row.type === '扣费' ||row.type === '补气' ||row.type === '扣气'  "></feededuction-detail>
                <with-gas :data="row" v-if="row.type==='物联网赠气' || row.type==='物联网赠费'||row.type==='卡表赠气'||row.type==='卡表赠费'"></with-gas>
                <replace-card-manageDetail :data="row" v-if=" row.type==='物联网补费'||row.type==='物联网扣费'||row.type==='机表补费'||row.type==='机表扣费'||row.type==='物联网补气'||row.type==='物联网扣气' "></replace-card-manageDetail>
                <blacklist-detail :data="row" v-if="row.type ==='拉黑' ||row.type === '取消拉黑' "></blacklist-detail>
                <advance-delivery-detail :data="row" v-if="row.type ==='卡表预交' "></advance-delivery-detail>
                <machinemetercenter-detail :data="row" v-if="row.type === '预存缴费'||row.type == '调价预存'"></machinemetercenter-detail>
                <price-adjustment-detail :data="row" v-if="row.type === '价格补差'"></price-adjustment-detail>
                <gasloss-detail :data="row" v-if="row.type === '气损收费' || row.type === '气损收费撤销'"></gasloss-detail>
                <garbage-detail :data="row" v-if="row.type === '垃圾费收费'"></garbage-detail>
              </div>
              <div style="margin-top: 8px;background: #FFF;" v-if="!$parent.$parent.$parent.isSelected(row)">
                <span>{{row.f_describe}}</span>
              </div>
            </panel>
          </accordion>
        </div>

      </criteria-paged>
    </partial-view>
    <record-cancel :data="cancel_data" :show.sync="cancel_show" @cancel="cancelOper()" @cancel-success="cancelSucc()" v-if="cancel_show"></record-cancel>
    <reissue-bill :data="reissue_data" :show.sync="reissue_show" @cancel="reissueOper()" @reissue-success="reissueSucc()" v-if="reissue_show"></reissue-bill>
  </div>
</template>
<script>
  /**
   *操作记录信息
   */
  import {PagedList} from 'vue-client'
  import co from 'co'

  let cancelGen = function *(self, data) {
    let msgRet = yield self.$showMessage('撤销后数据不可恢复，确认撤销录入吗？', ['confirm', 'cancel'])
    if (msgRet === 'cancel') return
    // 撤销操作完成，刷新界面
    self.search()
  }

  /**
   * 发票补打
   */
  let reprintGen = async function (self, row) {
    try {
      row.billUrl = self.getBillUrl(row)
      if (!row.billUrl) {
        self.$showMessage('当前操作类型暂时没有票据')
        return
      }
      row.f_bill_type = row.type
      row.f_bill_style = '普通收据'
      row.f_operator = self.$login.f.name
      row.f_operatorid = self.$login.f.id
      row.f_orgid = self.$login.f.orgid
      row.f_orgname = self.$login.f.orgs
      row.f_depid = self.$login.f.depids
      row.f_depname = self.$login.f.deps
      self.reissue_data = JSON.parse(JSON.stringify(row))
      if (row.type === '调价预存') {
        let id = await self.$resetpost('rs/sql/singleTable_OrderBy', {
          data: {
            items: 'f_surplus_id',
            tablename: 't_sellinggas',
            condition: `id = '${row.id}'`,
            orderitem: 'id'
          }
        }, {resolveMsg: null, rejectMsg: '查询优惠信息失败'})
        self.reissue_data.id = id.data[0].f_surplus_id
      }
      self.reissue_show = true
    } catch (error) {
      if (error.status) {
        self.$warn(`加载数据出错, ${JSON.stringify(error)}`, 'CardList')
      }
      throw error
    }
  }
  let asyncCardList = async function (self) {
    await self.$getConfig(self, 'CardList')
    console.log('操作汇总config', self.config)
  }
  export default {
    title: '操作汇总',
    data () {
      return {
        config: {
          cancleother: false,  // 默认可以撤销别人的操作
          cancletime: true  // 默认可以冲正今天以前的操作
        },
        model: new PagedList(`${this.sqlurl}`, 9999,
          {
            items: '"' + this.items + '"',
            tablename: '"' + this.tablename + '"',
            orderitem: '"' + this.orderitem + '"'
          }),
        show: false,
        asideTitle: '用户操作',
        row: Object,
        comp: null,
        operationtypes: this.$appdata.getParam('操作类型') ? [{
          label: '全部',
          value: ''
        }, ...this.$appdata.getParam('操作类型')] : [],

        cancel_show: false,
        cancel_data: null,
        criteriaShow: false,
        reissue_show: false,
        reissue_data: null,
        authArr: this.$login.r ? this.$login.r : []
      }
    },
    props: {
      sqlurl: {
        type: String,
        default: 'rs/sql/getRecord'
      },
      items: {
        type: String,
        default: '*'
      },
      tablename: {
        type: String,
        default: 't_record'
      },
      orderitem: {
        type: String,
        default: 'f_operate_date desc'
      },
      btns: {
        type: Array
      },
      operationtype: {
        type: String,
        default: ''
      },
      userinfoid: {},
      isOperate: {
        type: Boolean,
        default: true
      },
      f_orgid: ''
    },
    ready () {
      this.$refs.paged.$refs.cri.model.f_operat_type = [this.operationtype]
      asyncCardList(this)
      // this.search()
    },
    methods: {
      dateDes (date) {
        return this.$login.dateDescripte(date)
      },
      selected (row) {
        if (this.row === row) {
          this.row = null
        } else {
          this.row = row
        }
      },
      isSelected (row) {
        return this.row === row
      },
      search () {
        let condition = '1=1'
        if (this.f_orgid) {
          condition += `and (u.f_filialeid in ${this.f_orgid} or g.f_orgid in ${this.f_orgid}) `
        } else {
          condition += `and (u.f_filialeid = '${this.$login.f.orgid}' or g.f_orgid ='${this.$login.f.orgid}')`
        }
        this.$refs.pv.load(this.sqlurl, {data: {condition: condition}}).then((a) => {
          if (a.data.length === 0) {
            this.model.rows = []
            this.model.state = '错误'
            this.model.error = '没有符合条件的记录'
            return
          }
          this.model.state = '正确'
          this.model.rows = a.data
        })
      },
      disEvent (btn) {
        this.$dispatch(`${btn.eventName}`)
      },
      async operate (title, row) {
        console.log('撤销的这条数据的信息', row)
        if (title === '撤销') {
          // 验证是否能撤销
          let res = await this.$resetpost('rs/logic/recordRepealJudge', {data: row}, {
            resolveMsg: null,
            rejectMsg: '验证权限错误！！'
          })

          if (!res.data.pass) {
            this.$showMessage(res.data.msg)
            return
          }
          if(row.type==='政府补贴'){
            if(row.f_state ==='有效'){
              let condition =` u.f_userfiles_id = '${row.f_userfiles_id}'`
              let user = await this.$resetpost('rs/sql/sale_getUser', {data: {condition:condition}}, {
                resolveMsg: null,
                rejectMsg: '获取用户失败！！'
              })
              if(user.data.length>0){
                if(user.data[0].f_issupport_feededuction==='否'){
                  return this.$showAlert('当前表型不支持撤销扣费操作', 'warning', 1500)
                }
              } else {
                return this.$showAlert('获取用户信息失败', 'warning', 1500)
              }
            } else {
              return this.$showAlert('该记录已撤销请勿重复操作', 'warning', 1500)
            }

          }
          if (row.type === '卡表收费') {
            if (!this.authArr.includes('无卡收费撤销权限')) {
              this.$showAlert('当前用户没有【无卡收费撤销权限】，请联系管理员获取此权限后再进行该操作！', 'warning', 3000)
              return
            }
          }
          if (row.type === '物联网收费' || row.type === '卡表赠气' || row.type === '物联网赠费' || row.type === '卡表赠费' || row.type === '物联网赠气') {
            let table_name = this.$appdata.getSingleValue('新抄表')? 't_web_handplan' : 't_handplan'
            let getWebHand = await this.$SqlService.singleTable(table_name, `f_hand_state = '有效' and f_input_date > '${row.f_operate_date}' and f_userfiles_id = '${row.f_userfiles_id}'`)
            console.log('长度', getWebHand)
            if (getWebHand.data.length > 0) {
              this.$showAlert('此次物联网收费之后有结算，不能撤销此纪录', 'warning', 1500)
              return
            }
          } else if (row.type === '机表收费') {
            let getWebHand = await this.$SqlService.singleTable('t_handplan', `f_hand_state = '有效' and f_input_date > '${row.f_operate_date}' and f_whether_pay = '是' and f_userfiles_id = '${row.f_userfiles_id}'`)

            console.log('长度', getWebHand)
            if (getWebHand.data.length > 0) {
              this.$showAlert('此次机表收费之后有自动下账，不能撤销此纪录', 'warning', 1500)
              return
            }
            let sql = `select th.*from t_handplan th
            left join t_sellinghand tsh on th.id=tsh.f_hand_id
            where th.f_hand_state = '有效' and th.f_input_date > '${row.f_operate_date}' and tsh.f_debt_money>0
            and  th.f_userfiles_id = '${row.f_userfiles_id}' and tsh.f_state='有效'`
            let getwate = await this.$resetpost('rs/logic/sqlquery', {data: {sql: sql}}, {
              resolveMsg: null,
              rejectMsg: '获取记录详情出错！！'
            })
            if (getwate.data.length > 0) {
              this.$showAlert('此次机表收费之后有自动下账，不能撤销此纪录', 'warning', 1500)
              return
            }
          } else {
            if (this.authArr.includes('冲正权限')) {
              if (this.config.cancleother) {
                if (row.f_operator != this.$login.f.name) {
                  this.$showAlert('不能撤销不是自己进行的操作', 'warning', 1500)
                  return
                }
              }
              if (this.config.cancletime) {
                let a = this.$login.toStandardYearMonth()
                console.log('当前时间', a < row.f_operate_date)
                if (!this.authArr.includes('跨月撤销')) {
                  if (row.f_operate_date < a) {
                    this.$showAlert('不能撤销非本月的记录，请联系管理员获取【跨月撤销】的权限。', 'warning', 1500)
                    return
                  }
                }
              }
            } else {
              this.$showAlert('当前用户没有【冲正权限】', 'warning', 1500)
              return
            }
          }
        }

        if (title === '撤销') {
          this.cancel_show = true
          this.cancel_data = row
        } else {
          let reprint = reprintGen(this, row)
          return co(reprint)
        }
      },
      cancelOper () {
        this.cancel_data = null
        this.cancel_show = false
      },
      cancelSucc () {
        console.log('-----------------------------撤销成功了，隐藏掉')
        this.cancel_show = false
        this.$dispatch('refresh')
      },
      reissueOper () {
        this.reissue_data = null
        this.reissue_show = false
      },
      reissueSucc () {
        this.reissue_show = false
        this.$dispatch('refresh')
      },

      getBillUrl (row) {
        let type = row.type
        let name = ''
        // 根据type数据 选择调用的Logic
        if (type === '过户') {
          name = 'rs/report/transfer_bill'
        } else if (type === '换新表' || type === '气表清零') {
          name = 'rs/report/change_meter'
        } else if (type === '机表收费' || type === '机表收费撤销') {
          if (row.f_user_type === '非民用' && this.$login.r.includes('非民用纸质票据拆分')) {
            name = 'rs/report/fmy_machine_bill'
          } else {
            name = 'rs/report/machine_bill'
          }
        } else if (type === '物联网收费' || type === '物联网收费撤销' || type === '物联网开户' || type === '物联网赠气') {
          if (row.f_user_type === '非民用' && this.$login.r.includes('非民用纸质票据拆分')) {
            name = 'rs/report/fmy_iot_bill'
          } else {
            name = 'rs/report/iot_bill'
          }
        } else if (type === '物联网补费' || type === '物联网扣费' || type === '物联网补气' || type === '物联网扣气' || type === '机表补费' || type === '机表扣费') {
          name = 'rs/report/MakeUp'
        } else if (type === '超用收费') {
          name = 'rs/report/overuse_bill'
        } else if (type === '其他收费' || type === '其他收费撤销') {
          name = 'rs/report/otherCharge_bill'
        } else if (type === '补卡') {
          name = 'rs/report/replace_sell'
        } else if (type === '发卡售气') {
          if (row.f_user_type === '非民用' && this.$login.r.includes('非民用纸质票据拆分')) {
            name = 'rs/report/fmy_sendCard_bill'
          } else {
            if (row.f_meter_classify === '金额卡表' && this.$appdata.getSingleValue('金额气量区分卡表票据')) {
              name = 'rs/report/fee_sendCard_bill'
            } else {
              name = 'rs/report/sendCard_bill'
            }
          }
        } else if (type === '卡表收费' || type === '卡表收费撤销' || type === '卡表赠气' || type === '卡表收费撤销') {
          if (row.f_user_type === '非民用' && this.$login.r.includes('非民用纸质票据拆分')) {
            name = 'rs/report/fmy_card_bill'
          } else {
            if (row.f_meter_classify === '金额卡表' && this.$appdata.getSingleValue('金额气量区分卡表票据')) {
              name = 'rs/report/fee_card_bill'
            } else {
              name = 'rs/report/card_bill'
            }
          }
        } else if (type === '预存缴费') {
          name = 'rs/report/pre_sell'
        } else if (type === '调价预存') {
          name = 'rs/report/refund_sell'
        } else if (type === '退费') {
          name = 'rs/report/refund_sell'
        } else if (type === '调价补费') {
          name = 'rs/report/compensation_bill'
        } else if (type === '数码表收费') {
          name = 'rs/report/digtial_bill'
        } else if (type === '气损收费' || type === '气损收费撤销') {
          name = 'rs/report/gasloss_bill'
        } else if (type === '掉气补气') {
          name = 'rs/report/acceptOffGasAddGas_bill'
        } else if (type === '其他补气') {
          name = 'rs/report/acceptOtherGas_bill'
        } else if (type === '清零补气' || type === '换表补气') {
          if (row.f_meter_classify.indexOf('卡表') > -1) {
            name = 'rs/report/card_gas_bill'
          } else {
            name = 'rs/report/iot_sell'
          }
        } else if (type === '垃圾费收费') {
          name = 'rs/report/garbageChargeReport'
        }
        return name
      },
      // 撤销为统一操作，所以写到基础组件中
      operateCancel (row) {
        let cancel = cancelGen(this, row)
        co(cancel)
      },
      selfSearch (args) {
        // if (!this.$login.f.parent.parent.name.includes('统一资源管理')) {
        //   args.condition += `and f_filialeids = '${this.$login.f.f_orgids}'`
        // }
        if (this.f_orgid) {
          args.condition += `and r.f_orgid in ${this.f_orgid}`
        } else {
          args.condition += `and r.f_orgid = '${this.$login.f.orgid}'`
        }
        if (this.authArr.includes('操作记录查询限定')) {
          args.condition += ` and r.f_operatorid = '${this.$login.f.id}'`
        }
        this.model.search(args.condition, args.model)
      }
    },
    watch: {
      // 'userinfoid' (newVal) {
      //   this.model.rows={}
      //   if (newVal && newVal !== '') {
      //     this.$nextTick(function () {
      //       this.$refs.paged.$refs.cri.model.f_userinfo_code = newVal
      //     }.bind(this))
      //   }else{
      //     this.$nextTick(function () {
      //       this.$refs.paged.$refs.cri.model.f_userinfo_code = ""
      //     }.bind(this))
      //   }
      //   this.$refs.paged.$refs.cri.model.f_operat_type = ''
      // }
      'userinfoid' (newVal) {
        if (newVal && newVal !== '') {
          this.$nextTick(function () {
            this.$refs.paged.$refs.cri.model.f_userinfo_code = newVal
          }.bind(this))
          this.$refs.paged.$refs.cri.model.f_operat_type = ''
          let condition = `f_userinfo_code = '${newVal}' and u.f_filialeid = '${this.$login.f.orgid}'`
          this.$refs.pv.load(this.sqlurl, {data: {condition: condition}}).then((a) => {
            if (a.data.length === 0) {
              this.model.rows = []
              this.model.state = '错误'
              this.model.error = '没有符合条件的记录'
              return
            }
            this.model.state = '正确'
            this.model.rows = a.data
          })
        } else {
          this.model.rows = {}
          this.$nextTick(function () {
            this.$refs.paged.$refs.cri.model.f_userinfo_code = ''
          }.bind(this))
        }
      }
    }
  }
</script>
