create.blade.php 79 KB

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