<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-demo__scopecitycost}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
<!--          <el-input v-model="dataForm.advertiserId" placeholder="账户id" clearable></el-input>-->
          <el-select  filterable v-model="dataForm.advertiserId"  clearable placeholder="请选择账户">
            <el-option
                    v-for="item in advertisers"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.city" 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="dataForm.date"
                  type="date"
                  placeholder="选择统计日期"
                  value-format="yyyy-MM-dd HH:mm:ss">
          </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('sys:scopecitycost:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
<!--        <el-form-item>-->
<!--          <el-button v-if="$hasPermission('sys:scopecitycost: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="advertiserId" label="账户ID" header-align="center" align="center"></el-table-column>
        <el-table-column prop="advertiserName" label="账户名称" header-align="center" align="center"></el-table-column>
        <el-table-column prop="province" label="省份" header-align="center" align="center"></el-table-column>
        <el-table-column prop="city" label="城市" header-align="center" align="center"></el-table-column>
        <el-table-column prop="avgCost" label="平均单价" header-align="center" align="center"></el-table-column>
        <el-table-column prop="manuAvgCost" label="调整价" header-align="center" align="center"></el-table-column>
        <el-table-column prop="date" label="统计日期" header-align="center" align="center" sortable :formatter="convertDate"></el-table-column>
<!--        <el-table-column prop="status" label="状态（开1、关0）" 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 :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('sys:scopecitycost:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
<!--            <el-button v-if="$hasPermission('sys:scopecitycost: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 './scopecitycost-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      provinces:[],
      citys:[],
      advertisers:[],
      mixinViewModuleOptions: {
        getDataListURL: '/sys/scopecitycost/page',
        getDataListIsPage: true,
        exportURL: '/sys/scopecitycost/export',
        deleteURL: '/sys/scopecitycost',
        deleteIsBatch: true
      },
      dataForm: {
        id: '',
        date:'',
        advertiserId:'',
        city:''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  created () {
    if (this.mixinViewModuleOptions.createdIsNeed) {
      this.query()
      this.getCityOptions();
      this.getAdvertisersOptions();
    }
  },
  methods: {
    convertDate(row,column){
      if (row.date==null || row.date==""){
        return null;
      }
      return row.date.substring(0,10)
    },
    //初始化下拉框中的选项
    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(() => {})
    },
    //初始化广告主账户下拉框中的选项
    async getAdvertisersOptions() {
      this.$http.get(`/sys/rdadvertiser/list`).then(({data: res}) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.advertisers = [];
        if (res.data != null) {
          res.data.forEach(element => {
            this.advertisers.push({label: element.advertiserName, value: element.advertiserId})
          })
        }
      }).catch(() => {
      })
    }
  }
}
</script>
