<template>
	<view>
		<!-- <cu-custom bgColor="bg-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content"> 测试移动表单</block>
		</cu-custom> -->
		<view>
			<view class="uni-container">
				<uni-table ref="table" :loading="loading" stripe  emptyText="暂无更多数据" @selection-change="selectionChange">
					<uni-tr >
						<uni-th @filter-change="searchChangeHandle"   field="awardsName" @sort-change="sortChangeHandle"  align="center">奖项名称</uni-th>
						<uni-th @filter-change="searchChangeHandle"   field="prizeName" @sort-change="sortChangeHandle"  align="center">奖品名称</uni-th>
						<uni-th @filter-change="searchChangeHandle"   field="number"  @sort-change="sortChangeHandle"  align="center">数量</uni-th>
					</uni-tr>
					<uni-tr v-for="(row, index) in dataList" :key="index">
						<uni-td align="center" :style="row.showFlag === '2'?'background-color: bisque;':''">
							<span v-if="row.showFlag === '2'"><b>{{row.awardsName}}</b></span>
							<span v-if="row.showFlag === '1'"><b>{{row.awardsName}}</b></span>
							<span v-if="row.showFlag === '0'">{{row.awardsName}}</span>
						
						</uni-td>
						<uni-td align="center" :style="row.showFlag === '2'?'background-color: bisque;':''">
							<span v-if="row.showFlag === '2'"><b>{{row.prizeName}}</b></span>
							<span v-if="row.showFlag === '1'"><b>{{row.prizeName}}</b></span>
							<span v-if="row.showFlag === '0'">{{row.prizeName}}</span>
						</uni-td>
						<uni-td align="center" :style="row.showFlag === '2'?'background-color: bisque;':''">
							<span v-if="row.showFlag === '2'"><b>{{row.number}}</b></span>
							<span v-if="row.showFlag === '1'"><b>{{row.number}}</b></span>
							<span v-if="row.showFlag === '0'">{{row.number}}</span>
						</uni-td>
					</uni-tr>
				</uni-table>
				<!-- <view class="uni-pagination-box">
					<uni-pagination show-icon :page-size="tablePage.pageSize" :current="tablePage.currentPage" :total="tablePage.total" @change="currentChangeHandle" />
				</view> -->
			</view>
		
			<!-- <uni-fab
				:pattern=" {
							color: '#7A7E83',
							backgroundColor: '#fff',
							selectedColor: '#007AFF',
							buttonColor: '#007AFF'
						}"
				horizontal="right"
				vertical="bottom"
				@fabClick="add"
			></uni-fab> -->
		</view>
		</view>
</template>

<script>
  import uniFab from '@/components/uni-fab/uni-fab.vue';
  import TestMobileService from '@/api/test/luckyDraw/LuckyDrawService'
  export default {
	onShow(option) {
		
	},
	components:{
		uniFab
	},
    data () {
      return {
        searchForm: {},
        dataList: [], // 数据列表
        tablePage: {
          total: 0,
          currentPage: 1,
          pageSize: 10,
          orders: []
        },
        loading: false
      }
    },
    testMobileService: null,
	onLoad() {
	  this.testMobileService = new TestMobileService()
	  this.refreshList()
	},
    methods: {
	  // 新增
	  add (){
	  	uni.navigateTo({
	  	  url: '/pages/test/mobile/TestMobileForm'
	  	})
	  },
	  // 修改
	  edit (id) {
	  	uni.navigateTo({
	  	  url: '/pages/test/mobile/TestMobileForm?id='+id
	  	})
	  },
      // 删除
	  LuckyDraw (id,number,awardId) {
	  	uni.showModal({
	  		title: '提示',
	  		content: '您确认要对该奖项进行抽奖吗',
	  		showCancel: true,
	  		success: (res) => {
	  			if (res.confirm) {
	  				this.testMobileService.LuckyDraw(id,number,awardId).then(({data})=>{
						console.log(data)
	  					uni.showToast({
	  						title: data.msg,
	  						icon:"success"
	  					})
	  					this.refreshList()
	  				})
	  			}
	  		}
	  	});
	  },
	  /*获取数据列表 */
	  refreshList() {
	    this.loading = true
	    this.testMobileService.list({
	  	  'current': this.tablePage.currentPage,
	  	  'size': this.tablePage.pageSize,
	  	  'orders': this.tablePage.orders,
	  	  ...this.searchForm
	  	}).then(({data}) => {
	  	  this.dataList = data.records
	  	  this.tablePage.total = data.total
	  	  this.loading = false
	  	})
	  	
	  },
	  // 排序
	  sortChangeHandle (column) {
	  	this.tablePage.orders = []
	  	if (column.order != null) {
	  	  this.tablePage.orders.push({column: this.$utils.toLine(column.property), asc: column.order === 'ascending'})
	  	}
	  	this.refreshList()
	  },
	// 检索
	  searchChangeHandle (column) {
		this.searchForm[column.property] = column.filter
		this.refreshList()
	  },
	// 分页触发
	  currentChangeHandle (e) {
		this.tablePage.currentPage = e.current
		this.refreshList()
	  }
    }
  }
</script>

