index.blade.php 19 KB

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