<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="col-sm-2 form-group">
                  <label class="font_normal_body">组织机构</label>
                  <res-select :initresid='$parent.$parent.curorgid'
                              @res-select="$parent.$parent.getorg"
                              class="select select_list"
                              restype='organization'
                              style="width: 60%">
                  </res-select>
                </div>
                <div class="col-sm-2 form-group">
                  <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="col-sm-2 form-group">
                  <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 = '{}'" placeholder='客户姓名'>
                </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">-->
<!--                <div class="col-sm-2 form-group">-->
<!--                  <label class="font_normal_body">是否缴费</label>-->
<!--                  <v-select id="f_user_tye"-->
<!--                            v-model="model.f_whether_pay"-->
<!--                            placeholder='是否缴费'-->
<!--                            style="width: 60%"-->
<!--                            :value.sync="model.f_whether_pay"-->
<!--                            :options='$parent.$parent.whetherPay'-->
<!--                            condition="f_whether_pay = '{}'"-->
<!--                            close-on-select></v-select>-->
<!--                </div>-->
<!--                <div class="col-sm-2 form-group">-->
<!--                  <label class="font_normal_body">审核状态</label>-->
<!--                  <v-select id="f_user_tye"-->
<!--                            v-model="model.f_audit_state"-->
<!--                            placeholder='审核状态'-->
<!--                            style="width: 60%"-->
<!--                            :value.sync="model.f_audit_state"-->
<!--                            :options='$parent.$parent.f_audit_state'-->
<!--                            condition="f_audit_state {}"-->
<!--                            close-on-select></v-select>-->
<!--                </div>-->
<!--                <div class="col-sm-2 form-group">-->
<!--                  <label class="font_normal_body">审核人&nbsp;&nbsp;&nbsp;</label>-->
<!--                  <input type="text" class="input_search"  style="width: 60%" v-model="model.f_audit_person"-->
<!--                         condition="f_audit_person like '%{}%'" placeholder='客户姓名'>-->
<!--                </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>
                <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_card_id}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_total_gas}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_pregas}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_preamount}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_times}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_last_tablebase}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_curbalance}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_comments}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_othereason}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_type}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_operate_date}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_state}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_meter_brand}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_write_card}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_write_date}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_depname}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_write_operator}}</nobr></td>
              <td style="text-align: center;"><nobr>
                <button v-if="row.is_has_file=='是'" class="btn btn-link" @click.stop="$parent.$parent.$parent.view(row)">查看</button>
                <button v-if="row.f_notified_path" class="btn btn-link" @click.stop="$parent.$parent.$parent.imgShow(row.f_notified_path)">图像识别</button>
              </nobr></td>
            </template>
          </data-grid>
        </criteria-paged>
        <split-price :showdata="splitdata" :pricesplit="priceSplit" v-if="priceSplit" ></split-price>
      </div>
    </div>
  </div>
  <modal :show.sync="imgshow" v-ref:modal backdrop="true">
    <header slot="modal-header" class="modal-header">
      补气图像识别照片
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="from-group">
        <img-self :src="imgfilename"   width="500" height="500"></img-self>
      </div>
    </article>
    <footer slot="modal-footer" class="modal-footer">
      <button type="button" class="btn btn-success" @click='imgclose'>关闭</button>
    </footer>
  </modal>
</template>

<script>
  import {PagedList} from 'vue-client'
