<template>
  <div>
    <div style="flex: 1.5" class="flex">
      <div class="flex">
        <criteria-paged :model="model" v-ref:paged>
          <criteria partial='criteria' v-ref:criteria @condition-changed="$parent.selfSearch"
                    v-show="$parent.searchshow">
            <div novalidate class="form-inline auto" partial>
              <div class="row">
                  <div :class="$parent.$parent.styles" >
                  <label for="f_input_date" class="font_normal_body">开始日期</label>
                  <datepicker  placeholder="开始日期" style="width:60%"
                               v-model="model.f_startDate"
                               :value.sync="model.f_startDate"
                               :format="'yyyy-MM-dd HH:mm:ss'"
                               class="datepicker"
                               condition="f_operator_date >= '{}'"
                               :show-reset-button="true"
                               class="select"
                  >
                  </datepicker>
                </div>
                <div :class="$parent.$parent.styles" >
                  <label for="f_input_date" class="font_normal_body">结束日期</label>
                  <datepicker  placeholder="结束日期" style="width:60%"
                               v-model="model.f_endDate"
                               :value.sync="model.f_endDate"
                               :format="'yyyy-MM-dd HH:mm:ss'"
                               class="datepicker"
                               condition="f_operator_date <= '{}'"
                               :show-reset-button="true"
                  >
                  </datepicker>
                </div>

                <div class="span" style="float:right;">
                  <button class="button_search" @click="search()">查 询</button>
                  <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  :show-component="['company']" :initres="$parent.$parent.initres"  @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>
                <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"
                         condition="f_userinfo_code = '{}'" placeholder='客户编号'>
                </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_user_name"
                         condition="f_user_name like '%{}%'" placeholder='客户姓名'>
                </div>
                <div :class="$parent.$parent.styles">
                  <label class="font_normal_body">审核状态</label>
                  <v-select id="f_user_tye"
                            v-model="model.audit_state"
                            placeholder='审核状态'
                            style="width: 60%"
                            :value-single="true"
                            :value.sync="model.audit_state"
                            :options='$parent.$parent.f_audit_state'
                            condition="audit_state ='{}'"
                            close-on-select></v-select>
                </div>
                <div :class="$parent.$parent.styles">
                  <label class="font_normal_body">审核人&nbsp;&nbsp;&nbsp;</label>
                  <input type="text" class="input_search"  style="width: 60%" v-model="model.f_audit_operator"
                         condition="f_audit_operator like '%{}%'" placeholder='审核人'>
                </div>
                <div :class="$parent.$parent.styles">
                  <label class="font_normal_body" for="f_meter_classify">气表类型</label>
                  <v-select :options='$parent.$parent.meterType'
                            :value.sync="model.f_meter_classify"
                            close-on-select condition="f_meter_classify = '{}'"
                            placeholder='气表类型' value-single="true"
                            style="width: 60%"  v-model="model.f_meter_classify"></v-select>
                </div>
                <div :class="$parent.$parent.styles">
                  <label class="font_normal_body" for="f_gasbrand">气表品牌</label>
                  <v-select :value.sync="model.f_gasbrand"
                            :options='$parent.$parent.getMeterBrands(model.f_meter_classify)'
                            placeholder='气表品牌' close-on-select
                            condition="f_meter_brand = '{}'"
                            search v-model='model.f_gasbrand' v-ref:brand></v-select>
                </div>
              </div>
            </div>
          </criteria>
          <data-grid :model="model" v-ref:grid class="list_area table_sy" partial='list'>
            <template partial='head'>
              <tr>
                <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;"><nobr>{{$index + 1}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_userinfo_code}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_user_name}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_address}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_latefee_audit}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_last_balance}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_balance}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.audit_state}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_operator}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_depname}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_orgname}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_audit_date}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.audit_comments}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_audit_operator}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_audit_depname}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_audit_orgname}}</nobr></td>

              <td style="text-align: center;"><nobr>
                <button v-if="row.fileid" class="btn btn-link" @click.stop="$parent.$parent.$parent.view(row)">查看</button>
              </nobr></td>
            </template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>

</template>

<script>
  import {PagedList} from 'vue-client'
const myMap = new Map()
  export default {
    'title': '审核列表',
    data () {
      return {
        model: new PagedList('rs/sql/getAudit', 20,{tablename: `'${this.tablename}'`}),
        pj: this.$appdata.getParam('是否有附件') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('是否有附件')] : [],
        // 控制查询条件显示
        searchshow: true,
        f_audit_state: [{label: '全部', value: ''}, {label: '待审核', value: '待审核'}, {label: '通过', value: '通过'}, {label: '不通过', value: '不通过'}, {label: '其他', value: 'is null'}],
        // 公司下拉
        initres: {
          org: [this.$login.f.orgid],
          dep: [],
          user: []
        },
        allorgid: [],
        f_orgid: '',
        criteriaShow: false,
        meterType: [{label: '金额卡表', value: '金额卡表'}, {label: '气量卡表', value: '气量卡表'}, {label: '机表', value: '机表'}, {label: '物联网表', value: '物联网表'}],
        orgCondtionStr: ''
      }
    },
    async ready () {
      this.$refs.paged.$refs.criteria.model.f_startDate = this.$login.toStartAndEndDateString()[0] + ' 00:00:00'
      this.$refs.paged.$refs.criteria.model.f_endDate = this.$login.toStandardDateString() + ' 23:59:59'
      // this.$refs.paged.$refs.criteria.model.audit_state='待审核'
      this.search()
      await this.getinputtores()
    // this.getwarehouse()
  },
    props: ['showMessage','type','tablename','styles'],
    methods: {
      async getRes (condition, obj) {
        this.orgCondtionStr = condition
      },
      getMeterBrands (meterType) {
        let res = []
        if (meterType.length > 0) {
          this.meterbrands.forEach((item) => {
            if (item.value.f_meter_type === meterType[0]) {
              res.push({label: item.value.f_meter_brand, value: item.value.f_meter_brand})
            }
          })
        }
        return res
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      view (row) {
        this.$dispatch('showupload',row)
      },

      search () {
        this.$refs.paged.$refs.criteria.search()
      },
      importFile () {
        this.show = true
      },
      selfSearch (args) {
        if (!this.f_orgid) {
          this.f_orgid = this.$login.f.orgid
        }
        let f_orgstr = this.orgCondtionStr ? this.orgCondtionStr : "and f_orgid in ('" + this.f_orgid + "')"
        args.condition = `${args.condition} and autid_type='${this.type}'` + f_orgstr
        this.model.search(args.condition, args.model)
      },
      // 多选框初始化
      selectInit () {
        this.rowsdata = []
        this.all = []
        this.radio = []
      }
    },
    watch: {
      async 'orgCondtionStr' (val) {
        let res = val.match(/'(.*?)'/)
        console.log('正则提取:', res && res[1])
        if (res) {
          this.f_filialeid = res[1]
          if (res.input != null) {
            let resorgid = res.input.substring(res.input.indexOf("'"))
            if (resorgid != null && resorgid != '') {
              resorgid = resorgid.substring(0, resorgid.lastIndexOf("'") + 1)
            // resorgid = resorgid.replaceAll("'","");
              resorgid = resorgid.replace(/'/g, '')
              this.allorgid = resorgid.split(',')
            }
          }
          this.updateParams()
        }
      }
    },
    computed: {

    }
  }
</script>
<style>
  .datapanel {
    color: #333;
    background-color: white;
    padding: 10px 20px;
    border-radius: 15px;
  }
</style>
