create.blade.php 72 KB

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