<template>
  <div class="app-container" style="width:50%">
    <el-form v-loading="loading">
      <el-form-item label="IOSS" label-width="100px">
        <el-input v-model="ioss" />
      </el-form-item>
      <el-form-item label="跟踪号" label-width="100px">
        <el-input type="textarea" :autosize="{ minRows: 16, maxRows: 28 }" v-model="trackingNumber" placeholder="支持换行和逗号" />
      </el-form-item>
    </el-form>
    <div class="text-center">
      <el-button type="success" @click="submit">提交</el-button>
    </div>
  </div>
</template>

<script>
import { _fixIoss } from '@/api/ioss'
export default {
  name: 'FixIoss',
  data: function() {
    return {
      loading: false,
      trackingNumber: '',
      ioss: null
    }
  },
  methods: {
    submit() {
      const ioss = this.ioss
      const trackingNumber_ = this.trackingNumber.split(/[\n,]/)
      const trackingNumber = trackingNumber_.filter(item => item !== '')
      if (trackingNumber.length === 0) {
        this.$message({ message: '请填写跟踪号', type: 'error' })
        return
      }
      if (!ioss) {
        this.$message({ message: '请填写IOSS', type: 'error' })
        return
      }
      const param = { trackingNumber, ioss }
      this.loading = true

      _fixIoss(param)
        .then((res) => {
          this.$message({ message: '设置成功', type: 'success' })
        })
        .finally(() => {
          this.loading = false
        })
    }
  }
}
</script>

<style></style>
