<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>成品产品管理</title>
    <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body" pad15>
               <div class="layui-tab layui-tab-card">
                   <ul class="layui-tab-title">
                       <li class="layui-this">车型信息</li>
                       <li>海报信息</li>
                       <li>整车图片</li>
                       <li>车型图片</li>
                       <li>车型规格</li>
                   </ul>
                   <div class="layui-tab-content">
                       <div class="layui-tab-item layui-show">
                           <table class="layui-table">
                               <tr>
                                   <th style="width: 100px;">品牌名称</th>
                                   <td id="brand_name" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">车系名称</th>
                                   <td id="series_name" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">车型名称</th>
                                   <td id="name" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">定金金额</th>
                                   <td id="advance_pay_show" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">顶现金额</th>
                                   <td id="equal_pay_show" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">指导价格</th>
                                   <td id="price_show" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">本店价格</th>
                                   <td id="shop_price_show" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">车型介绍</th>
                                   <td id="describe" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">是否热门</th>
                                   <td id="hot_text" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">推荐数</th>
                                   <td id="recommend_count" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">成交数</th>
                                   <td id="success_count" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">收藏数</th>
                                   <td id="collection_count" class="cell"></td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">车型图片</th>
                                   <td>
                                       <img class="layui-upload-img" id="thumbnail" style="max-height: 250px;">
                                   </td>
                               </tr>
                               <tr>
                                   <th style="width: 100px;">备注</th>
                                   <td id="notes" class="cell"></td>
                               </tr>
                           </table>
                       </div>
                       <div class="layui-tab-item">
                           <img class="layui-upload-img" id="playbill" style="max-height: 250px;">
                       </div>
                       <div class="layui-tab-item">
                           <div class="layui-upload-list" id="images" style="display: flex;flex-wrap: wrap;">
                           </div>
                       </div>
                       <div class="layui-tab-item">
                           <div class="layui-upload" id="div_upload">
                           </div>
                       </div>
                       <div class="layui-tab-item">
                           <table class="layui-hide" id="datagrid"></table>
                       </div>
                   </div>
               </div>
            </div>
        </div>
    </div>

    <script src="../../layuiadmin/layui/layui.js?t=1"></script>
    <script>
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table','laydate', 'utils'], function () {
            var $ = layui.$;
            var table = layui.table;
            var admin = layui.admin;
            var options = null;

            var id = layui.view.getParameterByName('id');
            var editdata = JSON.parse(JSON.stringify(parent.layui.table.editdata));
            $('#thumbnail').attr('src', editdata.thumbnail_url);
            $('#playbill').attr('src', editdata.playbill_url);
            $('.cell').each(function (index, element) {
                element.innerHTML =  (editdata[element.id])
            });

            admin.req({
                 url: '/vehicle/images/?vehicle_model=' + id,
                done: function (res) {
                   $('#images').html('');
                   var data = res.data;
                   for (var i in data){
                       var html = '<div style="margin-top: 10px;"><a href="'+data[i].img_url+'" target="_blank"><img src="'+ data[i].img_url +'" class="layui-upload-img" style="margin-left: 5px;min-width: 80px; height: 100px;max-width: 200px;"></a></div>';
                        $('#images').append(html)
                   }
                }
             });

            admin.req({
                 url: '/option/search/?type=3'
                 ,done: function(res){
                     var data = res.data;
                     options = res.data;
                     for (var m in data){
                         var div_id='show_image_'+data[m].id;
                         var html  = '<span >'+data[m].name+'图片</span>' +
                         '<blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">' +
                         '<div class="layui-upload-list" id="'+div_id+'" style="display: flex;flex-wrap: wrap;"></div></blockquote>';
                         $('#div_upload').append(html)
                     }
                     loadUpload();
                 }
            });

            var loadUpload = function(){
                admin.req({
                     url: '/vehicle/model_images/?vehicle_model=' + id,
                    done: function (res) {
                       for (var i in options){
                          $('#show_image_' + options[i].id).html('');
                        }

                       var data = res.data;
                       for (var i in data){
                           var html = '<div style="margin-top: 10px;"><a href="'+data[i].img_url+'" target="_blank"><img src="'+ data[i].img_url +'" class="layui-upload-img" style="margin-left: 5px;min-width: 80px; height: 100px;max-width: 200px;"></a></div>';
                            $('#show_image_'+ data[i].type).append(html)
                       }
                    }
                 });
            };

            table.render({
              elem: '#datagrid'
              ,url: '/vehicle/model_specs/?vehicle_model=' + id
              ,cols: [[
                {field:'name_text', title:'名称',width: 150}
               ,{field:'value', title:'值',width: 100}
               ,{field:'notes', title:'备注',width: 200}
              ]]
              ,height: 'full-108'
            });
        })
    </script>
</body>
</html>
