index.blade.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. @extends('layouts.app')
  2. @section('title')计费模型-作业计费@endsection
  3. @section('content')
  4. <div id="nav2">
  5. @component('maintenance.menu')@endcomponent
  6. @component('maintenance.priceModel.operation.menu')@endcomponent
  7. </div>
  8. <div class="container-fluid mt-2" id="container">
  9. @include("maintenance.priceModel.operation._addOutStorageRuleModal")
  10. @include("maintenance.priceModel.operation._addFeature")
  11. <div id="form_div"></div>
  12. @if(Session::has('successTip'))
  13. <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
  14. @endif
  15. <table class="table table-hover table-striped text-nowrap">
  16. <tr>
  17. <th>序号</th>
  18. <th>操作</th>
  19. <th>名称</th>
  20. <th>类型</th>
  21. <th>策略</th>
  22. <th>项目</th>
  23. <th>计量</th>
  24. <th>单位</th>
  25. <th>单价</th>
  26. <th>优先级</th>
  27. <th>特征</th>
  28. <th>备注</th>
  29. <th>录入时间</th>
  30. <th>操作</th>
  31. </tr>
  32. <tr v-for="(model,i) in models" :id="'model-'+model.id">
  33. <td>@{{ i+1 }}</td>
  34. <td>
  35. <button v-if="model.operationType == '出库' && thisId != model.id" class="btn btn-sm btn-info" @click="showDetail(model.id)">维护详情</button>
  36. <button v-if="model.operationType == '出库' && thisId == model.id" class="btn btn-sm btn-dark" @click="thisId = ''">关闭详情</button>
  37. </td>
  38. <td>@{{ model.name }}</td>
  39. <td>@{{ model.operationType }}</td>
  40. <td>@{{ model.strategy }}</td>
  41. <td>
  42. <small v-for="owner in model.owners" class="m-0 font-weight-bold">@{{ owner.name }}<br></small>
  43. </td>
  44. <td>
  45. <label v-if="model.operationType == '出库'">/</label>
  46. <label v-else>@{{ model.ownerInStorageRuleAmount }}</label>
  47. </td>
  48. <td>
  49. <label v-if="model.operationType == '出库'">/</label>
  50. <label v-else>@{{ model.ownerInStorageRuleUnitName }}</label>
  51. </td>
  52. <td>
  53. <label v-if="model.operationType == '出库'">/</label>
  54. <label v-else>@{{ model.ownerInStorageRuleUnitPrice }}</label>
  55. </td>
  56. <td>@{{ model.priority }}</td>
  57. <td>@{{ model.feature }}</td>
  58. <td>@{{ model.remark }}</td>
  59. <td>@{{ model.createdAt }}</td>
  60. <td>
  61. @can("计费模型-作业-编辑")<button type="button" class="btn btn-sm btn-outline-info" @click="edit(model.id)">编辑</button>@endcan
  62. @can("计费模型-作业-删除")<button type="button" class="btn btn-sm btn-outline-danger" @click="delModel(model.id,i)">删除</button>@endcan
  63. </td>
  64. </tr>
  65. <tr id="detail" v-show="thisId">
  66. <td></td>
  67. <td colspan="9">
  68. <table class="table table-sm table-bordered">
  69. <tr class="text-success">
  70. <th>操作</th>
  71. <th>计费策略</th>
  72. <th>起步数</th>
  73. <th>单位</th>
  74. <th>单价</th>
  75. <th>优先级</th>
  76. <th class="text-center">特征</th>
  77. <th></th>
  78. </tr>
  79. <tr v-if="ownerOutStorageRules[thisId] && ownerOutStorageRules[thisId].length == 0">
  80. <td colspan="8">
  81. @can("计费模型-作业-编辑")<button class="btn btn-sm btn-outline-info" @click="showAddRuleModal()">新增</button>@endcan
  82. </td>
  83. </tr>
  84. <tr v-for="(item,i) in ownerOutStorageRules[thisId]">
  85. <td>
  86. <span v-if="updateDetailId != item.id">
  87. @can("计费模型-作业-编辑")<button class="btn btn-sm btn-outline-info" @click="showAddRuleModal()" v-if="i==0">新增</button>
  88. <button class="btn btn-sm btn-outline-info" @click="showUpdateDetail(item.id)">修改</button>@endcan
  89. </span>
  90. <span v-else>
  91. <button class="btn btn-sm btn-success" @click="submitUpdateDetail(item)">确定</button>
  92. <button class="btn btn-sm btn-danger" @click="updateDetailId = ''">取消</button>
  93. </span>
  94. </td>
  95. <td>@{{ item.strategy }}</td>
  96. <td>
  97. <label v-if="updateDetailId == item.id">
  98. <input type="number" min="0" id="detailAmount" class="form-control form-control-sm"
  99. :value="item.amount">
  100. </label>
  101. <label v-else>@{{ item.amount }}</label>
  102. </td>
  103. <td>
  104. <label v-if="updateDetailId == item.id">
  105. <select class="form-control form-control-sm" id="detailUnit">
  106. <option v-for="unit in units" :value="unit.id" v-if="unit.id==item.unit_id" selected>@{{ unit.name }}</option>
  107. <option v-for="unit in units" :value="unit.id" v-if="unit.id!=item.unit_id">@{{ unit.name }}</option>
  108. </select>
  109. </label>
  110. <label v-else>@{{ item.unit ? item.unit.name : '' }}</label>
  111. </td>
  112. <td>
  113. <label v-if="updateDetailId == item.id">
  114. <input type="number" min="0" step="0.001" id="detailUnitPrice" class="form-control form-control-sm"
  115. :value="item.unit_price">
  116. </label>
  117. <label v-else>@{{ item.unit_price }}</label>
  118. </td>
  119. <td>
  120. <label v-if="updateDetailId == item.id">
  121. <input type="number" min="0" id="detailPriority" class="form-control form-control-sm"
  122. :value="item.priority">
  123. </label>
  124. <label v-else>@{{ item.priority }}</label>
  125. </td>
  126. <td>@{{ item.featureFormat }}</td>
  127. <td>
  128. @can("计费模型-作业-编辑")<button class="btn btn-sm btn-success" v-if="item.strategy == '特征'" @click="showAddFeatureModal(i,item.feature)">维护特征</button>@endcan
  129. </td>
  130. </tr>
  131. </table>
  132. </td>
  133. </tr>
  134. </table>
  135. </div>
  136. @stop
  137. @section("lastScript")
  138. <script type="text/javascript" src="{{mix('js/queryForm/queryForm.js')}}"></script>
  139. <script>
  140. new Vue({
  141. el:"#container",
  142. data:{
  143. models : [
  144. @foreach($models as $model)
  145. {
  146. id : "{{$model->id}}",
  147. operationType : "{{$model->operation_type}}",
  148. name : "{{$model->name}}",
  149. strategy : "{{$model->strategy}}",
  150. feature : "{{$model->featureFormat}}",
  151. remark : "{{$model->remark}}",
  152. priority : "{{$model->priority}}",
  153. createdAt : "{{$model->created_at}}",
  154. ownerInStorageRuleAmount : "{{$model->ownerInStorageRule ? $model->ownerInStorageRule->amount : ''}}",
  155. ownerInStorageRuleUnitName : "{{$model->ownerInStorageRule ? ($model->ownerInStorageRule->unit ? $model->ownerInStorageRule->unit->name : '') : ''}}",
  156. ownerInStorageRuleUnitPrice : "{{$model->ownerInStorageRule ? $model->ownerInStorageRule->unit_price : ''}}",
  157. owners : {!! $model->ownerPriceOperationOwners !!},
  158. },
  159. @endforeach
  160. ],
  161. owners : [
  162. @foreach($owners as $owner)
  163. {name:"{{$owner->id}}",value:"{{$owner->name}}"},
  164. @endforeach
  165. ],
  166. thisId : "",
  167. ownerOutStorageRules : [],
  168. updateDetailId : '',
  169. units : null,
  170. type : ['商品名称','订单类型','承运商','店铺类型'],
  171. logic : ['包含','不包含','等于'],
  172. rule : {
  173. "strategy" : '特征',
  174. "amount" : "",
  175. "unit_id" : "",
  176. "unit_price" : "",
  177. "priority" : 0,
  178. },
  179. thisRuleIndex : "",
  180. features : [],
  181. existStrategy:{default:false,starting:false},
  182. },
  183. mounted(){
  184. let data=[
  185. [
  186. {name:'owner_id',type:'select_multiple_select',tip:['输入关键词快速定位下拉列表,回车确定','选择要显示的项目'],
  187. placeholder:['项目','定位或多选项目'],data:this.owners},
  188. {name: 'name', type: 'input', tip: '价格名称:可在左侧增加百分号(%)进行模糊搜索', placeholder: '价格名称'},
  189. ]
  190. ];
  191. this.form = new query({
  192. el:"#form_div",
  193. condition:data,
  194. });
  195. this.form.init();
  196. },
  197. methods:{
  198. showDetail(id){
  199. if (this.ownerOutStorageRules[id]){
  200. this.thisId = id;
  201. $("#model-"+id).after($("#detail"));
  202. return;
  203. }
  204. window.axios.post("{{url('maintenance/priceModel/operation/getOutStorageRule')}}",{id:id})
  205. .then(res=>{
  206. if (res.data.success){
  207. this.ownerOutStorageRules[id] = res.data.data;
  208. this.thisId = id;
  209. $("#model-"+id).after($("#detail"));
  210. return;
  211. }
  212. window.tempTip.setDuration(3000);
  213. window.tempTip.show(res.data.data);
  214. }).catch(err=>{
  215. window.tempTip.setDuration(3000);
  216. window.tempTip.show("网络错误:"+err);
  217. });
  218. },
  219. showUpdateDetail(id){
  220. if (!this.units)this._getUnits();
  221. this.updateDetailId = id;
  222. },
  223. _getUnits(){
  224. window.axios.post("{{url('maintenance/unit/getUnits')}}")
  225. .then(res=>{
  226. if (res.data.success){
  227. this.units = res.data.data;
  228. return;
  229. }
  230. window.tempTip.setDuration(3000);
  231. window.tempTip.show(res.data.data);
  232. }).catch(err=>{
  233. window.tempTip.setDuration(3000);
  234. window.tempTip.show("网络错误:"+err);
  235. });
  236. },
  237. submitUpdateDetail(item){
  238. let amount = $("#detailAmount").val();
  239. let unit_id = $("#detailUnit").val();
  240. let unit_price = $("#detailUnitPrice").val();
  241. let priority = $("#detailPriority").val();
  242. window.axios.post("{{url('maintenance/priceModel/operation/updateOutStorageRule')}}",
  243. {id:item.id,amount:amount,unit_id:unit_id,unit_price:unit_price,priority:priority})
  244. .then(res=>{
  245. if (res.data.success){
  246. item.amount = amount;
  247. if (item.unit_id != unit_id){
  248. this.units.some((unit)=>{
  249. if (unit_id == unit.id){
  250. item.unit = unit;
  251. return true;
  252. }
  253. });
  254. item.unit_id = unit_id;
  255. }
  256. item.unit_price = unit_price;
  257. item.priority = priority;
  258. this.updateDetailId = '';
  259. window.tempTip.setDuration(2000);
  260. window.tempTip.showSuccess("修改成功");
  261. return;
  262. }
  263. window.tempTip.setDuration(3000);
  264. window.tempTip.show(res.data.data);
  265. }).catch(err=>{
  266. window.tempTip.setDuration(3000);
  267. window.tempTip.show("网络错误:"+err);
  268. });
  269. },
  270. showAddRuleModal(){
  271. if (!this.units)this._getUnits();
  272. let startingSign = true;
  273. let defaultSign = true;
  274. this.ownerOutStorageRules[this.thisId].forEach(rule=>{
  275. if (rule.strategy == '默认')defaultSign = false;
  276. if (rule.strategy == '起步')startingSign = false;
  277. });
  278. if (!startingSign)this.existStrategy.starting = true;
  279. if (!defaultSign)this.existStrategy.default = true;
  280. $("#addOutStorageRule").modal("show");
  281. },
  282. submitRule(){
  283. if (!this.thisId || !this.rule.strategy || !this.rule.unit_id || !this.rule.unit_price){
  284. window.tempTip.setDuration(3000);
  285. window.tempTip.show("计费策略,单位,单价为必填项");
  286. return;
  287. }
  288. window.axios.post("{{url('maintenance/priceModel/operation/createOutStorageRule')}}",
  289. {owner_price_operation_id:this.thisId,strategy:this.rule.strategy,amount:this.rule.amount,unit_id:this.rule.unit_id,unit_price:this.rule.unit_price,priority:Number(this.rule.priority)})
  290. .then(res=>{
  291. if (res.data.success){
  292. this.ownerOutStorageRules[this.thisId].unshift(res.data.data);
  293. this.$forceUpdate();
  294. window.tempTip.setDuration(2000);
  295. window.tempTip.setIndex(1099);
  296. window.tempTip.showSuccess("新增出库策略成功");
  297. $("#addOutStorageRule").modal("hide");
  298. return;
  299. }
  300. window.tempTip.setDuration(3000);
  301. window.tempTip.setIndex(1099);
  302. window.tempTip.show(res.data.data);
  303. }).catch(err=>{
  304. window.tempTip.setDuration(3000);
  305. window.tempTip.show("网络错误:"+err);
  306. });
  307. },
  308. showAddFeatureModal(index,feature){
  309. window.axios.post("{{url('maintenance/priceModel/operation/getFeatures')}}", {feature:feature})
  310. .then(res=>{
  311. if (res.data.success){
  312. this.features = res.data.data;
  313. if (this.features.length === 0)this.addFeature();
  314. this.thisIndex = index;
  315. $("#addFeatureModal").modal("show");
  316. return;
  317. }
  318. window.tempTip.setDuration(3000);
  319. window.tempTip.show(res.data.data);
  320. }).catch(err=>{
  321. window.tempTip.setDuration(3000);
  322. window.tempTip.show("网络错误:"+err);
  323. });
  324. },
  325. addFeature(){
  326. this.features.push({
  327. "strategyGroupStartSign": false,
  328. "calculation" : "",
  329. "type" : "",
  330. "id" : "", //特征ID
  331. "logic" : "", //特征逻辑
  332. "describe" : "", //特征信息
  333. "strategyGroupEndSign" : false,
  334. });
  335. },
  336. delFeature(index) {
  337. this.$delete(this.features,index);
  338. },
  339. submitFeature(){
  340. window.axios.post("{{url('maintenance/priceModel/operation/addFeature')}}",
  341. {id:this.ownerOutStorageRules[this.thisId][this.thisIndex].id,features:this.features})
  342. .then(res=>{
  343. if (res.data.success){
  344. this.ownerOutStorageRules[this.thisId][this.thisIndex].featureFormat = res.data.data.featureFormat;
  345. this.ownerOutStorageRules[this.thisId][this.thisIndex].feature = res.data.data.feature;
  346. this.$forceUpdate();
  347. $("#addFeatureModal").modal("hide");
  348. window.tempTip.setDuration(2000);
  349. window.tempTip.setIndex(1099);
  350. window.tempTip.showSuccess("已更新特征");
  351. return;
  352. }
  353. window.tempTip.setDuration(3000);
  354. window.tempTip.setIndex(1099);
  355. window.tempTip.show(res.data.data);
  356. }).catch(err=>{
  357. window.tempTip.setDuration(3000);
  358. window.tempTip.setIndex(1099);
  359. window.tempTip.show("网络错误:"+err);
  360. });
  361. },
  362. delModel(id,index){
  363. window.tempTip.confirm("确定要删除该作业计费吗?",()=>{
  364. window.axios.delete("{{url('maintenance/priceModel/operation')}}/"+id)
  365. .then(res=>{
  366. if (res.data.success){
  367. this.$delete(this.models,index);
  368. window.tempTip.setDuration(2000);
  369. window.tempTip.showSuccess("已成功删除该条作业计费");
  370. return;
  371. }
  372. window.tempTip.setDuration(3000);
  373. window.tempTip.show(res.data.data);
  374. }).catch(err=>{
  375. window.tempTip.setDuration(3000);
  376. window.tempTip.show("网络错误:"+err);
  377. });
  378. });
  379. },
  380. edit(id){
  381. window.location.href = "{{url('maintenance/priceModel/operation')}}/"+id+"/edit";
  382. }
  383. },
  384. });
  385. </script>
  386. @stop