<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="form-group col-sm-2">
                  <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="form-group col-sm-2">
                  <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 like '%{}%'" placeholder='用户编号'>
                </div>
                <div
                  class="form-group col-sm-2">
                  <label class="font_normal_body">用户姓名</label>
                  <input type="text" class="input_search"  style="width: 60%" v-model="model.id"
                         condition="f_user_name = '{}'" placeholder='用户姓名'>
                </div>
                <div
                  class="form-group col-sm-2">
                  <label class="font_normal_body">是否限购</label>
                  <v-select :disabled=false
                            :options='$parent.$parent.limitstate'
                            :value-single="true"
                            :value.sync="model.limit_state"
                            close-on-select
                            placeholder='请选择'
                            v-model="model.limit_state"
                            condition="limit_state = '{}'"
                            search=fasle
                  >
                  </v-select>
                </div>
                <div style="float:right;margin-top: 8px" class="span">
                  <button class="button_spacing button_search" @click="$parent.$parent.updateAll()">设置限购</button>
                  <button class="button_spacing button_search" @click="$parent.$parent.cancelAll()">取消限购</button>
                  <button class="button_spacing button_search" @click="search()">查 询</button>
                  <export-excel
                    :data="{condition: $parent.$parent.condition}"
                    :field="$parent.$parent.getfield"
                    sqlurl="rs/logic/saleExport" sql-name="getlimit" template-name='限购管理'
                    :choose-col="true">
                  </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-if="$parent.$parent.criteriaShow">
                <div
                  class="form-group col-sm-2">
                  <label class="font_normal_body">表&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</label>
                  <input type="text" class="input_search"  style="width: 60%" v-model="model.f_user_name"
                         condition="f_meternumber like '%{}%'" placeholder='表号'>
                </div>
                <div
                  class="form-group col-sm-2">
                  <label class="font_normal_body">客户类型</label>
                  <v-select :value.sync="model.f_user_type" v-model="model.f_user_type"
                            :options='$parent.$parent.usertypes' placeholder='客户类型'
                            style="width:60%"
                            close-on-select
                            condition="f_user_type = '{}'"></v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">小&ensp;&ensp;&ensp;&ensp;区</label>
                  <v-select :value.sync="model.f_residential_area"
                            class="select_list select"
                            condition="f_residential_area in {}"
                            v-model="model.f_residential_area"
                            style="width: 60%"
                            multiple="true"
                            :options='$parent.$parent.residentialArea' placeholder='选择小区'
                            close-on-select v-el:cc>
                  </v-select>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">楼&emsp;&emsp;栋</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_building"
                         condition="f_building like '%{}%'" placeholder='楼栋'>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">单&emsp;&emsp;元</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_unit"
                         condition="f_unit like '%{}%'" placeholder='单元'>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">楼&emsp;&emsp;层</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_floor"
                         condition="f_floor like '%{}%'" placeholder='楼层'>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">门&ensp;牌&ensp;号</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_room"
                         condition="f_room like '%{}%'" placeholder='门牌号'>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">客户地址</label>
                  <input type="text" style="width:60%" class="input_search" v-model="model.f_address"
                         condition="f_address like '%{}%'" placeholder='客户地址'>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">气表品牌</label>
                  <v-select id="f_meter_brand"
                            v-model="model.f_meter_brand"
                            placeholder='气表品牌'
                            :value.sync="model.f_meter_brand"
                            :options='$parent.$parent.meterbrand'
                            condition="f_meter_brand = '{}'"
                            close-on-select style="width: 60%"></v-select>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">气价名称</label>
                  <v-select id="f_price_name"
                            v-model="model.f_price_name"
                            placeholder='气价名称'
                            :value.sync="model.f_price_name"
                            :options='$parent.$parent.price'
                            condition="f_price_name = '{}'"
                            close-on-select style="width: 60%"></v-select>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">客户状态</label>
                  <v-select id="f_user_state"
                            v-model="model.f_user_state"
                            placeholder='客户状态'
                            :value.sync="model.f_user_state"
                            :options='$parent.$parent.userStates'
                            condition="f_user_state = '{}'"
                            close-on-select style="width: 60%"></v-select>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">用气性质</label>
                  <v-select id="f_gasproperties"
                            v-model="model.f_gasproperties"
                            placeholder='用气性质'
                            :value.sync="model.f_gasproperties"
                            :options='$parent.$parent.gasproperties'
                            condition="f_gasproperties = '{}'"
                            close-on-select style="width: 60%"></v-select>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">限购原因</label>
                  <v-select id="f_price_name"
                            v-model="model.f_operate_reason"
                            placeholder='限购原因'
                            :options='$parent.$parent.operatereasons'
                            :value.sync="model.f_operate_reason"
                            condition="f_operate_reason like '%{}%'"
                            close-on-select style="width: 60%"></v-select>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">限购时间</label>
                  <datepicker placeholder="限购开始日期"
                              :value.sync="model.f_start_date"
                              v-model="model.f_start_date"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              condition="f_start_date >= '{}'"
                  ></datepicker>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">限购时间</label>
                  <datepicker placeholder="限购结束时间"
                              :value.sync="model.f_start_end"
                              v-model="model.f_start_end"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              condition="f_start_date <= '{}'"
                  ></datepicker>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">操作时间</label>
                  <datepicker placeholder="操作起始时间"
                              :value.sync="model.f_operate_date"
                              v-model="model.f_operate_date"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              condition="f_operate_date >= '{}'"
                  ></datepicker>
                </div>
                <div class="form-group col-sm-2">
                  <label class="font_normal_body">操作时间</label>
                  <datepicker placeholder="操作结束时间"
                            :value.sync="model.f_operate_end"
                            v-model="model.f_operate_end"
                            :format="'yyyy-MM-dd HH:mm:ss'"
                            condition="f_operate_date <= '{}'"></datepicker>
                </div>
              </div>
            </div>
          </criteria>
          <data-grid :model="model" v-ref:grid class="list_area table_sy" partial='list'>
            <template partial='head'>
              <tr>
                <th>
                  <nobr>
                  <input @keyup.enter="search" style="width:60%" type="checkbox" v-model='checked1' :checked="$parent.$parent.$parent.checked1"
                         @click="$parent.$parent.$parent.checkedALL()">全选</nobr></th>
                <th><nobr>用户编号</nobr></th>
                <th><nobr>用户姓名</nobr></th>
                <th><nobr>地址</nobr></th>
                <th><nobr>表号</nobr></th>
                <th><nobr>气表类型</nobr></th>
                <th v-if="!$parent.$parent.$parent.editList"><nobr>气表品牌</nobr></th>
                <th v-if="!$parent.$parent.$parent.editList"><nobr>气表型号</nobr></th>
                <th><nobr>气价名称</nobr></th>
                <th><nobr>用户类型</nobr></th>
                <th><nobr>用气性质</nobr></th>
                <th><nobr>限购原因</nobr></th>
                <th v-if="!$parent.$parent.$parent.editList"><nobr>所属部门</nobr></th>
                <th v-if="!$parent.$parent.$parent.editList"><nobr>所属公司</nobr></th>
                <th v-if="!$parent.$parent.$parent.editList"><nobr>限购状态</nobr></th>
                <th v-if="!$parent.$parent.$parent.editList"><nobr>查看历史</nobr></th>
              </tr>
            </template>
            <template partial='body'>
              <td style="text-align: center;">
                <input @keyup.enter="search" style="width:60%" type="checkbox" checked="checked" name="opertioninput"
                       @click="$parent.$parent.$parent.checked(row)"></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_meternumber}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_meter_type}}</nobr></td>
              <td style="text-align: center;" v-if="!$parent.$parent.$parent.editList"><nobr>{{row.f_meter_brand}}</nobr></td>
              <td style="text-align: center;" v-if="!$parent.$parent.$parent.editList"><nobr>{{row.f_meter_style}}</nobr></td>
              <td style="text-align: center;"><nobr>{{row.f_price_name}}</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_operate_reason}}</nobr></td>
              <td style="text-align: center;" v-if="!$parent.$parent.$parent.editList"><nobr>{{row.f_depname}}</nobr></td>
              <td style="text-align: center;" v-if="!$parent.$parent.$parent.editList"><nobr>{{row.f_orgname}}</nobr></td>
              <td style="text-align: center;" v-if="!$parent.$parent.$parent.editList"><nobr>
                {{row.limit_state}}
              </nobr></td>
              <td style="text-align: center;" v-if="!$parent.$parent.$parent.editList">
                <button type="button" name="button" class="button_search-2 button_spacing width-60"
                        @click.stop="$parent.$parent.$parent.showhistory(row)">查看</button>
              </td>
            </template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
  <limit-gas :show.sync="updateall"
             @limit="setLimitGas"></limit-gas>
  <modal  :show.sync="show" width="1200px" backdrop="true">
    <article slot="modal-body"  class="modal-body"  title="变更记录" style="height: 500px">
      <data-grid :model="history" style="height: 500px" class="list_area table_sy"  partial='list' v-ref:grid >
        <template partial='head'>
          <tr>
            <th style="white-space: nowrap;" ><nobr>限购类型</nobr></th>
            <th style="white-space: nowrap;" ><nobr>支付限制</nobr></th>
            <th style="white-space: nowrap;" ><nobr>周期类型</nobr></th>
            <th style="white-space: nowrap;" ><nobr>限购开始时间</nobr></th>
            <th style="white-space: nowrap;" ><nobr>限购量</nobr></th>
            <th style="white-space: nowrap;" ><nobr>当前状态</nobr></th>
            <th style="white-space: nowrap;" ><nobr>限购原因</nobr></th>
            <th style="white-space: nowrap;" ><nobr>创建人员</nobr></th>
            <th style="white-space: nowrap;" ><nobr>创建时间</nobr></th>
            <th style="white-space: nowrap;" ><nobr>作废人员</nobr></th>
            <th style="white-space: nowrap;" ><nobr>作废时间</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="white-space: nowrap;" >{{row.f_limit_style}}</td>
            <td style="white-space: nowrap;" >{{row.f_limit_type}}</td>
            <td style="white-space: nowrap;" >{{row.f_time_type}}</td>
            <td style="white-space: nowrap;" >{{row.f_start_date}}</td>
            <td style="white-space: nowrap;" >
              <div v-if="row.f_limit_style ==='按总量' && row.f_limit_type==='金额'">限购金额：{{row.f_limit_amount}}</div>
              <div v-if="row.f_limit_style ==='按总量' && row.f_limit_type==='气量'">限购气量：{{row.f_limit_value}}</div>
              <div v-if="row.f_limit_style !=='按总量' && row.f_limit_type==='气量'">限购{{row.f_limit_times}}次，每次最多{{row.f_limit_value}}方</div>
              <div v-if="row.f_limit_style !=='按总量' && row.f_limit_type==='金额'">限购{{row.f_limit_times}}次，每次最多{{row.f_limit_amount}}元</div>
            </td>
            <td style="white-space: nowrap;" >
              <div v-if="row.f_state !=='无效'">使用中</div>
              <div v-else>已作废</div>
            </td>
            <td style="white-space: nowrap;" >{{row.f_operate_reason}}</td>
            <td style="white-space: nowrap;" >{{row.f_operate_people}}</td>
            <td style="white-space: nowrap;" >{{row.f_operate_date}}</td>
            <td style="white-space: nowrap;" >{{row.f_cancel_people}}</td>
            <td style="white-space: nowrap;" >{{row.f_cancle_date}}</td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </article>
    <footer slot="modal-footer" class="modal-footer">

    </footer>
  </modal>
