<template>
  <el-button :type="type"   :disabled="!content.ID||(content.isLock=='Y'&&content.lockUser!=userName)" @click="lock" :priv="'com.zving.cms.Catalog.Content.Edit.'+catalogId">
    <span v-show="content.isLock=='Y'">
      <i class="fa fa-unlock-alt" style="padding-right:8px;padding-left:2px;"></i><span>解锁</span>
    </span>
    <span v-show="content.isLock!='Y'">
      <i class="fa fa-lock" style="padding-right:8px;padding-left:2px;"></i><span>锁定编辑</span>
    </span>
  </el-button>
</template>
<script>
import util from '@src/common/util.js'
export default {
  props: {
    content: {
      type: Object
    },
    catalogId: {
      type: [Number, String]
    },
    type: {
      type: [Number, String],
      default: ''
    }
  },
  data() {
    return {
      userName: localStorage.userName
    }
  },
  methods: {
    async lock() {
      let lockApi = `/ui/contentcore/contents/${this.content.ID}/lock`
      let resp = await (this.content.isLock === 'Y' ? axios.delete(lockApi) : axios.put(lockApi))
      util.showResponseMessage(resp.data)
      if (resp.data.status === 1) {
        this.content.isLock = (this.content.isLock === 'Y') ? 'N' : 'Y'
        this.$emit('refresh-content', this.content.ID)
      }
    }
  }
}
</script>
