create.blade.php 74 KB

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