<template>
  <div class="app-container">
    <el-form label-position="left" label-width="160px" style="width: 60%">
      <el-form-item label="渠道名称" prop="Name">
        <el-input v-model="dto.Name" />
      </el-form-item>

      <el-form-item label="渠道代码" prop="Code">
        <el-input v-model="dto.Code" :disabled="isEdit" />
      </el-form-item>

      <el-form-item label="是否启用" prop="Enable">
        <el-switch v-model="dto.Enable" />
      </el-form-item>

      <el-form-item label="是否显示" prop="IsShow">
        <el-switch v-model="dto.IsShow" />
      </el-form-item>

      <el-form-item label="渠道类型" prop="ChannelType">
        <el-select v-model="dto.ChannelType" :value="dto.ChannelType">
          <el-option
            v-for="item in channelTypes"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="参考时效" prop="Efficiency">
        <el-input v-model="dto.Efficiency" type="textarea" :rows="textRows" />
      </el-form-item>

      <el-form-item label="包裹限重" prop="MaxWeight">
        <el-input
          v-model="dto.MaxWeight"
          type="textarea"
          :rows="textRows"
        />
      </el-form-item>

      <el-form-item label="货件尺寸" prop="DimensionDescription">
        <el-input
          v-model="dto.DimensionDescription"
          type="textarea"
          :rows="textRows"
        />
      </el-form-item>

      <el-form-item label="计费方式" prop="BillingDescription">
        <el-input
          v-model="dto.BillingDescription"
          type="textarea"
          :rows="textRows"
        />
      </el-form-item>

      <el-form-item label="走货属性" prop="GoodsLimit">
        <el-input v-model="dto.GoodsLimit" type="textarea" :rows="textRows" />
      </el-form-item>

      <el-form-item label="申报要求" prop="DeclareDemand">
        <el-input
          v-model="dto.DeclareDemand"
          type="textarea"
          :rows="textRows"
        />
      </el-form-item>

      <el-form-item label="派送范围" prop="DeliveryRange">
        <el-input
          v-model="dto.DeliveryRange"
          type="textarea"
          :rows="textRows"
        />
      </el-form-item>

      <el-form-item label="包装要求" prop="PackingDemand">
        <el-input
          v-model="dto.PackingDemand"
          type="textarea"
          :rows="textRows"
        />
      </el-form-item>
      <el-form-item>
        <el-upload />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          :loading="saveLoading"
          @click="save()"
        >保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { _getChannel, save } from '@/api/publicChannel'
export default {
  name: 'PublicChannelEdit',
  data() {
    return {

      saveLoading: false,
      textRows: 2,
      channelTypes: [
        { name: '专线', id: 0 },
        { name: '快递', id: 1 },
        { name: '邮政小包', id: 2 },
        { name: '空派专线', id: 3 }
      ],
      dto: {}
    }
  },
  computed: {
    isEdit: function() {
      const id = this.$route.query.id
      console.log(id)
      return !!id && id > 0
    }
  },
  created() {
    const id = this.$route.query.id
    if (!!id && id > 0) {
      _getChannel(id).then(response => {
        this.dto = response
        this.dto.PickingProcess += ''
      })
    } else {
    }
  },
  methods: {
    save() {
      this.saveLoading = true
      save(this.dto).then((resp) => {
        this.saveLoading = false
        console.log(resp)
        const msg = resp
      }).catch(response => {
        this.saveLoading = false
      })
    }
  }
}
</script>

<style scoped>
.input {
  width: 100px;
}
.tag {
  margin-left: 1.5em;
}
</style>
