<template>
  <section class="AppMerchantDiscounts">
    <ai-list>
      <ai-title slot="title" title="商户优惠" isShowBottomBorder />
      <template #content>
        <ai-search-bar>
          <template #left>
            <el-input
              v-model="search.name"
              class="search-input"
              size="small"
              v-throttle="() => {page.current = 1, getList()}"
              placeholder="请输入商户名称"
              clearable
              @change="getList"
              @clear="page.current = 1, page.content = '', getList()"
              suffix-icon="iconfont iconSearch">
            </el-input>
            <el-input
              v-model="search.title"
              class="search-input"
              size="small"
              v-throttle="() => {page.current = 1, getList()}"
              placeholder="请输入优惠标题"
              clearable
              @change="getList"
              @clear="page.current = 1, page.content = '', getList()"
              suffix-icon="iconfont iconSearch">
            </el-input>
            <ai-select
              v-model="search.status"
              @change="page.current = 1, getList()"
              placeholder="状态"
              :selectList="dict.getDict('cwpStatus')">
            </ai-select>
          </template>
        </ai-search-bar>
        <ai-table :tableData="tableData" :total="page.total" :current.sync="page.current" 
        :size.sync="page.size" @getList="getList" :col-configs="colConfigs" :dict="dict">
          <el-table-column slot="options" label="操作" fixed="right" align="center">
            <template slot-scope="{ row }">
              <el-button type="text" @click.native="examine(row.id)">审核通过</el-button>
              <el-button type="text" @click.native="examine(row.id)">审核拒绝</el-button>
              <el-button type="text" @click.native="delBtn(row.id)">删除</el-button>
            </template>
          </el-table-column>
        </ai-table>
        <div class="qrCode" v-viewer="{movable: true}" v-show="false">
          <img :src="img">
        </div>
      </template>
    </ai-list>
  </section>
</template>

<script>
export default {
  name: 'AppMerchantDiscounts',
  label: '商户优惠',
  props: {
    instance: Function,
    dict: Object
  },
  data () {
    return {
      page: {
        current: 1,
        size: 10,
        total: 0,
      },
      tableData: [],
      img: '',
      isLoading: false,
      search: {
        name: '',
        title: '',
        status: ''
      }
    }
  },
  created () {
    this.$dict.load('').then(()=> {
      // this.getList()
    })
  },
  computed: {
    colConfigs() {
      return [
        {prop: "", label: "商户名称", align: "left", showOverflowTooltip: true},
        {prop: "", label: "优惠标题", align: "center"},
        {prop: "", label: "优惠内容", align: "center", width: "400px", render: (h, {row}) => h('p',{textAlign:'center'},
         `${row.intoBegintime}至${row.exitEndtime}`)},
        {prop: "", label: "状态", align: "center", dict:"tfx_activityStatus"},
        { slot: "options", },
      ]
    }
  },
  methods: {
    getList() {
      // this.instance.post(`api/appactivityinfo/list`,null, {
      //   params: {
      //     ...this.page,
      //   }
      // }).then(res=> {
      //   if(res?.data) {
      //     this.tableData = res.data.records
      //     this.page.total = res.data.total
      //   }
      // })
    },
    // 删除
    delBtn(id) {
      // this.$confirm('确定删除该记录？').then(() => {
      //   this.instance.post(`api/appactivityinfo/delete?ids=${id}`).then(res=>{
      //     if(res.code == 0) {
      //       this.$message.success('删除成功！')
      //       this.getList()
      //     }
      //   })
      // })
    },
    // 审核
    examine(id,type) {
      // let title = ''
      // if(type=='') {
      //   title = '确定要审核通过该活动吗？'
      // } else if(type=='') {
      //   title = '确定要审核拒绝该活动吗？'
      // }
      // this.$confirm(title).then(() => {
      //   this.instance.post(`api/appactivityinfo/stop?id=${id}`).then(res=>{
      //     if(res.code == 0) {
      //       this.$message.success('审核成功！')
      //       this.getList()
      //     }
      //   })
      // })
    },
  }
}
</script>

<style lang="scss" scoped>
.AppMerchantDiscounts {
  height: 100%;
}
</style>
