<template>
  <alert @closeAlert="closeAlert" :AlertTitle="AlertTitle" v-if="showAlert">
    <ul class="form-list">
      <li class="clearfix">
        <div class="pull-left name"><span v-if="IslookOrUpdate !== 'look'">*</span>商品名称</div>
        <div class="pull-left">
          <template v-if="IslookOrUpdate !== 'look'">
            <el-input placeholder="请输入商品名称" v-model="chooseItem.commodityName" clearable class="input-text">
            </el-input>
          </template>
          <template v-else>
            <div class="text">{{chooseItem.commodityName}}</div>
          </template>
        </div>
      </li>

      <li class="clearfix">
        <div class="pull-left name"><span v-if="IslookOrUpdate !== 'look'">*</span>品牌</div>
        <div class="pull-left">
          <template v-if="IslookOrUpdate !== 'look'">
            <el-input placeholder="请输入品牌" v-model="chooseItem.brand" clearable class="input-text">
            </el-input>
          </template>
          <template v-else>
            <div class="text">{{chooseItem.brand}}</div>
          </template>
        </div>
      </li>

      <li class="clearfix">
        <div class="pull-left name"><span v-if="IslookOrUpdate !== 'look'">*</span>规格型号</div>
        <div class="pull-left">
          <template v-if="IslookOrUpdate !== 'look'">
            <el-input placeholder="请输入规格型号" v-model="chooseItem.cmpCode" clearable class="input-text">
            </el-input>
          </template>
          <template v-else>
            <div class="text">{{chooseItem.cmpCode}}</div>
          </template>
        </div>
      </li>

      <li class="clearfix">
        <div class="pull-left name"><span v-if="IslookOrUpdate !== 'look'">*</span>海关编码</div>
        <div class="pull-left">
          <template v-if="IslookOrUpdate !== 'look'">
            <el-input placeholder="请输入海关编码" v-model="chooseItem.customerHouseCode" clearable class="input-text">
            </el-input>
          </template>
          <template v-else>
            <div class="text">{{chooseItem.customerHouseCode}}</div>
          </template>
        </div>
      </li>

      <li class="clearfix">
        <div class="pull-left name"><span v-if="IslookOrUpdate !== 'look'">*</span>规格书</div>
        <div class="pull-left">
          <a :href="chooseItem.dataSheetUrl" class="guigeshu" target="_blank" v-if="chooseItem.dataSheetUrl">
          </a>
          <input v-if="IslookOrUpdate !== 'look'" type="file" accept="image/jpeg,image/jpg,image/gif,image/bmp,image/png,.pdf" @change="upload" style="display: inline-block;vertical-align: middle">
          <img src="/nodownload.png" width="39px" height="39px" v-if="IslookOrUpdate === 'look' && !chooseItem.dataSheetUrl"/>
          <!--<template v-if="IslookOrUpdate !== 'look'">-->
            <!--<el-input placeholder="请输入海关编码" v-model="chooseItem.customerHouseCode" clearable class="input-text">-->
            <!--</el-input>-->
          <!--</template>-->
          <!--<template v-else>-->
            <!--<div class="text">{{chooseItem.customerHouseCode}}</div>-->
          <!--</template>-->
        </div>
      </li>

      <li class="clearfix">
        <div class="pull-left name"><span v-if="IslookOrUpdate === 'add'">*</span>申报要素</div>
        <div class="pull-left">
          <template v-if="IslookOrUpdate !== 'look'">
            <el-input :rows="3" type="textarea" placeholder="请填写申报要素" v-model="chooseItem.description" clearable class="input-text">
            </el-input>
          </template>
          <template v-else>
            <div class="text">{{chooseItem.description}}</div>
          </template>
        </div>
      </li>
      <li class="hrefA" v-if="IslookOrUpdate !== 'look'">
        <a href="http://www.hs-bianma.com/" target="_blank">申报要素查询网址-通关网</a>
      </li>
    </ul>
    <div class="control-btn">
      <template v-if="IslookOrUpdate !== 'look'">
        <div class="save" @click="closeAlert('save')">保存</div>
        <div class="cancel" @click="closeAlert()">取消</div>
      </template>
      <template v-else>
        <div class="save" @click="closeAlert()">关闭</div>
      </template>
    </div>
  </alert>
</template>

<script>
  import { Alert } from '@/components/common'
  export default {
    props: {
      IslookOrUpdate: {
        type: String,
        default: 'update'
      },
      AlertTitle: {
        type: String,
        default: '新增申报要素'
      },
      chooseItem: {
        type: Object,
        default: {}
      }
    },
    components: {
      Alert
    },
    data() {
      return {
        showAlert: false,
        fileName: ''
      }
    },
    methods: {
      closeAlert(_tp) {
        if (_tp) {
          if (!this.chooseItem.commodityName || this.chooseItem.commodityName.trim() === '' ) {
            this.$message({
              type: 'error',
              message: '请填写商品名称'
            })
          }
          else if (!this.chooseItem.brand || this.chooseItem.brand.trim() === '') {
            this.$message({type: 'error',message: '请填写品牌'})
          }
          else if (!this.chooseItem.cmpCode || this.chooseItem.cmpCode.trim() === '') {
            this.$message({
              type: 'error',
              message: '请填写规格型号'
            })
          }
          else if (!this.chooseItem.customerHouseCode || this.chooseItem.customerHouseCode.trim() === '') {
            this.$message({
              type: 'error',
              message: '请填写海关编码'
            })
          }
          else if (!this.chooseItem.description || this.chooseItem.description.trim() === '') {
            this.$message({
              type: 'error',
              message: '请填写申报要素'
            })
          }
          else {
            this.$emit('closeAlert', _tp, this.chooseItem, this.files)
            this.files = null
          }
        } else {
          this.$emit('closeAlert', _tp, this.chooseItem, this.files)
          this.files = null
        }
      },
      upload (e) {
        this.fileName = e.target.value
        this.files = e.target.files[0]
      },
      hide() {
        this.showAlert = false
      },
      show() {
        this.showAlert = true
      }
    }
  }
</script>

<style lang="scss" scoped>
  li.hrefA{
    font-size: 12px;
    a {color: #0d5ffe !important;}
    margin-left: 100px;
    margin-bottom: 0px !important;
    margin-top: -20px;
  }
  .guigeshu {
    width: 39px;
    height:39px;
    background: url(/spirit.png) no-repeat 0px -100px;
    margin: 0 auto;
    cursor: pointer;
    display: inline-block;
    vertical-align: top;
    margin-right: 20px;
  }
</style>
