<?php /* /www/wwwroot/jian/resources/views/Admin/goodsedit.blade.php */ ?>
<?php $__env->startSection('admin'); ?>
<script src="/admin/plugins/jquery/jquery.min.js"></script>
<script src="/admin/layer-v3.1.1/layer/layer.js"></script>
<!-- 图片裁剪 -->
<!-- <link rel="stylesheet" type="text/css" href="/img_cate/ycbootstrap.css"> -->
<link rel="stylesheet" type="text/css" href="/img_cate/reset.css">
<script src="/img_cate/jquery-1.10.2.js"></script>
<!-- <script src="/img_cate/jquery.min.js"></script> -->
<script src="/img_cate/iscroll-zoom.js" type="text/javascript" charset="utf-8"></script>
<script src="/img_cate/hammer.js" type="text/javascript" charset="utf-8"></script>
<script src="/img_cate/lrz.all.bundle.js" type="text/javascript" charset="utf-8"></script>
<script src="/img_cate/jquery.photoClip.min.js" type="text/javascript" charset="utf-8"></script>
<style>
  img {
    max-width: 100%;
  }
</style>
<div class="content-wrapper" style="min-height: 810px;">
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h4>编辑商品</h4>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/admin/index">首页</a></li>
              <li class="breadcrumb-item active">商品管理</li>
              <li class="breadcrumb-item active">商品列表</li>
              <li class="breadcrumb-item active">编辑商品</li>
            </ol>
          </div>
        </div>
      </div>
    </section>
    <div class="col-xs-3">
        <button class="btn btn-danger back" style="margin-left:17px;margin-bottom:15px"> 返回列表</button>
    </div>

    <section class="content">
        
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12">
            <div class="card">
              <div class="card-body p-0">
                <!-- 表单 -->
                <input type="hidden" value="<?php echo e($res -> id); ?>" id="goodsid">
                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4"><span style="color:red">*</span> 商品名称</label>
                        <input type="text" class="form-control col-md-6" id="goodsName" value="<?php echo e($res -> goods_name); ?>">
                    </div>
                </form>

                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4"><span style="color:red">*</span> 所属门店</label>
                        <select class="form-control col-md-6" id="md">
                            <?php $__currentLoopData = $md; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($val -> id); ?>" <?php if($res -> md_id == $val -> id): ?> selected <?php endif; ?>><?php echo e($val -> md_name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                </form>

                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4"><span style="color:red">*</span> 所属分类</label>
                        <select class="form-control col-md-6" id="goodsCate">
                          <?php $__currentLoopData = $cate; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($val -> id); ?>" <?php if($res -> pid == $val -> id): ?> selected <?php endif; ?>><?php echo e($val -> cate_name); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                </form>

                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-4"><span style="color:red">*</span> 商品价格</label>
                        <input type="number" class="form-control col-md-6" id="goodsPrice" value="<?php echo e($res -> price); ?>">
                    </div>
                </form>
                <!-- 图片裁剪代码 -->
                <body style="">
                  <div class="yc-upload-wrap col-md-6">
                  <div class="yc-upload-box">
                  <div class="container">
                  <div class="row">
                  <div class="col-md-12 col-sm-12 col-xs-12" style="padding:0;">
                  <div class="ycupload-mainbox">
                  <div class="ycupload-line"></div>
                  <div style="height:30px;"></div>
                  <div style="min-height:1px;">
                  <div class="container">
                  <div class="row">
                  <div class="col-md-12 col-sm-12 col-xs-12" style="padding-right:0;padding-left:36px;">

                  <div style="min-height:1px;line-height:160px;text-align:center;position:relative;" ontouchstart="">
                  <div class="cover-wrap" style="position: fixed; left: 0px; top: 0px; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.4); z-index: 10000000; text-align: center; display: none;">
                  <div class="" style="width:900px;height:600px;margin:100px auto;background-color:#FFFFFF;overflow: hidden;border-radius:4px;">
                  <div id="clipArea" style="margin: 10px; height: 520px; user-select: none; overflow: hidden; position: relative;"><div class="photo-clip-view" style="position: absolute; left: 50%; top: 50%; width: 428px; height: 321px; margin-left: -214px; margin-top: -160.5px;"><div class="photo-clip-moveLayer" style="transform-origin: 0px 0px 0px; transition-timing-function: cubic-bezier(0.1, 0.57, 0.1, 1); transition-duration: 0ms; transform: translate(0px, 0px) scale(1) translateZ(0px);"><div class="photo-clip-rotateLayer"></div></div></div><div class="photo-clip-mask" style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; pointer-events: none;"><div class="photo-clip-mask-left" style="position: absolute; left: 0px; right: 50%; top: 50%; bottom: 50%; width: auto; height: 321px; margin-right: 214px; margin-top: -160.5px; margin-bottom: -160.5px; background-color: rgba(0, 0, 0, 0.5);"></div><div class="photo-clip-mask-right" style="position: absolute; left: 50%; right: 0px; top: 50%; bottom: 50%; margin-left: 214px; margin-top: -160.5px; margin-bottom: -160.5px; background-color: rgba(0, 0, 0, 0.5);"></div><div class="photo-clip-mask-top" style="position: absolute; left: 0px; right: 0px; top: 0px; bottom: 50%; margin-bottom: 160.5px; background-color: rgba(0, 0, 0, 0.5);"></div><div class="photo-clip-mask-bottom" style="position: absolute; left: 0px; right: 0px; top: 50%; bottom: 0px; margin-top: 160.5px; background-color: rgba(0, 0, 0, 0.5);"></div><div class="photo-clip-area" style="border: 1px dashed rgb(221, 221, 221); position: absolute; left: 50%; top: 50%; width: 428px; height: 321px; margin-left: -215px; margin-top: -161.5px;"></div></div></div>
                  <div class="" style="height:56px;line-height:36px;text-align: center;padding-top:8px;">
                  <button id="clipBtn" style="width:120px;height: 36px;border-radius: 4px;background-color:#ff8a00;color: #FFFFFF;font-size: 14px;text-align: center;line-height: 36px;outline: none;">保存封面</button>
                  </div>
                  </div>
                  </div>
                  <div id="view" style="width: 214px; height: 160.5px; background-color: rgb(102, 102, 102); <?php if($res -> goods_images): ?> background:url('/<?php echo e($res -> goods_images); ?>'); <?php endif; ?> background-repeat: no-repeat; background-position: center center; background-size: contain;"></div>
                  <div style="height:10px;"></div>
                  <div class="" style="width:140px;height:32px;border-radius: 4px;background-color:#ff8a00;color: #FFFFFF;font-size: 14px;text-align:center;line-height:32px;outline:none;margin-left:37px;position:relative;">
                  点击上传封面图
                  <input type="file" id="file" style="cursor:pointer;opacity:0;filter:alpha(opacity=0);width:100%;height:100%;position:absolute;top:0;left:0;" accept="image/*">
                  </div>
                  </div>
                  </div>
                  </div>
                  </div>
                  </div>
                  </div>
                  </div>
                  </div>
                  </div>
                  </div>
                  </div>

                  </body>
                  
            <input type="hidden" id="imgURL">
                <!-- 文章 -->
                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputFile" class="col-md-4">商品介绍</label>
                        <div class="input-group col-md-6">
                            <!-- 加载编辑器的容器 -->
                              <script id="container" style="height:400px;" name="content" type="text/plain"><?php echo $res -> goods_description; ?></script>
                              <!-- 配置文件 -->
                              <script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
                              <!-- 编辑器源码文件 -->
                              <script type="text/javascript" src="/ueditor/ueditor.all.js"></script>
                              <!-- 实例化编辑器 -->
                              <script type="text/javascript">
                                  var ue = UE.getEditor('container');
                              </script>
                        </div>
                    </div>
                </form>
                <form class="form">
                    <div class="form-group m-4 col-sm-6">
                        <a class="btn btn-success ok" style="color:white">保存</a>
                    </div>
                </form>
                <!-- 表单结束 --> 

              </div>
            </div>
          </div>
        </div>
    </section>
  </div>

