<template>
  <div class="distributionMode-container">
    <div class="content-block">
      <div class="item">
        <div class="name">同城配送</div>
        <el-switch
          v-model="isCitySwitch"
          :active-text="switchText"
          @change="handleSwitchText"
        ></el-switch>
      </div>
      <div class="item-2">
        <div class="tips">
          启用同城配送后，在配送范围内的买家可以选择同城配送，你可以接入第三方配送，也可以自己配送。
        </div>
        <div class="compile-block">
          <span class="compile-item" @click="handelShowDialog()">
            默认配送方式
          </span>
          <span class="segmentation">|</span>
          <span class="compile-item" @click="handleCitySkip()">
            编辑同城配送
          </span>
        </div>
      </div>
    </div>
    <div class="content-block">
      <div class="item">
        <div class="name">上门自提</div>
        <el-switch
          v-model="isVisitSwitch"
          :active-text="visitSwitchText"
          @change="handleVisitSwitchText"
        ></el-switch>
      </div>
      <div class="item-2">
        <div class="tips">
          启用上门自提后，买家可以就近选择商品自提点，买家下单后，您需要确保买家指定的自提点商品库存充足。
        </div>
        <div class="compile-block">
          <span class="compile-item" @click="handleVisitSkip()">
            查看自提点
          </span>
        </div>
      </div>
    </div>
    <div class="footer">
      <div class="item-title">文字设置</div>
      <div class="item-block">
        <div class="item tips">
          修改文字后，手机端商城和PC端商城显示修改后的文字。
        </div>
        <div class="item">
          <div class="item-lable">同城配送</div>
          <el-input
            type="text"
            placeholder="请输入内容"
            v-model="form.cityText"
            maxlength="4"
            show-word-limit
            class="item-input"
          ></el-input>
        </div>
        <div class="item">
          <div class="item-lable">上门自提</div>
          <el-input
            type="text"
            placeholder="请输入内容"
            v-model="form.crvMoreText"
            maxlength="4"
            show-word-limit
            class="item-input"
          ></el-input>
        </div>
        <div class="item">
          <div class="item-lable">等待自提</div>
          <el-input
            type="text"
            placeholder="请输入内容"
            v-model="form.awaitPickUpText"
            maxlength="4"
            show-word-limit
            class="item-input"
          ></el-input>
        </div>
        <div class="item">
          <div class="item-lable">配送时间</div>
          <el-input
            type="text"
            placeholder="请输入内容"
            v-model="form.deliveryTimeText"
            maxlength="4"
            show-word-limit
            class="item-input"
          ></el-input>
        </div>
        <div class="item">
          <div class="item-lable">自提时间</div>
          <el-input
            type="text"
            placeholder="请输入内容"
            v-model="form.pickUpTimeText"
            maxlength="4"
            show-word-limit
            class="item-input"
          ></el-input>
        </div>
        <el-button class="btn" type="primary" size="medium">保存</el-button>
      </div>
    </div>
    <el-dialog
      class="default-delivery-dialog"
      :title="'默认配送方式'"
      :top="'40vh'"
      :width="'520px'"
      :visible.sync="showDialog"
      :before-close="handleCloseDialog"
    >
      <el-form
        ref="form"
        class="form-dialog"
        :model="formDialog"
        :rules="formDialogRules"
        label-width="110px"
      >
        <el-form-item label="默认配送方式" prop="distributionModeType">
          <el-select v-model="formDialog.distributionModeType">
            <el-option
              :label="item.label"
              :value="item.value"
              placeholder="请默认配送方式"
              v-for="(item, index) of distributionModeOpction"
              :key="index"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="medium" @click="showDialog = false">取 消</el-button>
        <el-button size="medium" type="primary" @click="showDialog = false">
          确 定
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'distributionMode',
  data() {
    return {
      isCitySwitch: false,
      isVisitSwitch: false,
      showDialog: false,
      switchText: '关闭',
      visitSwitchText: '关闭',
      form: {
        cityText: '同城配送',
        crvMoreText: '上门自提',
        awaitPickUpText: '等待自提',
        deliveryTimeText: '配送时间',
        pickUpTimeText: '自提时间',
      },
      formDialog: {
        distributionModeType: 0,
      },
      formDialogRules: {
        distributionModeType: [
          { required: true, message: '请选择默认配送方式', trigger: 'change' },
        ],
      },
      distributionModeOpction: [
        {
          value: 0,
          label: '商家配送',
        },
        {
          value: 1,
          label: '码科速送',
        },
      ],
    }
  },
  methods: {
    handleSwitchText(isSwitch) {
      if (isSwitch) {
        this.switchText = '开启'
      } else {
        this.switchText = '关闭'
      }
    },
    handleVisitSwitchText(isSwitch) {
      if (isSwitch) {
        this.visitSwitchText = '开启'
      } else {
        this.visitSwitchText = '关闭'
      }
    },
    handleVisitSkip() {
      this.$router.push({ path: '/selfPickUpSite' })
    },
    handleCitySkip() {
      this.$router.push({ path: '/localDelivery' })
    },
    handelShowDialog() {
      this.showDialog = true
    },
    handleCloseDialog() {
      this.showDialog = false
    },
  },
}
</script>

<style lang="scss">
.distributionMode-container {
  padding: 0 !important;
  background: #f6f8f9 !important;

  .content-block {
    display: flex;
    flex-flow: column;
    margin-bottom: 24px;
    background: #fff;

    .item {
      display: flex;
      padding: 16px 20px;
      justify-content: space-between;
      border-bottom: 1px solid #f2f2f2;
      line-height: 1;

      .name {
        color: #333;
        font-size: 16px;
        font-weight: bold;
      }
    }

    .item-2 {
      display: flex;
      justify-content: space-between;
      padding: 20px;

      .compile-block {
        color: #1890ff;

        .segmentation {
          padding: 0 8px;
          color: #000;
        }

        .compile-item {
          cursor: pointer;
        }
      }
    }
  }

  .footer {
    display: flex;
    flex-flow: column;
    background: #fff;

    .item-title {
      padding: 16px 20px;
      border-bottom: 1px solid #f2f2f2;
      font-size: 16px;
      font-weight: bold;
      color: #333;
      line-height: 1;
    }

    .item-block {
      padding: 20px;

      .tips {
        margin-bottom: 20px !important;
      }

      .item {
        display: flex;
        margin-bottom: 30px;
        align-items: center;

        &-lable {
          padding: 0 20px 0 10px;
          color: #333;
        }

        .item-input {
          width: 200px;
          height: 38px;

          .el-input__inner {
            height: 38px;
            line-height: 38px;
          }
        }
      }

      .btn {
        margin-left: 84px;
      }
    }
  }

  .default-delivery-dialog {
    .el-dialog {
      border: 0;
      border-radius: 6px;
      background-clip: padding-box;
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .el-dialog__header {
      padding: 12px 20px;
      border-bottom: 1px solid #f2f2f2;

      .el-dialog__title {
        font-size: 16px;
        color: rgba(0, 0, 0, 0.8);
        font-weight: 600;
      }

      .el-dialog__headerbtn {
        top: 12px;
      }
    }

    .el-dialog__body {
      padding: 16px 20px;
      font-size: 12px;
      line-height: 1.5;
      color: #666;
      min-height: 108px;
      overflow-y: auto;
      max-height: 620px;
      overflow: auto;

      .form-dialog {
        min-height: 150px;
      }

      .el-input__inner {
        height: 38px;
        width: 198px;
      }
    }

    .el-dialog__footer {
      border-top: 1px solid #f2f2f2;
      padding: 10px;
    }
  }
}
</style>