<commit_before><template>
    <div class="panel panel-primary good-in">
        <div class="panel-heading">商品出库</div>
        <div class="panel-body" v-show="!loading.fetch">
            <validator name="v">
                <div class="input-group">
                    <span class="input-group-addon">商品名称</span>
                    <div class="select2Div">
                        <select id="productName" style="width: 100%" v-model="model.id" v-validate:name="{required:true}">
                        </select>
                    </div>
                </div>
                <div class="input-group error-msg" v-if="$v.name.touched && $v.name.invalid">
                    <div v-if="$v.name.required" class="red-color">商品名称不能为空</div>
                </div>
                <div class="input-group">
                    <span class="input-group-addon">商品属性</span>
                    <div class="select2Div">
                        <select id="productAttr" style="width: 100%" v-model="model.attr">
                            <option v-for="attr in attrList" :value="attr.attr">{{attr.attr | remove-whitespace}}</option>
                        </select>
                    </div>
                </div>
                <div class="input-group">
                    <span class="input-group-addon">出库数量</span>
                    <input id="productAmount" type="text" class="form-control" placeholder="请输入出库数量" aria-describedby="productAmount" v-model="model.amount" v-validate:amount="{required:true, posInt: true}" :class="{'red-border': $v.amount && $v.amount.touched && $v.amount.invalid}" number>
                </div>
                <div class="input-group error-msg" v-if="$v.amount.touched && $v.amount.invalid">
                    <div v-if="$v.amount.required" class="red-color">出库数量不能为空</div>
                    <div v-if="!$v.amount.required && $v.amount.posInt" class="red-color">出库数量只能为正整数</div>
                </div>
                <div class="input-group">
                    <span class="input-group-addon" id="productAmount">出售总价</span>
                    <input type="text" class="form-control" placeholder="请输入商品总价" aria-describedby="productPriceIn" v-model="model.priceOut" v-validate:price="{required:true, number: true}" :class="{'red-border': $v.price && $v.price.touched && $v.price.invalid}">
                </div>
                <div class="input-group error-msg" v-if="$v.price.touched && $v.price.invalid">
                    <div v-if="$v.price.required" class="red-color">出售总价不能为空</div>
                    <div v-if="!$v.price.required && $v.price.number" class="red-color">出售总价只能为数字</div>
                </div>
                <div class="float-right btns">
                    <button type="button" class="btn btn-primary" @click="goodsOut">出库</button>
                    <button type="button" class="btn btn-danger" @click="reset">取消</button>
                </div>
            </validator>
        </div>
        <div class="empty" v-show="loading.fetch">
            <div class="msg">正在加载商品详情</div>
        </div>
    </div>
</template>
<script>
import API from '../../config/api';
import DICT from '../../config/dict';
import actions from '../../vuex/actions';
import 'select2';

