sortTab-editor-item.vue 2.65 KB
<template>
    <Form :model="formItem" :label-width="60">
        <FormItem label="标题">
            <Input :value="formItem.category_name" @input="onChangeCate" placeholder="标题"/>
        </FormItem>

        <FormItem label="more">
            <Input :value="formItem.productListTitle" @input="onChangeTitle" placeholder="跳转列表标题"/>
        </FormItem>

        <FormItem >
          <Select :value="formItem.type" @input="onChangeSelect">
            <Option value="sort">分类</Option>
            <Option value="series">系列</Option>
          </Select>
        </FormItem>

        <FormItem >
            <Input :value="formItem.type_id" placeholder="ID" @input="onChangeType" />
        </FormItem>

        <FormItem label="商品编码">
            <Input :value="formItem.product_ids" type="textarea" @input="onChangeIds" :rows="4" placeholder="多个商品以英文逗号分隔"/>
        </FormItem>

        <Button type="error" @click="onDelete">删除</Button>&nbsp; 提示:可拖动排序
    </Form>
</template>

<script>
export default {
  props: ["value", "id"],
  data() {
    let type = 'sort' in this.value.more_url.params ? 'sort' : 'series';
    let type_id = this.value.more_url.params[type] || ''
    let productListTitle = this.value.more_url.params.productListTitle || '';

    return {
      formItem: {
        category_name: this.value.category_name,
        product_ids: this.value.product_ids,
        productListTitle,
        type,
        type_id,
      }
    };
  },
  methods: {
    onDelete() {
      this.$emit('on-remove', this.id);
    },
    getValue() {
      let vm = this;

      return {
        category_name: vm.formItem.category_name,
        product_ids: vm.formItem.product_ids,
        more_url: {
          action: "go.ufo",
          params: {
            pagename: "productList",
            productListTitle: vm.formItem.productListTitle,
            [vm.formItem.type]: vm.formItem.type_id
          }
        }
      };
    },
    onChangeCate(v) {
      this.formItem.category_name = v;
      this.$emit('on-change', this.getValue());
    },
    onChangeTitle(v) {
      this.formItem.productListTitle = v;
      this.$emit('on-change', this.getValue());
    },
    onChangeSelect(v) {
      this.formItem.type = v;
      this.formItem.type_id = null;
      this.$emit('on-change', this.getValue());
    },
    onChangeType(v) {
      this.formItem.type_id = v;
      this.$emit('on-change', this.getValue());
    },
    onChangeIds(v) {
      this.formItem.product_ids = v;
      this.$emit('on-change', this.getValue());
    },
  }
};
</script>

<style scoped>
  .ivu-form-item {
    margin-bottom: 10px !important;
  }
</style>