<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>{{ __('跑腿设置') }}</span>
    </div>
    <div>
      <el-form
        ref="form"
        label-position="left"
        label-width="100px"
        :model="form"
        size="medium"
      >
        <el-form-item
          :label="__('起送距离')"
          label-width="120px"
          prop="sc_start_distance"
        >
          <el-input
            v-model="form.sc_start_distance"
            clearable
            :placeholder="__('请输入起送距离')"
            :style="{ width: '100%' }"
          />
        </el-form-item>
        <el-form-item
          :label="__('起送金额')"
          label-width="120px"
          prop="sc_start_amount"
        >
          <el-input
            v-model="form.sc_start_amount"
            clearable
            :placeholder="__('请输入起送金额')"
            :style="{ width: '100%' }"
          />
        </el-form-item>
        <el-form-item
          :label="__('超出起送距离外每公里金额')"
          label-width="120px"
          prop="sc_extra_amount"
        >
          <el-input
            v-model="form.sc_extra_amount"
            clearable
            :placeholder="__('请输入超出起送距离外每公里金额')"
            :style="{ width: '100%' }"
          />
        </el-form-item>
      </el-form>
    </div>
    <div>
      <div class="config-save" @click="save">{{ __('修改') }}</div>
    </div>
  </el-card>
</template>

<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import { get, edit } from '@/api/store/config'

  export default {
    name: 'StoreConfig',
    components: {},
    data() {
      return {
        form: {
          sc_start_distance: undefined,
          sc_start_amount: undefined,
          sc_extra_amount: undefined,
        },
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      __,
      async fetchData() {
        const { data } = await get()
        this.form = {
          sc_start_distance: data.sc_start_distance,
          sc_start_amount: data.sc_start_amount,
          sc_extra_amount: data.sc_extra_amount,
          store_id: data.store_id,
        }
      },
      save() {
        this.$baseConfirm(
          this.__('修改立马生效,是否继续？'),
          null,
          async () => {
            const { msg, status } = await edit(this.form)
            if (200 == status) {
              this.$baseMessage(msg, 'success')
            } else {
              this.$baseMessage(msg, 'error')
            }
          }
        )
      },
    },
  }
</script>
<style>
  .config-save {
    color: white;
    text-align: center;
    background-color: #2c2e30;
    padding: 12px;
  }
  .config-save:hover {
    background-color: #3d3d3d;
  }
</style>
