<template>
  <div>
    <el-card class="chain-detail-cart" style="width: 100%">
      <span>{{ __('请勿修改！ 仅仅由软件服务商初始化设定系统使用。') }}</span>
    </el-card>
    <el-row>
      <el-col :span="24">
        <el-card id="box-card-form-1">
          <div>
            <el-form
              ref="form"
              label-width="100px"
              :model="form"
              :rules="rules"
              size="medium"
            >
              <el-form-item
                :label="__('启用多店铺')"
                label-width="200px"
                prop="multishop_enable"
              >
                <el-radio-group v-model="form.multishop_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，则显示店铺列表及商品店铺信息') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('启用进销存')"
                label-width="200px"
                prop="invoicing_enable"
              >
                <el-radio-group v-model="form.invoicing_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>
                  {{
                    __(
                      '启用后，添加商品的时候不可以直接修改库存，通过进销存变动库存'
                    )
                  }}
                </p>
              </el-form-item>

              <el-form-item
                :label="__('允许商品评论')"
                label-width="200px"
                prop="evaluation_enable"
              >
                <el-radio-group v-model="form.evaluation_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，则显示评论及销量等等信息。') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('启用O2O')"
                label-width="200px"
                prop="o2o_enable"
              >
                <el-radio-group v-model="form.o2o_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>
                  {{
                    __(
                      '启用后，支持门店系统，支持门店自提、附近门店、附件店铺。'
                    )
                  }}
                </p>
              </el-form-item>

              <el-form-item
                :label="__('交易模式')"
                label-width="200px"
                prop="trade_mode"
              >
                <el-radio-group v-model="form.trade_mode" size="medium">
                  <el-radio
                    v-for="(item, index) in trade_modes"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>
                  {{
                    __(
                      '直接交易 - 商家直接收款； 担保交易：平台收款，平台和商家结算。'
                    )
                  }}
                </p>
              </el-form-item>

              <el-form-item
                :label="__('启用虚拟商品')"
                label-width="200px"
                prop="virtual_enable"
              >
                <el-radio-group v-model="form.virtual_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in virtual_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('启用es检索')"
                label-width="200px"
                prop="esearch_enable"
              >
                <el-radio-group v-model="form.esearch_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in virtual_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('商品展示')"
                label-width="200px"
                prop="product_show_type"
              >
                <el-radio-group v-model="form.product_show_type" size="medium">
                  <el-radio
                    v-for="(item, index) in product_show_types"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('是否允许商家更改规格值')"
                label-width="200px"
                prop="product_spec_edit"
              >
                <el-radio-group v-model="form.product_spec_edit" size="medium">
                  <el-radio
                    v-for="(item, index) in product_spec_edits"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>
                  {{
                    __(
                      '编辑已经发布的商品规格，会导致商品活动等等已经使用该商品的相关功能出现问题，慎重使用。'
                    )
                  }}
                </p>
              </el-form-item>

              <el-form-item
                :label="__('价格政策')"
                label-width="200px"
                prop="pricing_policy"
              >
                <el-radio-group v-model="form.pricing_policy" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>
                  {{
                    __(
                      '启用后并设定，则优先级高于标准等级定价及标准定价。'
                    )
                  }}
                </p>
              </el-form-item>

              <el-form-item
                :label="__('启用积分商城')"
                label-width="200px"
                prop="point_enable"
              >
                <el-radio-group v-model="form.point_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('右侧购物车栏')"
                label-width="200px"
                prop="sidecart_enable"
              >
                <el-radio-group v-model="form.sidecart_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('启用IM系统')"
                label-width="200px"
                prop="im_enable"
              >
                <el-radio-group v-model="form.im_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('启用SNS系统')"
                label-width="200px"
                prop="sns_enable"
              >
                <el-radio-group v-model="form.sns_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('启用教育系统')"
                label-width="200px"
                prop="edu_enable"
              >
                <el-radio-group v-model="form.edu_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('启用平台推广分销')"
                label-width="200px"
                prop="plantform_fx_enable"
              >
                <el-radio-group
                  v-model="form.plantform_fx_enable"
                  size="medium"
                >
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('是否启用门店系统')"
                label-width="200px"
                prop="chain_enable"
              >
                <el-radio-group v-model="form.chain_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，有门店系统') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用分销小店')"
                label-width="200px"
                prop="plantform_fx_westore_enable"
              >
                <el-radio-group
                  v-model="form.plantform_fx_westore_enable"
                  size="medium"
                >
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，分销者有独立分销小店。') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用供应商联营')"
                label-width="200px"
                prop="store_supplier_enable"
              >
                <el-radio-group
                  v-model="form.store_supplier_enable"
                  size="medium"
                >
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>
                  {{
                    __(
                      '启用后，有独立供应商，供应商负责供货发货，平台负责零售价格。'
                    )
                  }}
                </p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用批发市场')"
                label-width="200px"
                prop="supplier_market_enable"
              >
                <el-radio-group
                  v-model="form.supplier_market_enable"
                  size="medium"
                >
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，有独立批发市场') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用B2B供需大厅')"
                label-width="200px"
                prop="hall_b2b_enable"
              >
                <el-radio-group v-model="form.hall_b2b_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，有独立B2B供需大厅') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用B2B批量下单')"
                label-width="200px"
                prop="b2b_flag"
              >
                <el-radio-group v-model="form.b2b_flag" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，支持批量下单。') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用城市分站')"
                label-width="200px"
                prop="subsite_enable"
              >
                <el-radio-group v-model="form.subsite_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，有独立城市分站') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用直播系统')"
                label-width="200px"
                prop="live_enable"
              >
                <el-radio-group v-model="form.live_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in live_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，有独立直播系统。') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('阿里云直播')"
                label-width="200px"
                prop="live_enable"
              >
                <el-radio-group v-model="form.live_mode_aliyun" size="medium">
                  <el-radio
                    v-for="(item, index) in virtual_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，不同的直播模式。') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('小程序直播')"
                label-width="200px"
                prop="live_enable"
              >
                <el-radio-group v-model="form.live_mode_xcx" size="medium">
                  <el-radio
                    v-for="(item, index) in virtual_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，不同的直播模式。') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用广告系统')"
                label-width="200px"
                prop="adv_enable"
              >
                <el-radio-group v-model="form.adv_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in live_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，有独立广告系统。') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用信息发布系统')"
                label-width="200px"
                prop="info_enable"
              >
                <el-radio-group v-model="form.info_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in live_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，有独立信息发布系统。') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用订货系统')"
                label-width="200px"
                prop="dinghuo_enable"
              >
                <el-radio-group v-model="form.dinghuo_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in live_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>{{ __('启用后，可以企业B2B订货系统功能！。') }}</p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用配送时间')"
                label-width="200px"
                prop="delivery_time_enable"
              >
                <el-radio-group v-model="form.dinghuo_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>
                  {{
                    __(
                      '启用后，下单需要选择配送时间【适合本地生活服务O2O系统】。'
                    )
                  }}
                </p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用平台等级折扣')"
                label-width="200px"
                prop="user_level_rate_enable"
              >
                <el-radio-group
                  v-model="form.user_level_rate_enable"
                  size="medium"
                >
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>
                  {{
                    __(
                      '启用后，会员平台等级可以享受等级折扣【适合B2C系统或者自营BBC系统】。'
                    )
                  }}
                </p>
              </el-form-item>

              <el-form-item
                :label="__('是否启用平台等级价格')"
                label-width="200px"
                prop="user_level_price_enable"
              >
                <el-radio-group
                  v-model="form.user_level_price_enable"
                  size="medium"
                >
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
                <p>
                  {{
                    __(
                      '启用后，会员平台等级可以享受等级价格【适合B2C系统或者自营BBC系统】。'
                    )
                  }}
                </p>
              </el-form-item>

              <el-form-item
                :label="__('启用客户端缓存')"
                label-width="200px"
                prop="client_cache"
              >
                <el-radio-group v-model="form.client_cache" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('启用多语言')"
                label-width="200px"
                prop="multilang_enable"
              >
                <el-radio-group v-model="form.multilang_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('启用Service Workers离线缓存')"
                label-width="200px"
                prop="sw_enable"
              >
                <el-radio-group v-model="form.sw_enable" size="medium">
                  <el-radio
                    v-for="(item, index) in multishop_enables"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('是否显示销量')"
                label-width="200px"
                prop="product_salenum_flag"
              >
                <el-radio-group
                  v-model="form.product_salenum_flag"
                  size="medium"
                >
                  <el-radio
                    v-for="(item, index) in product_salenum_flagOptions"
                    :key="index"
                    :disabled="item.disabled"
                    :label="__(item.value)"
                  >
                    {{ __(item.label) }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>

              <el-form-item
                :label="__('虚拟销量')"
                label-width="200px"
                prop="product_virtual_salenum"
              >
                <el-input
                  v-model="form.product_virtual_salenum"
                  clearable
                  :placeholder="__('请输入虚拟销量')"
                  :style="{ width: '20%' }"
                />
              </el-form-item>
            </el-form>
          </div>
          <div>
            <el-button
              class="form-sub-btn"
              icon="el-icon-s-tools"
              type="primary"
              @click="handleEdit"
            >
              {{ __('修改') }}
            </el-button>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import { translateTitle as __ } from '@/utils/i18n'
  import Upload from '@/components/upload'
  import Area from '@/components/VabArea/area'
  import { doEdit, getList } from '@/api/base/config'

  export default {
    name: 'Sys',
    components: { Upload, Area },
    data() {
      return {
        address: {
          province: {},
          city: {},
          district: {},
        },
        form: {
          multishop_enable: null,
          invoicing_enable: null,
        },
        promoteForm: {
          plantform_poster_bg: null,
          product_poster_bg: null,
        },
        rules: {
          multishop_enable: [
            {
              required: true,
              message: this.__('商品是否需要审核不能为空'),
              trigger: 'change',
            },
          ],
        },
        multishop_enables: [
          {
            label: this.__('是'),
            value: '1',
          },
          {
            label: this.__('否'),
            value: '0',
          },
        ],
        product_salenum_flagOptions: [
          {
            label: this.__('是'),
            value: '1',
          },
          {
            label: this.__('否'),
            value: '0',
          },
        ],
        trade_modes: [
          {
            label: this.__('担保交易'),
            value: '1',
          },
          {
            label: this.__('直接交易'),
            value: '2',
          },
        ],
        virtual_enables: [
          {
            label: this.__('启用'),
            value: '1',
          },
          {
            label: this.__('禁用'),
            value: '0',
          },
        ],
        product_show_types: [
          {
            label: this.__('SPU'),
            value: 'SPU',
          },
          {
            label: this.__('SKU'),
            value: 'SKU',
          },
        ],
        product_spec_edits: [
          {
            label: this.__('可以'),
            value: '1',
          },
          {
            label: this.__('不可以'),
            value: '0',
          },
        ],
        live_enables: [
          {
            label: this.__('开启'),
            value: '1',
          },
          {
            label: this.__('关闭'),
            value: '0',
          },
        ],
        live_modes: [
          {
            label: this.__('阿里云直播'),
            value: '0',
          },
          {
            label: this.__('小程序直播'),
            value: '1',
          },
        ],
        default_shipping_districtOptions: [],
        default_shipping_districtProps: {
          multiple: false,
          label: 'label',
          value: 'value',
          children: 'children',
        },
      }
    },
    created() {
      this.fetchData()
    },

    methods: {
      __,
      async fetchData() {
        const { data } = await getList()
        this.form = {
          multishop_enable: data.multishop_enable,
          invoicing_enable: data.invoicing_enable,
          evaluation_enable: data.evaluation_enable,
          o2o_enable: data.o2o_enable,
          trade_mode: data.trade_mode,
          virtual_enable: data.virtual_enable,
          product_show_type: data.product_show_type,
          product_spec_edit: data.product_spec_edit,
          pricing_policy: data.pricing_policy,
          point_enable: data.point_enable,
          sidecart_enable: data.sidecart_enable,
          im_enable: data.im_enable,
          sns_enable: data.sns_enable,
          plantform_fx_enable: data.plantform_fx_enable,
          chain_enable: data.chain_enable,
          plantform_fx_westore_enable: data.plantform_fx_westore_enable,
          store_supplier_enable: data.store_supplier_enable,
          supplier_market_enable: data.supplier_market_enable,
          hall_b2b_enable: data.hall_b2b_enable,
          b2b_flag: data.b2b_flag,
          subsite_enable: data.subsite_enable,
          live_enable: data.live_enable,
          adv_enable: data.adv_enable,
          info_enable: data.info_enable,
          dinghuo_enable: data.dinghuo_enable,
          delivery_time_enable: data.delivery_time_enable,
          user_level_rate_enable: data.user_level_rate_enable,
          user_level_price_enable: data.user_level_price_enable,
          client_cache: data.client_cache,
          multilang_enable: data.multilang_enable,
          sw_enable: data.sw_enable,
          live_mode_aliyun: data.live_mode_aliyun,
          live_mode_xcx: data.live_mode_xcx,
          esearch_enable: data.esearch_enable,
          edu_enable: data.edu_enable,
          product_salenum_flag: data.product_salenum_flag,
          product_virtual_salenum: data.product_virtual_salenum,
        }
        this.promoteForm = {
          plantform_poster_bg: data.plantform_poster_bg,
          product_poster_bg: data.product_poster_bg,
        }
        this.setAddress(
          data.default_shipping_district,
          data.default_shipping_district_ids
        )
      },

      handleEdit() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            const { msg, status } = await doEdit({
              param: JSON.stringify(this.form),
            })
            this.$baseMessage(msg, 'success', false, 'vab-hey-message-success')
          } else {
            return false
          }
        })
      },
    },
  }
</script>

<style scoped>
  #box-card-form-1 {
    overflow: unset;
  }
  .image_font {
    color: #979898;
    font-size: 14px;
  }
</style>
