<order-history>
    <link rel="stylesheet" href="css/order-history.css">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
    <script src="https://rawgit.com/jquery/jquery-ui/master/ui/i18n/datepicker-ja.js"></script>
    <div class="main">
      <div class="content">
        <div class="page-title">
          <h2>注文履歴</h2>
        </div>
        <div class="form-wrapper">
          <table>
            <tr>
              <td>
                <input type="text" class="order_start_date datepicker" placeholder="yyyy/mm/dd"> ~ <input type="text" class="order_end_date datepicker1" placeholder="yyyy/mm/dd">
              </td>
              <td>
                <button class="search-btn reset-btn"><i class="fa fa-search"></i>この注文期間で絞り込む</button>
              </td>
            </tr>
          </table>
        </div>
        <div class="table-wrapper">

          <div class="table-head">
            <div class="table-head-left">
              <select id="status_select" onchange="{searchCartsByDropDownList}">
                <option value="0" selected>ステータスで絞り込む</option>
                <option value="11">承認待ち</option>
                <option value="4">注文済</option>
                <option value="5">キャンセル依頼</option>
                <option value="6">キャンセル済</option>
                <option value="7">入荷待</option>
                <option value="30">受入検収待ち</option>
                <option value="8">返品依頼</option>
                <option value="9">返品済</option>
                <option value="31">受入検収済</option>
                <option value="15">注文確認</option>
                <option value="16">注文確認（回答済み）</option>
                <!-- <option value="13">却下済み</option> -->
              </select>              
            </div>
            <div class="table-head-right">
              <progress id="progress" value="0" style="display:none;"></progress>
              <button id="link-download">CSVダウンロード</button>
            </div>
          </div>
          <table class="blue-table">
            <thead>
              <tr>
                <th>
                  <div>注文管理番号</div>
                  <div>見積管理番号</div>
                </th>
                <th style="width:82px">
                  <div>ご注文日</div>
                  <div>最終更新日</div>
                </th>
                <th>
                  <div>購入製品情報</div>
                  <div>販売店</div>
                </th>
                <th>
                  <div>発注者</div>
                  <div>希望納期</div>
                </th>
                <th>
                  <div>注文数量</div>
                  <div>納入数量</div>
                </th>
                <th>
                  <div>納入価格</div>
                  <div>納入金額</div>
                </th>
                <th>
                  <div>納品予定日</div>
                  <div>納品日</div>
                </th>
                <th class="cancel-box">ステータス</th>
                <th style="width:115px"></th>
                <th style="width:30px">CSV<br>絞込</th>
              </tr>
            </thead>
            <tbody>

              <tr each = {element, index in list_cart} id = { 'item-' + index } if={ element.status != '13' }>
              
                <td>
                  <div>{element.cart_seq}</br>{element.cart_seq_related ? '(' + element.cart_seq_related + ')':''}</div>
                  <div>{element.cart_seq_mitsumori_related}</div>
                </td>
                <td>
                  <div>{element.order_date}</div>
                  <div>{element.updatedate}</div>
                </td>
                <td class="left">
                  <dl>
                    <dt>品番</dt>
                    <dd><a href={ (element.is_deleted == 1 || element.item_sku == null || element.item_sku == '' || !element.item_sku_exist) ? '' : ('#search/basic_details/' + encodeURIComponent(element.item_sku)) } target="" style="{ (element.is_deleted == 1 || !element.item_sku_exist) ? 'color:black;text-decoration:none;cursor: auto;' : '' }">{ element.supp_sku }</a></dd>
                  </dl>
                  <dl>
                    <dt>品名</dt>
                    <dd>{ element.item_name }</dd>
                  </dl>
                  <dl>
                    <dt>容量・規格</dt>
                    <dd>{ element.capacity}  {(element.capacity && element.kikaku) ? '・' : '' } {element.kikaku }</dd>
                  </dl>
                  <dl>
                    <dt>販売元</dt>
                    <dd>{element.supp_co_name} {element.supp_name}</dd>
                  </dl>

                  <b class="discontinued" style="display:{(element.is_deleted == 1 ) ? 'block' : 'none'}">販売中止</b>
                  <div class="collapse" index="{index}"　id="detail-{index}">
                    <dl>
                      <dt>製造元</dt>
                      <dd>{ element.maker_name }</dd>
                    </dl>
                    <dl style="display:{navigation_list_cus_use_code[0] != '' ? 'block' : 'none'}">
                      <dt>{navigation_list_cus_use_code[0] != '' ? navigation_list_cus_use_code[0][0]['display_contents'] : ''}</dt>
                      <dd>{ element.customer_use_code_1 }</dd>
                    </dl>
                    <dl style="display:{navigation_list_cus_use_code[1] != '' ? 'block' : 'none'}">
                      <dt>{navigation_list_cus_use_code[1] != '' ? navigation_list_cus_use_code[1][0]['display_contents'] : ''}</dt>
                      <dd>{ element.customer_use_code_2 }</dd>
                    </dl>
                    <dl style="display:{navigation_list_cus_use_code[2] != '' ? 'block' : 'none'}">
                      <dt>{navigation_list_cus_use_code[2] != '' ? navigation_list_cus_use_code[2][0]['display_contents'] : ''}</dt>
                      <dd>{ element.customer_use_code_3 }</dd>
                    </dl>
                    <dl style="display:{navigation_list_cus_use_code[3] != '' ? 'block' : 'none'}">
                      <dt>{navigation_list_cus_use_code[3] != '' ? navigation_list_cus_use_code[3][0]['display_contents'] : ''}</dt>
                      <dd>{ element.customer_use_code_4 }</dd>
                    </dl>
                    <dl style="display:{navigation_list_cus_use_code[4] != '' ? 'block' : 'none'}">
                      <dt>{navigation_list_cus_use_code[4] != '' ? navigation_list_cus_use_code[4][0]['display_contents'] : ''}</dt>
                      <dd>{ element.customer_use_code_5 }</dd>
                    </dl>
                  </div>
                  <div class="see-more" style="text-align: center;border-top: none !important">
                      <a class="show-detail collapsed" data-toggle="collapse" href="#detail-{index}"></a>
                  </div>
                  <div>
                    { element.dealer_co_name } {element.dealer_dep_name}
                  </div>
                </td>
                <td class="left">
                  <p if={!element.customer_kikanname && !element.customer_sosikiname && !element.customer_tanto && !element.customer_email && !element.nonyu_zip && !element.nonyu_address1 && !element.nonyu_tel}>{ element.customer_user_name }</p>
                  <a class="ec52-delivery-address-open" index={index} if={element.customer_kikanname || element.customer_sosikiname || element.customer_tanto || element.customer_email || element.nonyu_zip || element.nonyu_address1 || element.nonyu_tel}>{ element.customer_user_name }</a>
                  <p>
                    <div class="comment-box" if={ element.comment_spp }>
                      <a class="commentOpen comment_spp">販売店へのコメント<i class="fa fa-commenting-o"></i></a>
                      <div class="text"><description id="description_spp_{index}"></description></div>
                    </div>
                  </p>
                  <p>   
                    <div class="comment-box" if={ element.comment_usr }>
                      <a class="commentOpen comment_user">社内コメント<i class="fa fa-commenting-o"></i></a>
                      <div class="text"><description id="description_usr_{index}"></description></div>
                    </div>
                  </p>
                  <div style="text-align: center;!important">
                    <div if={element.is_deleted != 1 &&  element.item_sku_exist && (element.status == 4 || element.status == 12)}>
                      <i class="fa fa-paperclip add_file file_cart" id="add_file_{index}" index="{index}" if={!element.attachment}></i>
                      <i class="fa fa-times delete-file-icon" id="delete-file-icon_{index}" onclick="{deleteFile}" index="{index}" style="display: none" if={!element.attachment}></i>
                      <input class="file_upload" id="file_upload_{index}" index={index} type="file" name="file" style="display: none;">
                      <i class="fa fa-file file_cart" title="{element.attachment}" onclick="{downloadFile}" if={element.attachment} fileName="{element.attachment}"></i>
                      <i class="fa fa-times delete-file-icon" id="delete-file-icon_{index}" if={element.attachment && (element.status == 4 || element.status == 12)} onclick="{deleteFile}" index="{index}" style="" fileName="{element.attachment}"></i>
                    </div>
                    <div style="text-align: center;!important" if={element.status != 4 && element.status != 12 && element.attachment}>
                      <i class="fa fa-file file_cart" onclick="{downloadFile}" fileName="{element.attachment}"></i>
                    </div>
                    <button style="margin-top: 7px" onclick={updateFile} class="" type="button" if={(element.status == 4 || element.status == 12) && !element.attachment && element.is_deleted != 1 &&  element.item_sku_exist}>更新</button>
                  </div>
                  <div>{ delivery_date_visible ? element.deliverydate : ''}</div>
                </td>
                <td>
                  <div>{ element.suryo }
                    <span class="text-nowrap" if={element.delivery_suryo_rest > 0 && element.cart_seq_related}>(納品残：{element.delivery_suryo_rest})</span>
                  </div>
                  <div>{ element.delivery_suryo } <br if={element.delivery_suryo}> { element.suryo > element.delivery_suryo && element.delivery_suryo ? '（分納）' : ''}</div>
                </td>
                <td class="right">
                  <div>{ !isNaN(parseInt(element.tanka)) ? parseInt(element.tanka).toLocaleString('en') + '円' : '' }</div>
                  <div>{ (element.delivery_suryo * element.tanka) > 0 ? parseInt(element.delivery_suryo * element.tanka).toLocaleString('en') + '円' : '' }</div>
                  <!-- {  parseInt(element.delivery_suryo * element.tanka).toLocaleString('en') }円 -->

                </td>
                <td>
                  <div>
                    <p>{ element.delivery_scheduled_date }</p>
                    <div class="comment-box" if={ element.comment_cst1 }>
                      <a class="commentOpen" style={ element.unread == '0' ? "color: red;" : "color: #0000cd"} index={index} onclick={ readComment } rel={element.unread }>販売店より<i class="fa fa-commenting-o" rel={element.unread } index={index}></i></a>
                      <div class="text"><description id="description_cst1_{index}"></description></div>
                    </div>
                    <div class="comment-box" if={ element.status == 15 } style="white-space: nowrap;">
                      <a class="" id="open-confirm" style={ element.status == '15' ? "color: red;" : "color: #0000cd"} index={index} >販売店への回答<i class="fa fa-commenting-o"index={index}></i></a>
                    </div>
                    <div class="comment-box" if={ element.comment_to_dealer !== null } style="white-space: nowrap;">
                         <a class="commentToDealerOpen" index={index}>販売店への回答<i class="fa fa-commenting-o" index={index}></i></a>
                          <div class="text"><description id="description_comment_to_dealer_{index}"></description></div>
                    </div>
                  </div>
                  <div class="nouhinbiTd">
                    <p class="date">{ element.delivery_date }</p>
                    <button class="kensyu-btn" onclick="{addToCart}" value="{index}" attrCart="status_31" style="display: {(element.status == 30) ? 'block' : 'none'}">受入検収</button>
                    <button class="reset-btn" style="display: {(element.status == 30) ? 'block' : 'none'}"  value="{index}" attrCart="status_8" onclick={ addToCart }><i class="fa fa-reply"></i>返品</button>
                    <button class="reset-btn" style="display: {(IWAI_SITE && (element.status == 4 || element.status == 12)) ? 'block' : 'none'}" value="{index}" attrCart="status_5" onclick={ addToCart }><i class="fa fa-times"></i>キャンセル依頼</button>
                  </div>
                </td>
                <td>
                  {(element.status == 4 || element.status == 12) ? '注文済':''}
                  {(element.status == 5) ? 'キャンセル依頼':''}
                  {(element.status == 6) ? 'キャンセル済':''}
                  {(element.status == 7) ? '入荷待':''}
                  {(element.status == 8) ? '返品依頼':''}
                  {(element.status == 9) ? '返品済':''}
                  {(element.status == 11) ? '承認待ち':''}
                  {(element.status == 30) ? '受入検収待ち':''}
                  {(element.status == 31) ? '受入検収済':''}
                  {(element.status == 13) ? '却下済み':''}
                  {(element.status == 15) ? '注文確認':''}
                  <div if={element.status == 16}>
                    注文確認
                    <p style="white-space: nowrap;">（回答済み）</p>
                  </div>
                  <a class="ec52-2-modal-open" cart_seq="{element.cart_seq}" index={index}>{ element.check_approver_status > 0 ? '承認履歴' : ''}</a>
                  <!-- <button if={element.status == 15} class="yellow-btn color-btn" style="margin-top: 10px">
                    回答
                  </button> -->
                </td>
                <td class="btntd" if={element.dealerCusFlg}>
                  <button class="color-btn red-btn" if={element.is_deleted != 1 && element.item_sku_exist} style="display: { arColumn(list_button, 'navigation_id', 'B002').length ? 'inline' : 'none' }" onclick={ ( element.selling_tanka != 0 && element.selling_tanka != '' && element.scm_bio) ?  addToCart : ''} value="{ index }" attrCart="status_0" disabled={(element.selling_tanka == 0 || element.selling_tanka == '' || !element.scm_bio) && element.inquiry != 1 ? 'disabled' : '' }><i class="fa fa-shopping-cart" aria-hidden="true"></i>カートへ</button>

                  <button class="color-btn green-btn" if={(element.is_deleted != 1 && element.item_sku_exist && element.scm_bio) || element.inquiry == 1} style="display: { arColumn(list_button, 'navigation_id', 'B003').length ? 'inline' : 'none' }" onclick="{addToCart}" value="{index}" attrCart="mitsu_1"><i class="fa fa-arrow-right"></i>見積フォルダ</button>
                  <span class="msg-item-sku-exist">{(element.is_deleted == 1 || !element.item_sku_exist) && element.inquiry != 1 ? 'この商品はカタログから削除されています' : ''}</span>
                  <input type="hidden" id="status_{index}" value="{element.status}">
                  <input type="hidden" id="customer_co_cd_{index}" value="{element.customer_co_cd}">

                  <input type="hidden" id="customer_dep_cd_{index}" value="{element.customer_dep_cd}">

                  <input type="hidden" id="ec_users_id_{index}" value="{element.ec_users_id}">
                </td>
                <td if={!element.dealerCusFlg}>
                  <span>この販売店事業所への発注／見積依頼は行えません</span>
                  <input type="hidden" id="status_{index}" value="{element.status}">
                  <input type="hidden" id="customer_co_cd_{index}" value="{element.customer_co_cd}">

                  <input type="hidden" id="customer_dep_cd_{index}" value="{element.customer_dep_cd}">

                  <input type="hidden" id="ec_users_id_{index}" value="{element.ec_users_id}">
                </td>
                <td style="vertical-align: center;position: relative;">
                  <input if={element.dealerCusFlg} type="checkbox" id="checkbox_download_{index}" name="checkbox_download" value="{element.cart_seq}">
                </td>
              </tr>
            </tbody>
          </table>
          <div id="paging" class="text-center">
            <ul class="pagination" id="pagination_ec51"></ul>
          </div>
        </div>
      </div>
    </div>
    <div class="o_modal" id="ec52-2-modal">
      <div class="o_modal_box">
        <div class="o_modal_head">
          <a id="ec52-2-modal-close"><i class="fa fa-times"></i></a>
        </div>
        <div class="o_modal_body">
          <div class="o_modal_main">
            <h3 class="modal-title">承認履歴</h3>
            <p>注文管理番号</p>
            <table class="history-form-table blue-table">
              <thead>
                <tr>
                  <th style="width:120px">承認者</th>
                  <th style="width:50px">承認<br/>階層</th>
                  <th style="width:60px">承認結果</th>
                  <th>コメント</th>
                  <th style="width:82px">承認日</th>
                </tr>
              </thead>
              <tbody>
                <tr each={element, index in approver_status}>
                  <td class="left">{element.name}</td>
                  <td>{element.approver_level}</td>
                  <td>{element.approved_flag == 1 ? '承認' : '却下'}</td>
                  <td class="left"><description id="description_approver_{index}"></description></td>
                  <td>{element.updatedate}</td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>

    <div class="o_modal" id="reply-confirm">
      <div class="o_modal_box confirm-comment-modal">
        <div class="o_modal_head">
          <a id="reply-confirm-close"><i class="fa fa-times"></i></a>
        </div>
        <div class="o_modal_body">
          <div class="o_modal_main">
            <h3 class="modal-title">販売店への回答</h3>
            <div class="center">
              <input type="hidden" id="cart-confirm">
              <textarea name="" id="comment_to_dealer" cols="30" rows="7"></textarea>
            </div>
            <div class="center" style="margin-top: 10px">
              <button type="button" id="reply-confirm-btn" onclick={customerConfirm} disabled>回答</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="o_modal" id="ec52-delivery-address">
      <div class="o_modal_box delivery-address-modal">
        <div class="o_modal_head">
          <a id="ec52-delivery-address-close"><i class="fa fa-times"></i></a>
        </div>
        <div class="o_modal_body">
          <div class="o_modal_main">
            <h3 class="modal-title">お届け先住所</h3>
            <div class="left">
              <p>{delivery_address.customer_kikanname}</p>
              <p>{delivery_address.customer_sosikiname}</p>
              <p>{delivery_address.customer_tanto}</p>
              <p>{delivery_address.customer_email}</p>
              <br>
              <p>{delivery_address.nonyu_zip}</p>
              <p>{delivery_address.nonyu_address1}</p>
              <p>{delivery_address.nonyu_address2}</p>
              <p>{delivery_address.nonyu_tel}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  <script>
      /* global $ */
      $(function(){
        selectFile();
        $('.commentOpen').on('click',function(){
          if($(this).hasClass('active')){
            if($(this).hasClass('comment_user')){
              $(this).removeClass('active').html('社内コメント<i class="fa fa-commenting-o"></i>');
            }else if($(this).hasClass('comment_spp')){
              $(this).removeClass('active').html('販売店へのコメント<i class="fa fa-commenting-o"></i>');
            }else{
              $(this).removeClass('active').html('販売店より<i class="fa fa-commenting-o"></i>');
            }
            $(this).next('.text').hide();
          }else{
            $(this).addClass('active').html('閉じる<i class="fa fa-times"></i>');
            $(this).next('.text').show();
          }
        });
        $('.commentToDealerOpen').on('click',function(){
          if($(this).hasClass('active')){
            $(this).removeClass('active').html('販売店への回答<i class="fa fa-commenting-o"></i>');
            $(this).next('.text').hide();
          }else{
            $(this).addClass('active').html('閉じる<i class="fa fa-times"></i>');
            $(this).next('.text').show();
          }
        });
        $('.ec52-2-modal-open').on('click',function(e){
          thisTag.comment_approver_index = $(e.target).attr('index');
          thisTag.update(thisTag.comment_approver_index);
          thisTag.getApproverStatus(e);
          
          $('#ec52-2-modal').fadeIn();
        });
        $('#ec52-2-modal-close').on('click',function(){
          $('#ec52-2-modal').fadeOut();
        });
      });
    </script>
  <script>
      var user_info = JSON.parse(localStorage.getItem('EcUserInfo'));
      this.list_button = user_info.list_navigation.B;
      this.list_navigation = user_info.list_navigation.S;
      this.list_navigationF = user_info.list_navigation.F;
      this.navigation_id = "";
      this.navigation_list_cus_use_code = opts.navigation_list;
      this.list_cart = opts.result;
      this.total = opts.total;
      this.list_cart_status = list_cart_status;
      this.sort = opts.sort;
      this.approver_status = [];
      this.list_download_checkbox = [];
      this.element = {};
      this.linkDownload = URL_API;
      this.accessTokenCognito = localStorage.getItem('accessTokenCognito');
      this.statusSelected = [4,5,6,7,8,9,30,31,13,12,11,15,16];
      this.screen = 'ec51';
      this.delivery_date_visible = false;
      this.comment_approver_index = '';
      this.IWAI_SITE = IWAI_SITE;
      this.delivery_address = '';
      var thisTag = this;
      var list_cart_update = opts.result;
      var page = 1;
      var totalPages = Math.ceil(thisTag.total/LIMIT_ON_PAGE);
      var visiblePages = 1;
      if(totalPages != 0){
          visiblePages =  5;
      }
      function updateDeliveryAddress() {
        $('.ec52-delivery-address-open').on('click',function(e){
          thisTag.delivery_address =  thisTag.list_cart[$(e.target).attr('index')];
          thisTag.update(thisTag.delivery_address);
          $('#ec52-delivery-address').fadeIn();
        });
        $('#ec52-delivery-address-close').on('click',function(){
          $('#ec52-delivery-address').fadeOut();
        });
      }
      $(function(){
          updateDeliveryAddress();
          var permission = true;
          $.each(thisTag.list_cart,function(i,e){
              riot.tag('description', '', function(opts) {   
                  this.root.innerHTML = opts.r;
              });
              riot.mount('#description_spp_' + i, {
                  r: e.comment_spp
              });
              riot.mount('#description_usr_' + i, {
                  r: e.comment_usr
              });
              riot.mount('#description_cst1_' + i, {
                  r: e.comment_cst1
              });
              riot.mount('#description_comment_to_dealer_' + i, {
                  r: e.comment_to_dealer
              });
              thisTag.update();
          });
          $.each(thisTag.list_navigation,function(i,e){
              if(e['navigation_id'] == 'S041'){
                  if(e['used_status'] == 'N'){       
                      permission = false;
                  } else if(e['used_status'] == 'Y'){
                      permission = true;
                      return false;
                  }
              } else {             
                  permission = false;
              }
          });
          $.each(thisTag.list_navigationF,function(i,e){
              if(e['navigation_id'] == 'F006'){
                  if(e['used_status'] == 'N'){       
                      thisTag.delivery_date_visible = false;
                  } else if(e['used_status'] == 'Y'){
                      thisTag.delivery_date_visible = true;
                      return false;
                  }
              } else {             
                  thisTag.delivery_date_visible = false;
              }
          });
          $(".reset-btn.clear").on("click",function(){
              $('.order_start_date').val("");
              $('.order_end_date').val("");
              $('#status_select').val(0);
          });

          $(document).on('click', '#open-confirm', function(e){
          // $('#open-confirm').on('click',function(e){
            let index = $(e.target).attr('index');
            $('#comment_to_dealer').val('');
            thisTag.update({element: thisTag.list_cart[$(e.target).attr('index')]});
            $('#reply-confirm').fadeIn();
          });

          $('#reply-confirm-close').on('click',function(e){
            $('#cart-confirm').val('');
            $('#reply-confirm-btn').prop('disabled', true);
            $('#reply-confirm').fadeOut();
          });

          if(!permission){
              var url = "#no-permission";
              $(location).attr("href", url);
          }
          /*$('.order_start_date').datetimepicker({
            format: 'Y/m/d',
            onShow:function( ct ){
              this.setOptions({
                 maxDate:$('.order_end_date').val()?$('.order_end_date').val():false
              })
            },

            timepicker:false
          });
          $('.order_end_date').datetimepicker({
            format: 'Y/m/d',
            onShow:function( ct ){
              this.setOptions({
                 minDate:$('.order_start_date').val()?$('.order_start_date').val():false
              })
            },

            timepicker:false
          });*/
          $(document).on('change', 'input[type=checkbox][name=checkbox_download]', function() {
            if($(this).is(':checked')){
              thisTag.list_download_checkbox.push($(this).val());
            } else {
              var index = thisTag.list_download_checkbox.indexOf($(this).val());
              if( index !== -1){
                thisTag.list_download_checkbox.splice(index, 1);
              }
            }
          });
          
          $('#link-download').click(function() {
              $('#progress').css({"display":"inline"});
              var that = this;
              var order_start_date = $(".order_start_date").val();
              var order_end_date = $(".order_end_date").val();
              var status = $("#status_select").val();
              switch(status) {
                  case '0':
                      thisTag.statusSelected = [4,5,6,7,8,9,30,31,13,12,11,15,16];
                      break;
                  case '4':
                      thisTag.statusSelected = [4,12];
                      break;
                  case '5':
                      thisTag.statusSelected = 5;
                      break;
                  case '6':
                      thisTag.statusSelected = 6;
                      break;
                  case '7':
                      thisTag.statusSelected = 7;
                      break;
                  case '8':
                      thisTag.statusSelected = 8;
                      break;
                  case '9':
                      thisTag.statusSelected = 9;
                      break;
                  case '30':
                      thisTag.statusSelected = 30;
                      break;
                  case '31':
                      thisTag.statusSelected = 31;
                      break;
                  case '13':
                      thisTag.statusSelected = 13;
                      break;
                  case '11':
                      thisTag.statusSelected = 11;
                      break;
                  case '15':
                      thisTag.statusSelected = 15;
                    break;
                  case '16':
                      thisTag.statusSelected = 16;
                    break;
                  default:
              }
              var page_url = thisTag.linkDownload + '/api/ec51/download?token=' + thisTag.accessTokenCognito + '&status=' + thisTag.statusSelected + '&order_start_date=' + order_start_date + '&order_end_date=' + order_end_date + '&list_download=' + thisTag.list_download_checkbox;
              var currentdate = new Date(); 
              var date = ((currentdate.getDate() < 10) ? "0":"") + currentdate.getDate();
              var month = (((currentdate.getMonth() + 1) < 10) ? "0":"") + (currentdate.getMonth()+1); 
              var year = currentdate.getFullYear(); 
              var hour = ((currentdate.getHours() < 10) ? "0":"") + currentdate.getHours(); 
              var minutes = ((currentdate.getMinutes() < 10) ? "0":"") + currentdate.getMinutes(); 
              var second = ((currentdate.getSeconds() < 10) ? "0":"") + currentdate.getSeconds();
              var req = new XMLHttpRequest();
              req.open("GET", page_url, true);
              req.addEventListener("progress", function (evt) {
                  if(evt.lengthComputable) {
                      var percentComplete = evt.loaded / evt.total;
                      console.log(percentComplete);
                      $("#progress").val(percentComplete);
                      
                      if(evt.loaded === evt.total){
                          setTimeout(function(){
                            $('#progress').css({"display":"none"});
                          },1000);
                      }
                  }
              }, false);

              req.responseType = "blob";
              req.onreadystatechange = function () {
                  if (req.readyState === 4 && req.status === 200) {
                      var filename = 'order_list_' + year + month + date + hour + minutes + second + '.csv';
                      if (typeof window.chrome !== 'undefined') {
                          // Chrome version
                          var link = document.createElement('a');
                          link.href = window.URL.createObjectURL(req.response);
                          link.download = filename;
                          link.click();
                      } else if (typeof window.navigator.msSaveBlob !== 'undefined') {
                          // IE version
                          var blob = new Blob([req.response], { type: 'application/force-download' });
                          window.navigator.msSaveBlob(blob, filename);
                      } else {
                          // Firefox version
                          var file = new File([req.response], filename, { type: 'application/force-download' });
                          window.open(URL.createObjectURL(file));
                      }
                  }
              };
              req.send();
          });




        $('#pagination_ec51').twbsPagination({
          totalPages: totalPages,
          visiblePages: visiblePages,
          startPage: thisTag.page,
          initiateStartPageClick: false,
          onPageClick: function (event, page) {
            thisTag.searchCarts(page);
          }
        }); 
        $(".search-btn").on('click', function(e){
            var page = 1;
            thisTag.searchCarts(page);
        });  
        thisTag.checkListButton();
        $('#comment_to_dealer').on('change keyup paste', function () {
          if ($.trim( $(this).val()) != '') {
            $('#reply-confirm-btn').prop("disabled", false);
          } else {
            $('#reply-confirm-btn').prop('disabled', true);
          }
        });
      });

      this.checkListButton = function(e){
        $naviArr = [];
        $.each(thisTag.list_button,function(index,item){
          $naviArr.push(item.navigation_id); 
        })
        thisTag.navigation_id = $naviArr;
        thisTag.update(thisTag.navigation_id);
      }
      this.getApproverStatus = function(e){
        var page = 1;
        var accessTokenCognito = localStorage.getItem('accessTokenCognito') !== null ? localStorage.getItem('accessTokenCognito') : '';
        var cart_seq = $(e.target).attr('cart_seq');
        var index = $(e.target).attr('index');
        var url = URL_API + '/api/get_single_approver_status?token=' + accessTokenCognito + '&cart_seq=' + cart_seq;
        $.ajax({
            url: url,
            type: 'GET',
            timeout: 60000,
            success: function (data) {
                if(data.status == 100){
                    riot.mount('app','maintain',{ messege:data.messege });
                    return false;
                }
                thisTag.approver_status = data.list;
                thisTag.update(thisTag.approver_status);    

                $.each(thisTag.approver_status,function(i,e){
                    riot.tag('description', '', function(opts) {   
                        this.root.innerHTML = opts.r;
                    });
                    riot.mount('#description_approver_' + i, {
                        r: e.approval_comment
                    });
                    thisTag.update();
                });            
            },
            error: function (xhr, stt, err) {
                alert('エラー');
            }
        });
      }
      this.searchCartsByDropDownList = function(e){
        var page = 1;
        var accessTokenCognito = localStorage.getItem('accessTokenCognito') !== null ? localStorage.getItem('accessTokenCognito') : '';
        var status = $("#status_select").val();
        switch(status) {
            case '0':
                thisTag.statusSelected = [4,5,6,7,8,9,30,31,13,12,11,15,16];
                break;
            case '4':
                thisTag.statusSelected = [4,12];
                break;
            case '5':
                thisTag.statusSelected = 5;
                break;
            case '6':
                thisTag.statusSelected = 6;
                break;
            case '7':
                thisTag.statusSelected = 7;
                break;
            case '8':
                thisTag.statusSelected = 8;
                break;
            case '9':
                thisTag.statusSelected = 9;
                break;
            case '30':
                thisTag.statusSelected = 30;
                break;
            case '31':
                thisTag.statusSelected = 31;
                break;
            case '13':
                thisTag.statusSelected = 13;
                break;
            case '11':
                thisTag.statusSelected = 11;
                break;
            case '15':
                thisTag.statusSelected = 15;
                break;
            case '16':
                thisTag.statusSelected = 16;
                break;
            default:
        }
        var url = URL_API + '/api/cart/list?token=' + accessTokenCognito + '&status=' + thisTag.statusSelected + '&page=' + page + '&screen=' + thisTag.screen;
        $.ajax({
            url: url,
            type: 'GET',
            timeout: 60000,
            success: function (data) {
                if(data.status == 100){
                    riot.mount('app','maintain',{ messege:data.messege });
                    return false;
                }
                thisTag.list_cart = data.cart_list;

                var totalPages = Math.ceil(data.total/LIMIT_ON_PAGE);
                thisTag.total_page = totalPages;
                var visiblePages = 1;
                if(totalPages != 0){
                    visiblePages =  5;
                } 
                var $pagination = $('#pagination_ec51');
                $pagination.twbsPagination('destroy');
                $pagination.twbsPagination({
                    totalPages: totalPages,
                    visiblePages: visiblePages,
                    startPage: page,
                    initiateStartPageClick: false,
                    onPageClick: function (event, page) {
                        thisTag.searchCarts(page);
                    }
                });

                thisTag.update(thisTag.list_cart);
                list_cart_update = thisTag.list_cart;
                updateDeliveryAddress();
                $('.commentOpen').on('click',function(){
                  if($(this).hasClass('active')){
                    if($(this).hasClass('comment_user')){
                      $(this).removeClass('active').html('社内コメント<i class="fa fa-commenting-o"></i>');
                    }else if($(this).hasClass('comment_spp')){
                      $(this).removeClass('active').html('販売店へのコメント<i class="fa fa-commenting-o"></i>');
                    }else{
                      $(this).removeClass('active').html('販売店より<i class="fa fa-commenting-o"></i>');
                    }
                    $(this).next('.text').hide();
                  }else{
                    $(this).addClass('active').html('閉じる<i class="fa fa-times"></i>');
                    $(this).next('.text').show();
                  }
                  $.each(thisTag.list_cart,function(i,e){
                    riot.tag('description', '', function(opts) {   
                        this.root.innerHTML = opts.r;
                    });
                    riot.mount('#description_approver_' + i, {
                        r: e.comment_approver
                    });
                    thisTag.update();
                  });
                });
                $('.commentToDealerOpen').on('click',function(){
                  if($(this).hasClass('active')){
                    $(this).removeClass('active').html('販売店への回答<i class="fa fa-commenting-o"></i>');
                    $(this).next('.text').hide();
                  }else{
                    $(this).addClass('active').html('閉じる<i class="fa fa-times"></i>');
                    $(this).next('.text').show();
                  }
                });
                $('.ec52-2-modal-open').on('click',function(e){
                  thisTag.getApproverStatus(e);
                  $('#ec52-2-modal').fadeIn();
                });
                $('#ec52-2-modal-close').on('click',function(){
                  $('#ec52-2-modal').fadeOut();
                });
                $.each(thisTag.list_cart,function(i,e){
                  riot.tag('description', '', function(opts) {   
                      this.root.innerHTML = opts.r;
                  });
                  riot.mount('#description_spp_' + i, {
                      r: e.comment_spp
                  });
                  riot.mount('#description_usr_' + i, {
                      r: e.comment_usr
                  });
                  riot.mount('#description_cst1_' + i, {
                      r: e.comment_cst1
                  });
                  riot.mount('#description_comment_to_dealer_' + i, {
                      r: e.comment_to_dealer
                  });
                  thisTag.update();
                });
            },
            error: function (xhr, stt, err) {
                alert('エラー');
            }
        });
      }
      this.searchCarts = function(page){
        var accessTokenCognito = localStorage.getItem('accessTokenCognito') !== null ? localStorage.getItem('accessTokenCognito') : '';
        var status = $("#status_select").val();
        var order_start_date = $(".order_start_date").val();
        var order_end_date = $(".order_end_date").val();
        countTotalCart();
        switch(status) {
            case '0':
                thisTag.statusSelected = [4,5,6,7,8,9,30,31,13,12,11,15,16];
                break;
            case '4':
                thisTag.statusSelected = [4,12];
                break;
            case '5':
                thisTag.statusSelected = 5;
                break;
            case '6':
                thisTag.statusSelected = 6;
                break;
            case '7':
                thisTag.statusSelected = 7;
                break;
            case '8':
                thisTag.statusSelected = 8;
                break;
            case '9':
                thisTag.statusSelected = 9;
                break;
            case '30':
                thisTag.statusSelected = 30;
                break;
            case '31':
                thisTag.statusSelected = 31;
                break;
            case '13':
                thisTag.statusSelected = 13;
                break;
            case '11':
                thisTag.statusSelected = 11;
                break;
            case '15':
                thisTag.statusSelected = 15;
                break;
            case '16':
                thisTag.statusSelected = 16;
                break;
            default:
        }

        var date = new Date();
        date.setMonth(date.getMonth() - 3);
        var order_date = date.getFullYear() +  '-' + (date.getMonth() + 1) + '-' + date.getDate();
        var sort = $("#sort").val();
        var url = URL_API + '/api/cart/list?token=' + accessTokenCognito + '&status=' + thisTag.statusSelected + '&page=' + page + '&screen=' + thisTag.screen + '&order_start_date=' + order_start_date + '&order_end_date=' + order_end_date;
        $.ajax({
            url: url,
            type: 'GET',
            timeout: 60000,
            success: function (data) {
                if(data.status == 100){
                    riot.mount('app','maintain',{ messege:data.messege });
                    return false;
                }
                thisTag.list_cart = data.cart_list;

                var totalPages = Math.ceil(data.total/LIMIT_ON_PAGE);
                thisTag.total_page = totalPages;
                var visiblePages = 1;
                if(totalPages != 0){
                    visiblePages =  5;
                } 
                var $pagination = $('#pagination_ec51');
                $pagination.twbsPagination('destroy');
                $pagination.twbsPagination({
                    totalPages: totalPages,
                    visiblePages: visiblePages,
                    startPage: page,
                    initiateStartPageClick: false,
                    onPageClick: function (event, page) {
                        thisTag.searchCarts(page);
                    }
                });

                thisTag.update(thisTag.list_cart);
                selectFile();
                list_cart_update = thisTag.list_cart;
                updateDeliveryAddress();
                $('.commentOpen').on('click',function(){
                  if($(this).hasClass('active')){
                    if($(this).hasClass('comment_user')){
                      $(this).removeClass('active').html('社内コメント<i class="fa fa-commenting-o"></i>');
                    }else if($(this).hasClass('comment_spp')){
                      $(this).removeClass('active').html('販売店へのコメント<i class="fa fa-commenting-o"></i>');
                    }else{
                      $(this).removeClass('active').html('販売店より<i class="fa fa-commenting-o"></i>');
                    }
                    $(this).next('.text').hide();
                  }else{
                    $(this).addClass('active').html('閉じる<i class="fa fa-times"></i>');
                    $(this).next('.text').show();
                  }
                  $.each(thisTag.list_cart,function(i,e){
                    riot.tag('description', '', function(opts) {   
                        this.root.innerHTML = opts.r;
                    });
                    riot.mount('#description_approver_' + i, {
                        r: e.comment_approver
                    });
                    thisTag.update();
                  });
                });
                
                $('.commentToDealerOpen').on('click',function(){
                  if($(this).hasClass('active')){
                    $(this).removeClass('active').html('販売店への回答<i class="fa fa-commenting-o"></i>');
                    $(this).next('.text').hide();
                  }else{
                    $(this).addClass('active').html('閉じる<i class="fa fa-times"></i>');
                    $(this).next('.text').show();
                  }
                });
                $('.ec52-2-modal-open').on('click',function(e){
                  thisTag.getApproverStatus(e);
                  $('#ec52-2-modal').fadeIn();
                });
                $('#ec52-2-modal-close').on('click',function(){
                  $('#ec52-2-modal').fadeOut();
                });
                $.each(thisTag.list_cart,function(i,e){
                    riot.tag('description', '', function(opts) {   
                        this.root.innerHTML = opts.r;
                    });
                    riot.mount('#description_spp_' + i, {
                        r: e.comment_spp
                    });
                    riot.mount('#description_usr_' + i, {
                        r: e.comment_usr
                    });
                    riot.mount('#description_cst1_' + i, {
                        r: e.comment_cst1
                    });
                    riot.mount('#description_comment_to_dealer_' + i, {
                        r: e.comment_to_dealer
                    });
                    thisTag.update();
                });
            },
            error: function (xhr, stt, err) {
                alert('エラー');
            }
        });
      }


      this.addToCart = function (e) {
          var index = e.target.value;
          var attrCart = $(e.target).attr('attrcart');
          var agent = localStorage.getItem('agent_id');
          var accessTokenCognito = localStorage.getItem('accessTokenCognito');
          var url = URL_API + '/api/cart/create?token=' + accessTokenCognito;
          var data = [];

          var raw_current_date = new Date();
          var current_date = raw_current_date.getFullYear() + "/" + (((raw_current_date.getMonth() + 1) < 10) ? "0":"") + (raw_current_date.getMonth() + 1) + "/" + ((raw_current_date.getDate() < 10) ? "0":"") + raw_current_date.getDate() + " " + ((raw_current_date.getHours() < 10) ? "0":"") + raw_current_date.getHours() + ":" + ((raw_current_date.getMinutes() < 10) ? "0":"") + raw_current_date.getMinutes() + ":" + ((raw_current_date.getSeconds() < 10) ? "0":"") + raw_current_date.getSeconds();

          var selling_tanka_int = '';

          if( typeof list_cart_update[index] !== 'undefined' ) {
              
              if( typeof list_cart_update[index].selling_tanka !== 'undefined' ) {

                selling_tanka_int = list_cart_update[index].selling_tanka ? list_cart_update[index].selling_tanka : '';
              
              }

          } 

          switch(attrCart) {
              case 'mitsu_1':
                  data.push({
                      // cart_seq: list_cart_update[index].cart_seq,
                      supp_sku: list_cart_update[index].supp_sku,
                      item_sku: list_cart_update[index].item_sku,
                      item_name: list_cart_update[index].item_name,
                      capacity: list_cart_update[index].capacity,
                      kikaku: list_cart_update[index].kikaku,
                      maker_name: list_cart_update[index].maker_name,
                      supp_co_cd: list_cart_update[index].supp_co_cd,
                      supp_co_name: list_cart_update[index].supp_co_name,
                      dealer_dep_cd: list_cart_update[index].dealer_dep_cd,
                      dealer_co_cd: list_cart_update[index].dealer_co_cd,
                      dealer_co_name: list_cart_update[index].dealer_co_name,
                      customer_co_cd: list_cart_update[index].customer_co_cd,
                      tanka: selling_tanka_int,
                      teika_tanka: list_cart_update[index].list_price,
                      agent_users_id: agent,
                      suryo: 1,
                      mitsumori_status: 1,
                  });
                  break;
              case 'status_31':
                  data.push({
                      cart_seq: list_cart_update[index].cart_seq,
                      supp_sku: list_cart_update[index].supp_sku,
                      sku: list_cart_update[index].sku,
                      item_name: list_cart_update[index].item_name,
                      capacity: list_cart_update[index].capacity,
                      kikaku: list_cart_update[index].kikaku,
                      maker_name: list_cart_update[index].maker_name,
                      supp_co_cd: list_cart_update[index].supp_co_cd,
                      // supp_co_name: list_cart_update[index].supp_co_name,
                      dealer_co_cd: list_cart_update[index].dealer_co_cd,
                      customer_co_cd: list_cart_update[index].customer_co_cd,
                      // dealer_co_name: list_cart_update[index].dealer_co_name,
                      // tanka: list_cart_update[index].tanka,
                      // teika_tanka: list_cart_update[index].teika_tanka,
                      suryo: list_cart_update[index].suryo,
                      deliverydate: list_cart_update[index].deliverydate,
                      comment_usr: list_cart_update[index].comment_usr,
                      customer_use_code_1: list_cart_update[index].customer_use_code_1,
                      customer_use_code_2: list_cart_update[index].customer_use_code_2,
                      agent_users_id: agent,
                      status: 31,
                      acceptance_date: current_date
                  });
                  break;
              case 'status_5':
                  if(!confirm('販売店にキャンセル依頼をします。\nおって販売店より回答を差し上げます。')){
                    return false;
                  }
                  data.push({
                      cart_seq: list_cart_update[index].cart_seq,
                      supp_sku: list_cart_update[index].supp_sku,
                      sku: list_cart_update[index].sku,
                      item_name: list_cart_update[index].item_name,
                      capacity: list_cart_update[index].capacity,
                      kikaku: list_cart_update[index].kikaku,
                      maker_name: list_cart_update[index].maker_name,
                      supp_co_cd: list_cart_update[index].supp_co_cd,
                      // supp_co_name: list_cart_update[index].supp_co_name,
                      customer_co_cd: list_cart_update[index].customer_co_cd,
                      dealer_co_cd: list_cart_update[index].dealer_co_cd,
                      // dealer_co_name: list_cart_update[index].dealer_co_name,
                      // tanka: list_cart_update[index].tanka,
                      // teika_tanka: list_cart_update[index].teika_tanka,
                      suryo: list_cart_update[index].suryo,
                      deliverydate: list_cart_update[index].deliverydate,
                      comment_usr: list_cart_update[index].comment_usr,
                      customer_use_code_1: list_cart_update[index].customer_use_code_1,
                      customer_use_code_2: list_cart_update[index].customer_use_code_2,
                      agent_users_id: agent,
                      status: 5,
                      cancellation_request_date: current_date
                  });
                  break;
              case 'status_8':
                  if(!confirm('販売店に返品依頼をします。\nおって販売店より回答を差し上げます。')){
                    return false;
                  }
                  data.push({
                      cart_seq: list_cart_update[index].cart_seq,
                      supp_sku: list_cart_update[index].supp_sku,
                      sku: list_cart_update[index].sku,
                      item_name: list_cart_update[index].item_name,
                      capacity: list_cart_update[index].capacity,
                      kikaku: list_cart_update[index].kikaku,
                      maker_name: list_cart_update[index].maker_name,
                      supp_co_cd: list_cart_update[index].supp_co_cd,
                      // supp_co_name: list_cart_update[index].supp_co_name,
                      customer_co_cd: list_cart_update[index].customer_co_cd,
                      dealer_co_cd: list_cart_update[index].dealer_co_cd,
                      // dealer_co_name: list_cart_update[index].dealer_co_name,
                      tanka: selling_tanka_int,
                      // suryo: list_cart_update[index].suryo,
                      // teika_tanka: list_cart_update[index].teika_tanka,
                      deliverydate: list_cart_update[index].deliverydate,
                      comment_usr: list_cart_update[index].comment_usr,
                      customer_use_code_1: list_cart_update[index].customer_use_code_1,
                      customer_use_code_2: list_cart_update[index].customer_use_code_2,
                      agent_users_id: agent,
                      status: 8,
                      return_request_date: current_date
                  });
                  break;
              case 'status_0':
                  data.push({
                      // cart_seq: list_cart_update[index].cart_seq,
                      supp_sku: list_cart_update[index].supp_sku,
                      item_sku: list_cart_update[index].item_sku,
                      item_name: list_cart_update[index].item_name,
                      capacity: list_cart_update[index].capacity,
                      kikaku: list_cart_update[index].kikaku,
                      maker_name: list_cart_update[index].maker_name,
                      supp_co_cd: list_cart_update[index].supp_co_cd,
                      supp_co_name: list_cart_update[index].supp_co_name,
                      customer_co_cd: list_cart_update[index].customer_co_cd,
                      dealer_dep_cd: list_cart_update[index].dealer_dep_cd,
                      dealer_co_cd: list_cart_update[index].dealer_co_cd,
                      dealer_co_name: list_cart_update[index].dealer_co_name,
                      // tanka: list_cart_update[index].tanka,
                      agent_users_id: agent,
                      // teika_tanka: list_cart_update[index].list_price,
                      suryo: 1,
                      status: 0,
                  });
                  break;
              default:
          }

          $.ajax({
              url: url,
              type: 'POST',
              data: {
                  data: data,
                  screen: 'ec51'
              },
              success: function (data) {
                  if(data.status == 100){
                      riot.mount('app','maintain',{ messege:data.messege });
                      return false;
                  }
                  // list_cart_update.splice(index, 1);
                  var page = 1;
                  thisTag.searchCarts(page);
                  switch(attrCart) {
                      case 'mitsu_1':
                          alert('見積フォルダに追加しました。\n見積フォルダから見積依頼処理を行ってください。');
                          break;
                      case 'status_31':
                          alert('受入検収しました。');
                          break;
                      case 'status_5':
                          alert('キャンセル依頼をしました。');
                          break;
                      case 'status_8':
                          alert('返品依頼をしました。');
                          break;
                      case 'status_0':
                          alert('カートに追加しました。\nカート画面から発注処理を行ってください。');
                          break;
                      default:
                  }
                  // $('#item-' + index).remove();
              },
              error: function (xhr, stt, error) {
                  alert('エラー');
              }
          });
      }
      this.sortCart = function (e) {
          var val = e.target.value;
          var accessTokenCognito = localStorage.getItem('accessTokenCognito');
          var status = $('#status_select').val();
          
          switch(status) {
              case '0':
                  thisTag.statusSelected = [4,5,6,7,8,9,30,31,13,12,11,15,16];
                  break;
              case '4':
                  thisTag.statusSelected = [4,12];
                  break;
              case '5':
                  thisTag.statusSelected = 5;
                  break;
              case '6':
                  thisTag.statusSelected = 6;
                  break;
              case '7':
                  thisTag.statusSelected = 7;
                  break;
              case '8':
                  thisTag.statusSelected = 8;
                  break;
              case '9':
                  thisTag.statusSelected = 9;
                  break;
              case '30':
                  thisTag.statusSelected = 30;
                  break;
              case '31':
                  thisTag.statusSelected = 31;
                  break;
              case '13':
                  thisTag.statusSelected = 13;
                  break;
              case '11':
                  thisTag.statusSelected = 11;
                  break;
              case '15':
                  thisTag.statusSelected = 15;
                break;
              case '16':
                  thisTag.statusSelected = 16;
                break;
              default:
          }

          var url = URL_API + '/api/cart/list?token=' + accessTokenCognito + '&status=' + thisTag.statusSelected + '&screen=' + thisTag.screen;

          $.ajax({
              url: url,
              type: 'GET',
              timeout: 60000,
              success: function (data) {
                if(data.status == 100){
                    riot.mount('app','maintain',{ messege:data.messege });
                    return false;
                }
                thisTag.list_cart = data.cart_list;

                var totalPages = Math.ceil(data.total/LIMIT_ON_PAGE);
                thisTag.total_page = totalPages;
                var visiblePages = 1;
                if(totalPages != 0){
                    visiblePages =  5;
                } 
                var $pagination = $('#pagination_ec51');
                $pagination.twbsPagination('destroy');
                $pagination.twbsPagination({
                    totalPages: totalPages,
                    visiblePages: visiblePages,
                    startPage: thisTag.page,
                    initiateStartPageClick: false,
                    onPageClick: function (event, page) {
                        thisTag.searchCarts(page);
                    }
                });

                thisTag.update(thisTag.list_cart);
                list_cart_update = thisTag.list_cart;
                $('.commentOpen').on('click',function(){
                  if($(this).hasClass('active')){
                    if($(this).hasClass('comment_user')){
                      $(this).removeClass('active').html('社内コメント<i class="fa fa-commenting-o"></i>');
                    }else if($(this).hasClass('comment_spp')){
                      $(this).removeClass('active').html('販売店へのコメント<i class="fa fa-commenting-o"></i>');
                    }else{
                      $(this).removeClass('active').html('販売店より<i class="fa fa-commenting-o"></i>');
                    }
                    $(this).next('.text').hide();
                  }else{
                    $(this).addClass('active').html('閉じる<i class="fa fa-times"></i>');
                    $(this).next('.text').show();
                  }
                  $.each(thisTag.list_cart,function(i,e){
                    riot.tag('description', '', function(opts) {   
                        this.root.innerHTML = opts.r;
                    });
                    riot.mount('#description_approver_' + i, {
                        r: e.comment_approver
                    });
                    thisTag.update();
                  });
                });
                $('.ec52-2-modal-open').on('click',function(e){
                  thisTag.getApproverStatus(e);
                  $('#ec52-2-modal').fadeIn();
                });
                $('#ec52-2-modal-close').on('click',function(){
                  $('#ec52-2-modal').fadeOut();
                });
                $.each(thisTag.list_cart,function(i,e){
                    riot.tag('description', '', function(opts) {   
                        this.root.innerHTML = opts.r;
                    });
                    riot.mount('#description_spp_' + i, {
                        r: e.comment_spp
                    });
                    riot.mount('#description_usr_' + i, {
                        r: e.comment_usr
                    });
                    riot.mount('#description_cst1_' + i, {
                        r: e.comment_cst1
                    });
                    riot.mount('#description_comment_to_dealer_' + i, {
                        r: e.comment_to_dealer
                    });
                    thisTag.update();
                });
              },
              error: function (xhr, stt, err) {
                  alert('エラー');
              }
          });
      }

      this.customerConfirm = function(e) {
          var cart_seq = thisTag.element.cart_seq;
          var comment_to_dealer = $('#comment_to_dealer').val();
          var data = {
            cart_seq: cart_seq,
            comment_to_dealer: comment_to_dealer,
            status: 16
          }
          var url = URL_API + '/api/cart/update_single_cart';
          var accessTokenCognito = localStorage.getItem('accessTokenCognito');
          var query = [];
          query.push('token=' + accessTokenCognito);
          query.push('screen=ec51');
          url += '?' + query.join('&');
          $.ajax({
              url: url,
              type: 'POST',
              data: data,
              success: function (res) {
                if(res.status == 100){
                    riot.mount('app','maintain',{ messege:res.messege });
                    return false;
                }
                if(res.message == 'success'){
                  thisTag.update({
                    list_cart: thisTag.list_cart
                  })
                  alert('送信しました。');
                  var page = 1;
                  thisTag.searchCarts(page);
                  $('#reply-confirm').fadeOut();
                } else if(res.message == 'errors') {
                    alert('errors');
                }
              },
              error: function () {
                  alert('error');
              }
          });
      }

      this.readComment = function(e) {
        if($(e.target).attr('rel') == 1 || typeof $(e.target).attr('index') == "undefined") {
          return false;
        }
        var index = $(e.target).attr('index');
        var cart_seq = thisTag.list_cart[index].cart_seq;
        var data = {
          cart_seq: cart_seq,
          unread: 1
        }
        var url = URL_API + '/api/cart/update_single_cart';
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var query = [];
        query.push('token=' + accessTokenCognito);
        query.push('screen=ec51');
        url += '?' + query.join('&');
        $.ajax({
            url: url,
            type: 'POST',
            data: data,
            success: function (res) {
              if(res.status == 100){
                  riot.mount('app','maintain',{ messege:res.messege });
                  return false;
              }
              if(res.message == 'success'){
                thisTag.list_cart[index].unread = 1;
                thisTag.update({
                  list_cart: thisTag.list_cart
                })
              } else if(res.message == 'errors') {
                  alert('errors');
              }
            },
            error: function () {
                alert('error');
            }
        });
      }
        
      this.deleteFile = function (e) {
        var index = $(e.target).attr('index');
        if (index) {
          $('#file_upload_' + index).val('');
          $('#delete-file-icon_' + index).hide();
          noFile(index);
        }
        var fileName = $(e.target).attr('fileName');
        if (fileName) {
            var item = e.item;
            var query = [];
            var accessTokenCognito = localStorage.getItem('accessTokenCognito');
            query.push('token=' + accessTokenCognito);
            query.push('sendmail_flg=' + 0);
            var url = URL_API + '/api/cart/create';
            
            url += '?' + query.join('&');
            
            var data = [];
                data.push({
                    cart_seq: item.element.cart_seq,
                    old_attachment: item.element.attachment,
                    backup_flag: 0,
                    attachment: '',
                });
            $.ajax({
                url: url,
                type: 'POST',
                timeout: 60000,
                data: {
                  data: data,
                },
                success: function (data) {
                    if(data.status == 100){
                        riot.mount('app','maintain',{ messege:data.messege });
                        return false;
                    }
                    if(data.message == 'success'){
                        var page = 1;
                        thisTag.searchCarts(page);
                    }
                 
                },
                error: function (xhr, stt, error) {
                    alert('エラー');
                }
            });
          
        }
      }

      this.updateFile = function (e) {
        var item = e.item;
        let i = item.index;
        var formData = new FormData();
        var data = [];
        if ($('#file_upload_' + i).val() != '' && $('#file_upload_' + i).val() !== undefined) {
            file_upload = $("#file_upload_" + i)[0].files[0];
            formData.append('file_upload_' + item.element.cart_seq, file_upload);
            data.push({
                cart_seq: item.element.cart_seq,
            });
            formData.append('cart_info', JSON.stringify(data));
            var query = [];
            var accessTokenCognito = localStorage.getItem('accessTokenCognito');
            query.push('token=' + accessTokenCognito);
            query.push('sendmail_flg=' + 0);
            var url = URL_API + '/api/cart/create';
            url += '?' + query.join('&');

            $.ajax({
                url: url,
                type: 'POST',
                timeout: 60000,
                dataType: 'JSON',
                data: formData,
                mimeType: "multipart/form-data",
                contentType: false,
                cache : false,
                processData: false,
                success: function (res) {
                    if(res.status == 100){
                        riot.mount('app','maintain',{ messege:res.messege });
                        return false;
                    }
                    if(res.status == 'not_authorize'){
                        var url = "#";
                        $(location).attr("href", url );
                        return false;
                    }
                    if(res.message == 'success'){
                      alert('ファイルを添付しました。');
                      var page = 1;
                      thisTag.searchCarts(page);
                    }else if(res.message == 'errors'){
                        alert('ファイルがまだアップできていません。');
                    }
                },
                error: function (xhr, stt, err) {
                    alert('ファイルがまだアップできていません。');
                }
            });
        }
      }

  </script>
  <script>
  DatepickerIntialize();
  </script>
  
</order-history>
