create.blade.php 85 KB

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