<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-demo__rdaudiencecity}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.advertiserId" placeholder="广告主账号" clearable></el-input>
        </el-form-item>
        <el-form-item>
<!--          <el-input v-model="dataForm.provinceName" placeholder="省份" clearable></el-input>-->
          <el-select v-model="dataForm.provinceName" clearable placeholder="请选择省份">
            <el-option
                    v-for="item in provinces"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
<!--          <el-input v-model="dataForm.cityName" placeholder="城市" clearable></el-input>-->
          <el-select v-model="dataForm.cityName" clearable placeholder="请选择城市">
            <el-option
                    v-for="item in citys"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker
                  v-model="date"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  @change="getTimes">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
<!--        <el-form-item>-->
<!--          <el-button v-if="$hasPermission('demo:rdaudiencecity:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>-->
<!--        </el-form-item>-->
<!--        <el-form-item>-->
<!--          <el-button v-if="$hasPermission('demo:rdaudiencecity:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>-->
<!--        </el-form-item>-->
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column>
<!--        <el-table-column prop="advertPlatform" label="所属广告平台" header-align="center" align="center"></el-table-column>-->
        <el-table-column prop="advertiserId" label="广告主账号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="date" label="日期" header-align="center" align="center"></el-table-column>
        <el-table-column prop="cost" label="总消耗(元)" header-align="center" align="center"></el-table-column>
        <el-table-column prop="shows" label="展示数" header-align="center" align="center"></el-table-column>
        <el-table-column prop="click" label="点击数" header-align="center" align="center"></el-table-column>
        <el-table-column prop="converts" label="转化数" header-align="center" align="center"></el-table-column>
        <el-table-column prop="provinceName" label="省份" header-align="center" align="center"></el-table-column>
        <el-table-column prop="cityName" label="城市" header-align="center" align="center"></el-table-column>
<!--        <el-table-column prop="status" label="状态（开1、关0）" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="createdBy" label="创建人" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="updatedBy" label="修改人" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="createTime" label="创建时间" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="updateTime" label="修改时间" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="deleteTime" label="删除时间" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">-->
<!--          <template slot-scope="scope">-->
<!--            <el-button v-if="$hasPermission('demo:rdaudiencecity:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>-->
<!--            <el-button v-if="$hasPermission('demo:rdaudiencecity:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './rdaudiencecity-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/sys/rdaudiencecity/page',
        getDataListIsPage: true,
        exportURL: '/sys/rdaudiencecity/export',
        deleteURL: '/sys/rdaudiencecity',
        deleteIsBatch: true
      },
      date:'',
      provinces:[],
      citys:[],
      dataForm: {
        id: '',
        advertiserId:'',
        startDate:'',
        endDate:'',
        provinceName:'',
        cityName:''
      }
    }
  },
  created () {
    if (this.mixinViewModuleOptions.createdIsNeed) {
      this.query()
      this.getCityOptions();
      this.getProvinceOptions();
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
    //利⽤change事件监听表单内容变化，并将选中的值赋值给所需要的两个字段
    //⽀付时间戳设置
    getTimes() {
      if (this.date != null) {
        this.dataForm.startDate = this.date[0]
        this.dataForm.endDate = this.date[1]
      }else{
        this.dataForm.startDate =''
        this.dataForm.endDate = ''
      }
    },
    //初始化下拉框中的选项
    async getProvinceOptions() {
      this.$http.get(`/sys/dict/data/list?dataType=landing_page_province`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.provinces=[];
        if (res.data!=null){
          res.data.forEach(element => {
            this.provinces.push({label:element.dictLabel,value:element.dictValue})
          })
        }
      }).catch(() => {})
    },
    //初始化下拉框中的选项
    async getCityOptions() {
      this.$http.get(`/sys/dict/data/list?dataType=landing_page_city`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.citys=[];
        if (res.data!=null){
          res.data.forEach(element => {
            this.citys.push({label:element.dictLabel,value:element.dictValue})
          })
        }
      }).catch(() => {})
    },
  }
}
</script>
