create.blade.php 79 KB

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