<template>
  <div class="mod--distributionBasicSet">
    <avue-crud ref="crud"
               :page="page"
               :data="dataList"
               :table-loading="dataListLoading"
               :option="tableOption"
               @search-change="searchChange"
               @on-load="getDataList"
               @refresh-change="refreshChange">
      <template slot-scope="scope"
                slot="menuLeft">

      </template>
      <template slot-scope="scope"
                slot="distributionSwitch">
        <el-tag v-if="scope.row.distributionSwitch == 0"
                type="warning"
                size="small">关闭</el-tag>
        <el-tag v-else-if="scope.row.distributionSwitch == 1"
                size="small"
                type="success">开启</el-tag>
        <el-tag v-else-if="scope.row.distributionSwitch == 2"
                type="danger"
                size="small">违规下线</el-tag>
        <el-tag v-else-if="scope.row.distributionSwitch == 3"
                type="warning"
                size="small">等待审核</el-tag>
      </template>
      <template slot-scope="scope"
                slot="parallelDeal">
        <el-tag v-if="scope.row.parallelDeal == 0"
                size="small"
                type="warning">关闭</el-tag>
        <el-tag v-else-if="scope.row.parallelDeal == 1"
                size="small"
                type="success">开启</el-tag>
      </template>
      <template slot-scope="scope"
                slot="ownBuyAward">
        <el-tag v-if="scope.row.ownBuyAward == 0"
                size="small"
                type="warning">关闭</el-tag>
        <el-tag v-else-if="scope.row.ownBuyAward == 1"
                size="small"
                type="success">开启</el-tag>
      </template>
      <template slot-scope="scope"
                slot="ownBuy">
        <el-tag v-if="scope.row.ownBuy === 0"
                size="small"
                type="warning">关闭</el-tag>
        <el-tag v-else-if="scope.row.ownBuy === 1"
                size="small"
                type="success">开启</el-tag>
      </template>
      <template slot-scope="scope"
                slot="settlementMethod">
        <el-tag v-if="scope.row.settlementMethod == 0"
                size="small"
                type="warning">关闭</el-tag>
        <el-tag v-else-if="scope.row.settlementMethod == 1"
                size="small"
                type="success">开启</el-tag>
      </template>

      <template slot-scope="scope"
                slot="menu">
        <el-button v-if="isAuth('platform:distributionBasicSet:info')"
                   icon="el-icon-edit"
                   size="small"
                   type="text"
                   @click="showSettingInfo(scope.row.basicSetId)">查看设置</el-button>
        <el-button type="text"
                   icon="el-icon-bottom"
                   size="small"
                   v-if="isAuth('platform:distributionBasicSet:update') && scope.row.distributionSwitch<2"
                   @click="offlineDistributionHandle(scope.row)">功能下线</el-button>
        <el-button type="text"
                   icon="el-icon-document-checked"
                   size="small"
                   v-if="isAuth('platform:distributionBasicSet:update') && scope.row.distributionSwitch > 1"
                   @click="distributionAuditHandle(scope.row.basicSetId)">下线管理</el-button>
        <!-- <el-button v-if="isAuth('platform:distributionBasicSet:delete')"
                   type="danger"
                   icon="el-icon-delete"
                   size="small"
                   @click="deleteHandle(scope.row.basicSetId)">删除</el-button> -->
      </template>
    </avue-crud>
    <!-- 商品审核弹窗 -->
    <DistributionAudit v-if="distributionAuditVisible"
                       ref="distributionAudit"
                       selectUrl='/platform/distributionBasicSet/getOfflineHandleEventByBasicSetId'
                       updateUrl='/platform/distributionBasicSet/auditDistribution'
                       @refreshDataList="refreshChange"></DistributionAudit>
  </div>
</template>
 <script>
import { tableOption } from '@/crud/marketing/distributionBasicSet'
import DistributionAudit from '@/components/offline-audit'
export default {
  data () {
    return {
      dataList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      dataListLoading: false,
      distributionAuditVisible: false,
      tableOption: tableOption,
      addOrUpdateVisible: false
    }
  },
  components: {
    DistributionAudit
  },
  created () {
  },
  mounted () {
  },
  methods: {
    getDataList (page, params) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/platform/distributionBasicSet/getShopDistributionPage'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign(
            {
              current: page == null ? this.page.currentPage : page.currentPage,
              size: page == null ? this.page.pageSize : page.pageSize
            },
            params
          )
        )
      }).then(({ data }) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    deleteHandle (id) {
      this.$confirm('确定进行删除操作?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http({
          url: this.$http.adornUrl('/distributionBasicSet/' + id),
          method: 'delete',
          data: this.$http.adornData({})
        }).then(({ data }) => {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.getDataList(this.page)
            }
          })
        })
      }).catch(() => { })
    },
    /**
     * 刷新回调
     */
    refreshChange () {
      this.getDataList(this.page)
    },
    searchChange (params) {
      this.getDataList(this.page, params)
    },
    /**
     * 下线分销活动处理
     */
    offlineDistributionHandle (row) {
      this.$prompt('确定对店铺[' + row.shopName + ']分销功能进行下线操作吗？如是，请填写下线理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then((obj) => {
        if (!obj.value) {
          this.$message.error('下架原因不能为空')
          return
        }
        this.$http({
          url: this.$http.adornUrl(`/platform/distributionBasicSet/offline`),
          method: 'post',
          data: this.$http.adornData({
            handleId: row.basicSetId,
            offlineReason: obj.value || null
          })
        }).then(({ data }) => {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.getDataList(this.page)
            }
          })
        })
      })
    },
    // 弹窗处理
    distributionAuditHandle (id) {
      this.distributionAuditVisible = true
      this.$nextTick(() => {
        this.$refs.distributionAudit.init(id)
      })
    },
    // 查看设置详情
    showSettingInfo (shopId) {
      this.$router.push({
        path: '/distributionSetting',
        query: {
          shopId: shopId
        }
      })
    }
  }
}
</script>
<style lang="scss">
.mod--distributionBasicSet {
}
</style>
