create.blade.php 81 KB

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