const myMap = new Map()

  export default {
    'title': '111',
    data () {
      return {
        model: new PagedList('rs/sql/fillgasFiles', 20),
        pj: this.$appdata.getParam('是否有附件') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('是否有附件')] : [],
        // 控制查询条件显示
        searchshow: true,
        whetherPay: [{label: '全部', value: ''}, {label: '是', value: '是'}, {label: '否', value: '否'}],
        f_audit_state: [{label: '全部', value: ''}, {label: '已审核', value: `= '已审核'`}, {label: '审核中', value: `= '审核中'`}, {label: '其他', value: 'is null'}],
        da: {
          rows: []
        },
        f_meternumber: '',
        splitdata: '',
        // 公司下拉
        curorgid: [this.$login.f.orgid],
        f_orgid: '',
        priceSplit: false,
        criteriaShow: false,
        imgshow: false,
        imgfilename: ''
      }
    },
    ready () {
      this.search()
      // this.getwarehouse()
    },
    props: ['showMessage'],
    methods: {
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
        this.f_filialeid = val[0]
      },
      imgclose () {
        this.imgshow = false
      },
      imgShow (val) {
        this.imgfilename = `rs/image/file/` + val
        this.imgshow = true
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      fileterprice (row) {
        this.splitdata = row
        this.priceSplit = true
        console.log('row==>', row)
      },
      init () {
        this.f_meternumber = ''
        this.da.rows = []
        myMap.clear()
      },
      view (row) {
        this.$parent.showupload = true
        this.$parent.row = row
      },
      cancelSet () {
        this.showSetModal = false
        this.init()
      },

      jump () {
        this.joinshow2 = false
        this.showSetModal = true
      },
      async getwarehouse () {

      },

      join1 (row) {
        this.joinrow = row
        this.joinshow = true
      },

      joinclose () {
        this.joinshow = false
      },
      joinclose2 () {
        this.joinshow2 = false
      },

      search () {
        this.$refs.paged.$refs.criteria.search()
      },
      importFile () {
        this.show = true
      },
      selfSearch (args) {
        if (!this.f_orgid) {
          this.getorg([this.$login.f.orgid])
        }
        console.log('查询。。。', this.f_orgid)
        if (this.f_orgid) {
          args.condition = `${args.condition} and f_orgid  in ${this.f_orgid}`
        }
        this.model.search(args.condition, args.model)
      },
      mergeRowData (joinrows) {

      },
      // 多选框初始化
      selectInit () {
        this.rowsdata = []
        this.all = []
        this.radio = []
      },
      select () {
        let index = this.model1.pageIndex - 1
        console.log('全选', this.all[index])
        if (!this.radio[index]) {
          this.radio.$set(index, [])
        }
        if (this.all[index]) {
          // 数据
          this.rowsdata[index] = Object.assign([], this.model1.rows)
          // 勾选
          for (var i = 0; i < this.model1.rows.length; i++) {
            this.radio[index].$set(i, true)
          }
        } else {
          // 数据
          this.rowsdata[index] = []
          // 不勾选
          for (var i = 0; i < this.model1.rows.length; i++) {
            this.radio[index].$set(i, false)
          }
        }
      },
      selectOne (event, row, i) {
        console.log('单选', event.target.checked)
        let index = this.model1.pageIndex - 1
        if (!this.rowsdata[index]) {
          this.rowsdata[index] = []
        }
        if (!this.radio[index]) {
          this.radio.$set(index, [])
        }
        if (event.target.checked) {
          // 数据
          this.rowsdata[index][i] = row
          // 勾选
          this.radio[index].$set(i, true)
          // 判断是否全部选中
          var allState = true
          if (this.model1.rows.length != this.radio[index].length) {
            allState = false
          }
          for (var state of this.radio[index]) {
            if (!state) {
              allState = false
            }
          }
          if (allState) {
            this.all.$set(index, true)
          } else {
            this.all.$set(index, false)
          }
        } else {
          // 数据
          this.rowsdata[index][i] = []
          // 不勾选
          this.radio[index].$set(i, false)
          // 任意取消一个则全选状态设为false
          this.all.$set(index, false)
        }
      }
    },
    computed: {
      ischecked () {
        return function (index, i) {
          // console.log("计算属性")
          if (!this.radio[index]) {
            return false
          }
          return this.radio[index][i]
        }
      },
      distributionstate () {
        return [{label: '全部', value: ''}, {label: '待分配', value: 'is null'}, {label: '已入库', value: 'is not null'}]
      }
    }
  }
</script>
<style>
  .datapanel {
    color: #333;
    background-color: white;
    padding: 10px 20px;
    border-radius: 15px;
  }
</style>

