added-purchase-template2.vue 28.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
<style scoped>
	.hei400{
		height: 400px;
	}
</style>
<template>
	<div class="container resource close-left-menu contaNEW" style="min-height: 809px;">
		<div class="pop-banner clearfix">
			 <div class="operate-btns">
			 	<a href="javascript:;" class="fbtn fb-return" @click='back'>返回</a>
			 	<a href="javascript:;" class="fbtn fb-remove" @click='abandon'>废弃此单</a>
			    <a href="javascript:void(0)" class="fbtn fb-save" @click='saveTrmedplan'>保存</a>
			    <a href="javascript:void(0)" class="fbtn fb-submit" @click='submitTrmedExternalplan'>飞送</a>
			 </div>
			<h3 class="current-module">新增采购计划</h3>
		</div>

		<!--order-orderlist-view start-->
		<div class="order-orderlist-view clearfix purchase-add-plan">
			<div class="fpart pd-form pd-form-lg-label">
	          <div class="fheader">
	            <h4 class='fh-notes'>订货信息</h4>
	            <div class="fr pap-tit-right" v-if="'/hospital/trmedplan:createCollection' | myqx">
	              <div class="checkbox-control checkbox-inline">
	                <input type="checkbox" name="cb" id="cball" v-model="collectionCheck">
	                <label class="checkbox" for="cball">收藏为订单模板</label>
	              </div>
	              请为模板起个好名字
	              <input type="text" v-model="collectionName">
	            </div>
	          </div>
	          <div class="group-row">
	            <div class="form-group must form-label">
	              <label for="cc1" class="label">订货日期</label>
	              <div class="control">
	                <datepicker :target.sync="trmedplan.planbegindate | getYMD" id='cc1' inpclass='inp4'></datepicker>
	              </div>
	            </div>
	            <div class="form-group form-label">
	              <label for="cc4" class="label">要货科室</label>
	              <div class="control">
	                <select-ui :list="departmentsList" :selected.sync="false" :emptyText="" v-model="trmedplan.meddeptguid" class='inp4' id='cc4'>
	                </select-ui>
	              </div>
	            </div>
	          </div>
	          <div class="group-row">
	            <div class="form-group must form-label must">
	              <label for="cc3" class="label w130">要求到货日期</label>
	              <div class="control">
	                <datepicker :target.sync="trmedplan.planenddate | getYMD" id='cc3' inpclass='inp6'></datepicker>
	              </div>
	            </div>
	            <div class="form-group form-label">
	              <label for="cc2" class="label">要货库房</label>
	              <div class="control select-style">
	                <select v-model="trmedplan.medstoreguid" class="inp4"> 
	                <option v-for="option in storeList" v-bind:value="option.value">
	                  {{option.label}}
	                </option>
	              </select>
	              </div>
	            </div>
	          </div>
	          <div class="group-row">
	            <div class="form-group form-label">
	              <label for="cc5" class="label">单据类型</label>
	              <div class="control">
	                <select-ui :list="$store.state.$billTypeList" :selected.sync="false" :emptyText="" v-model="trmedplan.billtype" id='cc5' class='inp4'>
	                </select-ui>
	              </div>
	            </div>
	          </div>
	          <div class="form-group form-label">
	            <label for="cc6" class="label">收货地点</label>
	            <div class="control input-has-txt">
	              <input class="inp4" type="text" id="cc6" v-model="trmedplan.address" placeholder="提示:长度不能超过30个汉字">
	              <!-- filed1 -->
	            </div>
	          </div>
	          <div class="form-group form-label mt-10">
	            <label for="cc7" class="label">备注</label>
	            <div class="control input-has-txt">
	              <input class="inp2" type="text" id="cc7" v-model="trmedplan.memo">
	              <!-- filed1 -->
	            </div>
	          </div>
	        </div>
			<div class="pap-tit mt-20">
				<div style='height:30px;line-height:30px;'>
