create.blade.php 83 KB

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