create.blade.php 79 KB

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