<em class="fW"> {{supplierNum}}</em>家供应商,<em class="fW"> {{TrmList.length}}</em>条明细,金额合计 <em class="fW"> {{priceS| numDigit 2}}</em>
			    </div>
		<!-- 	   	<div v-for='item in supList' style='height:30px;line-height:30px;'>
			   	  <em class="fW"> {{item.chineseName}}</em> 供应商,<em class="fW"> {{item.num}}</em>条明细,金额合计 <em class="fW"> {{item.price}}</em>
			   	
			   </div> -->
			<!--   <div>
			  	<em class="fW">333</em> 供应商,<em class="fW"> 3</em>条明细,金额合计 <em class="fW"> 100</em>
			  </div> -->
			 </div>
			 <table class="itable itable-td-long-text" v-if='supList.length>0'>
              <thead>
                <tr>
                  <th class="w50"></th>
                  <th class="w100"></th>
                  <th class="w60"></th>
                  <th class="w60"></th>
                </tr>
              </thead>
              <tbody>
               <tr v-for='item in supList'>
               		<td>{{$index+1}}</td>
               		<td class="t-left pr10">{{item.chineseName}}</td>
               		<td><span class="p-tit-green">{{item.num}}</span> 条品种数</td>
               		<td> {{item.price | numDigit 2}}</td>
               </tr>
              </tbody>
            </table>
            <div class="fheader no-bottom">
          		<h4 class="fh-good">商品列表</h4>
            </div>
	        <table class="itable itable-thead-13px itable-td-long-text itable-bordertop">
		          <thead>
		            <tr>
		              <th class="w50">序号</th>
		              <th class="w250 t-left">
		                <div class="p-lr-10">商品</div>
		              </th>
		              <th class="w170">供应商</th>
