<template>
  <div class="flex">
    <criteria-paged :model="model" v-ref:paged @sort="sort">
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row" >
            <div class="form-group col-sm-4" >
              <label class="font_normal_body">客户编号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_userinfo_code" placeholder='客户编号'
                     condition="info.f_userinfo_code = '{}'" @keyup.enter="search()">
            </div>
            <div class="form-group col-sm-4 button-range" >
              <button class="button_search" style="margin-right: 10px"  @click="search()" v-el:cba>查询</button>
              <button class="button_search" style="margin-right: 10px"  @click="$parent.$parent.autoMeterBookSort()">表箱号排序</button>
              <button class="button_search" style="margin-right: 10px"  @click="$parent.$parent.saveSort()">保存当前顺序</button>
              <button class="button_search" v-if="$parent.$parent.editsort == false" @click="$parent.$parent.editsort=true" v-el:cba>调整顺序</button>
              <button class="button_search" v-if="$parent.$parent.editsort == true" @click="$parent.$parent.saveEditSort" v-el:cba>保存顺序</button>
              <export-excel
                :data="{condition: $parent.$parent.condition,orderitem: $parent.$parent.orderitem}"
                :field="$parent.$parent.getfield"
                sqlurl="rs/logic/saleExport" sql-name="getMeterBookUser" :template-name="$parent.$parent.model.rows[0].f_book_name+'抄表册名'"
                :choose-col="true"></export-excel>
              <button class="button_export button_spacing" @click="$parent.$parent.importFile">导入</button>
              <div
                :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                @click="$parent.$parent.criteriaShow=!$parent.$parent.criteriaShow"
                class="button_spacing"
                style="float: right"></div>
            </div>
          </div>
          <div class="row" v-show="$parent.$parent.criteriaShow">
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">客户姓名</label>
              <input type="text" style="width:60%" class="input_search" v-model="model.f_user_name" placeholder='客户姓名'
                     condition="info.f_user_name = '{}'">
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">客户地址</label>
              <input type="text" style="width:60%" class="input_search" v-model="model.f_address"
                     condition="address.f_address like '%{}%'" placeholder='客户地址'>
            </div>
            <div class="col-sm-4 form-group">
              <label  class="font_normal_body">表&emsp;&emsp;号</label>
              <input style="width:60%" type="text" class="form-control" v-model="model.f_meternumber"
                     condition="uf.f_meternumber like '%{}%'" placeholder='表号'
              >
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">气表品牌</label>
              <v-select :value.sync="model.f_gasbrand_id"
                        v-model="model.f_gasbrand_id"
                        :options='$parent.$parent.meterbrands' placeholder='请选择'
                        condition="gb.f_meter_brand = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">气表类型</label>
              <v-select :value.sync="model.f_meter_type"
                        v-model="model.f_meter_type"
                        :options='$parent.$parent.meterTypes' placeholder='请选择'
                        condition="gb.f_meter_type = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">客户类型</label>
              <v-select :value.sync="model.f_user_type"
                        :options='$parent.$parent.usertypes'
                        @change="$parent.$parent.userTypeChange()"
                        placeholder='请选择' v-model="model.f_user_type"
                        condition="uf.f_user_type = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">用气性质</label>
              <v-select :value.sync="model.f_gasproperties" v-model="model.f_gasproperties"
                        :options='$parent.$parent.gasproperties' placeholder='请选择'
                        condition="uf.f_gasproperties = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">气价类型</label>
              <v-select :value.sync="model.pricetype" v-model="model.pricetype"
                        placeholder='气价类型' :options="$parent.$parent.pricetypes"
                        condition="sp.f_price_type = '{}'"
                        close-on-select v-ref:type>
              </v-select>
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">气价名称</label>
              <v-select :value.sync="model.f_price_id"
                        v-model="model.f_price_id"
                        :options="$parent.$parent.getPricenames"
                        placeholder='请选择'
                        condition="uf.f_price_id = '{}'"
                        close-on-select></v-select>
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">客户电话</label>
              <input class="input_search"
                     condition="info.f_user_phone = '{}'" placeholder='电话' style="width:60%"
                     type="text"
                     v-model="model.f_user_phone">
            </div>
            <div class="col-sm-4 form-group">
              <label  class="font_normal_body">小&emsp;&emsp;区</label>
              <input style="width:60%" type="text" class="form-control" v-model="model.f_residential_area"
                     condition="address.f_residential_area like '%{}%'" placeholder='小区'
              >
            </div>
            <div class="col-sm-4 form-group">
              <label  class="font_normal_body">楼&emsp;&emsp;栋</label>
              <input style="width:60%" type="text" class="form-control" v-model="model.f_building"
                     condition="address.f_building like '%{}%'" placeholder='楼栋'
              >
            </div>
            <div class="col-sm-4 form-group">
              <label  class="font_normal_body">单&emsp;&emsp;元</label>
              <input style="width:60%" type="text" class="form-control" v-model="model.f_unit"
                     condition="address.f_unit like '%{}%'" placeholder='单元'
              >
            </div>
            <div class="col-sm-4 form-group">
              <label  class="font_normal_body">表箱号&emsp;</label>
              <input style="width:60%" type="text" class="form-control" v-model="model.f_metertitles"
                     condition="uf.f_metertitles like '%{}%'"  placeholder='表箱号'
              >
            </div>
            <div class="col-sm-4 form-group">
              <label  class="font_normal_body">入户证号</label>
              <input style="width:60%" type="text" class="form-control" v-model="model.f_book_no"
                     condition="info.f_book_no like '%{}%'" placeholder='入户证号'
              >
            </div>
            <div class="col-sm-4 form-group">
              <label class="font_normal_body">抄&nbsp;表&nbsp;员&nbsp;</label>
              <v-select :value.sync="model.f_inputtor" v-model='model.f_inputtor'
                        style="width:60%"
                        multiple="true"
                        condition="uf.f_inputtor in {}"
                        :options='$parent.$parent.inputtores' placeholder='抄表员'
                        close-on-select
                        v-el:cc></v-select>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" class="table_sy"  partial='list' v-ref:grid>
        <template partial='head' >
          <tr>
            <th v-if="$parent.$parent.$parent.editsort"><nobr>排序</nobr></th>
            <th v-if="$parent.$parent.$parent.removebook"><nobr>移出</nobr></th>
            <th><nobr>客户编号</nobr></th>
            <th><nobr>客户名称</nobr></th>
            <th>
              <data-order field="f_address" name="客户地址"
                          :order.sync="$parent.$parent.$parent.orderFields.f_address"></data-order>
            </th>
            <th>
              <data-order field="f_street" name="街道"
                          :order.sync="$parent.$parent.$parent.orderFields.f_street"></data-order>
            </th>
            <th>
              <data-order field="f_residential_area" name="小区"
                          :order.sync="$parent.$parent.$parent.orderFields.f_residential_area"></data-order>
            </th>
            <th>
              <data-order field="f_building" name="楼栋"
                          :order.sync="$parent.$parent.$parent.orderFields.f_building"></data-order>
            </th>
            <th>
              <data-order field="f_unit" name="单元"
                          :order.sync="$parent.$parent.$parent.orderFields.f_unit"></data-order>
            </th>
            <th>
              <data-order field="f_floor" name="楼层"
                          :order.sync="$parent.$parent.$parent.orderFields.f_floor"></data-order>
            </th>
            <th>
              <data-order field="f_room" name="房间号"
                          :order.sync="$parent.$parent.$parent.orderFields.f_room"></data-order>
            </th>
            <th><nobr>客户电话</nobr></th>
            <th><nobr>表号</nobr></th>
            <th>
              <data-order field="f_meter_book_sort" name="册内排序"
                          :order.sync="$parent.$parent.$parent.orderFields.f_meter_book_sort"></data-order>
            </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' >
          <tr>
            <td style="text-align:center" v-if="$parent.$parent.$parent.editsort">
              <nobr>
                <span class="glyphicon glyphicon-arrow-up" @click="$parent.$parent.$parent.sortUp($index, row)" v-el:cba></span>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <span class="glyphicon glyphicon-arrow-down"  @click="$parent.$parent.$parent.sortDown($index, row)" v-el:cba></span>
              </nobr>
            </td>
            <td style="text-align:center" v-if="$parent.$parent.$parent.removebook">
              <nobr>
                <span title="移出表册" class="glyphicon glyphicon-paste"  style="font-size: 20px" @click="$parent.$parent.$parent.delete($index, row)" v-el:cba></span>
