create.blade.php 82 KB

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