create.blade.php 85 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679
  1. @extends('layouts.app')
  2. @section('title')项目编辑-项目管理@endsection
  3. @section("head")<link href="{{ mix('css/animation.css') }}" rel="stylesheet">@endsection
  4. @section('content')
  5. @component('customer.project.menu')
  6. @if($owner)
  7. <li class="nav-item">
  8. <a class="nav-link" href="{{URL::current()}}" :class="{active:isActive('edit',4)}">编辑</a>
  9. </li>
  10. @endif
  11. @endcomponent
  12. <div class="container-fluid card d-none" id="container">
  13. <div class="card-body offset-1">
  14. <div class="row">
  15. <div class="col-2 form-inline cursor-pointer text-dark" @click="switchBase('one')">
  16. <div class="h-100 w-25">
  17. <div class="h1 fillet text-center" :class="[base == 'one' ? 'sign' : '', (base!=='one' && !owner.name) ? 'bg-secondary border-secondary' : 'bg-info']">
  18. <span class="fa fa-edit ml-1 text-white"></span>
  19. </div>
  20. </div>
  21. <div class="h-100 w-75">
  22. <span class="font-weight-bold ml-1">基础信息</span><br>
  23. <span class="small ml-1">名称:@{{ owner.name }}</span><br>
  24. <span class="small ml-1">代码:@{{ owner.code }}</span><br>
  25. </div>
  26. </div>
  27. <div class="col-2">
  28. <hr class="w-100 mt-4 hr-info">
  29. </div>
  30. <div class="col-2 form-inline cursor-pointer text-dark" @click="switchBase('two')">
  31. <div class="h-100 w-25">
  32. <div class="h1 fillet text-center" :class="[base == 'two' ? 'sign' : '', (base!=='two' && !owner.customer_id) ? 'bg-secondary border-secondary' : 'bg-info']">
  33. <span class="fa fa-book ml-1 text-white"></span>
  34. </div>
  35. </div>
  36. <div class="h-100 w-75">
  37. <span class="font-weight-bold ml-1">详细描述</span><br>
  38. <span class="small ml-1">客户:@{{ owner.customer_name }}</span><br>
  39. <span class="small ml-1">小组:@{{ owner.owner_group_name }}</span><br>
  40. </div>
  41. </div>
  42. <div class="col-2">
  43. <hr class="w-100 mt-4 hr-info">
  44. </div>
  45. <div class="col-2 form-inline cursor-pointer text-dark" @click="switchBase('three')">
  46. <div class="h-100 w-25">
  47. <div class="h1 fillet text-center" :class="[base == 'three' ? 'sign' : '', (base!=='three' && !isExist) ? 'bg-secondary border-secondary' : 'bg-info']">
  48. <span class="fa fa-rmb ml-1 text-white "></span>
  49. </div>
  50. </div>
  51. <div class="h-100 w-75">
  52. <div class="font-weight-bold ml-1 h-100 mt-3">计费模型</div>
  53. </div>
  54. </div>
  55. </div>
  56. <div v-if="base == 'one'">
  57. @include("customer.project.part._one")
  58. </div>
  59. <div v-if="base == 'two'">
  60. @include("customer.project.part._two")
  61. </div>
  62. <div v-if="base == 'three'">
  63. <div v-show="isLoad">@include("customer.project.part._three")</div>
  64. <div class="row justify-content-center text-secondary" style="min-height: 200px;margin-left: -25%" v-show="!isLoad">
  65. <div class="align-self-center h1">
  66. <i class="fa fa-spinner fa-pulse"></i>
  67. </div>
  68. </div>
  69. </div>
  70. <hr class="mt-2">
  71. <div class="row mt-3" v-if="base != 'three' || isLoad">
  72. <div class="pull-right offset-7">
  73. <button type="button" class="btn btn-info ml-1 text-white" v-show="base !== 'one'" @click="back()">上一步</button>
  74. <button type="button" class="btn btn-info ml-1 text-white" v-show="base !== 'three'" @click="next()">下一步</button>
  75. <button type="button" class="btn btn-success ml-1" @click="success()">完成</button>
  76. <button type="button" class="btn btn-secondary ml-1" @click="reset()" v-show="base !== 'three'">重置</button>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. @stop
  82. @section('lastScript')
  83. <script>
  84. new Vue({
  85. el:"#container",
  86. data:{
  87. base:"one",
  88. owner : {
  89. id:"{{$owner->id ?? ''}}",
  90. name : "{{$owner->name ?? ''}}",
  91. code : "{{$owner->code ?? ''}}",
  92. customer_id : "{{$owner->customer_id ?? ''}}",
  93. customer_name : "{{ isset($owner) ? ($owner->customer ? $owner->customer->name : '') : ''}}",
  94. owner_group_name : "{{ isset($owner) ? ($owner->userOwnerGroup ? $owner->userOwnerGroup->name : '') : ''}}",
  95. owner_group_id : "{{$owner->user_owner_group_id ?? ''}}",
  96. user_workgroup_id : "{{$owner->user_workgroup_id ?? ''}}",
  97. warehouse_id : "{{ $owner->warehouse_id ?? ''}}",
  98. tax_rate_id : "{{$owner->tax_rate_id ?? ''}}",
  99. linkman : "{{$owner->linkman ?? ''}}",
  100. phone_number : "{{$owner->phone_number ?? ''}}",
  101. description : "{{$owner->description ?? ''}}",
  102. waring_line_on : "{{$owner->waring_line_on ?? ''}}",
  103. subjection : "{{$owner->subjection ?? ''}}",
  104. },
  105. ownerTemp : {},
  106. customers : [
  107. @foreach($customers as $customer)
  108. {id:"{{$customer->id}}",name:"{{$customer->name}}"},
  109. @endforeach
  110. ],
  111. ownerGroups : [
  112. @foreach($ownerGroups as $ownerGroup)
  113. {id:"{{$ownerGroup->id}}",name:"{{$ownerGroup->name}}"},
  114. @endforeach
  115. ],
  116. userGroups : [
  117. @foreach($userGroups as $userGroup)
  118. {id:"{{$userGroup->id}}",name:"{{$userGroup->name}}",warehouse_id:"{{$userGroup->warehouse_id}}"},
  119. @endforeach
  120. ],
  121. warehouses:[
  122. @foreach($warehouses as $warehouse)
  123. {id:"{{$warehouse->id}}",name:"{{$warehouse->name}}"},
  124. @endforeach
  125. ],
  126. style : '',
  127. errors : {!! $errors !!}, //全部的错误提示
  128. upList:{ //控制元素的渐入展开与收起
  129. storage : false,
  130. },
  131. type:"storage",//当前编辑类型 仓储,作业,物流...
  132. currentInputting:{
  133. edittingOperation:null,
  134. },
  135. model:{ //编辑元素绑定值
  136. storage:{
  137. counting_type : "",
  138. using_type : "",
  139. minimum_area : "",
  140. price : "",
  141. discount_type : "无减免",
  142. discount_value : "",
  143. unit_id : "",
  144. time_unit_id : "",
  145. },
  146. operation:{},
  147. express:{
  148. name:"",
  149. initial_weight:"",
  150. additional_weight:"",
  151. items:[],
  152. logistics:[],
  153. },
  154. logistic:{
  155. items:[],
  156. other_ranges:[],
  157. ranges:[],
  158. logistics:[],
  159. },
  160. directLogistic:{
  161. items:[],
  162. },
  163. },
  164. pool:{//基础数据选择池,以方便异步懒加载而非即时加载 例:units,owners等
  165. counting_type:[
  166. "包仓","灵活用仓","统单价"
  167. ],
  168. using_type:[
  169. "常温","恒温"
  170. ],
  171. discount_type:[
  172. "无减免","按单减免","固定减免"
  173. ],
  174. feature_type:{!! json_encode(\App\Feature::type,JSON_UNESCAPED_UNICODE) !!},
  175. logic : ['包含','不包含','等于'],
  176. ownerSubjections:{!! json_encode(\App\Owner::subjection,JSON_UNESCAPED_UNICODE) !!},
  177. },
  178. poolMapping:{},//基础数据选择池的映射对象 供展示使用
  179. selectedModel:{//已选定的计费模型
  180. storage:[],
  181. operation:[],
  182. express:[],
  183. logistic:[],
  184. directLogistic:{},
  185. },
  186. thisOperationItemIndex:-1,//当前选中的作业费子项下标,用以唤起特征模态框
  187. operationItems:{},//控制作业费子项的渐入展开
  188. importError:[],//导入时的错误数据原因
  189. isShowError:false,//是否展开导入错误信息
  190. isExist:Boolean("{{$isExist ?? false}}"),
  191. isLoad:false,//全局加载标记,符合条件时确保仅加载一次
  192. introduce:{},//引入model
  193. isSearch:false,//是否查询,用于加载动画显示
  194. searchResult:[],//查询结果
  195. searchResultMapping:{},//查询结果映射
  196. selectedResult:"",
  197. searchItem:{},//搜索子项集
  198. searchBase:5,//搜索基数
  199. hover:{},//可悬浮列表
  200. audit:{},
  201. filterCustomers:[],
  202. filterOwnerGroups:[],
  203. filterUserGroups:[],
  204. },
  205. created(){
  206. this.filterCustomers = JSON.parse(JSON.stringify(this.customers));
  207. this.filterOwnerGroups = JSON.parse(JSON.stringify(this.ownerGroups));
  208. this.filterUserGroups = JSON.parse(JSON.stringify(this.userGroups));
  209. },
  210. mounted(){
  211. let type = "{{$type ?? ''}}";
  212. if (type){
  213. this.base = "three";
  214. this.type = "";
  215. setTimeout(()=>{
  216. this.switchType(type);
  217. if (!this.isLoad && this.ownerTemp.id)this._loadPriceModel();//计费模型未被加载且项目ID存在时
  218. if (!this.isLoad && !this.ownerTemp.id) this.isLoad = true;
  219. },0);
  220. }
  221. this._resetOperation();
  222. this.ownerTemp = JSON.parse(JSON.stringify(this.owner));
  223. $('[data-toggle="tooltip"]').tooltip();
  224. $("#container").removeClass("d-none");
  225. },
  226. methods:{
  227. //重置作业计费数据
  228. _resetOperation(){
  229. this.model.operation = {
  230. operation_type:"入库",
  231. strategy:"默认",
  232. discount_count:[''],
  233. name:"",
  234. feature:"",
  235. total_discount_price:[''],
  236. items : [
  237. {strategy:"起步",type:"0",discount_price:['']},
  238. {strategy:"默认",discount_price:['']},
  239. {strategy:"特征",discount_price:['']},
  240. ],
  241. };
  242. },
  243. //悬浮效果
  244. hoverEffect(key,val){
  245. this.$set(this.hover,key,val);
  246. },
  247. //收起展开
  248. show(id){
  249. if (this.upList[id])$("#"+id).slideDown();
  250. else $("#"+id).slideUp();
  251. this.upList[id] = !this.upList[id];
  252. this.$forceUpdate();
  253. },
  254. //清除垃圾数据
  255. _clearRefuse(){
  256. this.errors = {};
  257. this.importError = [];
  258. this.selectedResult = "";
  259. this.searchResult = [];
  260. this.searchResultMapping = {};
  261. this.introduce = {};
  262. },
  263. //切换选项
  264. switchBase(base){
  265. if (!this.owner.id)return;
  266. if (base === this.base)return;
  267. if (base === 'three') this._loadStorage();
  268. if (base === 'two')this._getTaxRates()
  269. this.base = base;
  270. },
  271. //切换类型
  272. switchType(type){
  273. if (type === this.type)return;//相同终止是为了减少重复加载动作
  274. this._clearRefuse();//清除垃圾数据
  275. let parent = $("#parent");
  276. let dom = "";
  277. switch (type) {
  278. case "storage":
  279. this._loadStorage();
  280. dom = $("#storage-card");
  281. break;
  282. case "operation":
  283. this._loadOperation();
  284. dom = $("#operation-card");
  285. break;
  286. case "express":
  287. this._loadExpress();
  288. dom = $("#express-card");
  289. break;
  290. case "logistic":
  291. this._loadLogistic();
  292. dom = $("#logistic-card");
  293. break;
  294. case "directLogistic":
  295. this._loadDirectLogistic();
  296. dom = $("#directLogistic-card");
  297. break;
  298. }
  299. dom.addClass("animation-translation");
  300. dom.fadeOut(500);
  301. setTimeout(function(){
  302. dom.removeClass("animation-translation");
  303. parent.prepend(dom);
  304. dom.fadeIn();
  305. },400);
  306. this.type = type;
  307. },
  308. //下一步
  309. next(){
  310. switch (this.base) {
  311. case "one":
  312. this._verifyOne(()=>{
  313. this.base = "two";
  314. });
  315. break;
  316. case "two":
  317. if (this._verifyTwo())this.base = "three";
  318. this._loadStorage();
  319. break;
  320. }
  321. },
  322. //完成
  323. success(){
  324. switch (this.base) {
  325. case "one":
  326. this._verifyOne(()=>{
  327. window.location.href = "{{url('customer/project/index')}}";
  328. });
  329. break;
  330. case "two":
  331. if (this._verifyTwo())window.location.href = "{{url('customer/project/index')}}";
  332. break;
  333. default:
  334. window.tempTip.confirm("<span class='text-danger'>确定后计费模型未保存项将被抛弃,您确认仍要完成吗?</span>",()=>{
  335. window.location.href = "{{url('customer/project/index')}}";
  336. });
  337. break;
  338. }
  339. },
  340. //重置
  341. reset(){
  342. switch (this.base) {
  343. case "one":
  344. this.owner = this.ownerTemp;
  345. break;
  346. case "two":
  347. this.owner = this.ownerTemp;
  348. break;
  349. }
  350. },
  351. //验证基础信息
  352. _verifyOne(func){
  353. if (!this.owner.code){
  354. this.$set(this.errors,"code",["项目代码为必填项"]);
  355. return false;
  356. }
  357. if (!this.owner.name){
  358. this.$set(this.errors,"name",["项目名称为必填项"]);
  359. return false;
  360. }
  361. if (this.owner.name !== this.ownerTemp.name || this.owner.code !== this.ownerTemp.code){
  362. let url = "{{url('maintenance/owner/apiStore')}}";
  363. let params = {name:this.owner.name,code:this.owner.code,id:this.owner.id};
  364. window.tempTip.postBasicRequest(url,params,res=>{
  365. if (res.errors){
  366. this.errors = res.errors;
  367. return;
  368. }
  369. this.errors = {};
  370. this.owner.id = res.id;
  371. this.ownerTemp.id = res.id;
  372. this.ownerTemp.name = res.name;
  373. this.ownerTemp.code = res.code;
  374. func();
  375. });
  376. }else func();
  377. },
  378. //验证详细描述
  379. _verifyTwo(){
  380. let error = {};
  381. if (!this.owner.customer_id) error["customer_id"] = ["必须选择客户"];
  382. if (!this.owner.owner_group_id) error["owner_group_id"] = ["必须选择项目小组"];
  383. if (!this.owner.warehouse_id) error["warehouse_id"] = ["必须选择仓库"];
  384. if (!this.owner.user_workgroup_id) error["user_workgroup_id"] = ["必须选择仓库小组"];
  385. if (!this.owner.tax_rate_id) error["tax_rate_id"] = ["必须选择税率"];
  386. if (JSON.stringify(error) !== "{}"){
  387. this.errors = error;
  388. return;
  389. }
  390. let url = "{{url('customer/project/projectUpdate')}}";
  391. let params = this.owner;
  392. let old = this.ownerTemp;
  393. if (params.customer_id !== old.customer_id ||
  394. params.owner_group_id !== old.owner_group_id ||
  395. params.user_workgroup_id !== old.user_workgroup_id ||
  396. params.warehouse_id !== old.warehouse_id ||
  397. params.tax_rate_id !== old.tax_rate_id ||
  398. params.waring_line_on !== old.waring_line_on ||
  399. params.phone_number !== old.phone_number ||
  400. params.subjection !== old.subjection ||
  401. params.description !== old.description){
  402. let result = undefined;
  403. window.tempTip.postBasicRequest(url,params,res=>{
  404. if (res.errors){
  405. this.errors = res.errors;
  406. result = false;
  407. return;
  408. }
  409. this.errors = [];
  410. this.ownerTemp.customer_id = res.customer_id;
  411. this.ownerTemp.owner_group_id = res.owner_group_id;
  412. this.ownerTemp.user_workgroup_id = res.user_workgroup_id;
  413. this.ownerTemp.warehouse_id = res.warehouse_id;
  414. this.ownerTemp.tax_rate_id = res.tax_rate_id;
  415. this.ownerTemp.waring_line_on = res.waring_line_on;
  416. this.ownerTemp.phone_number = res.phone_number;
  417. this.ownerTemp.description = res.description;
  418. this.ownerTemp.customer_name = params.customer_name;
  419. this.ownerTemp.owner_group_name = params.owner_group_name;
  420. this.ownerTemp.subjection = params.subjection;
  421. result = true;
  422. });
  423. while (result){
  424. if (typeof result !== "undefined")return result;
  425. }
  426. }
  427. return true;
  428. },
  429. //上一步
  430. back(){
  431. switch (this.base) {
  432. case "two":
  433. this.base = 'one';
  434. break;
  435. case "three":
  436. this.base = 'two';
  437. break;
  438. }
  439. },
  440. //重载作业费
  441. _overrideOperation(operation){
  442. if (operation.discount_count){
  443. if (operation.discount_count) operation.discount_count = operation.discount_count.split(",");
  444. if (operation.total_discount_price) operation.total_discount_price = operation.total_discount_price.split(",");
  445. operation.isDiscount = true;
  446. }
  447. operation.items.forEach((item,j)=>{
  448. if (item.discount_price) operation.items[j].discount_price = item.discount_price.split(",");
  449. });
  450. if (operation.total_price)operation.isSingle = true;
  451. return operation;
  452. },
  453. //重载快递费
  454. _overrideExpress(express){
  455. express.logistics.forEach((logistic,j)=>{
  456. express.logistics[j] = logistic.id;
  457. });
  458. return JSON.parse(JSON.stringify(express).replace(/details/g,"items"));
  459. },
  460. //重载物流费
  461. _overrideLogistic(logistic){
  462. logistic.logistics.forEach((l,j)=>{
  463. logistic.logistics[j] = l.id;
  464. });
  465. return JSON.parse(JSON.stringify(logistic).replace(/details/g,"items"));
  466. },
  467. //重载直发费
  468. _overrideDirectLogistic(directLogistic){
  469. return JSON.parse(JSON.stringify(directLogistic).replace(/details/g,"items"));
  470. },
  471. //加载计费模型
  472. _loadPriceModel(){
  473. let url = "{{url('customer/project/getPriceModel')}}";
  474. let params = {id:this.ownerTemp.id};
  475. window.tempTip.postBasicRequest(url,params,res=>{
  476. let audit = {};
  477. if (res.storage_audit_count)audit.storage = true;
  478. if (res.operation_audit_count)audit.operation = true;
  479. if (res.express_audit_count)audit.express = true;
  480. if (res.logistic_audit_count)audit.logistic = true;
  481. if (res.direct_logistic_audit_count)audit.directLogistic = true;
  482. this.audit = audit;
  483. if (res.owner_storage_price_models.length>0)this.selectedModel.storage = res.owner_storage_price_models;
  484. if (res.owner_price_operations.length>0){
  485. this._loadOperation();
  486. res.owner_price_operations.forEach((operation,i)=>{res.owner_price_operations[i] = this._overrideOperation(operation);});
  487. this.selectedModel.operation = res.owner_price_operations;
  488. }
  489. if (res.owner_price_expresses.length>0){
  490. this._loadExpress();
  491. res.owner_price_expresses.forEach((express,i)=>{
  492. res.owner_price_expresses[i] = this._overrideExpress(express);
  493. this.upList['express-item-'+i] = true;
  494. });
  495. this.selectedModel.express = res.owner_price_expresses;
  496. }
  497. if (res.owner_price_logistics.length>0){
  498. if (res.owner_price_expresses.length===0)this._loadLogistic();
  499. else {this._getUnits();this._getCities();}
  500. res.owner_price_logistics.forEach((logistic,i)=>{
  501. res.owner_price_logistics[i] = this._overrideLogistic(logistic);
  502. this.upList['logistic-item-'+i] = true;
  503. });
  504. this.selectedModel.logistic = res.owner_price_logistics;
  505. }
  506. if (res.owner_price_direct_logistics.length>0){
  507. this._loadDirectLogistic();
  508. this.upList["directLogistic-item"] = true;
  509. this.selectedModel.directLogistic = this._overrideDirectLogistic(res.owner_price_direct_logistics[0]);
  510. }
  511. setTimeout(()=> {
  512. $(".up").slideUp();
  513. this.isLoad = true;
  514. },0)
  515. });
  516. },
  517. //加载仓储所需基础信息
  518. _loadStorage(){
  519. if (!this.pool.units)this._getUnits();
  520. if (!this.isLoad && this.ownerTemp.id)this._loadPriceModel();//计费模型未被加载且项目ID存在时
  521. if (!this.isLoad && !this.ownerTemp.id) this.isLoad = true;
  522. },
  523. //加载作业
  524. _loadOperation(){
  525. if (!this.pool.units)this._getUnits();
  526. },
  527. //加载快递
  528. _loadExpress(){
  529. if (!this.pool.provinces)this._getProvinces();
  530. if (!this.pool.logistics)this._getLogistics();
  531. },
  532. //加载物流
  533. _loadLogistic(){
  534. if (!this.pool.units) this._getUnits();
  535. if (!this.pool.provinces)this._getProvinces();
  536. if (!this.pool.cities)this._getCities();
  537. if (!this.pool.logistics)this._getLogistics();
  538. },
  539. //加载直发车
  540. _loadDirectLogistic(){
  541. if (!this.pool.cars)this._getCars();
  542. },
  543. //加载引入
  544. loadIntroduce(){
  545. if (!this.pool.owners)this._getOwners();
  546. if (!this.pool.logistics)this._getLogistics();
  547. },
  548. _setModelData(key,val){
  549. if (!val)return;
  550. let mapping = [];
  551. val.forEach(item=>{
  552. mapping[item.id] = item.name;
  553. });
  554. this.$set(this.pool,key,val);
  555. this.$set(this.poolMapping,key,mapping);
  556. },
  557. //获取项目
  558. _getOwners(){
  559. let url = "{{url('maintenance/owner/get')}}";
  560. window.tempTip.postBasicRequest(url,{},res=>{this._setModelData("owners",res);});
  561. },
  562. //获取单位
  563. _getUnits(){
  564. let url = "{{url('maintenance/unit/getUnits')}}";
  565. window.tempTip.postBasicRequest(url,{},res=>{this._setModelData("units",res);});
  566. },
  567. //获取省份
  568. _getProvinces(){
  569. let url = "{{url('maintenance/province/get')}}";
  570. window.tempTip.postBasicRequest(url,{},res=>{this._setModelData("provinces",res);});
  571. },
  572. //获取城市
  573. _getCities(){
  574. let url = "{{url('maintenance/city/get')}}";
  575. window.tempTip.postBasicRequest(url,{},res=>{this._setModelData("cities",res);});
  576. },
  577. //获取承运商
  578. _getLogistics(){
  579. let url = "{{url('maintenance/logistic/get')}}";
  580. window.tempTip.postBasicRequest(url,{type:''},res=>{
  581. this._setModelData("logistics",res);
  582. setTimeout(()=>{
  583. $(".selectpicker").selectpicker('refresh');
  584. },0);
  585. });
  586. },
  587. //获取车型
  588. _getCars(){
  589. let url = "{{url('maintenance/carType/get')}}";
  590. window.axios.post(url).then(res=>{this._setModelData("cars",res.data);});
  591. },
  592. //获取税率
  593. _getTaxRates(){
  594. let url = "{{url('maintenance/taxRate/get')}}";
  595. window.axios.post(url).then(res=>{this._setModelData("taxRates",res.data);});
  596. },
  597. //保存模型
  598. saveModel(){
  599. this._clearRefuse();
  600. switch (this.type) {
  601. case "storage":
  602. this._verifyStorage();
  603. break;
  604. case "operation":
  605. this._verifyOperation();
  606. break;
  607. case "express":
  608. this._verifyExpress();
  609. break;
  610. case "logistic":
  611. this._verifyLogistic();
  612. break;
  613. case "directLogistic":
  614. this._verifyDirectLogistic();
  615. break;
  616. }
  617. },
  618. _verifyStorage(){
  619. let error = {};
  620. if (!this.model.storage.counting_type)error["counting_type"] = ["未选择计费类型"];
  621. if (!this.model.storage.name)error["name"] = ["未填写名称"];
  622. if (!this.model.storage.using_type)error["using_type"] = ["未选择用仓类型"];
  623. if (!this.model.storage.price)error["price"] = ["未输入单价"];
  624. if (!this.model.storage.discount_type)error["discount_type"] = ["未选择减免类型"];
  625. if (!this.model.storage.unit_id)error["unit_id"] = ["未选择单位"];
  626. if (!this.model.storage.time_unit_id)error["time_unit_id"] = ["未选择计时单位"];
  627. if (JSON.stringify(error) !== "{}"){
  628. this.errors = error;
  629. return;
  630. }
  631. let url = "{{url('maintenance/priceModel/apiStoreStorage')}}";
  632. let params = this.model.storage;
  633. params.owner_id = this.ownerTemp.id;
  634. window.tempTip.postBasicRequest(url,params,res=>{
  635. if (res && res.errors){
  636. this.errors = res.errors;
  637. return;
  638. }
  639. if (this.model.storage.id){
  640. if (res) this.selectedModel.storage[this.model.storage.index] = this.model.storage;
  641. else this.$set(this.selectedModel.storage,this.model.storage.index,res);
  642. }else {
  643. this.model.storage.id = res;
  644. this.selectedModel.storage.unshift(this.model.storage);
  645. }
  646. this.model.storage = {
  647. name : "",
  648. counting_type : "",
  649. using_type : "",
  650. minimum_area : "",
  651. price : "",
  652. discount_type : "无减免",
  653. discount_value : "",
  654. unit_id : "",
  655. time_unit_id : "",
  656. };
  657. this.errors = {};
  658. this.audit.storage = true;
  659. });
  660. },
  661. _verifyOperation() {
  662. if (this.selectedModel.operation.length>0 && !this.model.operation.id){
  663. if (this.model.operation.strategy!=='特征'){
  664. if (!this.selectedModel.operation.every(operation=>{
  665. if (operation.operation_type === this.model.operation.operation_type && operation.strategy === this.model.operation.strategy){
  666. this.errors["operation_type"] = ["已存在同类型的"+operation.operation_type+"作业计费模型"];
  667. this.$forceUpdate();
  668. return false;
  669. }
  670. return true;
  671. }))return;
  672. }
  673. }
  674. if (!this.model.operation.name){
  675. this.$set(this.errors,"name",["名称不得为空"]);
  676. return;
  677. }
  678. if (this.model.operation.isDiscount){
  679. let sign = false;
  680. this.model.operation.discount_count.forEach((item,i)=>{
  681. if (!item || (i!==0 && Number(item)<=Number(this.model.operation.discount_count[i-1]))){
  682. this.$set(this.errors,"discount_count_"+i,["非法满减值"]);
  683. sign = true;
  684. }
  685. });
  686. if (sign){
  687. this.$forceUpdate();
  688. return;
  689. }
  690. }
  691. if (this.model.operation.isSingle && !this.model.operation.total_price){
  692. this.$set(this.errors,"total_price",["按单价格不存在"]);
  693. return;
  694. }
  695. if (this.model.operation.isDiscount && this.model.operation.isSingle){
  696. if (!this.model.operation.total_discount_price[0]){
  697. this.$set(this.errors,"total_discount_price",["满减价格不存在"]);
  698. return;
  699. }
  700. this.model.operation.total_discount_price.forEach((item,i)=>{
  701. if (i!==0 && !item)this.model.operation.total_discount_price[i] = this.model.operation.total_discount_price[i-1];
  702. })
  703. }
  704. if (!this.model.operation.isSingle){
  705. if ((this.model.operation.operation_type === '出库' && this._verifyOperationItem(0)) || this._verifyOperationItem(1))return;
  706. if (this.model.operation.items.length>2){
  707. for (let i=2;i<this.model.operation.items.length;i++){
  708. if (this._verifyOperationItem(i))return;
  709. }
  710. }
  711. this.model.operation.total_price = "";
  712. }else this.$set(this.model.operation,"items",[]);
  713. if (!this.model.operation.isDiscount) {
  714. this.model.operation.discount_count = [""];
  715. this.model.operation.total_discount_price = [""];
  716. }
  717. let url = "{{url('maintenance/priceModel/apiStoreOperation')}}";
  718. let params = this.model.operation;
  719. params.owner_id = this.ownerTemp.id;
  720. window.tempTip.postBasicRequest(url,params,res=>{
  721. if (res && res.errors){
  722. if (res.errors.owner_id){
  723. window.tempTip.show(res.errors.owner_id[0]);
  724. return;
  725. }
  726. this.errors = res.errors;
  727. return;
  728. }
  729. res.features = this.model.operation.features;
  730. res.featureFormat = this.model.operation.featureFormat;
  731. let sign = 0;
  732. if (res.operation_type === '入库') sign++;
  733. for (let i=0;i<res.items.length;i++){
  734. res.items[i].features = this.model.operation.items[sign]['features'];
  735. res.items[i].featureFormat = this.model.operation.items[sign]['featureFormat'];
  736. res.items[i].type = this.model.operation.items[sign]['type'];
  737. res.items[i].discount_price = res.items[i].discount_price ? res.items[i].discount_price.split(",") : [""];
  738. sign++;
  739. }
  740. if (res.discount_count)res.isDiscount = true;
  741. if (res.total_price)res.isSingle = true;
  742. res.discount_count = res.discount_count ? res.discount_count.split(",") : [""];
  743. res.total_discount_price = res.total_discount_price ? res.total_discount_price.split(",") : [""];
  744. if (params.id) this.selectedModel.operation[params.index] = res;
  745. else this.selectedModel.operation.push(res);
  746. this._resetOperation();
  747. this.errors = {};
  748. this.audit.operation = true;
  749. });
  750. },
  751. _verifyOperationItem(itemIndex){//验证作业费子项信息完整
  752. let obj = this.model.operation.items[itemIndex];
  753. let sign = false;
  754. if (obj.strategy === '特征' && !obj.feature) {
  755. this.errors['items.' + itemIndex + '.feature'] = ["必须选择特征"];
  756. sign = true;
  757. }
  758. if (obj.strategy!=='起步' && !obj.amount){
  759. this.errors['items.'+itemIndex+'.amount'] = ["数量不得为空"];
  760. sign = true;
  761. }else if (!obj.amount) obj.amount = 0;
  762. if (obj.strategy!=='起步' && !obj.unit_id){
  763. this.errors['items.'+itemIndex+'.unit_id'] = ["必须选择单位"];
  764. sign = true;
  765. }else if (!obj.unit_id) obj.unit_id = 0;
  766. if (!obj.unit_price){
  767. this.errors['items.'+itemIndex+'.unit_price'] = ["单价不得为空"];
  768. sign = true;
  769. }
  770. if (this.model.operation.isDiscount){
  771. if (!obj.discount_price[0]){
  772. this.errors['items.'+itemIndex+'.discount_price'] = ["满减单价不得为空"];
  773. sign = true;
  774. }else{
  775. obj.discount_price.forEach((item,i)=>{
  776. if (i!==0&&!item) obj.discount_price[i]=obj.discount_price[i-1];
  777. })
  778. }
  779. }
  780. if (sign)this.$forceUpdate();
  781. return sign;
  782. },
  783. _verifyExpress(){
  784. let error = {};
  785. if (!this.model.express.name)error.name = ["名称不得为空"];
  786. if (!this.model.express.initial_weight)error.initial_weight = ["首重不得为空"];
  787. if (!this.model.express.additional_weight)error.additional_weight = ["续重不得为空"];
  788. if (this.model.express.items.length>0){
  789. this.model.express.items.forEach((item,index)=>{
  790. if (!item.province_id)error["item."+index+".province_id"] = ["不存在"];
  791. if (!item.initial_weight_price)error["item."+index+".initial_weight_price"] = ["不存在"];
  792. if (!item.additional_weight_price)error["item."+index+".additional_weight_price"] = ["不存在"];
  793. });
  794. }
  795. if (JSON.stringify(error) !== "{}"){
  796. this.errors = error;
  797. return;
  798. }
  799. let url = "{{url('maintenance/priceModel/apiStoreExpress')}}";
  800. let params = this.model.express;
  801. params.owner_id = this.ownerTemp.id;
  802. window.tempTip.postBasicRequest(url,params,res=>{
  803. if (res && res.errors){
  804. this.errors = res.errors;
  805. if (res.errors.owner_id)window.tempTip.show(res.errors.owner_id[0]);
  806. return;
  807. }
  808. this.model.express.items.forEach((item,i)=>{
  809. item.id = res.details[i].id;
  810. });
  811. if (this.model.express.id){
  812. if (res.operation) this.model.express.id = res.id;
  813. this.selectedModel.express[this.model.express.index] = this.model.express;
  814. }else{
  815. this.model.express.id = res.id;
  816. this.selectedModel.express.unshift(this.model.express);
  817. }
  818. this.model.express = {
  819. name:"",
  820. logistics:[],
  821. initial_weight:"",
  822. additional_weight:"",
  823. items:[],
  824. };
  825. this.errors = {};
  826. this.importError = [];
  827. $(".selectpicker").filter('.express').selectpicker('val',[]);
  828. this.audit.express = true;
  829. });
  830. },
  831. _verifyLogistic(){
  832. let error = {};
  833. if (!this.model.logistic.name) error.name = ["名称不得为空"];
  834. if (!this.model.logistic.unit_id) error.unit_id = ["单位一不得为空"];
  835. if (!this.model.logistic.unit_range) error.unit_range = ["区间值不得为空"];
  836. if (!this.model.logistic.other_unit_id) error.other_unit_id = ["单位二不得为空"];
  837. if (!this.model.logistic.other_unit_range) error.other_unit_range = ["区间值不得为空"];
  838. if (JSON.stringify(error) !== "{}"){
  839. this.errors = error;
  840. return;
  841. }
  842. let url = "{{url('maintenance/priceModel/apiStoreLogistic')}}";
  843. let params = this.model.logistic;
  844. params.owner_id = this.ownerTemp.id;
  845. window.tempTip.postBasicRequest(url,params,res=>{
  846. if (res && res.errors){
  847. this.errors = res.errors;
  848. window.tempTip.show("检查您的子项详情列表是否完整");
  849. return;
  850. }
  851. this.model.logistic.items.forEach((item,i)=>{
  852. item.id = res.details[i].id;
  853. });
  854. if (this.model.logistic.id){
  855. if (res.operation) this.model.logistic.id = res.id;
  856. this.selectedModel.logistic[this.model.logistic.index] = this.model.logistic;
  857. }else {
  858. this.model.logistic.id = res.id;
  859. this.selectedModel.logistic.unshift(this.model.logistic);
  860. }
  861. this.model.logistic = {
  862. items:[],
  863. other_ranges:[],
  864. ranges:[],
  865. logistics:[],
  866. };
  867. this.errors = {};
  868. this.importError = [];
  869. $(".selectpicker").filter('.logistic').selectpicker('val',[]);
  870. this.audit.logistic = true;
  871. });
  872. },
  873. _verifyDirectLogistic(){
  874. let error = {};
  875. if (!this.model.directLogistic.name) error.name = ["名称不得为空"];
  876. if (!this.model.directLogistic.base_km) error.base_km = ["起步公里数不得为空"];
  877. if (JSON.stringify(error) !== "{}"){
  878. this.errors = error;
  879. return;
  880. }
  881. let url = "{{url('maintenance/priceModel/apiStoreDirectLogistic')}}";
  882. let params = this.model.directLogistic;
  883. params.owner_id = this.ownerTemp.id;
  884. window.tempTip.postBasicRequest(url,params,res=>{
  885. if (res && res.errors){
  886. this.errors = res.errors;
  887. return;
  888. }
  889. this.model.directLogistic.items.forEach((item,i)=>{
  890. item.id = res.details[i].id;
  891. });
  892. this.model.directLogistic.id = res.id;
  893. this.selectedModel.directLogistic = this.model.directLogistic;
  894. this.model.directLogistic = {
  895. items:[],
  896. };
  897. this.errors = {};
  898. this.importError = [];
  899. this.audit.directLogistic = true;
  900. });
  901. },
  902. //增加作业费特征子项
  903. addOperationItem(){
  904. this.model.operation.items.push({
  905. strategy:"特征",
  906. discount_price:new Array(this.model.operation.discount_count.length).fill(""),
  907. });
  908. },
  909. //删除作业费子项
  910. delOperationItem(index){
  911. this.$delete(this.model.operation.items,index);
  912. },
  913. //显示特征选择modal
  914. showAddFeatureModal(index){
  915. if (index === -1){
  916. if (!this.model.operation.feature){
  917. this.model.operation.features = this._createFeature();
  918. this.thisOperationItemIndex = index;
  919. this.$forceUpdate();
  920. $("#addFeatureModal").modal("show");
  921. return;
  922. }
  923. if (this.model.operation.features) {
  924. this.thisOperationItemIndex = index;
  925. $("#addFeatureModal").modal("show");
  926. return;
  927. }
  928. }else{
  929. if (!this.model.operation.items[index].feature){
  930. this.model.operation.items[index].features = this._createFeature();
  931. this.thisOperationItemIndex = index;
  932. this.$forceUpdate();
  933. $("#addFeatureModal").modal("show");
  934. return;
  935. }
  936. if (this.model.operation.items[index].features) {
  937. this.thisOperationItemIndex = index;
  938. $("#addFeatureModal").modal("show");
  939. return;
  940. }
  941. }
  942. let url = "{{url('maintenance/priceModel/operation/getFeatures')}}";
  943. let feature = index===-1 ? this.model.operation.feature : this.model.operation.items[index].feature;
  944. window.tempTip.postBasicRequest(url,{feature:feature},res=>{
  945. if (!res || res.length === 0){
  946. res = this._createFeature();
  947. }
  948. if (index === -1) this.model.operation.features = res;
  949. else this.model.operation.items[index].features = res;
  950. this.thisOperationItemIndex = index;
  951. this.$forceUpdate();
  952. $("#addFeatureModal").modal("show");
  953. });
  954. },
  955. //增加特征
  956. addFeature(){
  957. let obj = {
  958. "strategyGroupStartSign": false,
  959. "calculation" : "",
  960. "type" : "",
  961. "id" : "",
  962. "logic" : "",
  963. "describe" : "",
  964. "strategyGroupEndSign" : false,
  965. };
  966. if (this.thisOperationItemIndex === -1)this.model.operation.features.push(obj);
  967. else this.model.operation.items[this.thisOperationItemIndex].features.push(obj);
  968. this.$forceUpdate();
  969. },
  970. _createFeature(){
  971. return [{
  972. "strategyGroupStartSign": false,
  973. "calculation" : "",
  974. "type" : "",
  975. "id" : "",
  976. "logic" : "",
  977. "describe" : "",
  978. "strategyGroupEndSign" : false,
  979. }];
  980. },
  981. //删除特征
  982. delFeature(index) {
  983. if (this.thisOperationItemIndex === -1)this.$delete(this.model.operation.features,index);
  984. else this.$delete(this.model.operation.items[this.thisOperationItemIndex].features,index);
  985. this.$forceUpdate();
  986. },
  987. //提交特征更新现有
  988. submitFeature(){
  989. let url = "{{url('maintenance/priceModel/operation/getFeature')}}";
  990. let features = this.thisOperationItemIndex === -1 ? this.model.operation.features : this.model.operation.items[this.thisOperationItemIndex].features;
  991. window.tempTip.postBasicRequest(url,{features:features,isFormat:true},res=>{
  992. if (this.thisOperationItemIndex === -1){
  993. this.model.operation.feature = res.feature;
  994. this.model.operation.featureFormat = res.featureFormat;
  995. } else {
  996. this.model.operation.items[this.thisOperationItemIndex].feature = res.feature;
  997. this.model.operation.items[this.thisOperationItemIndex].featureFormat = res.featureFormat;
  998. this.$forceUpdate();
  999. }
  1000. $("#addFeatureModal").modal("hide");
  1001. return "已更新特征";
  1002. },true);
  1003. },
  1004. //移入移出时更改长文本显示效果
  1005. textClass(event,isOver){
  1006. event = event.target.children[0];
  1007. if (isOver) event.className = "text-overflow-warp-100";
  1008. else event.className = "cursor-pointer text-overflow-replace-100";
  1009. },
  1010. //展开子策略
  1011. showOperationItem(index){
  1012. let trId = "operation-tr-"+index;
  1013. let itemId = "operation-item-"+index;
  1014. if (this.operationItems['_'+index] && this.operationItems['_'+index]===true){
  1015. this.operationItems['_'+index] = false;
  1016. $("#"+itemId).slideUp(undefined,function () {
  1017. $("#"+trId).addClass("d-none");
  1018. });
  1019. }else {
  1020. $("#"+trId).removeClass("d-none");
  1021. this.operationItems['_'+index] = true;
  1022. $("#"+itemId).slideDown();
  1023. }
  1024. this.$forceUpdate();
  1025. },
  1026. //新增快递子项
  1027. addExpressItem(){
  1028. this.model.express.items.unshift({
  1029. province_id : "",
  1030. initial_weight_price:"",
  1031. additional_weight_price:"",
  1032. });
  1033. },
  1034. //删除快递子项
  1035. delExpressItem(index){
  1036. this.$delete(this.model.express.items,index);
  1037. },
  1038. //选择文件
  1039. selectFile(id){
  1040. this.importError = [];
  1041. $("#"+id).click();
  1042. },
  1043. //导入快递子项
  1044. importExpress(e){
  1045. let file=e.target.files[0];
  1046. window.tempTip.setDuration(3000);
  1047. if (!file){
  1048. window.tempTip.show("未选择文件");
  1049. return;
  1050. }
  1051. let formData = new FormData();
  1052. formData.append("file",file);
  1053. window.axios.post('{{url('maintenance/priceModel/express/import')}}',formData,{
  1054. 'Content-Type':'multipart/form-data'
  1055. }).then(res=>{
  1056. if (res.data.success) {
  1057. res.data.data.forEach(data=>{
  1058. let unique = this.model.express.items.every(item=>{
  1059. if (data.province_id === item.province_id)return false;
  1060. return true;
  1061. });
  1062. if (unique)this.model.express.items.push(data);
  1063. });
  1064. this.importError = res.data.errors;
  1065. window.tempTip.setDuration(2000);
  1066. window.tempTip.showSuccess("导入成功!");
  1067. return;
  1068. }
  1069. window.tempTip.show(res.data.data);
  1070. }).catch(err=> {
  1071. window.tempTip.show("网络错误:"+err);
  1072. })
  1073. },
  1074. //物流详情列表modal
  1075. showDetailModal() {
  1076. $("#logisticModal").modal("show");
  1077. },
  1078. //新增物流详情
  1079. addLogisticDetail(){
  1080. this.model.logistic.items.unshift({});
  1081. },
  1082. //导入物流详情
  1083. importLogistic(e){
  1084. window.tempTip.setIndex(1099);
  1085. let file=e.target.files[0];
  1086. if (!file){
  1087. window.tempTip.setDuration(3000);
  1088. window.tempTip.show("未选择文件");
  1089. return;
  1090. }
  1091. let formData = new FormData();
  1092. formData.append("file",file);
  1093. window.axios.post('{{url('maintenance/priceModel/logistic/import')}}',formData,{
  1094. 'Content-Type':'multipart/form-data'
  1095. }).then(res=>{
  1096. if (res.data.success) {
  1097. res.data.data.forEach(data=>{
  1098. //过滤非已选择单位的数据
  1099. let id = "";
  1100. if (data.unit_id === this.poolMapping.units[this.model.logistic.unit_id]) id = this.model.logistic.unit_id;
  1101. if (data.unit_id === this.poolMapping.units[this.model.logistic.other_unit_id]) id = this.model.logistic.other_unit_id;
  1102. if (id){
  1103. //过滤重复数据
  1104. let unique = this.model.logistic.items.every(item=>{
  1105. if (id === item.unit_id && data.range === item.range
  1106. && data.province_id === item.province_id && data.city_id === item.city_id)return false;
  1107. return true;
  1108. });
  1109. if (unique){
  1110. data.unit_id = id;
  1111. this.model.logistic.items.push(data);
  1112. }
  1113. }
  1114. });
  1115. this.importError = res.data.errors;
  1116. window.tempTip.setDuration(3000);
  1117. window.tempTip.showSuccess("导入成功!");
  1118. return;
  1119. }
  1120. window.tempTip.setDuration(3000);
  1121. window.tempTip.show(res.data.data);
  1122. }).catch(err=> {
  1123. window.tempTip.setDuration(3000);
  1124. window.tempTip.show("网络错误:"+err);
  1125. })
  1126. },
  1127. //删除物流子项
  1128. delLogisticItem(index){
  1129. this.$delete(this.model.logistic.items,index);
  1130. },
  1131. //改变物流区间时改变可选择项
  1132. changeRange(type){
  1133. if (type === 'ranges'){
  1134. this.model.logistic.ranges = this.model.logistic.unit_range.split(",");
  1135. }else{
  1136. this.model.logistic.other_ranges = this.model.logistic.other_unit_range.split(",");
  1137. }
  1138. },
  1139. //增加直发车子项
  1140. addDirectLogisticItem(){
  1141. this.model.directLogistic.items.unshift({
  1142. car_type_id : "",
  1143. base_fee:"",
  1144. additional_fee:"",
  1145. });
  1146. },
  1147. //导入直发车子项
  1148. importDirectLogistic(e){
  1149. window.tempTip.setIndex(1099);
  1150. let file=e.target.files[0];
  1151. if (!file){
  1152. window.tempTip.setDuration(3000);
  1153. window.tempTip.show("未选择文件");
  1154. return;
  1155. }
  1156. let formData = new FormData();
  1157. formData.append("file",file);
  1158. window.axios.post('{{url('maintenance/priceModel/directLogistic/import')}}',formData,{
  1159. 'Content-Type':'multipart/form-data'
  1160. }).then(res=>{
  1161. if (res.data.success) {
  1162. if (this.model.directLogistic.items.length > 0){
  1163. res.data.data.forEach(data=>{
  1164. let unique = this.model.directLogistic.items.every(item=>{
  1165. if (item.car_type_id === data.car_type_id)return false;
  1166. return true;
  1167. });
  1168. if (unique) this.model.directLogistic.items.unshift(data);
  1169. });
  1170. }else this.model.directLogistic.items = res.data.data;
  1171. this.importError = res.data.errors;
  1172. window.tempTip.setDuration(3000);
  1173. window.tempTip.showSuccess("导入成功!");
  1174. return;
  1175. }
  1176. window.tempTip.setDuration(3000);
  1177. window.tempTip.show(res.data.data);
  1178. }).catch(err=> {
  1179. window.tempTip.setDuration(3000);
  1180. window.tempTip.show("网络错误:"+err);
  1181. })
  1182. },
  1183. //删除直发车子项
  1184. delDirectLogisticItem(index){
  1185. this.$delete(this.model.directLogistic.items,index);
  1186. },
  1187. //改变客户
  1188. selectOwner(){
  1189. let id = this.owner.customer_id;
  1190. this.customers.some(customer=>{
  1191. if (id === customer.id){
  1192. this.owner.customer_name = customer.name;
  1193. return true;
  1194. }
  1195. });
  1196. },
  1197. //改变小组
  1198. selectGroup(){
  1199. let id = this.owner.owner_group_id;
  1200. this.ownerGroups.some(group=>{
  1201. if (id === group.id){
  1202. this.owner.owner_group_name = group.name;
  1203. return true;
  1204. }
  1205. });
  1206. },
  1207. //获取引入计费模型查询列表搜索
  1208. searchPriceModel(){
  1209. this.isSearch = true;
  1210. switch (this.type) {
  1211. case "storage":
  1212. this._getStoragePriceModel();
  1213. break;
  1214. case "operation":
  1215. this._getOperationPriceModel();
  1216. break;
  1217. case "express":
  1218. this._getExpressPriceModel();
  1219. break;
  1220. case "logistic":
  1221. this._getLogisticPriceModel();
  1222. break;
  1223. default:
  1224. this._getDirectLogisticPriceModel();
  1225. }
  1226. },
  1227. _getStoragePriceModel(){
  1228. let url = "{{url('maintenance/priceModel/apiGetStorage')}}";
  1229. window.tempTip.postBasicRequest(url,this.introduce,res=>{
  1230. let result = [];
  1231. let mapping = {};
  1232. res.forEach(model=> {
  1233. let text = model.name+" ("+model.counting_type+"-"+model.using_type+")";
  1234. result.push({id:model.id,text:text});
  1235. mapping[model.id] = {
  1236. name : model.name,
  1237. counting_type : model.counting_type,
  1238. using_type : model.using_type,
  1239. minimum_area : model.minimum_area,
  1240. price : model.price,
  1241. discount_type : model.discount_type,
  1242. discount_value : model.discount_value,
  1243. unit_id : model.unit_id,
  1244. };
  1245. });
  1246. this.searchResult = result;
  1247. this.searchResultMapping = mapping;
  1248. this.isSearch = false;
  1249. });
  1250. },
  1251. _getOperationPriceModel(){
  1252. let url = "{{url('maintenance/priceModel/apiGetOperation')}}";
  1253. window.tempTip.postBasicRequest(url,this.introduce,res=>{
  1254. let result = [];
  1255. let mapping = {};
  1256. res.forEach(model=> {
  1257. let text = model.name+" ("+model.operation_type+"-"+model.strategy+")";
  1258. result.push({id:model.id,text:text});
  1259. mapping[model.id] = {
  1260. name : model.name,
  1261. operation_type : model.operation_type,
  1262. strategy : model.strategy,
  1263. feature : model.feature,
  1264. featureFormat : model.featureFormat,
  1265. remark : model.remark,
  1266. items:model.items,
  1267. };
  1268. });
  1269. this.searchResult = result;
  1270. this.searchResultMapping = mapping;
  1271. this.isSearch = false;
  1272. });
  1273. },
  1274. _getExpressPriceModel(){
  1275. let url = "{{url('maintenance/priceModel/apiGetExpress')}}";
  1276. window.tempTip.postBasicRequest(url,this.introduce,res=>{
  1277. let result = [];
  1278. let mapping = {};
  1279. res.forEach(model=> {
  1280. let text = model.name+" (首重:"+model.initial_weight+"KG 续重:"+model.additional_weight+"KG)";
  1281. result.push({id:model.id,text:text});
  1282. let logistics = [];
  1283. model.logistics.forEach(logistic=>{
  1284. logistics.push(logistic.id);
  1285. });
  1286. let items = [];
  1287. model.details.forEach(item=>{
  1288. items.push({
  1289. province_id:item.province_id,
  1290. initial_weight_price:item.initial_weight_price,
  1291. additional_weight_price:item.additional_weight_price,
  1292. });
  1293. });
  1294. mapping[model.id] = {
  1295. logistics : logistics,
  1296. name:model.name,
  1297. initial_weight:model.initial_weight,
  1298. additional_weight:model.additional_weight,
  1299. items:items,
  1300. };
  1301. });
  1302. this.searchResult = result;
  1303. this.searchResultMapping = mapping;
  1304. this.isSearch = false;
  1305. });
  1306. },
  1307. _getLogisticPriceModel(){
  1308. let url = "{{url('maintenance/priceModel/apiGetLogistic')}}";
  1309. window.tempTip.postBasicRequest(url,this.introduce,res=>{
  1310. let result = [];
  1311. let mapping = {};
  1312. res.forEach(model=> {
  1313. let text = model.name+" (单位一:"+this.poolMapping.units[model.unit_id]+"["+model.unit_range+
  1314. "] 单位二:"+this.poolMapping.units[model.other_unit_id]+"["+model.other_unit_range+"])";
  1315. result.push({id:model.id,text:text});
  1316. let logistics = [];
  1317. model.logistics.forEach(logistic=>{
  1318. logistics.push(logistic.id);
  1319. });
  1320. let items = [];
  1321. model.details.forEach(item=>{
  1322. items.push({
  1323. unit_id:item.unit_id,
  1324. range:item.range,
  1325. province_id:item.province_id,
  1326. city_id:item.city_id,
  1327. unit_price:item.unit_price,
  1328. delivery_fee:item.delivery_fee,
  1329. initial_fee:item.initial_fee,
  1330. initial_amount:item.initial_amount,
  1331. rate:item.rate,
  1332. });
  1333. });
  1334. mapping[model.id] = {
  1335. logistics : logistics,
  1336. name:model.name,
  1337. unit_range:model.unit_range,
  1338. unit_id:model.unit_id,
  1339. other_unit_range:model.other_unit_range,
  1340. other_unit_id:model.other_unit_id,
  1341. pick_up_price:model.pick_up_price,
  1342. fuel_price:model.fuel_price,
  1343. service_price:model.service_price,
  1344. items:items,
  1345. };
  1346. });
  1347. this.searchResult = result;
  1348. this.searchResultMapping = mapping;
  1349. this.isSearch = false;
  1350. });
  1351. },
  1352. _getDirectLogisticPriceModel(){
  1353. let url = "{{url('maintenance/priceModel/apiGetDirectLogistic')}}";
  1354. window.tempTip.postBasicRequest(url,this.introduce,res=>{
  1355. let result = [];
  1356. let mapping = {};
  1357. res.forEach(model=> {
  1358. let text = model.name+" (起步数:"+model.base_km+"KM)";
  1359. result.push({id:model.id,text:text});
  1360. let items = [];
  1361. model.details.forEach(item=>{
  1362. items.push({
  1363. car_type_id:item.car_type_id,
  1364. base_fee:item.base_fee,
  1365. additional_fee:item.additional_fee,
  1366. });
  1367. });
  1368. mapping[model.id] = {
  1369. name:model.name,
  1370. base_km:model.base_km,
  1371. items:items,
  1372. };
  1373. });
  1374. this.searchResult = result;
  1375. this.searchResultMapping = mapping;
  1376. this.isSearch = false;
  1377. });
  1378. },
  1379. //提交引入
  1380. submitIntroduce(){
  1381. if (!this.selectedResult || !this.searchResultMapping[this.selectedResult]){
  1382. window.tempTip.setDuration(3000);
  1383. window.tempTip.show("尚未选择引入项,请单击选择列表,如列表为空则无结果");
  1384. return;
  1385. }
  1386. let model = this.searchResultMapping[this.selectedResult];
  1387. switch (this.type) {
  1388. case "storage":
  1389. this.model.storage = model;
  1390. break;
  1391. case "operation":
  1392. this.model.operation = model;
  1393. break;
  1394. case "express":
  1395. this.model.express = model;
  1396. break;
  1397. case "logistic":
  1398. this.model.logistic = model;
  1399. break;
  1400. default:
  1401. this.model.directLogistic = model;
  1402. break;
  1403. }
  1404. $("#introduce").modal('hide');
  1405. window.tempTip.setDuration(2000);
  1406. window.tempTip.showSuccess("引入成功");
  1407. },
  1408. //删除仓储
  1409. delStorage(item,index){
  1410. window.tempTip.confirm("您确定要删除仓储计费“"+item.name+"”吗?",()=>{
  1411. window.tempTip.postBasicRequest("{{url('maintenance/priceModel/apiDelStorage')}}",{id:item.id},res=>{
  1412. this.$delete(this.selectedModel.storage,index);
  1413. this.audit.storage = true;
  1414. return "删除“"+item.name+"”成功";
  1415. });
  1416. });
  1417. },
  1418. //删除作业
  1419. delOperation(item,index){
  1420. window.tempTip.confirm("您确定要删除作业计费“"+item.name+"”吗?",()=>{
  1421. window.tempTip.postBasicRequest("{{url('maintenance/priceModel/apiDelOperation')}}",{id:item.id},res=>{
  1422. this.$delete(this.selectedModel.operation,index);
  1423. this.audit.operation = true;
  1424. return "删除“"+item.name+"”成功";
  1425. });
  1426. });
  1427. },
  1428. //删除作业子项
  1429. deleteOperationItem(item,index,parentIndex){
  1430. window.tempTip.confirm("您确定要删除该作业子项吗?",()=>{
  1431. window.tempTip.postBasicRequest("{{url('maintenance/priceModel/apiDelOperationItem')}}",{id:item.id},res=>{
  1432. if (res) this.$set(this.selectedModel.operation,parentIndex,this._overrideOperation(res));
  1433. else this.$delete(this.selectedModel.operation[parentIndex].items,index);
  1434. this.audit.operation = true;
  1435. return "删除成功";
  1436. });
  1437. });
  1438. },
  1439. //删除快递
  1440. delExpress(item,index){
  1441. window.tempTip.confirm("您确定要删除该快递计费“"+item.name+"”吗?",()=>{
  1442. window.tempTip.postBasicRequest("{{url('maintenance/priceModel/apiDelExpress')}}",{id:item.id},res=>{
  1443. this.$delete(this.selectedModel.express,index);
  1444. this.audit.express = true;
  1445. return "删除“"+item.name+"”成功";
  1446. });
  1447. });
  1448. },
  1449. //删除快递子项
  1450. deleteExpressItem(item,index,parentIndex){
  1451. window.tempTip.confirm("您确定要删除该快递计费子项吗?",()=>{
  1452. window.tempTip.postBasicRequest("{{url('maintenance/priceModel/apiDelExpressItem')}}",{id:item.id},res=>{
  1453. if (res) this.$set(this.selectedModel.express,parentIndex,this._overrideExpress(res));
  1454. else this.$delete(this.selectedModel.express[parentIndex].items,index);
  1455. this.audit.express = true;
  1456. return "删除成功";
  1457. });
  1458. });
  1459. },
  1460. //删除物流
  1461. delLogistic(item,index){
  1462. window.tempTip.confirm("您确定要删除该物流计费“"+item.name+"”吗?",()=>{
  1463. window.tempTip.postBasicRequest("{{url('maintenance/priceModel/apiDelLogistic')}}",{id:item.id},res=>{
  1464. this.$delete(this.selectedModel.logistic,index);
  1465. this.audit.logistic = true;
  1466. return "删除“"+item.name+"”成功";
  1467. });
  1468. });
  1469. },
  1470. //删除物流子项
  1471. deleteLogisticItem(item,index,parentIndex){
  1472. window.tempTip.confirm("您确定要删除该物流计费子项吗?",()=>{
  1473. window.tempTip.postBasicRequest("{{url('maintenance/priceModel/apiDelLogisticItem')}}",{id:item.id},res=>{
  1474. if (res) this.$set(this.selectedModel.logistic,parentIndex,this._overrideLogistic(res));
  1475. else this.$delete(this.selectedModel.logistic[parentIndex].items,index);
  1476. this.audit.logistic = true;
  1477. return "删除成功";
  1478. });
  1479. });
  1480. },
  1481. //删除直发车
  1482. delDirectLogistic(item){
  1483. window.tempTip.confirm("您确定要删除该直发车计费“"+item.name+"”吗?",()=>{
  1484. window.tempTip.postBasicRequest("{{url('maintenance/priceModel/apiDelDirectLogistic')}}",{id:item.id},res=>{
  1485. this.selectedModel.directLogistic = {};
  1486. this.audit.directLogistic = true;
  1487. return "删除“"+item.name+"”成功";
  1488. });
  1489. });
  1490. },
  1491. //删除直发车子项
  1492. deleteDirectLogisticItem(item,index){
  1493. window.tempTip.confirm("您确定要删除该直发车计费子项吗?",()=>{
  1494. window.tempTip.postBasicRequest("{{url('maintenance/priceModel/apiDelDirectLogisticItem')}}",{id:item.id},res=>{
  1495. if (res) this.$set(this.selectedModel,"directLogistic",this._overrideDirectLogistic(res));
  1496. else this.$delete(this.selectedModel.directLogistic.items,index);
  1497. this.audit.directLogistic = true;
  1498. return "删除成功";
  1499. });
  1500. });
  1501. },
  1502. //编辑仓储
  1503. editStorage(index){
  1504. this.switchType("storage");
  1505. this.model.storage = JSON.parse(JSON.stringify(this.selectedModel.storage[index]));
  1506. this.model.storage.index = index;
  1507. },
  1508. //编辑作业
  1509. editOperation(index){
  1510. this.switchType("operation");
  1511. this.model.operation = JSON.parse(JSON.stringify(this.selectedModel.operation[index]));
  1512. if (this.model.operation.operation_type==='入库') this.model.operation.items.unshift({});
  1513. this.model.operation.index = index;
  1514. if (this.model.operation.items.length == 0){
  1515. this.model.operation.items = [
  1516. {strategy:"起步",type:"0"},
  1517. {strategy:"默认"},
  1518. {strategy:"特征"},
  1519. ];
  1520. }
  1521. },
  1522. //编辑快递
  1523. editExpress(index){
  1524. this.switchType("express");
  1525. this.model.express = JSON.parse(JSON.stringify(this.selectedModel.express[index]));
  1526. this.model.express.index = index;
  1527. },
  1528. //编辑物流
  1529. editLogistic(index){
  1530. this.switchType("logistic");
  1531. this.model.logistic = JSON.parse(JSON.stringify(this.selectedModel.logistic[index]));
  1532. this.model.logistic.ranges = this.model.logistic.unit_range.split(",");
  1533. this.model.logistic.other_ranges = this.model.logistic.other_unit_range.split(",");
  1534. this.model.logistic.index = index;
  1535. },
  1536. //编辑直发车
  1537. editDirectLogistic(){
  1538. this.switchType("directLogistic");
  1539. this.model.directLogistic = JSON.parse(JSON.stringify(this.selectedModel.directLogistic));
  1540. },
  1541. //搜索快递子项
  1542. searchExpress(e){
  1543. let val = e.target.value;
  1544. if (!val){
  1545. this.$set(this.searchItem,'express',null);
  1546. return;
  1547. }
  1548. let items = [];
  1549. this.model.express.items.forEach((item,i)=>{
  1550. if (this.poolMapping.provinces[item.province_id].indexOf(val) !== -1)items.push(i);
  1551. });
  1552. this.$set(this.searchItem,'express',items);
  1553. },
  1554. //搜索直发子项
  1555. searchDirectLogistic(e){
  1556. let val = e.target.value;
  1557. if (!val){
  1558. this.$set(this.searchItem,'directLogistic',null);
  1559. return;
  1560. }
  1561. let items = [];
  1562. this.model.directLogistic.items.forEach((item,i)=>{
  1563. if (this.poolMapping.cars[item.car_type_id].indexOf(val) !== -1)items.push(i);
  1564. });
  1565. this.$set(this.searchItem,'directLogistic',items);
  1566. },
  1567. //搜索物流子项
  1568. searchLogistic(e){
  1569. let val = e.target.value;
  1570. if (!val){
  1571. this.$set(this.searchItem,'logistic',null);
  1572. return;
  1573. }
  1574. let items = [];
  1575. this.model.logistic.items.forEach((item,i)=>{
  1576. if (item.unit_id || item.province_id || item.city_id){
  1577. if ((item.unit_id && this.poolMapping.units[item.unit_id].indexOf(val) !== -1) ||
  1578. (item.province_id && this.poolMapping.provinces[item.province_id].indexOf(val) !== -1) ||
  1579. (item.city_id && this.poolMapping.cities[item.city_id].indexOf(val) !== -1))items.push(i);
  1580. }
  1581. });
  1582. this.$set(this.searchItem,'logistic',items);
  1583. },
  1584. //增加阶梯满减阈值
  1585. addDiscount(arr){
  1586. this.model.operation.items.forEach(item=>{
  1587. item.discount_price.push('');
  1588. });
  1589. this.model.operation.total_discount_price.push("");
  1590. arr.push('');
  1591. },
  1592. //删除阶梯满减阈值
  1593. delDiscount(index){
  1594. this.model.operation.items.forEach((item,i)=>{
  1595. delete item.discount_price[index];
  1596. this.$set(this.model.operation.items,i,item);
  1597. });
  1598. this.$delete(this.model.operation.total_discount_price,index);
  1599. this.$delete(this.model.operation.discount_count,index);
  1600. },
  1601. //审核或恢复
  1602. auditOrRecoverModel(type,isAudit = true){
  1603. let url = "{{url('maintenance/priceModel/auditOrRecoverModel')}}";
  1604. let param = {owner_id:this.ownerTemp.id,type:type,isAudit:isAudit};
  1605. window.tempTip.confirm("确定要"+(isAudit ? '审核' : '恢复')+"上次的全部操作吗?",()=>{
  1606. window.tempTip.postBasicRequest(url,param,res=>{
  1607. switch (type){
  1608. case "storage":
  1609. this.selectedModel.storage = res;
  1610. break;
  1611. case "operation":
  1612. this._loadOperation();
  1613. res.forEach((operation,i)=>{res[i] = this._overrideOperation(operation);});
  1614. this.selectedModel.operation = res;
  1615. break;
  1616. case "express":
  1617. this._loadExpress();
  1618. res.forEach((express,i)=>{
  1619. res[i] = this._overrideExpress(express);
  1620. this.upList['express-item-'+i] = true;
  1621. });
  1622. this.selectedModel.express = res;
  1623. break;
  1624. case "logistic":
  1625. this._loadLogistic();
  1626. res.forEach((logistic,i)=>{
  1627. res[i] = this._overrideLogistic(logistic);
  1628. this.upList['logistic-item-'+i] = true;
  1629. });
  1630. this.selectedModel.logistic = res;
  1631. break;
  1632. case "directLogistic":
  1633. this._loadDirectLogistic();
  1634. this.upList["directLogistic-item"] = true;
  1635. this.selectedModel.directLogistic = this._overrideDirectLogistic(res[0]);
  1636. break;
  1637. }
  1638. this.$set(this.audit,type,false);
  1639. })
  1640. })
  1641. },
  1642. filterCustomer(e){
  1643. let value = $(e.target).val();
  1644. if (value===""){
  1645. this.filterCustomers=JSON.parse(JSON.stringify(this.customers));
  1646. return;
  1647. }
  1648. this.filterCustomers = this.customers.filter(function(item){
  1649. return item.name.includes(value);
  1650. })
  1651. },
  1652. filterOwnerGroup(e){
  1653. let value = $(e.target).val();
  1654. if (value===""){
  1655. this.filterOwnerGroups=JSON.parse(JSON.stringify(this.ownerGroups));
  1656. return;
  1657. }
  1658. this.filterOwnerGroups = this.ownerGroups.filter(function(item){
  1659. return item.name.includes(value);
  1660. })
  1661. },
  1662. filterUserGroup(e){
  1663. let value = $(e.target).val();
  1664. if (value===""){
  1665. this.filterCustomers=JSON.parse(JSON.stringify(this.customers));
  1666. return;
  1667. }
  1668. this.filterCustomers = this.customers.filter(function(item){
  1669. return item.name.includes(value);
  1670. })
  1671. },
  1672. },
  1673. });
  1674. </script>
  1675. @stop