<!-- 		              <th class="w70">业务员</th> -->
		              <th class="w70">订货数</th>
		              <th class="w70">订货单位</th>
		              <th class="w80">包装价格(元)</th>
		              <th class="w80">含税金额</th>
		              <th class="w90">操作</th>
		            </tr>
		          </thead>
		          <tbody>
		            <tr v-for="item in TrmList">
		              <td>{{$index + 1 | getIndex}}
		                <div class="pro-pic pro-pic-lg" v-if="item.pictContent != null && item.pictContent != undefined && item.pictContent != ''">
		                  <imagebox v-bind:imgarr="item.pictContent | original">
		                    <img class="pro-pic pro-pic-lg" style="margin-top:0px;" :src="item.pictContent | thumbnail">
		                    <span class="pic-max blue-search">
		                </span>
		                  </imagebox>
		                </div>
		                <div v-else>
		                  <img class="pro-pic pro-pic-lg" style="margin-top:0px;" src="/images/default.jpg">
		                </div>
		              </td>
		              <td class=" t-left">
		                <div class="p-lr-10"> {{item.goodscode}} <br/>
		                  <span class="p-tit-green">{{item.goodsname}}</span> <br/> {{item.goodsspec}} <br/>                  
		                  {{item.producer}} <br/> {{item.registKey}}
		                </div>
		              </td>
		              <td class="t-left pr10">
		              <!-- {{item.chineseName}} -->
		              	<select v-model="item.supplierGuid"> 
	                      <option v-for="option in item.maps" v-bind:value="option.supplierguid">
	                        {{option.chinesename}}
	                      </option>
	                    </select>
		          		</td>
		              <!-- <td class="t-left pr10">{{item.staffName}}</td> -->
		              
		              <td><input type="text" class="edit-number" v-model="item.poqty" style='height:34px;line-height: 34px;' @change="checkInfo(item.poqty, $index, 2)"></td>
		              <td class="pr10">{{item.unitstyle}}</td>
		            
		              <td class="t-right pr10">
		              	<input type="text" class="edit-number" v-model="item.price" style='height:34px;line-height: 34px;' @change="checkInfo(item.price, $index, 1)">
		      		  </td>
		              <td class="t-right pr10" v-if="item.poqty != null & item.poqty != ''">{{item.poqty * item.price | numDigit 2 | numFmt}}</td>
		                <td class="t-right pr10" v-else>{{0 * item.price | numDigit 2 | numFmt}}</td>
		              <td><a class="btn button-red" href="javascript:void(0);" @click="deleteitemList($index)">删除</a></td>
		            </tr>
		            <tr>
		              <td>
		                <div></div>
		              </td>
		              <td class="t-left">
		                <div class="control w230 h-30 fl">
		                  <input id="cn1" type="text" v-model="medname" title='请输入商品名称' @click='state=true' placeholder="商品名称、编号、厂商、注册证号"> 
		                  <div class="select-template" id="searchMore" v-if='state'>
		                    <div class="div-select before-none" style="width:100%;">
		                      <ul  style="z-index:3;top:0px;width:215%; margin-top: 0px;overflow:auto;margin-bottom:60px;"  id="sortable" :class='{"hei400": goodsList.length>3}'>
		                        <li class="div-select-item pl10 pr10 hover-none" style='line-height:20px;height:auto;'>
	                        		<table class="itable itable-thead-13px itable-td-long-text">
			                            <thead id="t_header">
								          </thead>
								          <tbody>
								            <tr v-for="item in goodsList" @click='goodsData(item)' track-by="$index">
								              <td class="w210 t-left">
								                <div class="p-lr-10"> {{item.goodscode}}<br/>
								                  <span class="p-tit-green" style=' color: #4aa8e5;'>{{item.goodsname}}</span>
								                  <br/>{{item.goodsspec}}<br/>{{item.producer}} <br/> {{item.registKey}}
								                </div>
								              </td>
								              <td class="t-left pr10">{{item.productor}}</td>
								              <td class="t-left pr10">{{item.chineseName}}</td>
								              <td class="t-left pr10">{{item.price}}元/{{item.unitstyle}}</td>
								            </tr>     
								          </tbody>
								        </table>
		                        </li>
		                        <li class="div-select-item pl10 pr10" v-show="goodsList.length==0 || goodsList == undefined">
		                            <span style="width:100%;">未查询到结果!</span>
		                        </li>
		                      </ul> 
		                    </div>
		                  </div>
		                </div>
		              </td>
		              <td></td>
		              <td></td>
		              <td></td>
		              <td></td>
		              <td></td>
		              <td></td>
		            </tr>
		          </tbody>
		        </table>


		<div class="modal " :class="showDialog=='Y'?'':'hide'">
                <div class="container resource">
                    <div class="audit-detail" style="width:540px;margin: 200px auto;">
                        <span class="close-win" v-on:click="closeDialog()"></span>

                        <div class="sdiv-9-9b">
                            <a class="btn-d btn-d-activate btn-d-lg" href="javascript:;" style='border-radius:8px;'>导入信息提示</a>
                        </div>

                        <div class="status-process wbe-0 clearfix pd20" style="padding-top:0px;">
                            <div class="sp-head sp-headb" v-for="m in mList" track-by="$index">
									<span class="sp-col w300">
				                    	<span class="control radio-control ">
				                      		<span>{{m}}</span>
										</span>
									</span>
                            </div>

                        </div>
                        <div class="sdiv9-9" style='padding: 20px;padding-bottom: 0px;'>
                            <button v-on:click="closeDialog()" class="btn button-red mar-none">关闭</button>
                        </div>
                    </div>
                </div>
            </div>
		<!--order-orderlist-view end-->

		 <!--新加提示信息 end-->
      <div class="roll-bg" v-if='requestS'>
        <div class="w60" style="margin:0 auto;">
          <img src="/images/roll.gif">
        </div>
        <div class="container resource t-center text-color-red">
          正在处理中,请勿关闭!
        </div>
      </div>

		

	</div>
