<template lang="html">
  <div class="channelAddVue pop-up">
    <div class="title">
      新建渠道表
      <i class="close" @click="close()"></i>
    </div>
    <div class="main">
      <div class="list">
        <p class="item">
          <span>渠道信息</span>:
          <input type="text" name="" v-model="data.pt" spellcheck="false">
        </p>
        <p class="item">
          <span>渠道对应</span>:
          <input type="text" name="" v-model="data.value" spellcheck="false">
        </p>
      </div>
    </div>
    <div class="btns">
      <button type="button" class="btn3" @click="submit()">确认</button>
      <button type="button" class="btn3" @click="close()">放弃</button>
    </div>
  </div>
</template>

<script>
import { bus, requestInsertChannel } from '@/vuex/request.js'

export default {
  data () {
    return {
      data: {
        value: '',
        pt: ''
      }
    }
  },
  mounted () {
    // 弹框弹出动画
    window.$(() => {
      bus.$emit('pop-up-show', '.channelAddVue.pop-up')
    })
  },
  methods: {
    // 关闭弹窗&动画
    close () {
      window.$(() => {
        bus.$emit('pop-up-close', '.channelAddVue.pop-up')
        setTimeout(() => {
          this.$emit('close')
        }, 500)
      })
    },
    submit () {
      let params = {}
      for (let n in this.data) {
        params[n] = this.data[n]
      }
      let flag = true
      for (let n in params) {
        if (params[n] === '') {
          flag = false
          break
        }
      }
      if (!flag) {
        bus.$emit('alert', '存在未填写项！')
        return false
      }
      let data = params
      requestInsertChannel(params, data, (response) => {
        if (response.data) {
          if (response.data.state) {
            bus.$emit('alert', response.data.message)
            this.$emit('update')
            this.$emit('close')
          } else {
            bus.$emit('alert', response.data.message)
          }
        } else {
          bus.$emit('alert', response + '.')
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.channelAddVue{
  width: 500px;
  .main{
    .list{
      overflow: hidden;
      .item{
        width: 100%;
        margin-bottom: 20px;
        span{
          display: inline-block;
          width: 100px;
        }
        input, select{
          width: 310px;
          height: 31px;
          background-color: #2F363E;
          border: 1px solid #505A64;
          background-image: none;
        }
      }
    }
    .handle{
      line-height: 100px;
      padding-left: 50px;
      label.checkbox input[type=checkbox]+span{
        background-color: #262B31;
        box-shadow: 0 0 0 1px #262B31;
        margin-right: 10px;
      }
    }
  }
}
</style>
