<!DOCTYPE html>
<html>
<head>
    <title>-添加/修改</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <!-- 所有的 css js 资源 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui@2.13.0/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../../static/sa.css">
    <script src="https://unpkg.com/vue@2.6.10/dist/vue.js"></script>
    <script src="https://unpkg.com/element-ui@2.13.0/lib/index.js"></script>
    <script src="https://unpkg.com/http-vue-loader@1.4.2/src/httpVueLoader.js"></script>
    <script src="https://unpkg.com/jquery@3.4.1/dist/jquery.js"></script>
    <script src="https://www.layuicdn.com/layer-v3.1.1/layer.js"></script>
    <script src="../../static/sa.js"></script>
    <style type="text/css">
        .c-panel .el-form .c-label {
            width: 15em !important;
        }

        .c-panel .el-form .el-input, .c-panel .el-form .el-textarea__inner {
            width: 250px;
        }
    </style>
</head>
<body>
<div class="vue-box" :class="{sbot: id}" style="display: none;" :style="'display: block;'">
    <!-- ------- 内容部分 ------- -->
    <div class="s-body">
        <div class="c-panel">
            <div class="c-title" v-if="id == 0">数据添加</div>
            <div class="c-title" v-else>数据修改</div>
            <el-form v-if="m">
                <sa-item type="text" name="产品学名" v-model="m.goodsName" br></sa-item>
                <sa-item type="num" name="毛重(kg)" v-model="m.grossWeight" br></sa-item>
                <sa-item type="num" name="数量(件)" v-model="m.num" br></sa-item>
                <!--						<sa-item type="text" name="生产日期" v-model="m.productionDate" br></sa-item>-->
                <div class="c-item br">
                    <label class="c-label">生产日期:</label>
                    <el-date-picker type="date" value-format="yyyy-MM-dd" v-model="m.productionDate"
                                    placeholder="请选择"></el-date-picker>
                </div>
                <sa-item type="num" name="保质期(天)" v-model="m.expirationDate" br></sa-item>
                <sa-item type="text" name="储存条件" v-model="m.storageMode" br></sa-item>
                <sa-item type="text" name="生产方式" v-model="m.productionMode" br></sa-item>
                <sa-item type="text" name="原产国" v-model="m.origin" br></sa-item>
                <sa-item type="text" name="进口冷链食品生产商注册号" v-model="m.producerCode" br></sa-item>
                <sa-item type="text" name="货主单位" v-model="m.sendUnit" br></sa-item>
                <sa-item type="text" name="收货单位" v-model="m.receiveUnit" br></sa-item>
                <sa-item type="text" name="货物流向" v-model="m.route" br></sa-item>
                <sa-item type="text" name="司机姓名" v-model="m.driverName" br></sa-item>
                <sa-item type="text" name="司机电话" v-model="m.driverPhone" br></sa-item>
                <!--						<sa-item type="text" name="代理商" v-model="m.agent" br></sa-item>-->
                <sa-item type="text" name="代理商电话" v-model="m.agentPhone" br></sa-item>
                <sa-item type="text" name="运输车(车头牌)" v-model="m.chinaCarNo" placeholder="运输车车头牌,多个请用逗号隔开" br></sa-item>
                <sa-item type="text" name="运输车(车尾牌)" v-model="m.chinaCarSuff" placeholder="运输车车尾牌,多个请用逗号隔开"
                         br></sa-item>
                <sa-item type="text" name="越南车车牌" v-model="m.carNo" br></sa-item>
                <sa-item type="text" name="海关报关单据" v-model="m.customProof" br></sa-item>
                <sa-item type="text" name="进口检验检疫证书" v-model="m.quarantineProof" br></sa-item>
                <sa-item type="text" name="商铺" v-model="m.shop" br></sa-item>
                <sa-item type="text" name="生产批号" v-model="m.productionCode" br></sa-item>
                <sa-item type="text" name="柜号" v-model="m.containerCode" br></sa-item>
                <sa-item name="" class="s-ok" br>
                    <el-button type="primary" icon="el-icon-plus" @click="ok()">保存</el-button>
                </sa-item>
            </el-form>
        </div>
    </div>
    <!-- ------- 底部按钮 ------- -->
    <div class="s-foot">
        <el-button type="primary" @click="ok()">确定</el-button>
        <el-button @click="sa.closeCurrIframe()">取消</el-button>
    </div>
