create.blade.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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" 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' && !owner.ownerStoragePriceModels) ? '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. <form method="POST" action="{{url('customer/project/store')}}" class="mt-5">
  56. @csrf
  57. <div v-if="base == 'one'">
  58. @include("customer.project._one")
  59. </div>
  60. <div v-if="base == 'two'">
  61. @include("customer.project._two")
  62. </div>
  63. <div v-if="base == 'three'">
  64. @include("customer.project._three")
  65. </div>
  66. <div class="row mt-3">
  67. <div class="pull-right offset-7">
  68. <button type="button" class="btn btn-info ml-1 text-white" v-show="base !== 'one'" @click="back()">上一步</button>
  69. <button type="button" class="btn btn-info ml-1 text-white" v-show="base !== 'three'" @click="next()">下一步</button>
  70. <button type="button" class="btn btn-success ml-1">完成</button>
  71. <button type="button" class="btn btn-secondary ml-1">重置</button>
  72. </div>
  73. </div>
  74. </form>
  75. </div>
  76. </div>
  77. @stop
  78. @section('lastScript')
  79. <script>
  80. new Vue({
  81. el:"#container",
  82. data:{
  83. base:"one",
  84. owner : {
  85. id:"{{old('id') ?? ($owner->id ?? '') }}",
  86. name : "{{old('name') ?? ($owner->name ?? '')}}",
  87. code : "{{old('code') ?? ($owner->code ?? '')}}",
  88. customer_id : "{{old('customer_id') ?? ($owner->customer_id ?? '')}}",
  89. customer_name : "{{ isset($owner) ? ($owner->customer ? $owner->customer->name : '') : ''}}",
  90. owner_group_name : "{{ isset($owner) ? ($owner->userOwnerGroup ? $owner->userOwnerGroup->name : '') : ''}}",
  91. owner_group_id : "{{old('owner_group_id') ?? ($owner->user_owner_group_id ?? '')}}",
  92. tax_rate : "{{old('tax_rate') ?? ($owner->tax_rate ?? '')}}",
  93. linkman : "{{old('linkman') ?? ($owner->linkman ?? '')}}",
  94. phone_number : "{{old('phone_number') ?? ($owner->phone_number ?? '')}}",
  95. description : "{{old('description') ?? ($owner->description ?? '')}}",
  96. waring_line_on : "{{old('waring_line_on') ?? ($owner->waring_line_on ?? '')}}",
  97. },
  98. ownerTemp : {
  99. id:"{{$owner->id ?? ''}}",
  100. name : "{{$owner->name ?? ''}}",
  101. code : "{{$owner->code ?? ''}}",
  102. customer_id : "{{$owner->customer_id ?? ''}}",
  103. customer_name : "{{ isset($owner) ? ($owner->customer ? $owner->customer->name : '') : ''}}",
  104. owner_group_name : "{{ isset($owner) ? ($owner->userOwnerGroup ? $owner->userOwnerGroup->name : '') : ''}}",
  105. owner_group_id : "{{$owner->user_owner_group_id ?? ''}}",
  106. owner_storage_price_model_id : "{{$owner->owner_storage_price_model_id ?? ''}}".split(','),
  107. tax_rate : "{{$owner->tax_rate ?? ''}}",
  108. linkman : "{{$owner->linkman ?? ''}}",
  109. phone_number : "{{$owner->phone_number ?? ''}}",
  110. description : "{{$owner->description ?? ''}}",
  111. waring_line_on : "{{$owner->waring_line_on ?? ''}}",
  112. },
  113. storagePriceModels : [
  114. @foreach($storagePriceModels as $storagePriceModel)
  115. { id:"{{$storagePriceModel->id}}",
  116. counting_type : "{{$storagePriceModel->counting_type}}",
  117. using_type : "{{$storagePriceModel->using_type}}",
  118. minimum_area : "{{$storagePriceModel->minimum_area}}",
  119. price : "{{$storagePriceModel->price}}",
  120. unit_name : "{{$storagePriceModel->unit ? $storagePriceModel->unit->name : ''}}",
  121. },
  122. @endforeach
  123. ],
  124. customers : [
  125. @foreach($customers as $customer)
  126. {id:"{{$customer->id}}",name:"{{$customer->name}}"},
  127. @endforeach
  128. ],
  129. ownerGroups : [
  130. @foreach($ownerGroups as $ownerGroup)
  131. {id:"{{$ownerGroup->id}}",name:"{{$ownerGroup->name}}"},
  132. @endforeach
  133. ],
  134. style : '',
  135. errors : {!! $errors !!}, //全部的错误提示
  136. display:false,
  137. upList:{ //控制元素的渐入展开与收起
  138. storage : false,
  139. },
  140. type:"storage",//当前编辑类型 仓储,作业,物流...
  141. model:{ //编辑元素绑定值
  142. storage:{
  143. counting_type : "",
  144. using_type : "",
  145. minimum_area : "",
  146. price : "",
  147. discount_type : "无减免",
  148. discount_value : "",
  149. unit_id : "",
  150. },
  151. operation:{
  152. operation_type:"入库",
  153. strategy:"默认",
  154. name:"",
  155. feature:"",
  156. items : [
  157. {strategy:"起步"},
  158. {strategy:"默认"},
  159. {strategy:"特征"},
  160. ],
  161. },
  162. },
  163. pool:{//基础数据选择池,以方便异步懒加载而非即时加载 例:units,owners等
  164. counting_type:[
  165. "包仓","灵活用仓","统单价"
  166. ],
  167. using_type:[
  168. "常温","恒温"
  169. ],
  170. discount_type:[
  171. "无减免","按单减免","固定减免"
  172. ],
  173. },
  174. poolMapping:{//基础数据选择池的映射对象 供展示使用
  175. },
  176. selectedModel:{//已选定的计费模型
  177. storage:[],
  178. },
  179. thisOperationItemIndex:-1,//当前选中的作业费子项下标,用以唤起特征模态框
  180. oldFeature:"",//上一个特征,如果与当前特征一致则无需再次转换特征
  181. },
  182. mounted(){
  183. if (this.errors.length===0 && this.owner.id){
  184. this.display = true;
  185. }
  186. },
  187. methods:{
  188. //收起展开
  189. show(id){
  190. if (this.upList[id])$("#"+id).slideDown();
  191. else $("#"+id).slideUp();
  192. this.upList[id] = !this.upList[id];
  193. },
  194. //切换选项
  195. switchBase(base){
  196. if (base === 'three') this._loadStorage();
  197. if (base === this.base)return;
  198. this.base = base;
  199. },
  200. //切换类型
  201. switchType(type){
  202. if (type === this.type)return;//相同终止是为了减少重复加载动作
  203. switch (type) {
  204. case "storage":
  205. this._loadStorage();
  206. break;
  207. case "operation":
  208. this._loadOperation();
  209. break;
  210. }
  211. this.type = type;
  212. },
  213. //下一步
  214. next(){
  215. switch (this.base) {
  216. case "one":
  217. this._verifyOne();
  218. break;
  219. case "two":
  220. this._verifyTwo();
  221. break;
  222. default:
  223. this._loadStorage();
  224. break;
  225. }
  226. },
  227. //验证基础信息
  228. _verifyOne(){
  229. if (!this.owner.name){
  230. this.errors["name"] = ["项目名称为必填项"];
  231. this.$forceUpdate();
  232. return;
  233. }
  234. if (!this.owner.code){
  235. this.errors["code"] = ["项目代码为必填项"];
  236. this.$forceUpdate();
  237. return;
  238. }
  239. this._requestRequest({name:this.owner.name,code:this.owner.code},"two")
  240. },
  241. //验证详细描述
  242. _verifyTwo(){
  243. if (!this.owner.customer_id){
  244. this.errors["customer_id"] = ["必须选择客户"];
  245. this.$forceUpdate();
  246. }
  247. if (!this.owner.owner_group_id){
  248. this.errors["owner_group_id"] = ["必须选择项目小组"];
  249. this.$forceUpdate();
  250. }
  251. /* this._requestRequest({
  252. customer_id:this.owner.customer_id,
  253. owner_group_id:this.owner.owner_group_id,
  254. tax_rate:this.owner.tax_rate,
  255. waring_line_on:this.owner.waring_line_on,
  256. },"three")*/
  257. },
  258. //上一步
  259. back(){
  260. switch (this.base) {
  261. case "two":
  262. this.base = 'one';
  263. break;
  264. case "three":
  265. this.base = 'two';
  266. break;
  267. }
  268. },
  269. //请求验证
  270. _requestRequest(params, next){
  271. let url = "{{url('customer/project/verify')}}";
  272. window.tempTip.postBasicRequest(url,params,res=>{
  273. if (res.length > 0){
  274. this.errors = res;
  275. this.$forceUpdate();
  276. }else{
  277. this.base = next;
  278. this.errors = [];
  279. }
  280. });
  281. },
  282. //加载仓储所需基础信息
  283. _loadStorage(){
  284. if (!this.pool.units)this._getUnits();
  285. },
  286. //加载作业
  287. _loadOperation(){
  288. if (!this.pool.units)this._getUnits();
  289. },
  290. //获取单位
  291. _getUnits(){
  292. let url = "{{url('maintenance/unit/getUnits')}}";
  293. window.tempTip.postBasicRequest(url,{},res=>{
  294. this.pool.units = res;
  295. let mapping = [];
  296. res.forEach(unit=>{
  297. mapping[unit.id] = unit.name;
  298. });
  299. this.poolMapping.units = mapping;
  300. this.$forceUpdate();
  301. });
  302. },
  303. //保存模型
  304. saveModel(){
  305. switch (this.type) {
  306. case "storage":
  307. this._verifyStorage();
  308. break;
  309. }
  310. },
  311. _verifyStorage(){
  312. if (!this.model.storage.counting_type){
  313. this.errors["counting_type"] = ["未选择计费类型"];
  314. this.$forceUpdate();
  315. return;
  316. }
  317. if (!this.model.storage.using_type){
  318. this.errors["using_type"] = ["未选择用仓类型"];
  319. this.$forceUpdate();
  320. return;
  321. }
  322. if (!this.model.storage.price){
  323. this.errors["price"] = ["未输入单价"];
  324. this.$forceUpdate();
  325. return;
  326. }
  327. if (!this.model.storage.discount_type){
  328. this.errors["discount_type"] = ["未选择减免类型"];
  329. this.$forceUpdate();
  330. return;
  331. }
  332. this.selectedModel.storage.unshift(this.model.storage);
  333. this.model.storage = {
  334. counting_type : "",
  335. using_type : "",
  336. minimum_area : "",
  337. price : "",
  338. discount_type : "无减免",
  339. discount_value : "",
  340. unit_id : "",
  341. };
  342. this.errors = [];
  343. },
  344. //增加作业费特征子项
  345. addOperationItem(){
  346. this.model.operation.items.push({
  347. strategy:"特征"
  348. });
  349. },
  350. //删除作业费子项
  351. delOperationItem(index){
  352. this.$delete(this.model.operation.items,index);
  353. },
  354. //显示特征选择modal
  355. showAddFeatureModal(index,feature){
  356. if (!feature){
  357. this.model.operation.items[index].features = [{
  358. "strategyGroupStartSign": false,
  359. "calculation" : "",
  360. "type" : "",
  361. "id" : "",
  362. "logic" : "",
  363. "describe" : "",
  364. "strategyGroupEndSign" : false,
  365. }];
  366. this.thisOperationItemIndex = index;
  367. $("#addFeatureModal").modal("show");
  368. return;
  369. }
  370. if (this.oldFeature === feature) {
  371. this.thisOperationItemIndex = index;
  372. $("#addFeatureModal").modal("show");
  373. return;
  374. }
  375. let url = "{{url('maintenance/priceModel/operation/getFeatures')}}";
  376. window.tempTip.postBasicRequest(url,{feature:feature},res=>{
  377. this.features = res.data.data;
  378. this.oldFeature = feature;
  379. if (!this.features || this.features.length === 0){
  380. this.features = [{
  381. "strategyGroupStartSign": false,
  382. "calculation" : "",
  383. "type" : "",
  384. "id" : "", //特征ID
  385. "logic" : "", //特征逻辑
  386. "describe" : "", //特征信息
  387. "strategyGroupEndSign" : false,
  388. }];
  389. }
  390. this.thisOperationItemIndex = index;
  391. $("#addFeatureModal").modal("show");
  392. });
  393. },
  394. },
  395. });
  396. </script>
  397. @stop