<price-set>
  <link rel="stylesheet" href="css/S02.css?v={ getDate() }">
  <div class="main">
    <div class="content">
      <div class="page-title">
        <h2>販売価格設定</h2>
      </div>

      <div>
        <div style="display: flex;justify-content: space-between;">
          <div class="">
          </div>
          <button style="background:#FFFFFF; color:#1C6BC0; border-radius:5px;" type="button" id="S02-3-Open">一括ダウンロード/アップロード</button>
        </div>
        <div class="border-line"></div>
      </div>
      <div class="form-wrapper">
        <form>
          <table>
            <tr>
              <th width="100px">得意先名</th>
              <td>
                  <div class="div-wraper-autocompleter">
                  <input id="companies_customer_comp_name" type="text"  placeholder="得意先名">
                  </div>
              </td>
            </tr>
            <tr>
              <th width="100px">得意先部門名</th>
              <td>
                  <div class="div-wraper-autocompleter">
                  <input id="departments_kyoten_name" type="text"  placeholder="得意先部門名">
                  </div>
              </td>
            </tr>
            <tr>
              <th>設定単位</th>
              <td colspan="2">
                <label><input type="radio" name="tanni" value="supplier">販売元メーカー</label>
                <label><input type="radio" name="tanni" value="manufacturer">製造元メーカー</label>
                <label><input type="radio" name="tanni" value="pricegroup">プライスグループ</label>
                <label><input type="radio" name="tanni" value="products">製品</label>
              </td>
            </tr>
            <tr>
              <td colspan="3">
                <div class="inTable">
                  <table id="supplier_search_table">
                    <tr>
                      <th width="110px">販売元メーカー</th>
                      <td>
                          <div class="div-wraper-autocompleter">
                          <input id="companies_supplier_comp_name" type="text" placeholder="販売元メーカー">
                          </div>
                      </td>
                    </tr>
                  </table>
                  <table id="manufacturer_search_table">
                    <tr>
                      <th width="110px">販売元メーカー</th>
                      <td><div class="div-wraper-autocompleter">
                          <input id="companies_supplier_comp_name2" type="text" placeholder="販売元メーカー">
                          </div>
                      </td>
                    </tr>
                    <tr>
                      <th>製造元メーカー</th>
                      <td><div class="div-wraper-autocompleter">
                          <input id="ec_products_maker_name" type="text" placeholder="製造元メーカー">
                          </div></td>
                    </tr>
                  </table>
                  <table id="pricegroup_search_table">
                    <tr>
                      <th width="110px">販売元メーカー</th>
                      <td>
                        <div class="div-wraper-autocompleter">
                          <input type="text" id="companies_supplier_comp_name3" placeholder=""></div>
                      </td>
                    </tr>
                    <tr>
                      <th width="110px">プライスグループ</th>
                      <td>
                        <div>
                          <input type="text" id="priceGroupFld" placeholder="部分一致検索">
                        </div>
                      </td>
                    </tr>
                    <!-- ==================================================================================== -->
                  </table>
                  <table id="products_search_table">
                    <tr>
                      <th width="110px">販売元メーカー</th>
                      <td>
                          <div class="div-wraper-autocompleter">
                          <input type="text" name="supplier_name" id="supplier_name" placeholder="販売元メーカー">
                          </div>
                      </td>
                      <th width="40px">品番</th>
                      <td><input type="text" name="supplier_sku" id="supplier_sku" placeholder="前方一致" ></td>
                    </tr>
                    <tr>
                      <th>製造元メーカー</th>
                      <td><div class="div-wraper-autocompleter"><input type="text" name="manufacturer" id="manufacturer" placeholder="製造元メーカー"></div></td>
                      <th>品名</th>
                      <td><input type="text" name="product_name" id="product_name" placeholder="中間一致"></td>
                    </tr>
                    <tr>
                    <td colspan="4" class="upload-btn-td">
                    </td>
                    </tr>
                  </table>
                </div>
              </td>
            </tr>
            <tr>
              <td colspan="3" class="btnTd">
                <button type="reset" class="reset-btn"><i class="fa fa-refresh"></i>条件クリア</button>
                <button style="background:#1C6BC0; color:#FFFFFF; border-radius:5px;" type="button" class="submit">販売価格検索</button>
              </td>
            </tr>
          </table>
        </form>
      </div>
      <div class="result-wrapper">
          <div class="result-div" id="supplier_result">
            <div class="result-head">
              <div class="btn-wrapper">
                  <button style="background:#2EB533; color:#FFFFFF; border-radius:5px;" type="button"  onclick={ updateSellingTankaRateSupplier } >販売価格登録</button>              
              </div>
            </div>
            <table class="blue-table">
              <thead>
                <tr>
                  <th>販売元メーカー</th>
                  <th>定価数</th>
                  <th width="120px">掛率</th>
                  <th width="120px">利益率</th>
                  <th width="70px">販売不可</th>
                  <th width="70px" if={ IWAI_SITE }>定価非表示</th>
                  <th class="blank"></th>
                  <th>キャンペーン数</th>
                  <th width="120px">掛率</th>
                </tr>
              </thead>
              <tbody>
                <tr each="{supplier,index in supplier_list}" class="supplier_list_tr">
                  <td>{supplier.comp_name}</td>
                  <td class="right">{ !isNaN(parseFloat(supplier.list_price)) ? parseFloat(supplier.list_price).toLocaleString('en') : '' }</td>
                  <td><input type="text" id="supplier_selling_tanka_rate_{index}" value="{supplier.selling_tanka_rate}" class="tankaRate" onchange={ changeTankaRateSupplier }></td>
                  <td><input type="text" id="supplier_profit_rate_{index}" class="supplier_profit_rate" old_value="{supplier.profit_rate}" value="{supplier.profit_rate}" disabled="{supplier.profit_rate_visible == 0 ? 'disabled' : ''}" onchange={ changeProfitRateSupplier }></td>
                  <td><input type="checkbox" id="supplier_no_sell_flag_{index}" checked="{(supplier.no_sellable_flag == 1) ? 'checked':'' }" onchange={ changeNoSellFlagSupplier } value="{(supplier.no_sellable_flag == 1) ? '1':'' }"></td>
                  <td if={ IWAI_SITE }><input type="checkbox" id="supplier_hidden_price_flag_{index}" checked="{(supplier.hidden_price_flag == 1) ? 'checked':'' }" onchange={ changeHiddenPriceFlagSupplier } value="{(supplier.hidden_price_flag == 1) ? '1':'' }"></td>
                  <td class="blank"></td>
                  <td class="right blue-td">{ !isNaN(parseFloat(supplier.list_price_campaign)) ? parseFloat(supplier.list_price_campaign).toLocaleString('en') : '' }</td>
                  <td class="blue-td"><input type="text" id="supplier_cam_selling_tanka_rate_{index}" value="{supplier.cam_selling_tanka_rate}" class="tankaRateCam" onchange={ changeCamTankaRateSupplier }></td>
                </tr>
              </tbody>
            </table>
            <div class="result-head" style="margin-top:5px;">
              <div class="btn-wrapper">
                  <button style="background:#2EB533; color:#FFFFFF; border-radius:5px;" type="button"  onclick={ updateSellingTankaRateSupplier } >販売価格登録</button>              
              </div>
            </div>
            <div id="paging" class="text-center">
              <ul class="pagination" id="pagination_supplier"></ul>
            </div>
          </div>
          <div class="result-div" id="manufacturer_result">
            <div class="result-head">
              <div class="btn-wrapper">
                <button style="background:#2EB533; color:#FFFFFF; border-radius:5px;" type="button" onclick={ updateSellingTankaRateManufacturer }>販売価格登録</button>
              </div>
            </div>
            <table class="blue-table">
              <thead>
                <tr>
                  <th>販売元メーカー</th>
                  <th>製造元メーカー</th>
                  <th>定価数</th>
                  <th width="100px">掛率</th>
                  <th width="100px">利益率</th>
                  <th width="70px">販売不可</th>
                  <th width="70px" if={ IWAI_SITE }>定価非表示</th>
                  <th class="blank"></th>
                  <th>キャンペーン数</th>
                  <th width="100px">掛率</th>
                </tr>
              </thead>
              <tbody>
                <tr each="{manufacturer,index in manufacturer_list}">
                  <td>{manufacturer.comp_name}</td>
                  <td>{manufacturer.maker_name}</td>
                  <td class="right">{ !isNaN(parseFloat(manufacturer.list_price)) ? parseFloat(manufacturer.list_price).toLocaleString('en') : '' }</td>
                  <td><input type="text" id="manu_selling_tanka_rate_{index}" value="{manufacturer.selling_tanka_rate}" class="tankaRate"  onchange={ changeSellingTankaManufacturer}></td>
                  <td><input type="text" id="manu_profit_rate_{index}" class="manu_profit_rate" old_value="{manufacturer.profit_rate}" value="{manufacturer.profit_rate}" disabled="{manufacturer.profit_rate_visible == 0 ? 'disabled' : ''}" onchange={ changeProfitRateManufacturer }></td>
                  <td><input type="checkbox" id="manu_no_sell_flag_{index}" checked="{(manufacturer.no_sellable_flag == 1) ? 'checked':'' }" onchange={ changeNoSellFlagManufacturer } value="{(manufacturer.no_sellable_flag == 1) ? '1':'' }"></td>
                  <td if={ IWAI_SITE }><input type="checkbox" id="manu_hidden_price_flag_{index}" checked="{(manufacturer.hidden_price_flag == 1) ? 'checked':'' }" onchange={ changeHiddenPriceFlagManufacturer } value="{(manufacturer.hidden_price_flag == 1) ? '1':'' }"></td>
                  <td class="blank"></td>
                  <td class="right blue-td">{ !isNaN(parseFloat(manufacturer.list_price_campaign)) ? parseFloat(manufacturer.list_price_campaign).toLocaleString('en') : '' }</td>
                  <td class="blue-td"><input type="text" id="manu_cam_selling_tanka_rate_{index}" value="{manufacturer.cam_selling_tanka_rate}" class="tankaRateCam"  onchange={ changeCamSellingTankaManufacturer}></td>
                </tr>
              </tbody>
            </table>
            <div class="result-head" style="margin-top:5px;">
              <div class="btn-wrapper">
                <button style="background:#2EB533; color:#FFFFFF; border-radius:5px;" type="button" onclick={ updateSellingTankaRateManufacturer }>販売価格登録</button>
              </div>
            </div>
            <div id="paging" class="text-center">
              <ul class="pagination" id="pagination_manufacturer"></ul>
            </div>
          </div>
          <div class="result-div" id="pricegroup_result">
            <div class="result-head">
              <div class="btn-wrapper">
                <button style="background:#2EB533; color:#FFFFFF; border-radius:5px;" type="button" onclick={ updateSellingTankaRatePriceGroup }>販売価格登録</button>
              </div>
            </div>
            <table class="blue-table">
              <thead>
                <tr>
                  <th>販売元メーカー</th>
                  <th>プライスグループ</th>
                  <th>定価数</th>
                  <th width="80px">掛率</th>
                  <th width="80px">利益率</th>
                  <th width="70px">販売不可</th>
                  <th width="70px" if={ IWAI_SITE }>定価非表示</th>
                  <th class="blank"></th>
                  <th>キャンペーン数</th>
                  <th width="80px">掛率</th>
                </tr>
              </thead>
              <tbody>
                <tr each="{pricegroup,index in pricegroup_list}">
                  <td>{pricegroup.comp_name}</td>
                  <td>{pricegroup.price_group}</td>
                  <td class="right">{ !isNaN(parseFloat(pricegroup.price_group_count)) ? parseFloat(pricegroup.price_group_count).toLocaleString('en') : '' }</td>
                  <td><input type="text" id="pricegroup_selling_tanka_rate_{index}" value="{pricegroup.selling_tanka_rate}" class="tankaRatePriceGroup" onchange={ changeSellingTankaPriceGroup }></td>
                  <td><input type="text" id="pricegroup_profit_rate_{index}" class="pricegroup_profit_rate" old_value="{pricegroup.profit_rate}" value="{pricegroup.profit_rate}" disabled="{pricegroup.profit_rate_visible == 0 ? 'disabled' : ''}" onchange={ changeProfitRatePriceGroup }></td>
                  <td><input type="checkbox" id="pricegroup_no_sell_flag_{index}" checked="{(pricegroup.no_sellable_flag == 1) ? 'checked':'' }" onchange={ changeNoSellFlagPriceGroup } value="{(pricegroup.no_sellable_flag == 1) ? '1':'' }"></td>
                  <td if={ IWAI_SITE }><input type="checkbox" id="pricegroup_hidden_price_flag_{index}" checked="{(pricegroup.hidden_price_flag == 1) ? 'checked':'' }" onchange={ changeHiddenPriceFlagPriceGroup } value="{(pricegroup.hidden_price_flag == 1) ? '1':'' }"></td>
                  <td class="blank"></td>
                  <td class="right blue-td">{ !isNaN(parseFloat(pricegroup.list_price_campaign)) ? parseFloat(pricegroup.list_price_campaign).toLocaleString('en') : '' }</td>
                  <td class="blue-td"><input type="text" id="pricegroup_cam_selling_tanka_rate_{index}" value="{pricegroup.cam_selling_tanka_rate}" class="tankaRatePriceGroupCam" onchange={ changeCamSellingTankaPriceGroup }></td>
                </tr>
              </tbody>
            </table>

            <div class="result-head" style="margin-top:5px;">
              <div class="btn-wrapper">
                <button style="background:#2EB533; color:#FFFFFF; border-radius:5px;" type="button" onclick={ updateSellingTankaRatePriceGroup }>販売価格登録</button>
              </div>
            </div>

            <div id="paging" class="text-center">
              <ul class="pagination" id="pagination_pricegroup"></ul>
            </div>
          </div>
          <div class="result-div" id="products_result">
            <div class="result-head result-head-product">
              <div class="campaign-head-result">
                <label>
                キャンペーン中の商品のみ検索
                <input type="checkbox" class="search-campaign">
                </label>
              </div>
              <div>
                <div class="batch-input">
                  <dl>
                    <dt>一括設定:</dt>
                    <dd>
                        <label>掛率<input type="text" id="disCountRate" class="disCountRate" onchange={ changeCollectSettingDisCountRate}></label>
                      <button type="button" onclick={ collectSettingDisCountRate }>一括入力</button>
                    </dd>
                  </dl>
                </div>
                <div class="btn-wrapper">
                  <button style="background:#2EB533; color:#FFFFFF; border-radius:5px;" type="button" onclick={updateProductSellingTankaRate}>販売価格登録</button>
                </div>
              </div>
            </div>
            <table class="blue-table">
              <thead>
                <tr>
                  <th>販売元メーカー</th>
                  <th>製造元メーカー</th>
                  <th>品番</th>
                  <th>品名</th>
                  <th>定価</th>
                  <th width="80px">納入価格</th>
                  <th width="50px">掛率</th>
                  <th width="50px">利益率</th>
                  <th width="30px">販売<br/>不可</th>
                  <th width="70px" if={ IWAI_SITE }>定価非表示</th>
                  <th class="blank"></th>
                  <th>キャンペーン価格</th>
                  <th width="80px">掛率</th>
                </tr>
              </thead>
              <tbody>
                <tr each="{product,index in product_list}">
                  <td>{product.comp_name}</td>
                  <td>{product.maker_name}</td>
                  <td>{product.supplier_sku}</td>
                  <td>{product.name_jp} <br> {product.name}</td>
                  <td>{ !isNaN(parseFloat(product.list_price)) ? parseFloat(product.list_price).toLocaleString('en') : '' }</td>
                  <td><input type="text" id="product_selling_tanka_{index}" class="sellingTanka" value="{product.selling_tanka}" onchange={ changeSellingTanka }></td>
                  <td><input type="text" id="product_selling_tanka_rate_{index}" value="{product.selling_tanka_rate}" class="sellingTankaRate" onchange={ changeSellingTankaRate}></td>
                  <td><input type="text" id="product_profit_rate_{index}" class="product_profit_rate" old_value="{product.profit_rate}" value="{product.profit_rate}" disabled="{product.profit_rate_visible == 0 ? 'disabled' : ''}" onchange={ changeProfitRate }></td>
                  <td><input type="checkbox" id="product_no_sell_flag_{index}" checked="{(product.no_sellable_flag == 1) ? 'checked':'' }" onchange={ changeNoSellFlag } value="{(product.no_sellable_flag == 1) ? '1':'' }"></td>
                  <td if={ IWAI_SITE }><input type="checkbox" id="product_hidden_price_flag_{index}" checked="{(product.hidden_price_flag == 1) ? 'checked':'' }" onchange={ changeHiddenPriceFlag } value="{(product.hidden_price_flag == 1) ? '1':'' }"></td>
                  <td class="blank"></td>
                  <td class="right blue-td">{ !isNaN(parseFloat(product.campaign_retail_price)) ? parseFloat(product.campaign_retail_price).toLocaleString('en') : '' }</td>
                  <td class="blue-td"><input type="text" id="product_cam_selling_tanka_rate_{index}" value="{product.cam_selling_tanka_rate}" class="sellingTankaRateCam" onchange={ changeCamSellingTankaRate}></td>
                </tr>
              </tbody>
            </table>
            <div class="result-head" style="margin-top:5px;">
              <div class="btn-wrapper">
               <button style="background:#2EB533; color:#FFFFFF; border-radius:5px;" type="button" onclick={updateProductSellingTankaRate}>販売価格登録</button>
              </div>
            </div>
            <div id="paging" class="text-center">
              <ul class="pagination" id="pagination_product"></ul>
            </div>
          </div>
          
      </div>
    </div>
  </div>
  <upload-set-modal></upload-set-modal>

  <script>
      
    /* global $ */
    this.custNames = opts.custNames;
    this.kyotNames = '';
    this.suppNames = opts.suppNames;
    this.makerNames = opts.makerNames;
    this.companies_customer_comp_name = '';
    this.changedProductList = [];
    this.changedSupplierList = [];
    this.changedManufacturerList = [];
    this.changedPriceGroupList = [];
    this.changedFileList = [];
    this.pagination_links = [];
    this.currentPage = 1;
    this.currentSupplierPage = 1;
    this.currentManufacturePage = 1;
    this.currentPriceGroupPage = 1;
    this.currentFilePage = 1;
    this.comp_code_search = ''; 
    this.customer_dep_cd_search = '';
    this.supplier_comp_code_search = '';
    this.supplier_comp_code_search2 = '';
    this.supplier_comp_code_search3 = '';
    this.supplier_comp_code_search4 = '';
    this.list_comp_code = [];
    this.status_check_pricing_unit = false;
    this.list_kyoten_code = [];
    this.IWAI_SITE = IWAI_SITE;
    var thisTag = this;

    $(document).on('change', '.search-campaign', function(event) {
      $('.submit').trigger('click');
    });
    validateIntNumber(number){
        var reg = /^\d+$/;
        if(number.length == 0){
            return true;
        }
        if (!reg.test(number)) {
            return false;
        }  
        return true;  
    }
    convertToHalfWidth(e){
        String.prototype.toHalfWidth = function() {
            return this.replace(/[Ａ-Ｚａ-ｚ０-９]/g, function(s) {return String.fromCharCode(s.charCodeAt(0) - 0xFEE0)});
        };

        String.prototype.toFullWidth = function() {
            return this.replace(/[A-Za-z0-9]/g, function(s) {return String.fromCharCode(s.charCodeAt(0) + 0xFEE0);});
        };
        var target = $(e.target);
        var val = target.val();
//            target.val('  '); // double space
        if(target.hasClass('sellingTanka') || target.hasClass('tankaRatePriceGroup') || target.hasClass('manu_profit_rate') || target.hasClass('supplier_profit_rate') || target.hasClass('pricegroup_profit_rate') || target.hasClass('product_profit_rate') || (target.hasClass('sellingTankaRate') || target.hasClass('tankaRate') || target.hasClass('disCountRate') || target.hasClass('sellingTankaRateCam') || target.hasClass('tankaRatePriceGroupCam') || target.hasClass('tankaRateCam'))){
            val = val.toHalfWidth().replace('．', '.'); 
//            var patt = /^[+]?(0\.\d+)?$/; 
            var patt = /^(0)?(\.\d+)?$/;
            var patt2 = /^(1)?(\.[0]+)?$/;
            if((patt.test(val.toHalfWidth()) && val.toHalfWidth() != 0)|| patt2.test(val.toHalfWidth())){
//            if(patt.test(val.toHalfWidth())){
                target.val(''); // double space
                target.val(val.toHalfWidth());
            } else {
                if(target.hasClass('sellingTanka')){
                    // if(  !Number.isInteger(val) ){
                    //     alert("納入価格を再度入力してください。");
                    //     target.val('');
                    //     return;
                    // } 
                    if(  val < 0 ){
                        alert("納入価格を再度入力してください。");
                        target.val('');
                        return;
                    } 
                    if( val >= 9999999 ){
                        alert("納入価格を再度入力してください。");
                        target.val('');
                        return;
                    } 
                }
                if(!target.hasClass('sellingTanka')) {
                    alert("０から１の数字を入力してください。");
                    target.val('');
                    return;
                }
                
            }
            
        } else {
//            var patt = /[^0-9]/g;
            var patt = /^([1-9][0-9]*)?(\.\d+)?$/;
            var patt2 = /^(0)?(\.\d+)?$/;
            if(patt.test(val.toHalfWidth()) || (patt2.test(val.toHalfWidth()) && val.toHalfWidth() != 0)){
                target.val(''); // double space
                target.val(val.toHalfWidth());
            } else {
//                confirm("半角数字で入力してください。")
                confirm("販売価に半角正数を入力してください。");
                target.val('');
                    return;
            }
        }   
            
    }
     
    changeTankaRateSupplier(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.supplier.selling_tanka_rate = $(e.target).val();
        
        this.supplier_list = this.supplier_list.filter(function(supplier) {
            if(supplier.supplier_comp_code == this.supplier.supplier_comp_code && this.supplier.customer_comp_code == supplier.customer_comp_code){
                supplier.selling_tanka_rate = $(e.target).val();
            }
            return supplier;
            
        }, item)
        this.changedSupplierList = this.changedSupplierList.filter(function(supplier) {
            if(this.supplier.supplier_comp_code == supplier.supplier_comp_code && this.supplier.customer_comp_code == supplier.customer_comp_code){     isNew = false;
                return this;
            }else{
                return supplier;
            }
        }, item)
            if(isNew){
                this.changedSupplierList.push(item.supplier);
            }
    }

    changeCamTankaRateSupplier(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.supplier.cam_selling_tanka_rate = $(e.target).val();
        
        this.supplier_list = this.supplier_list.filter(function(supplier) {
            if(supplier.supplier_comp_code == this.supplier.supplier_comp_code && this.supplier.customer_comp_code == supplier.customer_comp_code){
                supplier.cam_selling_tanka_rate = $(e.target).val();
            }
            return supplier;
            
        }, item)
        this.changedSupplierList = this.changedSupplierList.filter(function(supplier) {
            if(this.supplier.supplier_comp_code == supplier.supplier_comp_code && this.supplier.customer_comp_code == supplier.customer_comp_code){     isNew = false;
                return this;
            }else{
                return supplier;
            }
        }, item)
            if(isNew){
                this.changedSupplierList.push(item.supplier);
            }
    }
   
    changeProfitRateSupplier(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.supplier.profit_rate = $(e.target).val();
        
        this.supplier_list = this.supplier_list.filter(function(supplier) {
            if(supplier.supplier_comp_code == this.supplier.supplier_comp_code && this.supplier.customer_comp_code == supplier.customer_comp_code){
                supplier.profit_rate = $(e.target).val();
            }
            return supplier;
            
        }, item)
        this.changedSupplierList = this.changedSupplierList.filter(function(supplier) {
            if(this.supplier.supplier_comp_code == supplier.supplier_comp_code && this.supplier.customer_comp_code == supplier.customer_comp_code){     isNew = false;
                return this;
            }else{
                return supplier;
            }
        }, item)
            if(isNew){
                this.changedSupplierList.push(item.supplier);
            }
    }

    changeNoSellFlagSupplier(e){
        this.convertToHalfWidth(e);
        // looped item
        var checkTest = e.target.checked;
        var item = e.item
        var isNew = true;
        item.supplier.no_sellable_flag = $(e.target).val();
        
        this.supplier_list = this.supplier_list.filter(function(supplier) {
            if(supplier.supplier_comp_code == this.supplier.supplier_comp_code && this.supplier.customer_comp_code == supplier.customer_comp_code){
                if(checkTest == true){
                    supplier.no_sellable_flag = 1;
                    $(e.target).val(1);
                } else {
                    supplier.no_sellable_flag = '';
                    $(e.target).val('');
                }
            }
            return supplier;
            
        }, item)
        this.changedSupplierList = this.changedSupplierList.filter(function(supplier) {
            if(this.supplier.supplier_comp_code == supplier.supplier_comp_code && this.supplier.customer_comp_code == supplier.customer_comp_code){     
                isNew = false;
                return this;
            }else{
                return supplier;
            }
        }, item)
            if(isNew){
                this.changedSupplierList.push(item.supplier);
            }
    }

    changeHiddenPriceFlagSupplier(e) {
      this.convertToHalfWidth(e);
      // looped item
      var checkTest = e.target.checked;
      var item = e.item;
      var isNew = true;
      item.supplier.hidden_price_flag = $(e.target).val();

      this.supplier_list = this.supplier_list.filter(function (supplier) {
        if (supplier.supplier_comp_code == this.supplier.supplier_comp_code && this.supplier.customer_comp_code == supplier.customer_comp_code) {
          if (checkTest == true) {
            supplier.hidden_price_flag = 1;
            $(e.target).val(1);
          } else {
            supplier.hidden_price_flag = '';
            $(e.target).val('');
          }
        }
        return supplier;

      }, item);
      this.changedSupplierList = this.changedSupplierList.filter(function (supplier) {
        if (this.supplier.supplier_comp_code == supplier.supplier_comp_code && this.supplier.customer_comp_code == supplier.customer_comp_code) {
          isNew = false;
          return this;
        } else {
          return supplier;
        }
      }, item);
      if (isNew) {
        this.changedSupplierList.push(item.supplier);
      }
    }
    updateSellingTankaRateSupplier(e){
        this.changedSupplierList;
          
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var url = URL_API + '/api/selling_prices/saveSellingTankaRateSupp?token=' + accessTokenCognito + '&companies_customer_comp_name=' + encodeURI($('#companies_customer_comp_name').val());
        var comp_name = $('#companies_customer_comp_name').val();
        var comp_code = '';

        if(comp_name == ''){
            alert("得意先を指定してください。");
            // thisTag.supplier_list = [];
            // thisTag.update(thisTag.supplier_list);
            // thisTag.supplier_list = thisTag.supplier_list_old;
            searchSupplier(thisTag.currentPage);
            return false;
        }

        $.each(thisTag.custNames, function(i,e){
            if(e['value'] == comp_name){
                comp_code = e['comp_code'];
            }
        });
        var data = [];
        $.each(this.changedSupplierList, function( index, supplier ) {
            data.push({
                'seq': supplier.seq,
                'selling_tanka_rate': supplier.selling_tanka_rate,
                'supp_co_cd': supplier.supplier_comp_code,
                'customer_co_cd': comp_code,
                'profit_rate' : supplier.profit_rate,
                'no_sellable_flag' : supplier.no_sellable_flag,
                'cam_selling_tanka_rate': supplier.cam_selling_tanka_rate,
                'hidden_price_flag': supplier.hidden_price_flag
            });
            if(thisTag.customer_dep_cd_search != '') {
                data[index].customer_dep_cd = thisTag.customer_dep_cd_search;
            }
        });

        if(data.length > 0){
            var pricing_unit = [2,3,5];
            thisTag.checkPricingUnitBeforePost(data, pricing_unit);
            if(thisTag.status_check_pricing_unit){
              return false;
            }

            thisTag.status_check_pricing_unit = false;
            $.ajax({
                url: url,
                type: 'POST',
                timeout: 20000,
                data: {
                    data: data
                },
                async:false,
                success: function (res) {
                    if(res.status == 100){
                        riot.mount('app','maintain',{ messege:res.messege });
                        return false;
                    }
                    if(res.message == 'success'){
                        thisTag.changedSupplierList = [];
                        alert('更新しました。');
                        searchSupplier(thisTag.currentSupplierPage);

                    }
                },
                error: function (xhr, stt, err) {
                    if(xhr.responseJSON.message[0]){
                        for(var p in xhr.responseJSON.message[0]){
                            var msg = '';
                            var obj = xhr.responseJSON.message[0][p];
                            var maxLength = 'maxLength'
                            switch(p) {
                                case 'selling_tanka_rate':
                                        if(maxLength in obj){
                                                msg = 'field tanka rate : ' + obj.maxLength;
                                                alert(msg);
                                        }
                                        break;
                                case 'selling_tanka':
                                        if(maxLength in obj){
                                                msg = 'field tanka : ' + obj.maxLength;
                                                alert(msg);
                                        }
                                        break;
                                default:

                            }
                        }
                    }
                }
            });
        }  
    }
    


    changeSellingTankaManufacturer(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.manufacturer.selling_tanka_rate = $(e.target).val();
        
        this.manufacturer_list = this.manufacturer_list.filter(function(manufacturer) {
            if (manufacturer.maker_name == item.manufacturer.maker_name && this.manufacturer.supp_co_cd == manufacturer.supp_co_cd && this.manufacturer.customer_comp_code == manufacturer.customer_comp_code) {
                manufacturer.selling_tanka_rate = $(e.target).val();
            }

            return manufacturer;
            
        }, item)
        this.changedManufacturerList = this.changedManufacturerList.filter(function(manufacturer) {
            if(this.manufacturer.maker_name == manufacturer.maker_name && this.manufacturer.supp_co_cd == manufacturer.supp_co_cd && this.manufacturer.customer_comp_code == manufacturer.customer_comp_code){
                isNew = false;

                return this;
            }else{

                return manufacturer;
            }
        }, item)
        
        if(isNew){
            this.changedManufacturerList.push(item.manufacturer);
        }
    }

    changeCamSellingTankaManufacturer(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.manufacturer.cam_selling_tanka_rate = $(e.target).val();
        
        this.manufacturer_list = this.manufacturer_list.filter(function(manufacturer) {
            if (manufacturer.maker_name == item.manufacturer.maker_name && this.manufacturer.supp_co_cd == manufacturer.supp_co_cd && this.manufacturer.customer_comp_code == manufacturer.customer_comp_code) {
                manufacturer.cam_selling_tanka_rate = $(e.target).val();
            }

            return manufacturer;
            
        }, item)
        this.changedManufacturerList = this.changedManufacturerList.filter(function(manufacturer) {
            if(this.manufacturer.maker_name == manufacturer.maker_name && this.manufacturer.supp_co_cd == manufacturer.supp_co_cd && this.manufacturer.customer_comp_code == manufacturer.customer_comp_code){
                isNew = false;

                return this;
            }else{

                return manufacturer;
            }
        }, item)
        
        if(isNew){
            this.changedManufacturerList.push(item.manufacturer);
        }
    }

    changeProfitRateManufacturer(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.manufacturer.profit_rate = $(e.target).val();
        
        this.manufacturer_list = this.manufacturer_list.filter(function(manufacturer) {
            if (manufacturer.maker_name == item.manufacturer.maker_name && this.manufacturer.supp_co_cd == manufacturer.supp_co_cd && this.manufacturer.customer_comp_code == manufacturer.customer_comp_code) {
                manufacturer.profit_rate = $(e.target).val();
            }

            return manufacturer;
            
        }, item)
        this.changedManufacturerList = this.changedManufacturerList.filter(function(manufacturer) {
            if(this.manufacturer.maker_name == manufacturer.maker_name && this.manufacturer.supp_co_cd == manufacturer.supp_co_cd && this.manufacturer.customer_comp_code == manufacturer.customer_comp_code){
                isNew = false;

                return this;
            }else{

                return manufacturer;
            }
        }, item)
        
        if(isNew){
            this.changedManufacturerList.push(item.manufacturer);
        }
    }

    changeNoSellFlagManufacturer(e){
        this.convertToHalfWidth(e);
        // looped item
        var checkTest = e.target.checked;
        var item = e.item
        var isNew = true;
        item.manufacturer.no_sellable_flag = $(e.target).val();
        
        this.manufacturer_list = this.manufacturer_list.filter(function(manufacturer) {
            if (manufacturer.maker_name == item.manufacturer.maker_name && this.manufacturer.supp_co_cd == manufacturer.supp_co_cd && this.manufacturer.customer_comp_code == manufacturer.customer_comp_code) {
                if(checkTest == true){
                    manufacturer.no_sellable_flag = 1;
                    $(e.target).val(1);
                } else {
                    manufacturer.no_sellable_flag = '';
                    $(e.target).val('');
                }
            }

            return manufacturer;
            
        }, item)
        this.changedManufacturerList = this.changedManufacturerList.filter(function(manufacturer) {
            if(this.manufacturer.maker_name == manufacturer.maker_name && this.manufacturer.supp_co_cd == manufacturer.supp_co_cd && this.manufacturer.customer_comp_code == manufacturer.customer_comp_code){
                isNew = false;

                return this;
            }else{

                return manufacturer;
            }
        }, item)
        
        if(isNew){
            this.changedManufacturerList.push(item.manufacturer);
        }
    }

    changeHiddenPriceFlagManufacturer(e) {
      this.convertToHalfWidth(e);
      // looped item
      var checkTest = e.target.checked;
      var item = e.item;
      var isNew = true;
      item.manufacturer.hidden_price_flag = $(e.target).val();

      this.manufacturer_list = this.manufacturer_list.filter(function (manufacturer) {
        if (manufacturer.maker_name == item.manufacturer.maker_name && this.manufacturer.supp_co_cd == manufacturer.supp_co_cd && this.manufacturer.customer_comp_code == manufacturer.customer_comp_code) {
          if (checkTest == true) {
            manufacturer.hidden_price_flag = 1;
            $(e.target).val(1);
          } else {
            manufacturer.hidden_price_flag = '';
            $(e.target).val('');
          }
        }

        return manufacturer;

      }, item);
      this.changedManufacturerList = this.changedManufacturerList.filter(function (manufacturer) {
        if (this.manufacturer.maker_name == manufacturer.maker_name && this.manufacturer.supp_co_cd == manufacturer.supp_co_cd && this.manufacturer.customer_comp_code == manufacturer.customer_comp_code) {
          isNew = false;

          return this;
        } else {

          return manufacturer;
        }
      }, item);

      if (isNew) {
        this.changedManufacturerList.push(item.manufacturer);
      }
    }


    updateSellingTankaRateManufacturer(e){
        this.changedManufacturerList;
        
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var url = URL_API + '/api/selling_prices/saveSellingTankaRateManufacturer?token=' + accessTokenCognito + '&companies_customer_comp_name=' + encodeURI($('#companies_customer_comp_name').val());
        var comp_name = $('#companies_customer_comp_name').val();
        if(comp_name == ''){
            alert("得意先を指定してください。");
            searchManufacturer(thisTag.currentPage);
            return false;
        }
        $.each(thisTag.custNames, function(i,e){
            if(e['value'] == comp_name){
                comp_code = e['comp_code'];
            }
        });

        var data = [];
        $.each(this.changedManufacturerList, function( index, manufacturer ) {
            data.push({
                'seq': manufacturer.seq,
                'selling_tanka_rate': manufacturer.selling_tanka_rate,
                'supp_co_cd': manufacturer.supplier_comp_code,
                'maker_name': manufacturer.maker_name,
                'customer_co_cd': comp_code,
                'profit_rate': manufacturer.profit_rate,
                'no_sellable_flag': manufacturer.no_sellable_flag,    
                'cam_selling_tanka_rate': manufacturer.cam_selling_tanka_rate,
                'hidden_price_flag': manufacturer.hidden_price_flag
            })
            if(thisTag.customer_dep_cd_search != '') {
                data[index].customer_dep_cd = thisTag.customer_dep_cd_search;
            }
        });

        if(data.length > 0){
            var pricing_unit = [1,3,5];
            thisTag.checkPricingUnitBeforePost(data, pricing_unit);
            if(thisTag.status_check_pricing_unit){
              return false;
            }
            thisTag.status_check_pricing_unit = false;
            $.ajax({
                url: url,
                type: 'POST',
                timeout: 20000,
                data: {
                    data: data
                },
                success: function (res) {
                    if(res.message == 'success'){
                        thisTag.changedManufacturerList = [];
                        alert('更新しました。');
                        searchManufacturer(thisTag.currentManufacturePage);
                    }
                },
                error: function (xhr, stt, err) {
                    if(xhr.responseJSON.message[0]){
                        for(var p in xhr.responseJSON.message[0]){
                            var msg = '';
                            var obj = xhr.responseJSON.message[0][p];
                            var maxLength = 'maxLength'
                            switch(p) {
                                case 'selling_tanka_rate':
                                        if(maxLength in obj){
                                                msg = 'field tanka rate : ' + obj.maxLength;
                                                alert(msg);
                                        }
                                        break;
                                case 'selling_tanka':
                                        if(maxLength in obj){
                                                msg = 'field tanka : ' + obj.maxLength;
                                                alert(msg);
                                        }
                                        break;
                                default:

                            }
                        }
                    }
                }
            });
        }
           
          
    }

    updateSellingTankaRatePriceGroup(e){
        this.changedPriceGroupList;
        
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var url = URL_API + '/api/selling_prices/saveSellingTankaRatePriceGroup?token=' + accessTokenCognito + '&companies_customer_comp_name=' + encodeURI($('#companies_customer_comp_name').val());
        var comp_name = $('#companies_customer_comp_name').val();
        if(comp_name == ''){
            alert("得意先を指定してください。");
            searchPriceGroup(thisTag.currentPage);
            return false;
        }
        $.each(thisTag.custNames, function(i,e){
            if(e['value'] == comp_name){
                comp_code = e['comp_code'];
            }
        });
        var data = [];
        $.each(this.changedPriceGroupList, function( index, pricegroup ) {
            data.push({
                'seq': pricegroup.seq,
                'price_group': pricegroup.price_group ,
                'selling_tanka_rate': pricegroup.selling_tanka_rate,
                'customer_co_cd': comp_code,
                'supp_co_cd': pricegroup.supplier_comp_code,
                'profit_rate': pricegroup.profit_rate,
                'no_sellable_flag': pricegroup.no_sellable_flag,
                'cam_selling_tanka_rate': pricegroup.cam_selling_tanka_rate,
                'hidden_price_flag': pricegroup.hidden_price_flag
                })
            if(thisTag.customer_dep_cd_search != '') {
                data[index].customer_dep_cd = thisTag.customer_dep_cd_search;
            }
        });

        if(data.length > 0){
            var pricing_unit = [1,2,5];
            thisTag.checkPricingUnitBeforePost(data, pricing_unit);
            if(thisTag.status_check_pricing_unit){
              return false;
            }
            thisTag.status_check_pricing_unit = false;
            $.ajax({
                url: url,
                type: 'POST',
                timeout: 20000,
                data: {
                    data: data
                },
                success: function (res) {
                    if(res.status == 100){
                        riot.mount('app','maintain',{ messege:res.messege });
                        return false;
                    }
                    if(res.message == 'success'){
                        thisTag.changedPriceGroupList = [];
                        alert('更新しました。');
                        searchPriceGroup(thisTag.currentPriceGroupPage);

                    }
                },
                error: function (xhr, stt, err) {
                    if(xhr.responseJSON.message[0]){
                        for(var p in xhr.responseJSON.message[0]){
                            var msg = '';
                            var obj = xhr.responseJSON.message[0][p];
                            var maxLength = 'maxLength'
                            switch(p) {
                                case 'selling_tanka_rate':
                                        if(maxLength in obj){
                                                msg = 'field tanka rate : ' + obj.maxLength;
                                                alert(msg);
                                        }
                                        break;
                                case 'selling_tanka':
                                        if(maxLength in obj){
                                                msg = 'field tanka : ' + obj.maxLength;
                                                alert(msg);
                                        }
                                        break;
                                default:

                            }
                        }
                    }
                }
            });
        }
           
          
    }
    changeCollectSettingDisCountRate(e){
        this.convertToHalfWidth(e);
    }
    collectSettingDisCountRate(e){
        var disCountRate = $('#disCountRate').val();
        if(!disCountRate){
            alert('一括設定；掛率に入力がありません。');
            return;
        }
        
         this.product_list = this.product_list.filter(function(product) {
            var isNew = true;
                product.selling_tanka_rate = disCountRate
            thisTag.changedProductList = thisTag.changedProductList.filter(function(changedProduct) {
                
                if(changedProduct.sku == this.sku && this.customer_comp_cd == changedProduct.customer_comp_cd && this.supplier_comp_code == changedProduct.supplier_comp_code && this.maker_name == changedProduct.maker_name){
                     changedProduct.selling_tanka_rate = this.selling_tanka_rate;
                     isNew = false;
                }
                return changedProduct;
            }, product)
            
            if(isNew){
                thisTag.changedProductList.push(product);
            }
            
            return product;
            
            
        })
        
        
    }

    changeSellingTankaPriceGroup(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.pricegroup.selling_tanka_rate = $(e.target).val();
        
        this.pricegroup_list = this.pricegroup_list.filter(function(pricegroup) {
            if( this.pricegroup.comp_name == pricegroup.comp_name && this.pricegroup.price_group == pricegroup.price_group && this.pricegroup.price_group_count == pricegroup.price_group_count ){
                pricegroup.selling_tanka_rate = $(e.target).val();
            }

            return pricegroup;
            
        }, item)
        this.changedPriceGroupList = this.changedPriceGroupList.filter(function(pricegroup) {
            if(this.pricegroup.comp_name == pricegroup.comp_name && this.pricegroup.price_group == pricegroup.price_group && this.pricegroup.price_group_count == pricegroup.price_group_count ){
                isNew = false;
        
                return this;
            }else{
                return pricegroup;
            }
        }, item)
        if(isNew){
            this.changedPriceGroupList.push(item.pricegroup);
        }
    }

    changeCamSellingTankaPriceGroup(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.pricegroup.cam_selling_tanka_rate = $(e.target).val();
        
        this.pricegroup_list = this.pricegroup_list.filter(function(pricegroup) {
            if( this.pricegroup.comp_name == pricegroup.comp_name && this.pricegroup.price_group == pricegroup.price_group && this.pricegroup.price_group_count == pricegroup.price_group_count ){
                pricegroup.cam_selling_tanka_rate = $(e.target).val();
            }

            return pricegroup;
            
        }, item)
        this.changedPriceGroupList = this.changedPriceGroupList.filter(function(pricegroup) {
            if(this.pricegroup.comp_name == pricegroup.comp_name && this.pricegroup.price_group == pricegroup.price_group && this.pricegroup.price_group_count == pricegroup.price_group_count ){
                isNew = false;
        
                return this;
            }else{
                return pricegroup;
            }
        }, item)
        if(isNew){
            this.changedPriceGroupList.push(item.pricegroup);
        }
    }

    changeProfitRatePriceGroup(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.pricegroup.profit_rate = $(e.target).val();
        
        this.pricegroup_list = this.pricegroup_list.filter(function(pricegroup) {
            if( this.pricegroup.comp_name == pricegroup.comp_name && this.pricegroup.price_group == pricegroup.price_group && this.pricegroup.price_group_count == pricegroup.price_group_count ){
                pricegroup.profit_rate = $(e.target).val();
            }

            return pricegroup;
            
        }, item)
        this.changedPriceGroupList = this.changedPriceGroupList.filter(function(pricegroup) {
            if(this.pricegroup.comp_name == pricegroup.comp_name && this.pricegroup.price_group == pricegroup.price_group && this.pricegroup.price_group_count == pricegroup.price_group_count ){
                isNew = false;
        
                return this;
            }else{
                return pricegroup;
            }
        }, item)

        if(isNew){
            this.changedPriceGroupList.push(item.pricegroup);
        }
    }

    changeNoSellFlagPriceGroup(e){
        this.convertToHalfWidth(e);

        var checkTest = e.target.checked;
        // looped item
        var item = e.item
        var isNew = true;
        item.pricegroup.no_sellable_flag = $(e.target).val();
        
        this.pricegroup_list = this.pricegroup_list.filter(function(pricegroup) {
            if( this.pricegroup.comp_name == pricegroup.comp_name && this.pricegroup.price_group == pricegroup.price_group && this.pricegroup.price_group_count == pricegroup.price_group_count ){
              if(checkTest == true){
                pricegroup.no_sellable_flag = 1;
                $(e.target).val(1);
              } else {
                pricegroup.no_sellable_flag = '';
                $(e.target).val('');
              }
            }

            return pricegroup;
            
        }, item)
        this.changedPriceGroupList = this.changedPriceGroupList.filter(function(pricegroup) {
            if(this.pricegroup.comp_name == pricegroup.comp_name && this.pricegroup.price_group == pricegroup.price_group && this.pricegroup.price_group_count == pricegroup.price_group_count ){
                isNew = false;
        
                return this;
            }else{
                return pricegroup;
            }
        }, item)

        if(isNew){
            this.changedPriceGroupList.push(item.pricegroup);
        }
    }

    changeHiddenPriceFlagPriceGroup(e) {
      this.convertToHalfWidth(e);
      var checkTest = e.target.checked;
      // looped item
      var item = e.item;
      var isNew = true;
      item.pricegroup.hidden_price_flag = $(e.target).val();

      this.pricegroup_list = this.pricegroup_list.filter(function (pricegroup) {
        if (this.pricegroup.comp_name == pricegroup.comp_name && this.pricegroup.price_group == pricegroup.price_group && this.pricegroup.price_group_count == pricegroup.price_group_count) {
          if (checkTest == true) {
            pricegroup.hidden_price_flag = 1;
            $(e.target).val(1);
          } else {
            pricegroup.hidden_price_flag = '';
            $(e.target).val('');
          }
        }

        return pricegroup;

      }, item);
      this.changedPriceGroupList = this.changedPriceGroupList.filter(function (pricegroup) {
        if (this.pricegroup.comp_name == pricegroup.comp_name && this.pricegroup.price_group == pricegroup.price_group && this.pricegroup.price_group_count == pricegroup.price_group_count) {
          isNew = false;

          return this;
        } else {
          return pricegroup;
        }
      }, item);

      if (isNew) {
        this.changedPriceGroupList.push(item.pricegroup);
      }
    }

    changeSellingTanka(e){
        // looped item
        this.convertToHalfWidth(e);
        var checkFormatNumber = this.validateIntNumber($(e.target).val());
        if(!checkFormatNumber){
            alert('納入価格を正数のみで入力してください。');
            $(e.target).val('');
            return false;
        }
        var item = e.item
        var isNew = true;
        item.product.selling_tanka = $(e.target).val();
        this.product_list = this.product_list.filter(function(product) {
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                product.selling_tanka = $(e.target).val();
            }
            return product;
            
        }, item)
        this.changedProductList = this.changedProductList.filter(function(product) {
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                isNew = false;
                return this;
            }else{
                return product;
            }
            
        }, item)
        if(isNew){
            this.changedProductList.push(item.product);
        }
        
    }

    changeCamSellingTanka(e){
        this.convertToHalfWidth(e);
        var item = e.item
        var isNew = true;
        item.product.cam_selling_tanka_rate = $(e.target).val();

        this.product_list = this.product_list.filter(function(pricegroup) {
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                product.cam_selling_tanka_rate = $(e.target).val();
            }

            return product;
            
        }, item)
        this.changedProductList = this.changedProductList.filter(function(product) {
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                isNew = false;
                return this;
            }else{
                return product;
            }
            
        }, item)
        if(isNew){
            this.changedProductList.push(item.product);
        }
        
    }

    changeSellingTankaRate(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.product.selling_tanka_rate = $(e.target).val();
        this.product_list = this.product_list.filter(function(product) {
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                product.selling_tanka_rate = $(e.target).val();
            }
            return product;
        },item)
        
        
        this.changedProductList = this.changedProductList.filter(function(product){
            
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                 isNew = false;
                return this;
            }else{
                return product;
            }
        }, item)
        if(isNew){
            this.changedProductList.push(item.product);
        }
        
        
    }

    changeCamSellingTankaRate(e){
        this.convertToHalfWidth(e);
        // looped item
        var item = e.item
        var isNew = true;
        item.product.cam_selling_tanka_rate = $(e.target).val();
        this.product_list = this.product_list.filter(function(product) {
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                product.cam_selling_tanka_rate = $(e.target).val();
            }
            return product;
        },item)
        
        
        this.changedProductList = this.changedProductList.filter(function(product){
            
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                 isNew = false;
                return this;
            }else{
                return product;
            }
        }, item)
        if(isNew){
            this.changedProductList.push(item.product);
        }
        
        
    }

    changeProfitRate(e){
        // looped item
        this.convertToHalfWidth(e);
        var item = e.item
        var isNew = true;
        item.product.profit_rate = $(e.target).val();
        this.product_list = this.product_list.filter(function(product) {
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                product.profit_rate = $(e.target).val();
            }
            return product;
            
        }, item)
        this.changedProductList = this.changedProductList.filter(function(product) {
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                isNew = false;
                return this;
            }else{
                return product;
            }
            
        }, item)
        if(isNew){
            this.changedProductList.push(item.product);
        }
        
    }

    changeNoSellFlag(e){
        // looped item
        this.convertToHalfWidth(e);
        var checkTest = e.target.checked;
        var item = e.item
        var isNew = true;
        item.product.no_sellable_flag = $(e.target).val();
        this.product_list = this.product_list.filter(function(product) {
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                if(checkTest == true){
                    product.no_sellable_flag = 1;
                    $(e.target).val(1);
                } else {
                    product.no_sellable_flag = '';
                    $(e.target).val('');
                }
            }
            return product;
            
        }, item)
        this.changedProductList = this.changedProductList.filter(function(product) {
            if(this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name){
                isNew = false;
                return this;
            }else{
                return product;
            }
            
        }, item)
        if(isNew){
            this.changedProductList.push(item.product);
        }
        
    }

    changeHiddenPriceFlag(e){
        // looped item
      this.convertToHalfWidth(e);
      var checkTest = e.target.checked;
      var item = e.item;
      var isNew = true;
      item.product.hidden_price_flag = $(e.target).val();
      this.product_list = this.product_list.filter(function (product) {
        if (this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name) {
          if (checkTest == true) {
            product.hidden_price_flag = 1;
            $(e.target).val(1);
          } else {
            product.hidden_price_flag = '';
            $(e.target).val('');
          }
        }
        return product;

      }, item);
      this.changedProductList = this.changedProductList.filter(function (product) {
        if (this.product.sku == product.sku && this.product.customer_comp_cd == product.customer_comp_cd && this.product.supplier_comp_code == product.supplier_comp_code && this.product.maker_name == product.maker_name) {
          isNew = false;
          return this;
        } else {
          return product;
        }

      }, item);
      if (isNew) {
        this.changedProductList.push(item.product);
      }
    }
    updateProductSellingTankaRate(e){
        this.changedProductList;
          
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var url = URL_API + '/api/selling_prices/saveSellingTankaRate?token=' + accessTokenCognito + '&companies_customer_comp_name=' + encodeURI($('#companies_customer_comp_name').val());
        var comp_name = $('#companies_customer_comp_name').val();
        if(comp_name == ''){
            alert("得意先を指定してください。");
            searchProducts(thisTag.currentPage);
            return false;
        }
        $.each(thisTag.custNames, function(i,e){
            if(e['value'] == comp_name){
                comp_code = e['comp_code'];
            }
        });
        var data = [];

        $.each(this.changedProductList, function( index, product ) {
            data.push({
                'seq': product.seq,
                'selling_tanka': product.selling_tanka,
                'selling_tanka_rate': product.selling_tanka_rate,
                'supp_co_cd': product.supplier_comp_code,
                'item_sku': product.sku,
                
                'maker_name': product.maker_name,
                'supp_sku': product.supplier_sku,
                'customer_co_cd': comp_code,
                'profit_rate': product.profit_rate,
                'no_sellable_flag': product.no_sellable_flag,
                'contract_item_flag': product.contract_item_flag,
                'cam_selling_tanka_rate': product.cam_selling_tanka_rate,
                'hidden_price_flag': product.hidden_price_flag
                })
            if(thisTag.customer_dep_cd_search != '') {
                data[index].customer_dep_cd = thisTag.customer_dep_cd_search;
            }
        });

        if(data.length > 0){
          var pricing_unit = [1,2,3];
            thisTag.checkPricingUnitBeforePost(data, pricing_unit);
            if(thisTag.status_check_pricing_unit){
              return false;
            }
            thisTag.status_check_pricing_unit = false;
            $.ajax({
                url: url,
                type: 'POST',
                timeout: 20000,
                data: {
                    data: data
                },
                success: function (res) {
                    if(res.status == 100){
                        riot.mount('app','maintain',{ messege:res.messege });
                        return false;
                    }
                    if(res.message == 'success'){

                        thisTag.changedProductList = [];

                        var page = thisTag.currentPage; //$('#page').val();
                        alert('更新しました。');

                        searchProducts(page);


                    }
                },
                error: function (xhr, stt, err) {
                    if(xhr.responseJSON.message[0]){
                        for(var p in xhr.responseJSON.message[0]){
                            var msg = '';
                            var obj = xhr.responseJSON.message[0][p];
                            var maxLength = 'maxLength'
                            switch(p) {
                                case 'selling_tanka_rate':
                                        if(maxLength in obj){
                                                msg = 'field tanka rate : ' + obj.maxLength;
                                                alert(msg);
                                        }
                                        break;
                                case 'selling_tanka':
                                        if(maxLength in obj){
                                                msg = 'field tanka : ' + obj.maxLength;
                                                alert(msg);
                                        }
                                        break;
                                case 'cam_selling_tanka_rate':
                                        if(maxLength in obj){
                                                msg = 'field cam_selling_tanka_rate : ' + obj.maxLength;
                                                alert(msg);
                                        }
                                        break;
                                default:

                            }
                        }
                    }
                }
            });
        }           
          
    }
    this.checkPricingUnitBeforePost = function(data, pricing_unit){
      var accessTokenCognito = localStorage.getItem('accessTokenCognito');
      var url = URL_API + '/api/s02/check_pricing_unit?token=' + accessTokenCognito;
      $.ajax({
        url: url,
        type: "POST",
        timeout: 60000,
        data: {
          data: data,
          pricing_unit: pricing_unit
        },
        async: false,
        beforeSend: function(){
          $('#img-loader').show();
        },
        success: function(res){
          if(res.status == 100){
              riot.mount('app','maintain',{ messege:res.messege });
              return false;
          }
          var count = res.count;
          var text = [];

          if(count){
              var pricing_one = count['pricing_one'] ? count['pricing_one'] : 0;
              var pricing_two = count['pricing_two'] ? count['pricing_two'] : 0;
              var pricing_three = count['pricing_three'] ? count['pricing_three'] : 0;
              var pricing_five = count['pricing_five'] ? count['pricing_five'] : 0;
              if(pricing_one > 0 || pricing_two > 0 || pricing_three > 0 || pricing_five > 0){
                text.push("登録しようとしている販売元メーカーですでに登録済みの設定があります。\n");
              }
              if(pricing_one > 0){
                text.push("設定単位 販売元メーカー：" + pricing_one + '件\n');
              }
              if(pricing_two > 0){
                text.push("設定単位 製造元メーカー：" + pricing_two + '件\n');
              }
              if(pricing_three > 0){
                text.push("設定単位 プライスグループ：" + pricing_three + '件\n');
              }
              if(pricing_five > 0){
                text.push("設定単位 製品：" + pricing_five + '件\n');
              }
              // text.push("" + pricing_four + '件\n');
              if(text.length > 0){
                if(!confirm(text.join(""))){
                  thisTag.status_check_pricing_unit = true;
                } else {
                  thisTag.status_check_pricing_unit = false;
                }
              }
          }
        }, 
        complete: function(){
          $('#img-loader').hide();
        },
        error: function(err){
          alert("error");
        }
      });
    }
    $(function(){

      /***modal-open***/
      $('#S02-3-Open').on('click',function(){
        var filePage = 1;
        searchFile(filePage);
     
      });
      $('#S02-3-Close').on('click',function(){
        $('#S02-3').fadeOut();
      });
      /***価格設定単価***/
      $('input[name="tanni"]').on('change',function(){
        $('.result-div').hide();
        var val = $('input[name="tanni"]:checked').val();
        if(val == 'supplier'){
          searchTableSlide('#supplier_search_table');
        }else if(val == 'manufacturer'){
          searchTableSlide('#manufacturer_search_table');
        }else if(val == 'products'){
          searchTableSlide('#products_search_table');
        }else if(val == "pricegroup"){
          searchTableSlide('#pricegroup_search_table');
        }
      });
      $('.reset-btn').on('click',function(){
        $('.inTable').slideUp(function(){
          $('.inTable').children('table').hide();
        });
        thisTag.update({
            companies_customer_comp_name: '',
            customer_dep_cd_search: '',
            supplier_comp_code_search: '',
            supplier_comp_code_search2: '',
            supplier_comp_code_search3: '',
            supplier_comp_code_search4: '',
            suppNames: opts.suppNames
        });
        thisTag.getListSuggestSupplier(thisTag.suppNames);
      });
      /***検索結果***/
      $('.submit').on('click',function(){
        
        var val = $('input[name="tanni"]:checked').val();
        if(val == 'supplier'){
            if($("#companies_customer_comp_name").val() == ''){
                alert("得意先を指定してください。");
                return false;
            }
            var supPage = 1;
            thisTag.currentPage = supPage;
            searchSupplier(supPage);
        }else if(val == 'manufacturer'){
            if($("#companies_customer_comp_name").val() == ''){
                alert("得意先を指定してください。");
                return false;
            }
            var pageManuFact = 1;
            thisTag.currentPage = pageManuFact;
            searchManufacturer(pageManuFact);
        }else if(val == 'products'){
            if($('#supplier_name').val() || $('#manufacturer').val() || $('#supplier_sku').val() || $('#product_name').val() || $('#companies_customer_comp_name').val()){
                if($("#companies_customer_comp_name").val() == ''){
                    alert("得意先を指定してください。");
                    return false;
                }
                var page = 1;
                thisTag.currentPage = page;
                searchProducts(page);
            }else{
                if($("#companies_customer_comp_name").val() == ''){
                    alert("得意先を指定してください。");
                    return false;
                }
                alert('「販売元メーカー」「製造元メーカー」「品番」「品名」の何れかは必須です。');
            }
        }else if(val == 'pricegroup'){
            if($("#companies_customer_comp_name").val() == ''){
                alert("得意先を指定してください。");
                return false;
            }
            var pricePage = 1;
            thisTag.currentPage = pricePage;
            searchPriceGroup(pricePage);
        }else{
            alert('設定単位を選択してください。');
        }
        $('#departments_kyoten_name').on('change', function() {
            if($(this).val() == '') {
                thisTag.update({
                    customer_dep_cd_search: ''
                });
            }
        });
        $('#companies_supplier_comp_name').on('change', function() {
            if($(this).val() == '') {
                thisTag.update({
                    supplier_comp_code_search: ''
                });
            }
        });
        $('#companies_supplier_comp_name2').on('change', function() {
            if($(this).val() == '') {
                thisTag.update({
                    supplier_comp_code_search2: ''
                });
            }
        });
        $('#companies_supplier_comp_name3').on('change', function() {
            if($(this).val() == '') {
                thisTag.update({
                    supplier_comp_code_search3: ''
                });
            }
        });
        $('#supplier_name').on('change', function() {
            if($(this).val() == '') {
                thisTag.update({
                    supplier_comp_code_search4: ''
                });
            }
        });
      });
      
        let res = [];
        for (var i = thisTag.custNames.length - 1; i >= 0; i--) {
            if(thisTag.custNames[i].value == null) {
                continue;
            }
            res.push({value: thisTag.custNames[i].value, label: thisTag.custNames[i].value, comp_index: i});
        }
        $("#companies_customer_comp_name").autocompleter("destroy");
        $('#companies_customer_comp_name').autocompleter({
            limit:10000,
            highlightMatches:true,
            source: res,
            callback: function(value, index, object) {
                if($("#companies_customer_comp_name").val() != '' && thisTag.custNames[object.comp_index].comp_code) {
                    $('#departments_kyoten_name').val('');
                    thisTag.update({
                        companies_customer_comp_name: thisTag.custNames[object.comp_index].value,
                        comp_code_search: thisTag.custNames[object.comp_index].comp_code,
                        customer_dep_cd_search: ''
                    });
                    var querySuggest = [];
                    var accessTokenCognito = localStorage.getItem('accessTokenCognito');
                    querySuggest.push('token=' + accessTokenCognito);
                    querySuggest.push('comp_code=' + thisTag.comp_code_search);
                    var url = URL_API + '/api/s02/companies/getSuggestionSupplier';
                    url += '?' + querySuggest.join('&');
                    $.ajax({
                        url: url,
                        type: 'GET',
                        timeout: 60000,
                        success: function (data) {
                            if(data.status == 100){
                                riot.mount('app','maintain',{ messege:data.messege });
                                return false;
                            }
                            if(data.status == 'not_authorize'){
                                var url = "#";
                                $(location).attr("href", url );
                                return false;
                            }
                            thisTag.suppNames = data.supplier_list;
                            thisTag.kyotNames = data.kyoten_list;
                            thisTag.update(thisTag.suppNames);
                            thisTag.update(thisTag.kyotNames);
                            $.each(thisTag.suppNames, function(i,e){
                                thisTag.list_comp_code.push(e['comp_code']);
                            });

                            $.each(thisTag.kyotNames, function(i,e){
                                thisTag.list_kyoten_code.push(e['comp_code']);
                            });

                            $("#departments_kyoten_name").autocompleter("destroy");
                            thisTag.getListSuggestSupplier(data.supplier_list);
                            $("#companies_supplier_comp_name").val('');
                            $("#companies_supplier_comp_name2").val('');
                            $("#companies_supplier_comp_name3").val('');
                            $("#supplier_name").val('');
                            $('#departments_kyoten_name').autocompleter({
                                limit:10000,
                                highlightMatches:true,
                                source: thisTag.kyotNames,
                                callback: function(value, index, object) {
                                    thisTag.update({
                                        customer_dep_cd_search: object.comp_code
                                    });
                                }
                            });
                            $('#manufacturer').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.makerNames });
                            $('#ec_products_maker_name').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.makerNames });
                        },
                        error: function (xhr, stt, err) {
                            alert('error');
                        }
                    });
                } else {
                    thisTag.update({companies_customer_comp_name: ''});
                }
            }
        });
   
        $('#companies_customer_comp_name').on('change', function() {
            if($(this).val() == '') {
                $("#companies_supplier_comp_name").autocompleter("destroy");
                $("#companies_supplier_comp_name2").autocompleter("destroy");
                $("#companies_supplier_comp_name3").autocompleter("destroy");
                $("#supplier_name").autocompleter("destroy");
                $('#departments_kyoten_name').autocompleter("destroy");
                $('#manufacturer').autocompleter("destroy");
                $('#ec_products_maker_name').autocompleter("destroy");
                $("#companies_supplier_comp_name").val('');
                $("#companies_supplier_comp_name2").val('');
                $("#companies_supplier_comp_name3").val('');
                $("#supplier_name").val('');
                $("#departments_kyoten_name").val('');
                $("#manufacturer").val('');
                $("#ec_products_maker_name").val('');
                thisTag.update({
                    supplier_comp_code_search: '',
                    supplier_comp_code_search2: '',
                    supplier_comp_code_search3: '',
                    supplier_comp_code_search4: '',
                    customer_dep_cd_search: ''
                });
            }
        });
    });
    this.getListSuggestSupplier = function(suppNames) {
        $("#companies_supplier_comp_name").autocompleter("destroy");
        $("#companies_supplier_comp_name2").autocompleter("destroy");
        $("#companies_supplier_comp_name3").autocompleter("destroy");
        $("#supplier_name").autocompleter("destroy");
        $('#companies_supplier_comp_name').autocompleter({
            limit:10000,
            highlightMatches:true,
            source: suppNames,
            callback: function(value, index, object) {
                thisTag.update({
                    supplier_comp_code_search: object.comp_code
                });
            }
        });
        $('#companies_supplier_comp_name2').autocompleter({
          limit:10000,
          highlightMatches:true,
          source: suppNames,
          callback: function(value, index, object) {
            $("#ec_products_maker_name").val('');
            var accessTokenCognito = localStorage.getItem('accessTokenCognito');
            var url = URL_API + '/api/s02/get-manufacturer-name-by-id?token=' + accessTokenCognito + '&companies_supplier_comp_name=' + object.comp_code;
              $.ajax({
                url: url,
                type: 'GET',
                timeout: 20000,
                success: function (res) {
                    if(res.status == 100){
                        riot.mount('app','maintain',{ messege:res.messege });
                        return false;
                    }
                    if(res.message == 'success'){
                      $("#ec_products_maker_name").autocompleter("destroy");
                      $('#ec_products_maker_name').autocompleter({ limit:10000,highlightMatches:true, source: res.maker_name_list });
                    }
                },
                error: function (xhr, stt, err) {
                }
              });
              thisTag.update({
                  supplier_comp_code_search2: object.comp_code
              });
          }
        });
        $('#companies_supplier_comp_name3').autocompleter({
            limit:10000,
            highlightMatches:true,
            source: suppNames,
            callback: function(value, index, object) {
                thisTag.update({
                    supplier_comp_code_search3: object.comp_code
                });
            }
        });
        $('#supplier_name').autocompleter({
          limit:10000,
          highlightMatches:true,
          source: suppNames,
          callback: function(value, index, object) {
            $("#manufacturer").val('');
            var accessTokenCognito = localStorage.getItem('accessTokenCognito');
            var url = URL_API + '/api/s02/get-manufacturer-name-by-id?token=' + accessTokenCognito + '&companies_supplier_comp_name=' + object.comp_code;
              $.ajax({
                url: url,
                type: 'GET',
                timeout: 20000,
                success: function (res) {
                    if(res.status == 100){
                        riot.mount('app','maintain',{ messege:res.messege });
                        return false;
                    }
                    if(res.message == 'success'){
                      $("#manufacturer").autocompleter("destroy");
                      $('#manufacturer').autocompleter({ limit:10000,highlightMatches:true, source: res.maker_name_list });
                    }
                },
                error: function (xhr, stt, err) {
                }
              });
              thisTag.update({
                  supplier_comp_code_search4: object.comp_code
              });
          }
        });
    }

    function searchTableSlide(id){
      var allTable = $('.inTable').children('table');
      $('.inTable').slideUp(function(){
        allTable.hide();
        $(id).show();
      });
      $('.inTable').slideDown();
    }
    function searchProducts(page) {
        
        thisTag.changedProductList = [];
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        
                    thisTag.currentPage = page;
                    $('.result-div').hide();
                    var url = URL_API + '/api/s02/product_list';
                    
                    var query = [];
                    query.push('token=' + accessTokenCognito);
                    var companies_customer_comp_name = encodeURI(thisTag.companies_customer_comp_name);
                    if (companies_customer_comp_name) {
                        query.push('companies_customer_comp_name='+companies_customer_comp_name);
                    }
                    var companies_supplier_comp_name = encodeURI($('#supplier_name').val());
                    if (companies_supplier_comp_name) {
                        query.push('supplier_name='+companies_supplier_comp_name);
                    }
                    var companies_supplier_comp_name = encodeURI($('#manufacturer').val());
                    if (companies_supplier_comp_name) {
                        query.push('manufacturer='+companies_supplier_comp_name);
                    }
                    var companies_supplier_comp_name = encodeURIComponent($('#supplier_sku').val());
                    if (companies_supplier_comp_name) {
                        query.push('supplier_sku='+companies_supplier_comp_name);
                    }
                    var companies_supplier_comp_name = encodeURI($('#product_name').val());
                    if (companies_supplier_comp_name) {
                        query.push('product_name='+companies_supplier_comp_name);
                    }
                    if (thisTag.customer_dep_cd_search) {
                        query.push('customer_dep_cd='+thisTag.customer_dep_cd_search);
                    }
                    if (thisTag.supplier_comp_code_search4) {
                        query.push('supplier_comp_code='+thisTag.supplier_comp_code_search4);
                    }
                    if ($('.search-campaign').is(":checked")) {
                        query.push('campaign_only=1');
                    }

                    query.push('comp_code=' + thisTag.comp_code_search);
                    query.push('page='+page);
                    query.push('limit=' + LIMIT_ON_PAGE);
                    url += '?' + query.join('&');


                    $.ajax({
                        url: url,
                        type: 'GET',
                        timeout: 60000,
                        success: function (res) {
                            if(res.status == 100){
                                riot.mount('app','maintain',{ messege:res.messege });
                                return false;
                            }
                            thisTag.product_list = res.product_list;
                            
                            $('#products_result').show();    
                            var data = res;
                            var results = data.product_list;
                            var totalPages = Math.ceil(data.page_total/LIMIT_ON_PAGE);
                            var visiblePages = 1;
                            if(totalPages != 0){
                                visiblePages =  5;
                            } 
                            var $pagination = $('#pagination_product');
                            $pagination.twbsPagination('destroy');
                            $pagination.twbsPagination({
                                totalPages: totalPages,
                                visiblePages: visiblePages,
                                startPage: page,
                                initiateStartPageClick: false,
                                onPageClick: function (event, page) {
                                    searchProducts(page);
                                    thisTag.currentPage = page;
                                }
                            });
                            
                            thisTag.update(thisTag.product_list);
                            
                        },
                        error: function () {
                            alert('error');
                        }
                    });
    }

    function searchSupplier(page) {
        
        thisTag.currentSupplierPage = page;
        thisTag.changedSupplierList = [];
        $('.result-div').hide();
        var url = URL_API + '/api/s02/supplier_list';
        
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var query = [];
        query.push('token=' + accessTokenCognito);
        var companies_customer_comp_name = encodeURI(thisTag.companies_customer_comp_name);
        if (companies_customer_comp_name) {
            query.push('companies_customer_comp_name='+companies_customer_comp_name);
        }
        var companies_supplier_comp_name = encodeURI($('#companies_supplier_comp_name').val());
        if (companies_supplier_comp_name) {
            query.push('companies_supplier_comp_name='+companies_supplier_comp_name);
        }
        if (thisTag.customer_dep_cd_search) {
            query.push('customer_dep_cd='+thisTag.customer_dep_cd_search);
        }
        if (thisTag.supplier_comp_code_search) {
            query.push('supplier_comp_code='+thisTag.supplier_comp_code_search);
        }
        query.push('comp_code=' + thisTag.comp_code_search);
        query.push('page='+page);
        query.push('limit=' + LIMIT_ON_PAGE);
        url += '?' + query.join('&');
        $.ajax({
            url: url,
            type: 'GET',
            success: function (res) {
                if(res.status == 100){
                    riot.mount('app','maintain',{ messege:res.messege });
                    return false;
                }
                thisTag.supplier_list = res.supplier_list;
                var data = res;
                var results = data.supplier_list;
                var totalPages = Math.ceil(data.total/LIMIT_ON_PAGE);
                var visiblePages = 1;
                if(totalPages != 0){
                    visiblePages =  5;
                } 
                var $pagination = $('#pagination_supplier');
                $pagination.twbsPagination('destroy');
                $pagination.twbsPagination({
                    totalPages: totalPages,
                    visiblePages: visiblePages,
                    startPage: page,
                    initiateStartPageClick: false,
                    onPageClick: function (event, page) {

                        searchSupplier(page);
                        thisTag.currentPage = page;
                    }
                });

                thisTag.update(thisTag.supplier_list);    
            },
            error: function () {
                alert('error');
            }
        });
        $('#supplier_result').show();
    }


    function searchManufacturer(page) {
        thisTag.changedManufacturerList = [];
        thisTag.currentManufacturePage = page;
        $('.result-div').hide();
        var url = URL_API + '/api/s02/manufacturer_list';
        
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var query = [];
        query.push('token=' + accessTokenCognito);
        var companies_customer_comp_name = encodeURI(thisTag.companies_customer_comp_name);
        if (companies_customer_comp_name) {
            query.push('companies_customer_comp_name='+companies_customer_comp_name);
        }
        var companies_supplier_comp_name = encodeURI($('#companies_supplier_comp_name2').val());
        if (companies_supplier_comp_name) {
            query.push('companies_supplier_comp_name='+companies_supplier_comp_name);
        }
        var ec_products_maker_name = encodeURI($('#ec_products_maker_name').val());
        if (ec_products_maker_name) {
            query.push('ec_products_maker_name='+ec_products_maker_name);
        }
        if (thisTag.customer_dep_cd_search) {
            query.push('customer_dep_cd='+thisTag.customer_dep_cd_search);
        }
        if (thisTag.supplier_comp_code_search2) {
            query.push('supplier_comp_code='+thisTag.supplier_comp_code_search2);
        }
        query.push('comp_code=' + thisTag.comp_code_search);
        query.push('page='+page);
        query.push('limit=' + LIMIT_ON_PAGE);
        url += '?' + query.join('&');
        $.ajax({
            url: url,
            type: 'GET',
            success: function (res) {
                if(res.status == 100){
                    riot.mount('app','maintain',{ messege:res.messege });
                    return false;
                }
                thisTag.manufacturer_list = res.manufacturer_list;
                var data = res;
                var results = data.manufacturer_list;
                var totalPages = Math.ceil(data.total/LIMIT_ON_PAGE);
                var visiblePages = 1;
                if(totalPages != 0){
                    visiblePages =  5;
                } 
                var $pagination = $('#pagination_manufacturer');
                $pagination.twbsPagination('destroy');
                $pagination.twbsPagination({
                    totalPages: totalPages,
                    visiblePages: visiblePages,
                    startPage: page,
                    initiateStartPageClick: false,
                    onPageClick: function (event, page) {

                        searchManufacturer(page);
                         thisTag.currentPage = page;
                   }
                });

                thisTag.update(thisTag.manufacturer_list);
                
                
                
                
            },
            error: function () {
                alert('error');
            }
        });
        $('#manufacturer_result').show();
    }


    function searchPriceGroup(page){
      thisTag.changedPriceGroupList = [];
      thisTag.currentPriceGroupPage = page;
      $('.result-div').hide();
      var url = URL_API + '/api/s02/pricegroup_list';
      
      var accessTokenCognito = localStorage.getItem('accessTokenCognito');
      var query = [];
      query.push('token=' + accessTokenCognito);

      var companies_supplier_comp_name = encodeURI($('#companies_supplier_comp_name3').val());
      if (companies_supplier_comp_name) {
          query.push('companies_supplier_comp_name='+companies_supplier_comp_name);
      }
      var companies_customer_comp_name = encodeURI(thisTag.companies_customer_comp_name);
      if (companies_customer_comp_name) {
        query.push('companies_customer_comp_name='+companies_customer_comp_name);
      }

      var price_group_val = $('#priceGroupFld').val();
      if (price_group_val) {
        query.push('search_price_group='+ price_group_val);
      }
  
        if (thisTag.customer_dep_cd_search) {
            query.push('customer_dep_cd='+thisTag.customer_dep_cd_search);
        }
        if (thisTag.supplier_comp_code_search3) {
            query.push('supplier_comp_code='+thisTag.supplier_comp_code_search3);
        }
      query.push('comp_code=' + thisTag.comp_code_search);
      query.push('page='+page);
      query.push('limit=' + LIMIT_ON_PAGE);
      url += '?' + query.join('&');
      $.ajax({
          url: url,
          type: 'GET',
          success: function (res) {
              if(res.status == 100){
                  riot.mount('app','maintain',{ messege:res.messege });
                  return false;
              }
              thisTag.pricegroup_list = res.pricegroup_list; 
              var data = res;
              var results = data.pricegroup_list;
              var totalPages = Math.ceil(data.total/LIMIT_ON_PAGE);
              var visiblePages = 1;
              if(totalPages != 0){
                  visiblePages =  5;
              } 
              var $pagination = $('#pagination_pricegroup');
              $pagination.twbsPagination('destroy');
              $pagination.twbsPagination({
                  totalPages: totalPages,
                  visiblePages: visiblePages,
                  startPage: page,
                  initiateStartPageClick: false,
                  onPageClick: function (event, page) {

                      searchPriceGroup(page);
                    thisTag.currentPage = page;
                  }
              });

              thisTag.update(thisTag.pricegroup_list);
             
          },
          error: function () {
              alert('error');
          }
      });
      $('#pricegroup_result').show();
    }

    function searchFile(page){
      thisTag.changedFileList = [];
      thisTag.currentFilePage = page;
      //$('.result-div').hide();
      var url = URL_API + '/api/s02/file_list_s02';
      
      var accessTokenCognito = localStorage.getItem('accessTokenCognito');
      var query = [];
      query.push('token=' + accessTokenCognito);

      query.push('page='+page);
      query.push('limit=' + LIMIT_ON_PAGE);
      url += '?' + query.join('&');
      $("#S02-3").fadeIn();
      $.ajax({
          url: url,
          type: 'GET',
          success: function (res) {
              if(res.status == 100){
                  riot.mount('app','maintain',{ messege:res.messege });
                  return false;
              }
              thisTag.file_list = res.list;
              riot.mount('upload-set-modal', {
                  list_file: res.list,
                  cust_names: thisTag.custNames,
                  cust_names: thisTag.custNames,
                  comp_name_search: $('#companies_customer_comp_name').val(),
                  comp_code_search: thisTag.comp_code_search,
                  dep_name_search: $('#departments_kyoten_name').val(),
                  dep_code_search: thisTag.customer_dep_cd_search
                });
              $("#S02-3").fadeIn();  
              var data = res;
              var results = data.list;
              var totalPages = Math.ceil(data.total/LIMIT_ON_PAGE);
              var visiblePages = 1;
              if(totalPages != 0){
                  visiblePages =  5;
              } 
              var $pagination = $('#pagination_file');
              $pagination.twbsPagination('destroy');
              $pagination.twbsPagination({
                  totalPages: totalPages,
                  visiblePages: visiblePages,
                  startPage: page,
                  initiateStartPageClick: false,
                  onPageClick: function (event, page) {

                      searchFile(page);
                            thisTag.currentPage = page;
                      }
              });

              thisTag.update(thisTag.file_list);
   
          },
          error: function () {
              alert('error');
          }
      });
    }
  </script>

</price-set>
