<template>
  <el-dialog
    title="修改过闸次数"
    :visible.sync="visible"
    width="900px"
    @close="handleClose">
    <div class="table-box">
      <div class="block-title">
        会员景点过闸次数
      </div>
      <el-table
        ref="dataTable"
        border
        stripe
        :row-key="(row) => row.id"
        v-loading="loading"
        :data="memberScenics">
        <el-table-column
          prop="id"
          label="编号">
        </el-table-column>
        <el-table-column
          prop="member_id"
          label="会员ID">
        </el-table-column>
        <el-table-column
          prop="scenic_name"
          label="景区">
        </el-table-column>
        <el-table-column
          prop="checked_times"
          label="过闸次数">
          <template slot-scope="props">
            <el-input-number
              style="width:100px; display:flex"
              v-model="props.row.checked_times"
              :min="0"
              :precision="0"
              :controls="false"
              size="normal"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column
          label="上次过闸时间">
          <template slot-scope="props">
            {{ props.row.last_checkTime | formatTime }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <span slot="footer">
      <el-button @click="handleClose">取消</el-button>
      <el-button
        type="primary"
        @click="submit">提交</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { updateCheckTimes } from '@/api/member'
export default {
  components: {
  },
  data () {
    return {
      loading: false,
      visible: false,
      memberScenics: [],
      form: {
        checked_times: ''
      }
    }
  },
  watch: {
    visible (val) {

    }
  },
  methods: {
    show (data) {
      this.visible = true

      this.memberScenics = data.memberScenics
    },
    handleSelectionChange (val) {
      this.multipleSelection = val
    },
    handleClose () {
      this.visible = false
      this.$refs.dataTable.clearSelection()
      this.$refs.form.resetFields()
    },
    submit () {
      const params = this.memberScenics.map((i) => {
        return {
          member_id: i.member_id,
          scenic_id: i.scenic_id,
          checked_times: i.checked_times }
      })

      updateCheckTimes(params).then(res => {
        this.$message.success('修改成功')
        this.$emit('updateList')
        this.handleClose()
      }).catch(err => {
        console.error(err)
      })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