<script>
$('.back').click(function(){
    window.location.href="/admin/goodscate/goods";
})
//选择门店联动
$('#md').change(function(){
    let id = $('#md option:selected').val();
    if(!id){
      layer.alert('参数不全');
      return false;
    }
    ajax(id);
})
function ajax(id)
{
  $.get('/admin/goodscate/goodsGetCate',{id:id},function(res){
        if(res.length){
          //干掉旧的数据
          $('#goodsCate').html('');
          for( x in res ){
            $('#goodsCate').append('<option value='+res[x].id+'>'+res[x].cate_name+'</option>');
          }
        }
    })
}
  var clipArea = new bjj.PhotoClip("#clipArea", {
      size: [500, 380],// 截取框的宽和高组成的数组。默认值为[260,260]
      outputSize: [0, 0], // 输出图像的宽和高组成的数组。默认值为[0,0]，表示输出图像原始大小
      //outputType: "jpg", // 指定输出图片的类型，可选 "jpg" 和 "png" 两种种类型，默认为 "jpg"
      file: "#file", // 上传图片的<input type="file">控件的选择器或者DOM对象
      view: "#view", // 显示截取后图像的容器的选择器或者DOM对象
      ok: "#clipBtn", // 确认截图按钮的选择器或者DOM对象
      loadStart: function() {
        $('.cover-wrap').fadeIn();
        console.log("照片读取中");
      },
      loadComplete: function() {
        console.log("照片读取完成");
      },
      clipFinish: function(dataURL) {
        $('.cover-wrap').fadeOut();
        $('#view').css('background-size','100% 100%');
        if(dataURL){
          $('#imgURL').val(dataURL);
        }
      }
    });
$('.ok').click(function(){
  var id = $('#goodsid').val();
  var imgURL = $('#imgURL').val();
  var goodsName = $('#goodsName').val();
  var goodsCate = $('#goodsCate').val();
  var goodsPrice = $('#goodsPrice').val();
  var md_id = $('#md').val();
  var goodsDescription = ue.getContent();
  if(!goodsName || !goodsCate || !goodsPrice) {
    layer.alert('请填写必填信息');
    return false;
  }
  $.post('/admin/goodscate/goodsUpdate',{md_id:md_id,id:id,imgURL:imgURL,goodsName:goodsName,goodsCate:goodsCate,goodsPrice:goodsPrice,goodsDescription:goodsDescription},function(res){
          if(res.code == '1000'){
                layer.msg(res.msg);
                window.location.reload();
            }else{
                layer.alert(res.msg);
            }
  })
})
</script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('title','商品添加'); ?>
<?php $__env->startSection('goods','menu-open'); ?>
<?php $__env->startSection('goods2','active'); ?>
<?php $__env->startSection('goodslist','active'); ?>
<?php echo $__env->make('Public.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>