zhao
2021-06-24 02ca96debc6056275d58e55d97f7885a195542d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutVue.cshtml";
}
@section head{
    <style>
        .el-input {
            font-size: 14px;
            display: inline-block;
            width: 120px;
        }
    </style>
    }
<el-container id="idMain">
        <el-form label-width="100px" class="demo-ruleForm" v-bind:inline="true">
            <el-form-item label="仓库名:">
                <hh-select-url v-model="stockCode"
                               url="/Basic/Common/StockList"
                               valuefield="CN_S_STOCK_CODE"
                               textfield="CN_S_STOCK_NAME"
                               datafield="Data">
                </hh-select-url>
            </el-form-item>
        </el-form>
        <el-tabs type="card" v-on:click="handleClick">
            <el-tab-pane v-for="group in groups" v-bind:label="group.CN_S_GROUP">
                <el-form label-width="150px" class="demo-ruleForm" v-bind:inline="true">
                    <el-form-item v-for="item in groupItems[group.CN_S_GROUP]" v-bind:label="item.CN_S_NAME">
                        <el-input v-if="item.CN_S_VALUE_TYPE==='数值'" required size="mini" v-model="item.CN_S_VALUE"></el-input>
                        <el-checkbox v-if="item.CN_S_VALUE_TYPE==='bool'" v-model="item.CN_S_VALUE"></el-checkbox>
                        <hh-select-url v-if="item.CN_S_VALUE_TYPE==='字典'"
                                       v-model="item.CN_S_VALUE"
                                       v-bind:url="'/Basic/Common/GetDictionary?dictName='+item.CN_S_DIC_NAME"
                                       valuefield="NAME"
                                       textfield="NAME">
                        </hh-select-url>
                    </el-form-item>
                </el-form>
            </el-tab-pane>
        </el-tabs>
        <el-footer>
            <el-row style="padding:10px;text-align:center" >
                <el-button size="mini" type="primary" v-on:click="save" v-show="!readOnly">保 存</el-button>
            </el-row>
        </el-footer>
</el-container>
 
@section scripts{
<script src="~/Content/js/linq.js_ver2.2.0.2/linq.js"></script>
    <script>
        new Vue({
            el: '#idMain',
            data: {
                stockCode:"",
                groups: [], //策略分组
                groupItems: {},//分组内的设置项
                oldValues: [],//旧的设置选项
                items: [],//总的设置选项
                values: [],
                changedItemSum:0,//更新值的项目数量
            },
            mounted: function () {
                var $this = this;
                this.loadData();
            },
            watch: {
                stockCode: function ()
                {
                    this.loadValue();
                }
            },
            methods: {
                loadData: function () {
                    var $this = this;
                    ajaxManage({
                        url: "@Url.Action("GetSetOption")",
                        success: function (result) {
                            result.Data.forEach(function (value, index, array) {
                                if (value.CN_S_VALUE_TYPE == 'bool')
                                    value.CN_S_VALUE = value.CN_S_VALUE == 'Y' ? true : false;
                            });
                            $this.items = result.Data;
                            $this.groups = Enumerable.From(result.Data).GroupBy("$.CN_S_GROUP", null,
                            function (key, g) {
                                var result2 = {
                                    CN_S_GROUP: key
                                }
                                return result2;
                            }).ToArray();
 
                            $this.groups.forEach(function (value, index, array) {
                                $this.groupItems[value.CN_S_GROUP] = Enumerable.From($this.items).Where("x=>x.CN_S_GROUP=='" + value.CN_S_GROUP + "'").ToArray();
                            });
                        }
                    });
                },
                loadValue: function () {
                    var $this = this;
                    ajaxManage({
                        url: "@Url.Action("GetOptionValue")?stockCode=" + $this.stockCode,
                        success: function (result)
                        {
                            if (result.Success) {
                                //获取仓库下的设置值
                                $this.items.forEach(function (value, index, array) {
                                    if (value.CN_S_VALUE_TYPE == 'bool') {
                                        $this.CN_S_VALUE = false;
                                    }
                                    else {
                                        $this.CN_S_VALUE = '';
                                    }
                                });
 
                                result.Data.forEach(function (value, index, array) {
                                    var obj = Enumerable.From($this.items).Where("x=>x.CN_S_CODE=='" + value.CN_S_CODE + "'").ToArray()[0];
                                    if (obj.CN_S_VALUE_TYPE == 'bool') {
                                        obj.CN_S_VALUE = value.CN_S_VALUE == 'Y' ? true : false;
                                    }
                                    else {
                                        obj.CN_S_VALUE = value.CN_S_VALUE;
                                    }
                                });
 
                                $this.oldValues = JSON.parse(JSON.stringify($this.items));
                            }
                            else {
                                alert(result.Msg);
                            }
                        }
                    });
                },
                handleClick:function(tab, event) 
                {
                    console.log(tab, event);
                },
                save: function () {
                    var $this = this;
 
                    if ($this.stockCode == "")
                    {
                        wms.error("请选择仓库!");
                        return false;
                    }
 
                    var newItems = [];
 
                    $this.items.forEach(function (value, index, array) {
                        var oldValue = $this.oldValues[value.CN_S_CODE];
 
                        var newItemObj = Enumerable.From($this.items).Where("x=>x.CN_S_CODE=='" + value.CN_S_CODE + "'").ToArray()[0];
                        
                        if (newItemObj.CN_S_VALUE != oldValue) {
                            if (newItemObj.CN_S_VALUE_TYPE == "bool") {
                                if (newItemObj.CN_S_VALUE)
                                    newItems.push({ CN_S_CODE: newItemObj.CN_S_CODE, CN_S_VALUE: "Y" });
                                else
                                    newItems.push({ CN_S_CODE: newItemObj.CN_S_CODE, CN_S_VALUE: "N" });
                            }
                            else
                                newItems.push({ CN_S_CODE: newItemObj.CN_S_CODE, CN_S_VALUE: newItemObj.CN_S_VALUE });
                        }
                    });
 
                    ajaxManage({
                        url: "@Url.Action("Save")?stockCode=" + $this.stockCode + "&ChangedItems=" + JSON.stringify(newItems),
                        success: function (result) {
                            if (result.Success)
                            {
                                wms.success("保存成功!");
                            }
                            else
                                wms.error(result.Msg);
                        }
                    });
                }
            }
        });
 </script>
}