2018年5月25日 星期五

[Vue] vue-form - Get form state from component


  Vue.js    vue-form     validator


Introduction


vue-form is for form validation for Vue.js 2.2+.
Here is a tip for how to get form-state from component to enable/disable a button in parent (Vue instance).





Environment


vue.js 2.5.13
bootstrap 4.0.0
vue-form 4.7.1



Implement


The concept is store form-state in both parent and sub-component.

Parent

JS

var app = new Vue({
    el: '#app',
    data: {
        formstate: null;
},
}


HTML

<user-info @update-state="function(val){ formstate=val; }"
 ></user-info>
<input type="button" value="Save" :disabled="formstate.$invalid" class="form-control" />

We will create user-info component later, now in html we shall provide an event: update-state, as an emit callback for component: user-info.



Component

We need to watch the form-state and emit the parent event in order to update the one in parent.

Vue.use(VueForm);

Vue.component('user-info', {
    data: function () {
        return {
            formstate: {},
            user: {
                name: "",
                nickname:""
            }
        }
    },
    watch: {
        formstate: function (newVal, oldVal) {
            var vm = this;
            this.$emit('update-state', this.formstate);

        }
    },
    template: `<vue-form :state="formstate">
                <div class="form-group required">
                    <label class="control-label col-md-4">Name</label>
                    <validate class="col-md-8 text-left">
                        <input type="text" v-model="user.name" name="userName" required />
                    </validate>
                </div>
              <div class="form-group required">
                    <label class="control-label col-md-4">Nickname</label>
                    <validate class="col-md-8 text-left">
                        <input type="text" v-model="user.nickname" name="userNickname" required />
                    </validate>
                </div>
            </vue-form>`
});



Result





Quick way by using .sync Modifier

.sync Modifier is new on Vue.js 2.3.0+
We can refactor our codes in a cleaner way like this,

Parent: Modify HTML

<user-info :state.sync="formstate"></user-info>
<input type="button" value="Save" :disabled="formstate.$invalid" class="form-control" />


In :state.sync="formstate"

state: the prop of component
.sync: .sync Modifier
formstate: the prop of parent


It is the shorthand(sugar) for the following pattern:

<user-info :state="formstate" v-on:update:title="formstate = $event"></user-info>



Component

Since we know how .sync Modifier works.
We then update the emit-event name in component.

Vue.use(VueForm);

Vue.component('user-info', {

    props: ['state'],
    watch: {
        formstate: function (newVal, oldVal) {
            var vm = this;
            this.$emit('update:state', this.formstate);
        }
    },
    data: skip…
    template: `skip…`
`
});


Which will result in the same effect for enable/disable the parent’s submit button.



Reference





2018年5月18日 星期五

[SAP TM] 07. Create Forwarding order


 SAP   Transportation Management  


Introduction


上一個章節我們提到多種產生運輸需求(託運單)的來源。 其實在SAP TM已經開好interface的情況下,也可以在B2B的方式由其他系統觸發SAP TM自動建立一張託運單 (Forwarding order)

而在託運單上面,需要記錄運送的方式、運輸工具、時間和出貨及到貨地點等資訊。
接下來我們將實際在SAP TM上建立一張Forwarding order(託運單)


Environment


SAP TM 9.3 SP06
NetWeaver 7.4


Features


建立託運單

NWBC路徑:【Forwarding Order ManagementCreate Forwarding Order




選擇Forwarding Order Type,再Continue




設定一般資訊

General Data】頁面,選擇Order Date(訂單日期)Sales Organization(銷售組織)



同一頁面下,選擇對應的Movement Type








繼續往下設定託運的貨物 (可設定更上層的包裝Package)




在往下則是設定貨物(Product/Package)的運送細節,比較重要的是Locations and Dates/Times】。
可設定撿貨和送貨的日期時間地點。




設定業務夥伴(Business Partner)

設定此託運單的BP

1.  下單者 Ordering Party
2.  出貨者 Shipper
3.  收貨者 Consignee



若有需要可再帶入更多BP到此張託運單。



計算運費(Optional)

需先建立Forwarding Agreement(託運協議)後,點選上方功能列中的【Calculate ChargesCalculate Charges




計算運費後,可到【Charges】頁面查看運費資訊。




儲存託運單並完成建立




基本上一張託運單由上面的步驟可建立完成,但視業務及公司要求可能需維護更多的細節在託運單(Forwarding order)上。




Reference


SAP TM100 Process In Transportatin Management class