var Out = Vue.extend({
    name: 'out',
    data() {
        return {
            model: {
                id: "",
                name: "",
                attr: "",
                amount: 0,
                priceOut: ""
            },
            attrList: [],
            loading: {
                fetch: false,
                fetchList: false,
                out: false
            }
        }
    },
    ready() {
        var self = this;
        $(this.$el).find('#productName').select2({
            placeholder: "请输入商品名称（必填）",
            language: DICT.select2[this.lang],
            ajax: {
                url: API.searchGood,
                data(params) {
                    return {
                        name: params.term,
                        page: params.page
                    };
                },
                dataType: 'json',
                delay: 700,
                processResults: function(resp, params) {
                    var ret = [];
                    resp.forEach((r) => {
                        ret.push({
                            id: r.id,
                            text: r.name
                        })
                    })

                    return {
                        results: ret
                    };
                }
            }
        }).on('select2:select', (event) => {
            var data = event.params.data;
            if (data) {
                self.model.id = data.id;
                self.model.name = data.text;
                self.fetchCombination();
            }
        })
        $(this.$el).find('#productAttr').select2({
            placeholder: "请选择商品属性",
            language: DICT.select2[this.lang],
            minimumResultsForSearch: Infinity
        })

        this.$watch('model.id', this.changeSelect);
        this.init();
    },
    watch: {
        attrList() {
            $(this.$el).find('#productAttr').trigger('change');
        }
    },
    methods: {
        fetchCombination() {
            var self = this;
            $.ajax({
                url: API.attrCombination,
                data: {
                    good_id: this.model.id
                },
                success(rows) {
                    self.attrList = rows;
                },
                error() {
                    self.attrList = [];
                }
            })
        },
        init() {
            var id = this.$route.query.id;<commit_msg>add search box<commit_after><template>
    <div class="panel panel-primary good-in">
        <div class="panel-heading">商品出库</div>
        <div class="panel-body" v-show="!loading.fetch">
            <validator name="v">
                <div class="input-group">
                    <span class="input-group-addon">商品名称</span>
                    <div class="select2Div">
                        <select id="productName" style="width: 100%" v-model="model.id" v-validate:name="{required:true}">
                        </select>
                    </div>
                </div>
                <div class="input-group error-msg" v-if="$v.name.touched && $v.name.invalid">
                    <div v-if="$v.name.required" class="red-color">商品名称不能为空</div>
                </div>
                <div class="input-group">
                    <span class="input-group-addon">商品属性</span>
                    <div class="select2Div">
                        <select id="productAttr" style="width: 100%" v-model="model.attr">
                            <option v-for="attr in attrList" :value="attr.attr">{{attr.attr | remove-whitespace}}</option>
                        </select>
                    </div>
                </div>
                <div class="input-group">
                    <span class="input-group-addon">出库数量</span>
                    <input id="productAmount" type="text" class="form-control" placeholder="请输入出库数量" aria-describedby="productAmount" v-model="model.amount" v-validate:amount="{required:true, posInt: true}" :class="{'red-border': $v.amount && $v.amount.touched && $v.amount.invalid}" number>
                </div>
                <div class="input-group error-msg" v-if="$v.amount.touched && $v.amount.invalid">
                    <div v-if="$v.amount.required" class="red-color">出库数量不能为空</div>
                    <div v-if="!$v.amount.required && $v.amount.posInt" class="red-color">出库数量只能为正整数</div>
                </div>
                <div class="input-group">
                    <span class="input-group-addon" id="productAmount">出售总价</span>
                    <input type="text" class="form-control" placeholder="请输入商品总价" aria-describedby="productPriceIn" v-model="model.priceOut" v-validate:price="{required:true, number: true}" :class="{'red-border': $v.price && $v.price.touched && $v.price.invalid}">
                </div>
                <div class="input-group error-msg" v-if="$v.price.touched && $v.price.invalid">
                    <div v-if="$v.price.required" class="red-color">出售总价不能为空</div>
                    <div v-if="!$v.price.required && $v.price.number" class="red-color">出售总价只能为数字</div>
                </div>
                <div class="float-right btns">
                    <button type="button" class="btn btn-primary" @click="goodsOut">出库</button>
                    <button type="button" class="btn btn-danger" @click="reset">取消</button>
                </div>
            </validator>
        </div>
        <div class="empty" v-show="loading.fetch">
            <div class="msg">正在加载商品详情</div>
        </div>
    </div>
</template>
<script>
import API from '../../config/api';
import DICT from '../../config/dict';
import actions from '../../vuex/actions';
import 'select2';

var Out = Vue.extend({
    name: 'out',
    data() {
        return {
            model: {
                id: "",
                name: "",
                attr: "",
                amount: 0,
                priceOut: ""
            },
            attrList: [],
            loading: {
                fetch: false,
                fetchList: false,
                out: false
            }
        }
    },
    ready() {
        var self = this;
        $(this.$el).find('#productName').select2({
            placeholder: "请输入商品名称（必填）",
            language: DICT.select2[this.lang],
            ajax: {
                url: API.searchGood,
                data(params) {
                    return {
                        name: params.term,
                        page: params.page
                    };
                },
                dataType: 'json',
                delay: 700,
                processResults: function(resp, params) {
                    var ret = [];
                    resp.forEach((r) => {
                        ret.push({
                            id: r.id,
                            text: r.name
                        })
                    })

                    return {
                        results: ret
                    };
                }
            }
        }).on('select2:select', (event) => {
            var data = event.params.data;
            if (data) {
                self.model.id = data.id;
                self.model.name = data.text;
                self.fetchCombination();
            }
        })
        $(this.$el).find('#productAttr').select2({
            placeholder: "请选择商品属性",
            language: DICT.select2[this.lang]
        })

        this.$watch('model.id', this.changeSelect);
        this.init();
    },
    watch: {
        attrList() {
            $(this.$el).find('#productAttr').trigger('change');
        }
    },
    methods: {
        fetchCombination() {
            var self = this;
            $.ajax({
                url: API.attrCombination,
                data: {
                    good_id: this.model.id
                },
                success(rows) {
                    self.attrList = rows;
                },
                error() {
                    self.attrList = [];
                }
            })
        },
        init() {
            var id = this.$route.query.id;
{'fraction_non_alphanumeric': 0.1525991189427313, 'fraction_numerical': 0.003171806167400881, 'mean_word_length': 1.2715629377626576, 'pattern_counts': {'":': 0, '<': 133, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3288135', 'n_tokens_mistral': 3316, 'n_tokens_neox': 3202, 'n_words': 525}