</template>

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

  export default {
    'title': '',
    data () {
      return {
        usertypes: this.$appdata.getParam('客户类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('客户类型')] : [],
        pj: this.$appdata.getParam('是否有附件') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('是否有附件')] : [],
        model: new PagedList('rs/sql/getlimit', 20),
        // model: new PagedList('rs/sql/singleTable_OrderBy', 20, {items: '"s.*,ui.f_userinfo_code"', tablename: '"t_sellinggas s left join t_userinfo ui on s.f_userinfo_id=ui.f_userinfo_id"', orderitem: '"f_delivery_date"'}),
        // 控制查询条件显示
        searchshow: true,
        criteriaShow: false,
        // 控制样式
        editList: false,
        // 公司下拉
        curorgid: [this.$login.f.orgid],
        excelTable: true,
        condition: '',
        limitstate: [{label:'全部',value:''},{label:'已限购',value:'已限购'},{label:'未限购',value:'未限购'}],
        gasproperties: this.$appdata.getParam('用气性质') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')] : [],
        userStates: this.$appdata.getParam('用户状态') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用户状态')] : [],
        operatereasons: this.$appdata.getParam('限购原因') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('限购原因')] : [],
        limit_state: '',
        getfield: {
          'id': '收费编号',
          'f_userinfo_code': '用户编号',
          'f_user_name': '用户姓名',
          'f_payment': '收费形式',
          'f_state': '是否有效',
          'f_bill_style': '收据类型',
          'f_operate_date': '操作时间',
          'f_pregas': '购气气量',
          'f_address': '地址',
          'f_user_type': '气量用途',
          'f_preamount': '用气金额',
          'f_collection': '收费金额',
          'f_operator': '操作员',
          'f_depname': '所属部门',
          'f_user_state': '客户状态',
          'f_gasproperties': '用气性质',
          'f_operate_reason': '限购原因',
          'f_start_date': '限购日期',
          'f_orgname': '所属公司'
        },
        f_orgid: '',
        checked1: true,
        map: new Map(),
        show:false,
        updateall:false,
        history: {
          rows: []
        },
        residentialArea: [],
        meterbrand: [],
        price: [],
        da: {
          rows: []
        },
        f_meternumber: '',
        updateall:false
      }
    },
    async ready () {
      await this.$LoadParams.loadParam()
      await this.initQueryParam()
      await this.getaddress()
      this.search()
      // this.getwarehouse()
    },
    events: {
      'showfiles' (val) {
        console.log(val)
      }
    },
    props: ['showMessage'],
    methods: {
      initQueryParam () {
        let arr = []
        this.$GetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          temp.label = item.label
          temp.value = item.value.f_meter_brand
          arr.push(temp)
        })
        this.meterbrand = [{label: '全部', value: ''}, ...arr]
        let arr2 = []
        this.$GetSaleParam.prices.forEach((item) => {
          let temp = {}
          temp.label = item.f_price_name
          temp.value = item.f_price_name
          arr2.push(temp)
        })
        this.price = [{label: '全部', value: ''}, ...arr2]
      },
      async getaddress () {
        console.log('开始获取小区')
        let data = await this.$resetpost('rs/sql/manage_getarealist', {
          data: {
            condition: `1=1 and s.f_filialeid = '${this.$login.f.orgid}'`
          }
        }, {resolveMsg: null, rejectMsg: '获取小区失败!'})
        console.log('小区', data)
        let house = []
        house.push()
        for (let row of data.data) {
          console.log('开始保存小区')
          house.push({label: row.f_residential_area, value: row.f_residential_area})
        }
        this.residentialArea = house
      },
      updateAll(){
        if(this.limit_state !=='未限购'){
          this.$showAlert('请更改是否限购条件为未限购，重新查询后再进行此操作', 'warning', 2000)
          return
        }
        if(this.model.rows.length ===0){
          this.$showAlert('当前未查询出任何用户，请更改查询条件重新查询', 'warning', 2000)
          return
        }
        this.updateall = true
      },
      async showhistory(row){

        let limit = await this.$resetpost('rs/sql/singleTable_OrderBy',
          {data: {items:'*',tablename: 't_limit_gas', condition: `f_userinfo_id ='${row.f_userinfo_id}'`,orderitem:'id desc'}},
          {resolveMsg: null, rejectMsg: null})
        this.history.rows = limit.data
        this.show = true
      },
      cancelAll(){
        if(this.limit_state !=='已限购'){
          this.$showAlert('请更改是否限购条件为已限购，重新查询后再进行此操作', 'warning', 2000)
          return
        }
        if(this.model.rows.length ===0){
          this.$showAlert('当前未查询出任何用户，请更改查询条件重新查询', 'warning', 2000)
          return
        }
        this.$showMessage('确定要批量取消这些用户的限购吗？', ['confirm', 'cancel']).then(async (res) => {
          if (res === 'confirm') {
            let param = {}
            param.f_state = '无效'
            param.f_cancel_people = this.$login.f.name
            param.f_cancle_date = this.$login.toStandardTimeString()
            let array = []
            this.map.forEach((value, key, map) => {
              array.push(map.get(key))
            })
            console.log('asdasd',array)
            if (array.length>0){
              let condition = `id in (''`
              array.forEach((row) => {
                condition = condition+`,'${row.id}'`
              })
              condition = condition+ `)`

              console.log('asdasd',condition)
              param.condition= condition
              await this.$resetpost('rs/logic/cancellimitall',param)
              this.search()
            } else{
              this.$showMessage('当前未勾选用户，将取消当前页面所有查询出来的用户的限购，确定要操作吗？', ['confirm', 'cancel']).then(async (res) => {
                if (res === 'confirm') {
                  param.condition= this.condition
                  await this.$resetpost('rs/logic/cancellimitall',param)
                  this.search()
                }
              })
            }
          }
        })
      },
      async setLimitGas(val){
        console.log('asdasd',val)
        let param = val
        param.f_state = '有效'
        param.f_operate_people = this.$login.f.name
        param.f_operate_date = this.$login.toStandardTimeString()
        let array = []
        this.map.forEach((value, key, map) => {
          array.push(map.get(key))
        })
        console.log('asdasd',array)
        if (array.length>0){
          let condition = `f_userinfo_id in (''`
          array.forEach((row) => {
            condition = condition+`,'${row.f_userinfo_id}'`
          })
          condition = condition+ `)`

          console.log('asdasd',condition)
          param.condition= condition
          await this.$resetpost('rs/logic/setlimitall',param)
          this.search()
        } else{
          this.$showMessage('当前未勾选用户，将为所有查询出来的用户添加限购，确定要操作吗？', ['confirm', 'cancel']).then(async (res) => {
            if (res === 'confirm') {
              param.condition= this.condition
              await this.$resetpost('rs/logic/setlimitall',param)
              this.search()
            }
          })

        }
      },
      checkedALL () {
        this.checked1 = !this.checked1
        let box = document.getElementsByName('opertioninput')
        for (var i = 0; i < box.length; i++) {
          box[i].checked = this.checked1
        }
      },
      checked (val) {
        let f_userinfo_id = val.f_userinfo_id
        let id = val.id
        if (this.map.has(f_userinfo_id)) {
          this.map.delete(f_userinfo_id)
        } else {
          this.map.set(f_userinfo_id, {f_userinfo_id: f_userinfo_id,id:id})
        }
      },
      mapset (array) {
        this.map.clear()
        for (let i = 0; i < array.length; i++) {
          let f_userinfo_id = array[i].f_userinfo_id
          let id = array[i].id
          this.map.set(f_userinfo_id, {f_userinfo_id: f_userinfo_id,id:id})
        }
      },
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
        this.f_filialeid = val[0]
      },
      view (row) {
        this.$parent.showupload = true
        this.$parent.row = row
      },
      init () {
        this.f_meternumber = ''
        this.da.rows = []
        myMap.clear()
      },
      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.limit_state = args.model.limit_state
        this.model.search(args.condition, args.model)
        this.condition = args.condition

        this.$dispatch('listclose')
      },
      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'}]
      }
    },
    watch: {
      'model.pageIndex' () {
        this.checked1 = false
        this.mapset(this.model.rows)
        this.checkedALL()
      },
      'model.rows' () {
        this.checked1 = false
        this.mapset(this.model.rows)
        this.checkedALL()
      },
      'checked1' (val) {
        if (val) {
          this.mapset(this.model.rows)
        } else {
          this.map.clear()
        }
      }
    }
  }
</script>
<style>
  .datapanel {
    color: #333;
    background-color: white;
    padding: 10px 20px;
    border-radius: 15px;
  }
</style>
