<template>
  <div class="mod-seckill-shopAuditing">
    <avue-crud
      ref="crud"
      :page="page"
      :data="dataList"
      :table-loading="dataListLoading"
      :option="tableOption"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @on-load="getDataList"
      @refresh-change="refreshChange"
    >
      <!-- <template slot="search">
        <el-col :md="10" :xs="24">
          <el-form-item label="投放时间">
            <el-date-picker
              v-model="dateRange"
              type="datetimerange"
              range-separator="至"
              value-format="yyyy-MM-dd HH:mm:ss"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </template>
      <template slot="menuLeft">
        <el-button icon="el-icon-search" size="small" type="primary" @click="insertShop()">新增</el-button>
      </template> -->
      <template slot-scope="scope" slot="menu">
        <el-button
          icon="el-icon-edit"
          size="small"
          type="primary"
          v-if="isAuth('shop:shopAuditing:audit') && scope.row.shopStatus === -1"
          @click="auditHandle(scope.row.shopId)"
        >审核</el-button>
        <el-button
          icon="el-icon-search"
          size="small"
          type="primary"
          v-else-if="isAuth('shop:shopAuditing:info')"
          @click="auditHandle(scope.row.shopId)"
        >查看</el-button>
          <!-- v-if="isAuth('shop:shopAuditing:audit') && scope.row.mobile" -->
        <el-button
          icon="el-icon-search"
          size="small"
          type="primary"
          v-if="isAuth('shop:shopAuditing:audit')"
          @click="shopAccountHandle(scope.row.shopId)"
        >账号管理</el-button>
        <!-- <el-button
          type="danger"
          icon="el-icon-bottom"
          size="small"
          v-if="isAuth('shop:shopAuditing:lowerShelfShop') && scope.row.shopStatus == 1"
          @click="offlineHandle(scope.row)"
        >下线店铺</el-button>
        <el-button
          icon="el-icon-document-checked"
          size="small"
          type="danger"
          v-if="isAuth('shop:shopAuditing:lowerShelfShop') && scope.row.shopStatus > 1"
          @click="shopAuditHandle(scope.row.shopId)"
        >下线管理</el-button> -->
      </template>
      <template slot-scope="scope" slot="status">
        <el-tag v-if="scope.row.status === 0" size="small">未审核</el-tag>
        <el-tag v-else-if="scope.row.status === 1" size="small" type="success">已通过</el-tag>
        <el-tag v-else-if="scope.row.status === -1" size="small" type="danger">未通过</el-tag>
        <el-tag v-else size="small" type="success">平台创建</el-tag>
      </template>
      <template slot-scope="scope" slot="shopStatus">
        <el-tag v-if="scope.row.shopStatus === -1" size="small" type="info">未开通</el-tag>
        <el-tag v-else-if="scope.row.shopStatus === 0" size="small">停业中</el-tag>
        <el-tag v-else-if="scope.row.shopStatus === 1" size="small" type="success">营业中</el-tag>
        <el-tag v-else-if="scope.row.shopStatus === 2" size="small" type="danger">违规下线</el-tag>
        <el-tag v-else-if="scope.row.shopStatus === 3" size="small" type="warning">待审核</el-tag>
      </template>
    </avue-crud>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="refreshChange"></add-or-update>
    <!-- 商品审核弹窗 -->
    <ShopAudit
      v-if="shopAuditVisible"
      ref="shopAudit"
      selectUrl="/platform/shopDetail/getOfflineHandleEventByShopId"
      updateUrl="/platform/shopDetail/auditShop"
      @refreshDataList="refreshChange"
    ></ShopAudit>
    <!-- 账号管理 -->
    <ShopAccount v-if="shopAccountVisible" ref="shopAccount" @refreshDataList="refreshChange"></ShopAccount>
  </div>
</template>

<script>
import { tableOption } from '@/crud/platform/auditShop'
import AddOrUpdate from './auditShop-add-or-update.vue'
// import ShopAudit from '@/components/offline-audit'
import ShopAudit from './shopOfflineHandle'
import ShopAccount from './shop-account.vue'
export default {
  data () {
    return {
      dataList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      searchForm: {}, // 搜索
      dateRange: [],
      dataListSelections: [],
      dataListLoading: false,
      tableOption: tableOption,
      addOrUpdateVisible: false,
      shopAuditVisible: false,
      shopAccountVisible: false
    }
  },
  components: {
    AddOrUpdate,
    ShopAudit,
    ShopAccount
  },
  created () {
  },
  mounted () {
  },
  methods: {
    getDataList (page, params) {
      params = this.searchForm
      console.log(params)
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/shop/shopAuditing/page'),
        method: 'get',
        params: this.$http.adornParams(Object.assign({
          'current': page.currentPage,
          'size': page.pageSize,
          'beginTime': this.dateRange ? this.dateRange[0] : null, // 开始时间
          'endTime': this.dateRange ? this.dateRange[1] : null // 结束时间
        }, params
        ))
      }).then(({ data }) => {
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    // 查看 / 审核
    auditHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    // 账号管理
    shopAccountHandle (id) {
      this.shopAccountVisible = true
      this.$nextTick(() => {
        this.$refs.shopAccount.init(id)
      })
    },
    // 新增 / 修改
    insertShop () {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init()
      })
    },
    // 下架店铺
    offlineHandle (row) {
      this.$prompt('确定对店铺[' + row.shopName + ']进行下线操作？如是，请填写下线理由', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then((obj) => {
        if (!obj.value) {
          this.$message.error('下线原因不能为空')
          return
        }
        this.$http({
          url: this.$http.adornUrl(`/platform/shopDetail/offline`),
          method: 'post',
          data: this.$http.adornData({
            handleId: row.shopId,
            offlineReason: obj.value || null
          })
        }).then(({ data }) => {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.getDataList(this.page)
            }
          })
        })
      })
    },
    /**
     * 刷新回调
     */
    refreshChange () {
      this.page = this.$refs.crud.$refs.tablePage.defaultPage
      this.getDataList(this.page)
    },
    // 清空自定义数据
    searchReset () {
      this.dateRange = []
    },
    searchChange (params) {
      this.searchForm = params
      console.log('a', this.dateRange)
      this.getDataList(this.page)
    },
    // 多选变化
    selectionChange (val) {
      this.dataListSelections = val
    },
    // 弹窗处理
    shopAuditHandle (id) {
      this.shopAuditVisible = true
      this.$nextTick(() => {
        this.$refs.shopAudit.init(id)
      })
    }
  }
}
</script>
<style lang="scss">
.mod-seckill-shopAuditing {
}
</style>
