<template>
  <div class="app-container">
    <el-card shadow="never">
      <h3>快线匹配规则</h3>
      <el-form>
        <el-form-item label="450g以下">
          <el-select v-model="model.GrE450ChannelId" placeholder="渠道名称" filterable>
            <el-option
              v-for="item in channelsListGrE"
              :key="item.Id"
              :label="item.Name"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="大于450g">
          <el-select v-model="model.LeE450ChannelId" placeholder="渠道名称" filterable>
            <el-option
              v-for="item in channelsListLeE"
              :key="item.Id"
              :label="item.Name"
              :value="item.Id"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save">保存</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import { _getDeliverChannel } from '@/api/baseInfo'
import { GetKMath, SetKMath } from '@/api/channel/kMath'
export default {
  name: 'ChannelKMath',
  data() {
    return {
      model: {
        GrE450ChannelId: 0, LeE450ChannelId: 0
      },
      channelsListGrE: [],
      channelsListLeE: []
    }
  },
  created() {
    _getDeliverChannel().then(response => {
      this.channelsListGrE = response.filter(x => {
        return x.Id == 210 || x.Id == 216 || x.Id == 218 || x.Id == 244 || x.Id == 246 || x.Id == 248 || x.Id == 292
      })
      this.channelsListLeE = response.filter(x => {
        return x.Id == 211 || x.Id == 217 || x.Id == 219 || x.Id == 245 || x.Id == 247 || x.Id == 250 || x.Id == 293
      })
    })
    GetKMath().then(r => {
      this.model = r
    })
  },
  methods: {
    save() {
      SetKMath(this.model).then(r => {
        this.$alert('更新成功')
        this.GetKMath()
      })
    }
  }

}
</script>