</div>
<script>

    var app = new Vue({
        components: {
            "sa-item": httpVueLoader('../../sa-frame/com/sa-item.vue')
        },
        el: '.vue-box',
        data: {
            id: sa.p('id', 0),		// 获取超链接中的id参数(0=添加,非0=修改)
            m: null,		// 实体对象
        },
        methods: {
            // 创建一个 默认Model
            createModel: function () {
                return {
                    id: '',		// 主键
                    businessId: '',		// 业务id
                    goodsName: '',		// 产品学名
                    grossWeight: '',		// 毛重
                    num: '',		// 件数
                    productionDate: '',		// 生产日期
                    expirationDate: '',		// 保质期
                    storageMode: '',		// 储存条件
                    productionMode: '',		// 生产方式
                    origin: '',		// 原产国
                    producerCode: '',		// 进口冷链食品生产商注册号
                    sendUnit: '',		// 货主单位
                    receiveUnit: '',		// 收货单位
                    route: '',		// 货物流向
                    driverName: '',		// 司机姓名
                    driverPhone: '',		// 联系电话(司机)
                    agent: '',		// 代理商
                    agentPhone: '',		// 联系电话(代理人)
                    chinaCarNo: '',		// 运输车车牌
                    chinaCarSuff: '',
                    carNo: '',		// 越南车车牌
                    customProof: '',		// 海关报关单据
                    quarantineProof: '',		// 进口检验检疫证书
                    shop: '',		// 商铺(互助组)
                    productionCode: '',		// 生产批号
                    containerCode: '',		// 柜号
                }
            },
            // 提交数据
            ok: function () {
                // 表单校验
                let m = this.m;
                sa.checkNull(m.goodsName, '请输入 [产品学名]');
                sa.checkNull(m.grossWeight, '请输入 [毛重]');
                sa.checkNull(m.num, '请输入 [数量]');
                sa.checkNull(m.productionDate, '请输入 [生产日期]');
                sa.checkNull(m.expirationDate, '请输入 [保质期]');
                sa.checkNull(m.storageMode, '请输入 [储存条件]');
                sa.checkNull(m.productionMode, '请输入 [生产方式]');
                sa.checkNull(m.origin, '请输入 [原产国]');
                sa.checkNull(m.producerCode, '请输入 [进口冷链食品生产商注册号]');
                sa.checkNull(m.sendUnit, '请输入 [货主单位]');
                sa.checkNull(m.receiveUnit, '请输入 [收货单位]');
                sa.checkNull(m.route, '请输入 [货物流向]');
                sa.checkNull(m.driverName, '请输入 [司机姓名]');
                sa.checkNull(m.driverPhone, '请输入 [司机联系电话]');
                // sa.checkNull(m.agent, '请输入 [代理商]');
                sa.checkNull(m.agentPhone, '请输入 [代理商联系电话]');
                if (!sa.isPhone(m.agentPhone)) {
                    sa.error('代理商联系电话不正确')
                    return;
                }
                sa.checkNull(m.chinaCarNo, '请输入 [运输车车头牌]');
                sa.checkNull(m.chinaCarSuff, '请输入 [运输车车尾牌]');
                sa.checkNull(m.carNo, '请输入 [越南车车牌]');
                sa.checkNull(m.customProof, '请输入 [海关报关单据]');
                sa.checkNull(m.quarantineProof, '请输入 [进口检验检疫证书]');
                // sa.checkNull(m.shop, '请输入 [商铺]');
                // sa.checkNull(m.productionCode, '请输入 [生产批号]');
                // sa.checkNull(m.containerCode, '请输入 [柜号]');

                // 开始增加或修改
                if (this.id <= 0) {	// 添加
                    sa.ajax('/TbDeclare/add', m, function (res) {
                        sa.alert('增加成功', this.clean);
                    }.bind(this));
                } else {	// 修改
                    sa.ajax('/TbDeclare/update', m, function (res) {
                        sa.alert('修改成功', this.clean);
                    }.bind(this));
                }
            },
            // 添加/修改 完成后的动作
            clean: function () {
                if (this.id == 0) {
                    this.m = this.createModel();
                } else {
                    parent.app.f5();		// 刷新父页面列表
                    sa.closeCurrIframe();	// 关闭本页
                }
            }
        },
        mounted: function () {
            // 初始化数据
            if (this.id <= 0) {
                this.m = this.createModel();
            } else {
                sa.ajax('/TbDeclare/getById?id=' + this.id, function (res) {
                    this.m = res.data;
                    if (res.data == null) {
                        sa.alert('未能查找到 id=' + this.id + " 详细数据");
                    }
                }.bind(this))
            }
        }
    })

</script>
</body>
</html>