</template>
<script>
	module.exports = {
		data: function() {
			return {
				medname:'',
				departmentsSearch: {
		          parameter_category: '',
		          parameter_medguid: '',
		        },
		        trmedplan:{},
		        storeList:[],
		        departmentsList:[],
		        goodsList:[],
		        TrmList:[],
		        state:false,
		        parmas:{
					trmedstatement:{},
					trmedstatementdetails:[]
				},
				priceS:0,
				supplierS:[],
				supplierNum:0,
				collectionCheck:false,
				collectionName:'',
				fifthStep:true, 
				requestS:false,
				billGuid:'',
				billtypeList:[],
				fileType: 'file',
                tagType: 'a',
                med: 'importTrmedPlanGoods',
                fileLabel: '文件导入',

				zdyfdate:'',
				dzbegindate:'',
				dzenddate:'',
				memo:'',
				trmedstatementdetails:[],
				showDialog:'N',
				state:1,
				list: {},
				billstate: '',
				search: {
					pageSize: 50,
					page: 1,
					totalPages: 0,
				},
				supList:[]
				
			};
		},
		methods: {
			// 检索的商品 选中
			goodsData:function(item){
				var self = this;
				var state=false;

		    	if(self.TrmList==0){
		    		self.TrmList.push(item);
		    	}else{
		    		for(var a=0;a<self.TrmList.length;a++){
			    		if(self.TrmList[a].guid==item.guid && self.TrmList[a].supplierGuid==item.supplierGuid){
			    			layer.msg('该商品已存在');
			    			state=true;
			    		}
			    	}
			    	if(!state){
			    		self.TrmList.push(item);
			    	}
		    	}
		    	self.supplierS.push(item.supplierGuid);
		   		self.unique(self.supplierS);
		    	self.$set('state',false)
				self.$set('medname','');
				self.$set('goodsList',[]);
				
			},
			// 删除商品 
			deleteitemList:function(index){
				var self = this;
				self.TrmList.splice(index,1);
			},
			getData: function() {
				var self = this;

				Ajax.post('/hospitalTrmedplan/listMfmedgoods2', {
						'goodsname': self.medname,departguid:self.trmedplan.meddeptguid,storeguid:self.trmedplan.medstoreguid
					})
					.then(function(response) {
						var data = response.data.data;
						if(response.data.errorCode == 0) {
							self.$set('goodsList',data);
						} else {
							layer.msg(response.data.message);
						}
					});
			},
			 checkInfo: function (poqty, index, code) {
		        var self = this;
		        if (poqty <= 0) {
		          self.MessageBox({
		            title: '警告',
		            message: "请输入大于0的正整数!",
		            type: 'alert'
		          }, function (action) {
		            if (action == 'confirm') {
		              if (code == 1) {
		                self.$set('mfmedgoodsTempList[' + index + '].poqty', '');
		              } else {
		                self.$set('trmedplandetailList[' + index + '].poqty', '');
		              }
		            }
		          });
		        }
		        var type = /^\d{1,8}$/;
		        var reg = new RegExp(type);
		        if (poqty.match(reg) == null) {
		          self.MessageBox({
		            title: '警告',
		            message: "请输入长度小于8的正整数!",
		            type: 'alert'
		          }, function (action) {
		            if (action == 'confirm') {
		              if (code == 1) {
		                self.$set('mfmedgoodsTempList[' + index + '].poqty', '');
		              } else {
		                self.$set('trmedplandetailList[' + index + '].poqty', '');
		              }
		            }
		          });
		        }
		      },
			// 科室下拉表
		      getDepartments: function () {
		        var self = this;
		        self.departmentsSearch.parameter_category = '2';
		        Ajax.get('/util/departmentsInfo', self.departmentsSearch)
		          .then(function (response) {
		            var data = response.data.data;
		            self.$set("departmentsList", data);
		          })
		      },
		      // 库房下拉表
		      getStore: function () {
		        var self = this;
		        self.departmentsSearch.parameter_category = '1';
		        Ajax.get('/util/departmentsInfo', self.departmentsSearch)
		          .then(function (response) {
		            var data = response.data.data;
		            self.$set("storeList", data);
		          })
		      },
		      // 单据类型
		      getBilltype: function () {
		        var self = this;

		        Ajax.get('/hospitalTrmedplan/getCategory')
		          .then(function (response) {
		            var data = response.data.data;
		            if (response.data.errorCode == 0) {
		              if (data == '01') {
		                self.$set('billtypeList', [{
		                  "label": "普耗",
		                  "value": "01"
		                }, {
		                  "label": "跟台高值",
		                  "value": "02"
		                }, {
		                  "label": "备货高值",
		                  "value": "03"
		                }]);
		              } else if (data == '02') {
		                self.$set('billtypeList', [{
		                  "label": "药品",
		                  "value": "04"
		                }]);
		              } else if (data == '03') {
		                self.$set('billtypeList', [{
		                  "label": "后勤物资",
		                  "value": "05"
		                }]);
		              } else if (data == '04') {
		                self.$set('billtypeList', [{
		                  "label": "消毒用品",
		                  "value": "06"
		                }]);
		              } else if (data == '05') {
		                self.$set('billtypeList', [{
		                  "label": "洗涤用品",
		                  "value": "07"
		                }]);
		              } else if (data == '06') {
		                self.$set('billtypeList', [{
		                  "label": "中药材",
		                  "value": "08"
		                }]);
		              } else if (data == '07') {
		                self.$set('billtypeList', [{
		                  "label": "设施设备",
		                  "value": "09"
		                }]);
		              } else {
		                self.$set('billtypeList', self.ctns.billtype);
		              }
		            } else {
		            	 layer.msg(response.data.message);
		            }

		          })


		      },
            // 清空
            empty:function(){
            	if(this.trmedstatementdetails.length==0){
            		layer.msg('没有需要清空的数据!');
            		return;
            	}else{

            		this.$set('trmedstatementdetails', []);
            		layer.msg('清空成功!');
            	}
            	
            },
            // 提交保存校验
            verfiy:function(){
            	var self = this;
            	if (self.trmedplan.billtype == null || self.trmedplan.billtype == undefined || self.trmedplan.billtype ==
		          '') {
		          	layer.msg('请选择单据类型!');
		          return;
		        }
		        if (self.trmedplan.planenddate == null || self.trmedplan.planenddate == undefined || self.trmedplan.planenddate ==
		          '') {
		          	layer.msg('要求到货日期格式不正确或是空!');
		          return;
		        }
		        if (self.collectionCheck) {
		          if (!self.collectionName) {
		          		layer.msg('您需要为您的收藏夹取个名字!');
		          		return;
		          } 
		        } 
            },
             saveTrmedplan: function (code) {
		        var self = this;
		        var obj={};
		        if(self.TrmList.length==0){
		        	layer.msg('请选择商品!');
		        	return;
		        }
		        for(var a=0;a<self.TrmList.length;a++){
		        	if(!self.TrmList[a].poqty){
		        		layer.msg('请输入订货数');
		        		return;
		        	}
		        	self.TrmList[a].taxprice=self.TrmList[a].price;
		        	self.TrmList[a].goodsguid=self.TrmList[a].guid;
		        }

		        for(var a=0;a<self.TrmList.length;a++){
		        	for(var i=0;i<self.TrmList[a].maps.length;i++){
		        		if(self.TrmList[a].maps[i].supplierguid==self.TrmList[a].supplierGuid){
		        			self.TrmList[a].supplierName=self.TrmList[a].maps[i].chinesename;
		        			self.TrmList[a].supplierGuid=self.TrmList[a].maps[i].supplierguid;
		        			self.TrmList[a].staffGuid=self.TrmList[a].maps[i].staffguid;
		        			self.TrmList[a].staffName=self.TrmList[a].maps[i].staffname;
		        			break;
		        		}
		        	}

		        }

		        self.$set('requestS',true);
		        // self.verfiy();
		        
		        obj.collectionCheck=self.collectionCheck;
		        obj.collectionName=self.collectionName;  
		        obj.trmedplan=self.trmedplan;
		        obj.createConditionList=self.TrmList;
		        obj.guid=self.billGuid;
	


		        Ajax.post('/hospitalTrmedplan/newCreateTrmedplan', obj)
		          .then(function (response) {
		            var data = response.data;
		            if (data.errorCode == 0) {
		            	layer.msg('保存成功!');
		         
		                self.billGuid=data.data.guid;
		            } else {
		         		layer.msg(data.message);

		            }
		            self.$set('requestS',false);
		          })
		      },
		      deletePlan: function () {
		        var self = this;
		        var billno = self.billno;
		        Ajax.post('/hospitalTrmedplan/deletePlan', {
		            'billno': billno
		          })
		          .then(function (response) {
		            var data = response.data;
		            if (data.errorCode == 0) {
		              self.MessageBox({
		                title: '提示',
		                message: '删除成功!',
		                type: 'alert'
		              }, function (action) {
		                window.location.reload();
		              });
		            } else {
		            	layer.msg(data.message);
		              return true;
		            }
		          })
		      },
		      // 提交采购计划
		      submitTrmedExternalplan: function () {
		        var self = this;
		        var obj={};


		        if(self.TrmList.length==0){
		        	layer.msg('请选择商品!');
		        	return;
		        }
		        for(var a=0;a<self.TrmList.length;a++){
		        	if(!self.TrmList[a].poqty){
		        		layer.msg('请输入订货数');
		        		return;
		        	}
		        	self.TrmList[a].taxprice=self.TrmList[a].price;
		        	self.TrmList[a].goodsguid=self.TrmList[a].guid;
		        }

		        for(var a=0;a<self.TrmList.length;a++){
		        	for(var i=0;i<self.TrmList[a].maps.length;i++){
		        		if(self.TrmList[a].maps[i].supplierguid==self.TrmList[a].supplierGuid){
		        			self.TrmList[a].supplierName=self.TrmList[a].maps[i].chinesename;
		        			self.TrmList[a].supplierGuid=self.TrmList[a].maps[i].supplierguid;
		        			self.TrmList[a].staffGuid=self.TrmList[a].maps[i].staffguid;
		        			self.TrmList[a].staffName=self.TrmList[a].maps[i].staffname;
		        			break;
		        		}
		        	}

		        }

		        self.$set('requestS',true);
		        // self.verfiy();
		        obj.guid=self.billGuid;
		        obj.collectionCheck=self.collectionCheck;
		        obj.collectionName=self.collectionName;  
		        obj.trmedplan=self.trmedplan;
		        obj.createConditionList=self.TrmList;


		        Ajax.post('/hospitalTrmedplan/newUpdTrmedplan', obj)
		          .then(function (response) {
		            var data = response.data.data;
		            if (response.data.errorCode == 0) {
		            		layer.msg('提交成功!');			            	
		            		self.$set('trmedplan',{});
		            		self.init();
			        		self.trmedplan.planbegindate=self.GetDate().enddate;
			        		localStorage.setItem('TrmedplanArr',JSON.stringify(data));

			        		self.$router.go({ 'path': '/addedPurchaseSub' });

		            } else {
		            	layer.msg(response.data.message);	
		            }
		            self.$set('requestS',false);
		          })
		      },
            unique:function (arr) {
            	var self = this;
			 	var result=[];
				  for(var i=0; i<arr.length; i++){
				    if(result.indexOf(arr[i])==-1){
				      result.push(arr[i])
				    }
				  }
				  self.$set('supplierNum',result.length);
			},
			init:function(){
				var self = this;
				self.$set('collectionCheck',false);
   				self.$set('collectionName','');  
        		self.$set('TrmList',[]);
        		self.$set('trmedplan',{});
        		self.$set('supplierS',[]);
        		self.$set('supplierNum',0);
        		self.$set('billGuid','');
        		this.$set('trmedplan.planbegindate',this.GetDate().enddate);
			},
			abandon:function(){
				var self = this;
				if(!self.billGuid){
					self.init();
					layer.msg('废弃成功!');
				}

				 Ajax.post('/hospitalTrmedplan/newDeleteTrmedplan', {
		            'guid': self.billGuid
		          })
		          .then(function (response) {
		            var data = response.data;
		            if (data.errorCode == 0) {
		              self.MessageBox({
		                title: '提示',
		                message: '废弃成功!',
		                type: 'alert'
		              }, function (action) {
		                self.init();
		              });
		            } else {
		            	layer.msg(data.messsage);
		            }
		          })
				
			},
			getList:function(){
				var self = this;
				 Ajax.post('/hospitalTrmedplan/getCollectionmedPlanGoods', {guid:self.guid})
		          .then(function (response) {
		            	var data = response.data.data;
			           if(response.data.errorCode==0){
			           		// self.$set('trmedplan',data.trcollectionmedplan);
			           		
			           		self.$set('trmedplan.address',data.trcollectionmedplan.address);
			           		self.$set('trmedplan.meddeptguid',data.trcollectionmedplan.meddeptguid);
			           		self.$set('trmedplan.medstoreguid',data.trcollectionmedplan.medstoreguid);
			           		self.$set('trmedplan.memo',data.trcollectionmedplan.memo);
			           		self.$set('trmedplan.billtype',data.trcollectionmedplan.billtype);

			           		self.$set('TrmList',data.mfmedgoodsVOs);

			           }else{
			           		layer.msg(response.data.messsage);
			           }
		          })
				
			},
			back:function(){
				this.init();
				window.history.go(-1);
			},
			checkData:function (arr){
				var arr=JSON.parse( JSON.stringify(arr));
		       var match={},i=0,item,key,tempArr={},newArr=[],a={},b={};
        // console.log(arr)
		        for(;i<arr.length;i++){
		            key='';
		            item=arr[i];
		            key=item["supplierGuid"];
		           if(match[key]===true){//存在
		                a.price = item.price||0;//取价格
		                a.poqty = item.poqty||0;//取数量
		                //价格
		                if(tempArr[key]['price']){
		                    tempArr[key]['price']+= a.price *a.poqty
		                    console.log(a.price *a.poqty);
		                }else{
		                    tempArr[key]['price'] = a.price*a.poqty
		                    console.log(a.price *a.poqty);
		                }
		                //数量
		                if(tempArr[key]['poqty']){
		                    tempArr[key]['poqty']+= 0;
		                }else{
		                    tempArr[key]['poqty'] = 0;
		                }
		                 tempArr[key]['num']++;
		               
		           }else{//不存在
		           		item.num=1;
		                match[key]=true; 
		                tempArr[key]=item;
		                tempArr[key].price=item.price*item.poqty;
		                console.log(item.price*item.poqty);
		           }
		        }
		        for(var k in tempArr){
		            // if(tempArr[k]!==false){
		                newArr.push(tempArr[k])
		            // }
		        }
		        return newArr;
		    }

		},
		route: {
			activate: function() {
				var self = this;
				this.guid=this.$route.params.guid;
				this.init();
				this.$set('trmedplan.planbegindate',this.GetDate().enddate);
				this.getDepartments();
				this.getStore();
				this.getBilltype();
				setTimeout(function(){
					self.getList();
				},1000)
			},
		},
		watch:{
			'medname':function(){

					this.getData();
			},
			'TrmList':{
				handler(curVal,oldVal){
            var self = this;
					  var list=self.TrmList;
					  var newTrmList=[];

						self.$set('priceS',0);
						for(var a=0;a<list.length;a++){
							if(list[a].poqty * list[a].price){
								self.priceS=list[a].poqty * list[a].price+self.priceS;
								self.supplierS.push(list[a].supplierGuid);

							}
						}	
						 newTrmList=self.checkData(list);
						
				  		self.$set('supList',newTrmList);

          },
          deep:true
				 
				
			},
			// 'trmedplan.meddeptguid':function(){
			// 	this.init();
			// }
		}
	};
</script>