create.blade.php 81 KB

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