<!--                <button class="btn btn-deltete width-10" @click="$parent.$parent.$parent.delete($index, row)"><a style="color: #e51a1abf"><b>移出表册</b></a></button>-->
              </nobr>
            </td>
            <td style="text-align:center"><nobr><span @click="$parent.$parent.$parent.dealmsg(row)"><a><b>{{row.f_userinfo_code}}</b></a></span></nobr></td>
            <td style="text-align:center"><nobr>{{row.f_user_name}}</nobr></td>
            <td style="text-align:center;white-space: nowrap;"><nobr>{{row.f_address}}</nobr></td>
            <td style="text-align:center;white-space: nowrap;"><nobr>{{row.f_street}}</nobr></td>
            <td style="text-align:center;white-space: nowrap;"><nobr>{{row.f_residential_area}}</nobr></td>
            <td style="text-align:center;white-space: nowrap;"><nobr>{{row.f_building}}</nobr></td>
            <td style="text-align:center;white-space: nowrap;"><nobr>{{row.f_unit}}</nobr></td>
            <td style="text-align:center;white-space: nowrap;"><nobr>{{row.f_floor}}</nobr></td>
            <td style="text-align:center;white-space: nowrap;"><nobr>{{row.f_room}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_user_phone}}</nobr></td>
            <td style="text-align:center;white-space: nowrap;"><nobr>{{row.f_meternumber}}</nobr></td>
            <td style="text-align:center;"><nobr>{{row.f_meter_book_sort}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_book_name}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_inputtor}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_metertitles}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_book_no}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_meter_base}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_user_type}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_gasproperties}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_meter_brand}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_meter_style}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_hand_date}}</nobr></td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
  <modal :show.sync="sortShow" width="500px" title="修改册内排序" v-ref:modal large backdrop="false">
    <article slot="modal-body" class="modal-body">
      <div>
        <div class="row app-row">
          <p class="col-sm-6">客户编号:{{row.f_userinfo_code}}</p>
          <p class="col-sm-6">客户姓名:{{row.f_user_name}}</p>
          <p class="col-sm-6">所在表册:{{row.f_book_name}}</p>
          <p class="col-sm-6">册内排序:{{row.f_meter_book_sort}}</p>
          <label for="f_plan_name" class="font text-left">目标用户编号:</label>
          <input type="text" @change="getBook()" class="search_input input-font"  v-model="fileinfo.code" placeholder='目标用户编号'
          >
        </div>
        <div class="row app-row" v-show="fileinfo.meterbook && fileinfo.sort">
          <p class="col-sm-6">表册:{{fileinfo.meterbook}}</p>
          <p class="col-sm-6">册内排序:{{fileinfo.sort}}</p>
        </div>
        <div class="row app-row">
          <div class="col-sm-6" style="text-align: center;">

            <button type="button" class="button_search" style="width:40%;background-color: #499EDF;color:#f2f6fa" :disabled="!(fileinfo.meterbook && fileinfo.sort)" @click="sortEdit(0)"><img src="./../../../../static/images/meterBook/up.png"  style="width: 20%;margin-left:-10px"></img>&nbsp;前</button>
          </div>
          <div class="col-sm-6" style="text-align: center;">
            <button type="button" class="button_search" style="width:40%;background-color: #499EDF;color:#f2f6fa" :disabled="!(fileinfo.meterbook && fileinfo.sort)" @click="sortEdit(1)">后&nbsp;<img src="./../../../../static/images/meterBook/down.png"  style="width: 20%;"></img></button>
          </div>
        </div>
      </div>


    </article>
    <footer slot="modal-footer" class="modal-footer" v-show="false">

    </footer>
  </modal>
  <modal :show.sync="show" width="800px" title="文件导入" v-ref:modal large backdrop="false">
    <article slot="modal-body" class="modal-body">
      <file-upload class="my-file-uploader " name="UploadFile"  style="border-radius: 2px;"
                   action="rs/file/uploadFile" tagname="导入表册用户" v-ref:file  multiple></file-upload>
    </article>
    <footer slot="modal-footer" class="modal-footer">
    </footer>
  </modal>
