<template>
  <div class="basic-main" style="height: 98%">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div class="form-horizontal select-overspread container-fluid auto" novalidate partial>
          <div class="row">
            <div class="form-group col-sm-2">
              <label class="font_normal_body">用户编号</label>
              <input type="text" style="width:60%" class="input_search" v-model="model.f_userinfo_code"
                     placeholder='用户编号'
                     condition="f_userinfo_code = '{}'">
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">其他收费状态</label>
              <v-select v-model="model.f_state"
                        placeholder='其他收费状态'
                        :value.sync="model.f_state"
                        :options='$parent.$parent.states'
                        close-on-select
                        condition=" {} "
                        @change="$parent.$parent.search">
              </v-select>
            </div>

            <div class="span" style="float:right;">
              <button class="button_search button_spacing width-60" @click="search()" v-el:cx>查询</button>
              <button class="button_search button_spacing width-60"
                      @click="$parent.$parent.allsuccess()" v-el:cx>全部通过
              </button>
              <button class="button_search button_spacing width-60"
                      @click="$parent.$parent.allfaild()" v-el:cx>全部不通过
              </button>
              <!--<export-excel :data="{condition: condition}" bean="自助抄表审核导出" sqlurl="rs/logic/exportfile"></export-excel>-->
              <div
                :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                @click="$parent.$parent.hidden()" class="button_spacing" style="float: right">
              </div>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">
            <res-select-group :initres="$parent.$parent.initres" @re-res="$parent.$parent.getRes"
                              v-ref:sel></res-select-group>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
        <template partial='head'>
          <tr>
            <th>序号</th>
<!--            <th>用户编号</th>-->
<!--            <th>表编号</th>-->
<!--            <th>表编号</th>-->
            <th>用户名称</th>
            <th>用户类型</th>
            <th>用气性质</th>
            <th>地址</th>
            <th>服务人员</th>

            <th>操作日期</th>
            <th>费用类型</th>
            <th>是否付款</th>
            <th>本次购买时间</th>
            <th>收款单据</th>

            <th>其他收费状态</th>
            <th>备注</th>

            <th>操作</th>

          </tr>
        </template>
        <template partial='body'>
          <td style="text-align:center">{{ $index + 1 }}</td>

<!--          <td style="text-align:center">{{ row.f_userinfo_id }}</td>-->
<!--          <td style="text-align:center">{{ row.f_userfiles_id }}</td>-->
<!--          <td style="text-align:center">{{ row.f_user_id }}</td>-->
          <td style="text-align:center">{{ row.f_user_name }}</td>
          <td style="text-align:center">{{ row.f_user_type }}</td>
          <td style="text-align:center">{{ row.f_gasproperties }}</td>
          <td style="text-align:center">{{ row.f_address }}</td>
          <td style="text-align:center">{{ row.f_service_person }}</td>

          <td style="text-align:center">{{ row.f_operate_date }}</td>
          <td style="text-align:center">{{ row.f_fee_type }}</td>
          <td style="text-align:center">{{ row.f_is_pay }}</td>
          <td style="text-align:center">{{ row.f_fee_time }}</td>
          <td style="text-align:center">{{ row.f_serial_number }}</td>

          <td style="text-align:center">{{ row.f_state }}</td>
          <td style="text-align:center">{{ row.f_comments }}</td>

          <td style="text-align: center">
            <nobr>
            <button type="button" class="button_search button_spacing width-60" v-if="row.f_state==='待审核'"
                    @click.stop="$parent.$parent.$parent.success(row)">通过
            </button>
            <button type="button" class="button_search button_spacing width-60" v-if="row.f_state==='待审核'"
                    @click.stop="$parent.$parent.$parent.faild(row)">不通过
            </button>
            </nobr>
          </td>
        </template>
      </data-grid>
    </criteria-paged>

    <modal :show.sync="show" v-ref:modal backdrop="false">
      <header slot="modal-header" class="modal-header">
        <h4 class="modal-title">请填写不通过原因</h4>
      </header>
      <article slot="modal-body" class="modal-body">
        <div class="form-group">
          <input type="text" class="form-control" v-model="pushdata.cause"
                 placeholder='请填写不通过原因,原因将会推送给用户'>
        </div>
      </article>
      <footer slot="modal-footer" class="modal-footer">
        <button v-show="show" type="button" class="btn btn-default" @click='show = false'>取消</button>
        <button v-show="show" type="button" class="btn btn-success" @click='confirm()'>确认</button>
      </footer>
    </modal>
  </div>
</template>
<style>
.meterbasehaserr {
  color: #E26868 !important;
  font-weight: 700
}
</style>
<script>
import {PagedList} from 'vue-client'

let readyGen = async function (self) {
  await self.$LoadParams.loadMeterBook(self.f_filialeid)
  self.loadMeterBooks()
  self.getfield = self.config.excelHeaders
  self.reflash()
}

export default {
  name: 'OtherChargeAudit',
  title: '其他收费审核',
  data () {
    return {
      initres: {
        org: [this.$login.f.orgid],
        dep: [],
        user: []
      },
      orgCondtionStr: '',
      criteriaShow: false,
      show: false,
      pushdata: {openid: '', cause: ''},
      row: null,
      model: new PagedList('rs/sql/getOtherChargeNoPay', 20),
      states: [
        {label: '全部', value: ``},
        {label: '待审核', value: ` f_state = '待审核' `},
        {label: '有效', value: ` f_state = '有效' `},
        {label: '无效', value: ` f_state = '无效' `},
        {label: '撤销', value: ` f_state = '撤销' `},
        {label: '冲正', value: ` f_state = '冲正' `}],
    }
  },
  ready () {
    setTimeout(()=>{
      this.search()
    },300)
  },
  methods: {
    loadMeterBooks () {
      this.meterbooks = [...this.meterbooks, ...this.$GetSaleParam.getMeterBooks()]
    },
    getRes (obj) {
      this.orgCondtionStr = obj
    },
    hidden () {
      this.criteriaShow = !this.criteriaShow
    },
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    selfSearch (args) {
      if (!this.orgCondtionStr) {
        args.condition = `${args.condition}` + ' and f_orgid in ' + `('`+this.$login.f.orgid+`')`
      } else {
        args.condition = `${args.condition}` + this.orgCondtionStr
      }
      this.model.search(args.condition, args.model)
    },
    async allsuccess () {
      let res = await this.$showMessage('确定通过全部其他收费审核吗?操作后将不可取消', ['confirm', 'cancel'])
      let condition = []
      if (res === 'confirm') {
        if (this.model.rows.length >= 0) {
            let rows = this.model.rows.filter((row)=>{
              if(row.f_state === '待审核'){
                return row
              }
            })
            rows.forEach((row)=>{
              console.log(row)
              row['f_audit_person'] = this.$login.f.name
            })
            let data = {
              data: rows
            }
            await this.$resetpost('rs/logic/otherChargeAuditPassAll', data, {resolveMsg: '操作成功', rejectMsg: '操作失败'})
            this.search()
        } else {
          this.$showMessage('暂无数据')
        }
      }
    },
    async success (row) {
      let res = await this.$showMessage('确定审核通过吗?操作后将不可取消', ['confirm', 'cancel'])
      if (res === 'confirm') {
        row['f_audit_person'] = this.$login.f.name
        let data = {
          data: row
        }
        await this.$resetpost('rs/logic/otherChargeAuditPass', data, {resolveMsg: '操作成功', rejectMsg: '操作失败'})
        this.search()
      }
    },
    async allfaild () {
      let res = await this.$showMessage('确定不通过全部其他收费审核吗?操作后将不可取消', ['confirm', 'cancel'])
      let condition = '('
      if (res === 'confirm') {
        let rows = this.model.rows.filter((row)=>{
          if(row.f_state === '待审核'){
            return row
          }
        })
        rows.forEach((row)=>{
          console.log(row)
          row['f_audit_person'] = this.$login.f.name
        })
        if (rows.length > 0) {
            let data = {
              data: rows
            }
            await this.$resetpost('rs/logic/otherChargeAuditNoPassAll', data, {resolveMsg: '操作成功', rejectMsg: '操作失败'})
            this.search()

        } else {
          this.$showMessage('暂无数据')
        }
      }
    },
    async faild (row) {
      let res = await this.$showMessage('确定审核不通过吗?操作后将不可取消', ['confirm', 'cancel'])
      if (res === 'confirm') {
        row['f_audit_person'] = this.$login.f.name
        let data = {
          data: row
        }
        await this.$resetpost('rs/logic/otherChargeAuditNoPass', data, {resolveMsg: '操作成功', rejectMsg: '操作失败'})
        this.search()
      }
    },
    // async confirm () {
    //   //更新不通过原因
    //   let update = `UPDATE t_handplan SET f_examinereason ='${this.pushdata.cause}' where id = ${this.update_f_examinereason_id}`
    //   await this.$resetpost('rs/logic/runSQL', {sql: update}, {resolveMsg: '原因提交成功', rejectMsg: '操作失败'})
    //   console.log(update)
    //   await this.$resetpost('rs/logic/weixinHanPlanAudit', this.row, {resolveMsg: '操作成功', rejectMsg: '操作失败'})
    //   await this.$resetpost('http://www.hunanhongdaranqi.com/weixin/rs/logic/meterReadFailed', this.pushdata, {
    //     resolveMsg: null,
    //     rejectMsg: null
    //   })
    //   this.show = false
    //   this.search()
    // }
  },
  computed: {
    // inputtores () {
    //   // 获取抄表员
    //   console.log('获取抄表员', this.$login.f)
    //   let rs = []
    //   if (this.$login.f.f_gasman.length > 0) {
    //     for (let i = 0; i < this.$login.f.f_gasman.length; i++) {
    //       let temp = {
    //         label: this.$login.f.f_gasman[i].name,
    //         value: this.$login.f.f_gasman[i].name
    //       }
    //       rs.push(temp)
    //     }
    //   }
    //   this.inputtores2 = rs
    //   return [...rs]
    // }
  }
}
</script>