</template>

<script>
  import {HttpResetClass, PagedList} from 'vue-client'
  let readyGen = async function (self) {
    self.getfield = self.config.excelHeaders
    //   await this.$LoadParams.loadParam(this.f_filialeid)
    self.search()
    await self.$LoadParams.loadParam()
    self.initParams()
  }

  export default {
    title: '',
    data () {
      return {
        model: new PagedList('rs/sql/getMeterBookUser', 20, {orderitem: this.orderitem ? '"' + this.orderitem + ' "' : `'f_meter_book_sort asc'`}),
        condition: '',
        getfield: {},
        show: false,
        removebook: true,
        row: null,
        sortShow: false,
        fileinfo: {
          code: null,
          meterbook: null,
          booknum: null,
          sort: null,
          fileid: null,
          infoid: null
        },
        gasproperties: [],
        f_filialeid: this.$login.f.orgid,
        newinfo: {
          f_user_type: '',
          f_gasproperties: '',
          pricetype: '',
          bookname: '',
          f_perform_date: this.$login.toStandardDateString() + ' 00:00:00' // 操作时间
        },
        meterbrands: [],
        adjustables: [],
        meterstyle: {},
        criteriaShow: false,
        editsort: false,
        // 排序
        sortitem: 'f_meter_book_sort',
        rule: 'asc',
        orderitem: 'f_meter_book_sort asc',
        orderFields: {
          f_meter_book_sort: 'no'
        },
        config: {
          excelHeaders: {
            'f_userfiles_id': '系统识别号',
            'f_book_name': '抄表册名称',
            'f_userinfo_code': '客户编号',
            'f_user_name': '客户姓名',
            'f_user_phone': '客户电话',
            'f_meternumber': '表号',
            'f_address': '客户地址',
            'f_inputtor': '抄表员',
            'f_meter_book_sort': '册内排序',
            'f_metertitles': '表箱号',
            'f_meter_base': '表底数',
            'f_user_type': '用户类型',
            'f_gasproperties': '用气类型',
            'f_meter_classify': '气表品牌',
            'f_gasmodel_id': '气表型号',
            'f_hand_date': '抄表日期'
          }
        }
      }
    },
    props: ['f_meterbook_num', 'usercount'],
    async ready () {
      readyGen(this)
    },
    methods: {
      sort (field, rule) {
        // 将所有排序方式设为不排序，实现相互排斥
        for (let key in this.orderFields) {
          if (key === field) {
            this.orderFields[key] = rule
          } else {
            this.orderFields[key] = 'no'
          }
        }
        // 如果新规则不排序，还原为默认排序
        if (rule === 'no') {
          this.model.paramSource.orderitem = `'f_meter_book_sort asc'`
          this.rule = 'asc'
          this.sortitem = 'f_meter_book_sort'
        } else {
          this.model.paramSource.orderitem = `'${field} ${rule}'`
          this.orderitem = this.model.paramSource.orderitem
          this.rule = rule
          this.sortitem = field
        }
        this.search()
      },
      async saveSort () {
        if (!this.$login.r.find(value => value == '册内用户排序')) {
          this.$showMessage('你没有【册内用户排序】的权限,请联系管理员!')
          return
        }
        if (this.model.count < this.usercount) {
          this.$showAlert('该功能适用于给表册内所有用户排序的情况，请去掉查询条件', 'warning', 3000)
        } else {
          this.$showMessage('此操作会将表册内用户按照现有查询结果的顺序排序，是否继续', ['confirm', 'cancel']).then((res) => {
            if (res == 'confirm') {
              this.$resetpost('rs/logic/changeBookSort',
                {
                  data: {
                    f_meter_book_num: this.f_meterbook_num,
                    sortitem: this.sortitem,
                    rule: this.rule
                  }
                }, {resolveMsg: '已成功修改册内排序！！', rejectMsg: '册内排序修改失败！！'})
              this.search()
            }
          })
        }
      },
      async autoMeterBookSort () {
        if (!this.$login.r.find(value => value == '册内用户排序')) {
          this.$showMessage('你没有【册内用户排序】的权限,请联系管理员!')
          return
        }
        this.$showMessage('请确认是否按照表箱自动排序？', ['confirm', 'cancel']).then((res) => {
          if (res == 'confirm') {
            this.$resetpost('rs/logic/autoMeterBookSort',
              {
                data: {
                  f_meter_book_num: this.f_meterbook_num,
                  sortitem: this.sortitem,
                  rule: this.rule
                }
              }, {resolveMsg: '册内排序完成！！', rejectMsg: '册内排序修改失败！！'})
            this.search()
          }
        })
      },
      importFile () {
        if (!this.$login.r.find(value => value == '表册排序导入')) {
          this.$showMessage('你没有【表册排序导入】的权限,请联系管理员!')
          return
        }
        this.show = true
      },
      async sortEdit (position) {
        if (!this.fileinfo.code) {
          this.$showMessage('请输入目标用户编号')
          return
        }
        //  position:
        //  0--将改用户的表册顺序排到目标用户前
        //  1--将改用户的表册顺序排到目标用户后
        if ((!this.fileinfo.sort) || (!this.fileinfo.booknum)) {
          this.$showMessage('目标用户无表册或在表册内无排序')
          return
        }
        let http = new HttpResetClass()
        await http.load('POST', 'rs/logic/sale_editBookSort', {data: {fileinfo: this.fileinfo, position: position, userfilesid: this.row.f_userfiles_id}}, {resolveMsg: '已成功将改表移到指定的表册位置', rejectMsg: '移动册内位置失败'})
        this.fileinfo = {
          code: null,
          fileid: null,
          booknum: null,
          meterbook: null,
          infoid: null,
          sort: null
        }
        this.sortShow = false
        this.search()
      },
      async getBook () {
        if (this.fileinfo.code) {
          let http = new HttpResetClass()
          let res = await http.load('POST', 'rs/sql/sale_getUserMeterBook', {
            data: {
              condition: `i.f_userinfo_code='${this.fileinfo.code}'`
            }
          }, {resolveMsg: null, rejectMsg: null})
          console.log('-------------------res:', res.data)
          if (res.data.length === 1) {
            if ((!res.data[0].f_meter_book_sort) || (!res.data[0].f_meter_book_num)) {
              this.$showMessage('该用户不在表册内或在表册内无排序')
              this.fileinfo = {
                code: this.fileinfo.code,
                fileid: null,
                booknum: null,
                meterbook: null,
                infoid: null,
                sort: null
              }
              return
            }
            this.fileinfo.meterbook = res.data[0].f_book_name
            this.fileinfo.sort = res.data[0].f_meter_book_sort
            this.fileinfo.fileid = res.data[0].f_userfiles_id
            this.fileinfo.infoid = res.data[0].f_userinfo_id
            this.fileinfo.booknum = res.data[0].f_meter_book_num
          } else {
            this.$showMessage('请核对输入的用户编号')
            this.fileinfo = {
              code: this.fileinfo.code,
              fileid: null,
              booknum: null,
              meterbook: null,
              infoid: null,
              sort: null
            }
          }
        }
      },
      async saveEditSort () {
        for (let item of this.$refs.paged.$refs.grid.model.rows) {
          let param = {
            f_userfiles_id: item.f_userfiles_id,
            version: item.fileversion,
            f_meter_book_sort: item.f_meter_book_sort
          }
          let http = new HttpResetClass()
          await http.load('POST', 'rs/entity/t_userfiles',
            param,
            {resolveMsg: null, rejectMsg: '保存失败'})
        }
        this.editsort = false
      },
      // 下移按钮
      sortDown (index, row) {
        if (index === (this.model.rows.length - 1)) {
          this.$showAlert('已经是本页最后一个了', 'warning', 2000)
        } else {
          let rows = this.$refs.paged.$refs.grid.model.rows
          this.$refs.paged.$refs.grid.model.rows = []
          let temp = rows[index + 1]
          rows[index + 1] = rows[index]
          rows[index] = temp
          let tempsort = rows[index + 1].f_meter_book_sort
          rows[index + 1].f_meter_book_sort = rows[index].f_meter_book_sort
          rows[index].f_meter_book_sort = tempsort
          this.$refs.paged.$refs.grid.model.rows = rows
        }
      },
      // 上移按钮
      sortUp (index, row) {
        if (index === 0) {
          this.$showAlert('已经是本页第一个了', 'warning', 2000)
        } else {
          let rows = this.$refs.paged.$refs.grid.model.rows
          this.$refs.paged.$refs.grid.model.rows = []
          let temp = rows[index - 1]
          rows[index - 1] = rows[index]
          rows[index] = temp
          console.log('--------------this.$refs.paged.$refs.grid.model.rows,', rows)
          let tempsort = rows[index - 1].f_meter_book_sort
          rows[index - 1].f_meter_book_sort = rows[index].f_meter_book_sort
          rows[index].f_meter_book_sort = tempsort
          this.$refs.paged.$refs.grid.model.rows = rows
        }
      },
      // 移出表册
      async delete (index, row) {
        let param = {
          f_userfiles_id: row.f_userfiles_id,
          version: row.fileversion,
          f_meter_book_sort: '',
          f_meter_book_num: ''
        }
        let http = new HttpResetClass()
        await http.load('POST', 'rs/entity/t_userfiles',
          param,
          {resolveMsg: null, rejectMsg: '保存失败'})
        this.$refs.paged.$refs.criteria.search()
      },
      close () {
        this.show = false
        this.newinfo = {
          f_user_type: '',
          f_gasproperties: '',
          pricetype: '',
          bookname: ''
        }
      },
      userTypeChange () {
        this.gasproperties = []
        if (this.$refs.paged.$refs.criteria.model !== null) {
          this.$refs.paged.$refs.criteria.model.f_gasproperties = ''
          this.gasproperties = this.$appdata.getParam(this.$refs.paged.$refs.criteria.model.f_user_type[0])
        } else {
          this.gasproperties = [{label: '全部', value: ''}]
        }
      },
      async initParams () {
        console.log('=================>加载', this.$GetSaleParam.getGasbrand())
        let arr = []
        let filter = this.$login.f.orgid
        this.$GetSaleParam.getAdjustable(filter).forEach((item) => {
          let temp = {}
          temp.label = `[${item.value.f_adjustable_id}]-${item.label}`
          temp.value = `${item.value.id}`
          arr.push(temp)
        })
        this.adjustables = [{label: '全部', value: ''}, ...arr]
        // 初始化气表品牌
        let brandArr = []
        this.$GetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          temp.label = item.label
          temp.value = item.value.id
          brandArr.push(temp)
          // 取出对应气表型号
          let styleArr = []
          for (let row of item.value.gasmodel) {
            styleArr.push({label: row.label, value: row.value.id})
          }
          this.meterstyle[temp.value] = styleArr
        })
        this.meterbrands = [{label: '全部', value: ''}, ...brandArr]
        // 初始化气表价格
        this.prices = this.$GetSaleParam.getPrice(filter)
      },
      sortModelval () {
        let sortModel = []
        Object.keys(this.fields).forEach((key) => {
          if (this.modelval.includes(key)) {
            sortModel.push(key)
          }
        })
        this.modelval = sortModel
        console.log('选择的打印的字段', this.modelval)
      },
      async updateParams () {
        await this.$MagLoadParams.loadParam(this.f_filialeid)
        this.initParams()
      },

      loadMeterBooks () {
        let meterbrand = this.$GetSaleParam.getGasbrand()
        for (let row of meterbrand) {
          console.log(row)
          this.meterbrands.push({label: row.label, value: row.value.id})
        }
      },
      search () {
        this.$refs.paged.$refs.criteria.search()
      },

      selfSearch (args) {
        this.editsort = false
        args.condition = `${args.condition} and f_meter_book_num = '${this.f_meterbook_num}'`
        this.condition = args.condition
        this.model.search(args.condition, args.model)
      },
      dealmsg (val) {
        this.$parent.f_userinfo_id = val.f_userinfo_id
        this.$parent.listpage = false
      }

    },
    watch: {
      'f_meterbook_num' (val) {
        this.search()
      }
    },
    events: {
      onFileUpload: function (file, res) {
        this.$resetpost('rs/logic/upLoadBookFile',
          {data: {
            condition: this.condition,
            filepath: res.f_downloadpath
          }
          },
          {resolveMsg: null, rejectMsg: '上传失败'}).then((res) => {
            this.show = false
            this.$showAlert(`导入成功`, 'success', 2000)
            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)
          }
        }
        return [ ...rs]
      },
      pricetypes () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气价类型')]
      },
      meterTypes () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')]
      },
      usertypes () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      getPricenames () {
        console.log('getPricenames======')
        let f_user_type = this.$refs.paged.$refs.criteria.model.f_user_type
        let f_gasproperties = this.$refs.paged.$refs.criteria.model.f_gasproperties
        let pricetype = this.$refs.paged.$refs.criteria.model.pricetype
        console.log('打印一下:', pricetype)
        if (this.$refs.paged.$refs.criteria.model !== null) {
          let rs = []
          let priceArr = []
          if (pricetype.length > 0 && f_user_type.length > 0 && f_gasproperties.length > 0) {
            let params = {
              f_user_type: f_user_type[0],
              f_gasproperties: f_gasproperties[0],
              f_price_type: pricetype[0]
            }
            console.log('params', params)
            console.log('getPricenames======', this.$GetSaleParam.getPrice(params))
            this.$GetSaleParam.getPrice(params).forEach((item) => {
              let temp = {}
              temp.label = item.label
              temp.value = item.value.f_price_id
              priceArr.push(temp)
            })
            rs = [ ...priceArr]
          }
          if (rs.length === 0) {
            console.log('rs读出来是空')
            this.$refs.paged.$refs.criteria.model.f_price_name = ''
          }
          return rs
        }
      }

    }

  }
</script>
