info.blade.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. @extends('layouts.base')
  2. @section('title', '编辑配送模板')
  3. @section('content')
  4. <link rel="stylesheet" type="text/css" href="{{static_url('yunshop/goods/vue-goods1.css')}}"/>
  5. <div class="all">
  6. <div id="app" v-cloak>
  7. <div class="vue-crumbs">
  8. <a @click="goParent">配送模板</a> > 配送方式设置
  9. </div>
  10. <div class="vue-main">
  11. <div class="vue-main-title">
  12. <div class="vue-main-title-left"></div>
  13. <div class="vue-main-title-content">配送方式设置</div>
  14. </div>
  15. <div class="vue-main-form">
  16. <el-form ref="form" :model="form" :rules="rules" label-width="15%">
  17. <el-form-item label="排序" prop="display_order">
  18. <el-input v-model="form.display_order" style="width:70%;"></el-input>
  19. </el-form-item>
  20. <el-form-item label="配送方式名称" prop="dispatch_name">
  21. <el-input v-model="form.dispatch_name" style="width:70%;"></el-input>
  22. </el-form-item>
  23. <el-form-item label="计算方式" prop="calculate_type">
  24. <el-radio v-model.number="form.calculate_type" :label="0">按重量计费</el-radio>
  25. <el-radio v-model.number="form.calculate_type" :label="1">按件计费</el-radio>
  26. </el-form-item>
  27. <el-form-item label="配送区域" prop="explain_content">
  28. <table class="el-table" style="width:90%">
  29. <tr style="border-bottom:1px solid #EBEEF5">
  30. <th style="width:40%">运送到</th>
  31. <th>[[form.calculate_type==1?'首件(个)':'首重(克)']]</th>
  32. <th>[[form.calculate_type==1?'运费(元)':'首费(元)']]</th>
  33. <th>[[form.calculate_type==1?'续件(个)':'续重(克)']]</th>
  34. <th>续费(元)</th>
  35. <th style="width:80px">操作</th>
  36. </tr>
  37. <tr v-if="form.calculate_type==1">
  38. <td>
  39. 全国【默认运费】
  40. </td>
  41. <td>
  42. <el-input v-model="form.first_piece" style="width:80%"></el-input>
  43. </td>
  44. <td>
  45. <el-input v-model="form.first_piece_price" style="width:80%"></el-input>
  46. </td>
  47. <td>
  48. <el-input v-model="form.another_piece" style="width:80%"></el-input>
  49. </td>
  50. <td>
  51. <el-input v-model="form.another_piece_price" style="width:80%"></el-input>
  52. </td>
  53. <td>
  54. </td>
  55. </tr>
  56. <tr v-else>
  57. <td>
  58. 全国【默认运费】
  59. </td>
  60. <td>
  61. <el-input v-model="form.first_weight" style="width:80%"></el-input>
  62. </td>
  63. <td>
  64. <el-input v-model="form.first_weight_price" style="width:80%"></el-input>
  65. </td>
  66. <td>
  67. <el-input v-model="form.another_weight" style="width:80%"></el-input>
  68. </td>
  69. <td>
  70. <el-input v-model="form.another_weight_price" style="width:80%"></el-input>
  71. </td>
  72. <td>
  73. </td>
  74. </tr>
  75. <tr v-if="form.calculate_type==1" v-for="(item,index) in piece" :key="index">
  76. <td>
  77. <!-- <div style="font-size:12px;font-weight:600;line-height:18px;margin-right: 15px">
  78. <span v-for="(item1,index1) in item.areas" :key="index1">[[item1]];</span>
  79. </div> -->
  80. <div style="font-size:12px;font-weight:600;line-height:18px;margin-right: 15px">
  81. [[item.areas]]
  82. </div>
  83. <el-button size="small" @click="openVisible('piece',index)">选择区域</el-button>
  84. </td>
  85. <td>
  86. <el-input v-model="item.first_piece" style="width:80%"></el-input>
  87. </td>
  88. <td>
  89. <el-input v-model="item.first_piece_price" style="width:80%"></el-input>
  90. </td>
  91. <td>
  92. <el-input v-model="item.another_piece" style="width:80%"></el-input>
  93. </td>
  94. <td>
  95. <el-input v-model="item.another_piece_price" style="width:80%"></el-input>
  96. </td>
  97. <td>
  98. <el-link :underline="false" @click="delList('piece',index)" class="vue-assist-color"> 删除</el-link>
  99. </td>
  100. </tr>
  101. <tr v-if="!form.calculate_type || form.calculate_type==0" v-for="(item,index) in weight" :key="index">
  102. <td>
  103. <!-- <div style="font-size:12px;font-weight:600;line-height:18px;margin-right: 15px">
  104. <span v-for="(item1,index1) in item.areas" :key="index1">[[item1]];</span>
  105. </div> -->
  106. <div style="font-size:12px;font-weight:600;line-height:18px;margin-right: 15px">
  107. [[item.areas]]
  108. </div>
  109. <el-button size="small" @click="openVisible('weight',index)">选择区域</el-button>
  110. </td>
  111. <td>
  112. <el-input v-model="item.first_weight" style="width:80%"></el-input>
  113. </td>
  114. <td>
  115. <el-input v-model="item.first_weight_price" style="width:80%"></el-input>
  116. </td>
  117. <td>
  118. <el-input v-model="item.another_weight" style="width:80%"></el-input>
  119. </td>
  120. <td>
  121. <el-input v-model="item.another_weight_price" style="width:80%"></el-input>
  122. </td>
  123. <td>
  124. <el-link :underline="false" @click="delList('weight',index)" class="vue-assist-color"> 删除</el-link>
  125. </td>
  126. </tr>
  127. </table>
  128. <el-button type="primary" plain icon="el-icon-plus" size="small" @click="addList">新增配送区域</el-button>
  129. <div class="tip" v-if="form.calculate_type==1">根据件数来计算运费,当物品不足《首件数量》时,按照《首件费用》计算,超过部分按照《续件数量》和《续件费用》乘积来计算</div>
  130. <div class="tip" v-else>根据重量来计算运费,当物品不足《首重重量》时,按照《首重费用》计算,超过部分按照《续重重量》和《续重费用》乘积来计算</div>
  131. </el-form-item>
  132. <el-form-item label="是否为默认快递模板" prop="is_default">
  133. <el-switch v-model="form.is_default" :active-value="1" :inactive-value="0"></el-switch>
  134. </el-form-item>
  135. <el-form-item label="是否显示" prop="enabled">
  136. <el-switch v-model="form.enabled" :active-value="1" :inactive-value="0"></el-switch>
  137. </el-form-item>
  138. </el-form>
  139. </div>
  140. </div>
  141. <!-- 分页 -->
  142. <div class="vue-page">
  143. <div class="vue-center">
  144. <el-button type="primary" @click="submitForm('form')">保存设置</el-button>
  145. <el-button @click="goBack">返回</el-button>
  146. </div>
  147. </div>
  148. <el-dialog title="请选择地区" :visible.sync="centerDialogVisible" center v-if="chooseIndex!=-1&&showVisible" :before-close="beforeClose">
  149. <el-tree
  150. v-loading="loading"
  151. :props="props"
  152. node-key="id"
  153. :default-checked-keys="chooseItem.area_ids"
  154. :default-expanded-keys="chooseItem.province_ids"
  155. show-checkbox
  156. lazy
  157. @check-change="checkAreas"
  158. ref="addressTree"
  159. :data="treeData"
  160. :load="loadNode"
  161. style="height:500px;overflow:auto"
  162. >
  163. </el-tree>
  164. <span slot="footer" class="dialog-footer">
  165. <el-button @click="beforeClose">取 消</el-button>
  166. <el-button type="primary" @click="saveAreas">确 定</el-button>
  167. </span>
  168. </el-dialog>
  169. </div>
  170. </div>
  171. <script>
  172. var app = new Vue({
  173. el:"#app",
  174. delimiters: ['[[', ']]'],
  175. name: 'test',
  176. data() {
  177. let id = {!! $id?:0 !!};
  178. console.log(id);
  179. return{
  180. id:id,
  181. submit_link:'',
  182. piece:[],//按件计费-区域数据
  183. weight:[],//按重量计费-区域数据
  184. form:{
  185. areas:'全国 [默认运费]',
  186. first_weight:'0',
  187. first_weight_price:'0',
  188. another_weight:'0',
  189. another_weight_price:'0',
  190. },
  191. chooseIndex:-1,
  192. chooseName:'weight',
  193. chooseItem:{},
  194. chooseAreas:[],
  195. chooseAreaIds:[],
  196. chooseProvinceIds:[],
  197. centerDialogVisible:false,
  198. showVisible:false,
  199. props: {
  200. label: 'areaname',
  201. children: 'children',
  202. isLeaf: 'isLeaf'
  203. },
  204. loading: false,
  205. treeData: [],
  206. rules:{
  207. dispatch_name:{ required: true, message: '请输入配送方式名称'}
  208. },
  209. }
  210. },
  211. created() {
  212. },
  213. mounted() {
  214. let json = {};
  215. if(!this.id) {
  216. this.submit_link = '{!! yzWebFullUrl('goods.dispatch.add') !!}';
  217. }
  218. else {
  219. this.submit_link = '{!! yzWebFullUrl('goods.dispatch.edit') !!}';
  220. json.id = this.id;
  221. }
  222. this.getData(json);
  223. },
  224. methods: {
  225. getData(json) {
  226. let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
  227. this.$http.post(this.submit_link,json).then(function (response) {
  228. if (response.data.result){
  229. this.form = {
  230. ...response.data.data.dispatch,
  231. enabled:response.data.data.dispatch.enabled || 0,
  232. calculate_type:response.data.data.dispatch.calculate_type || 0,
  233. is_default:response.data.data.dispatch.is_default || 0,
  234. areas:response.data.data.dispatch.areas || '全国 [默认运费]',
  235. };
  236. // 兼容旧的数据格式
  237. if(response.data.data.dispatch.weight_data instanceof Object == true) {
  238. for(var i in response.data.data.dispatch.weight_data) {
  239. console.log(response.data.data.dispatch.weight_data[i])
  240. this.weight.push(response.data.data.dispatch.weight_data[i])
  241. }
  242. }
  243. else {
  244. this.weight = response.data.data.dispatch.weight_data || [];
  245. }
  246. if(response.data.data.dispatch.piece_data instanceof Object == true) {
  247. for(var i in response.data.data.dispatch.piece_data) {
  248. console.log(response.data.data.dispatch.piece_data[i])
  249. this.piece.push(response.data.data.dispatch.piece_data[i])
  250. }
  251. }
  252. else {
  253. this.piece = response.data.data.dispatch.piece_data || [];
  254. }
  255. // this.form.enabled = 1;
  256. console.log(this.piece_data)
  257. // console.log(this.form)
  258. }
  259. else {
  260. this.$message({message: response.data.msg,type: 'error'});
  261. }
  262. loading.close();
  263. },function (response) {
  264. this.$message({message: response.data.msg,type: 'error'});
  265. loading.close();
  266. }
  267. );
  268. },
  269. goParent() {
  270. window.location.href = `{!! yzWebFullUrl('goods.dispatch.index') !!}`;
  271. },
  272. submitForm(formName) {
  273. let that = this;
  274. let json = this.form;
  275. json.weight = this.weight;
  276. json.piece = this.piece;
  277. let json1 = {
  278. dispatch:json
  279. }
  280. if(this.id) {
  281. json1.id = this.id
  282. }
  283. this.$refs[formName].validate((valid) => {
  284. if (valid) {
  285. let loading = this.$loading({target:document.querySelector(".content"),background: 'rgba(0, 0, 0, 0)'});
  286. this.$http.post(this.submit_link,json1).then(response => {
  287. if (response.data.result) {
  288. this.$message({type: 'success',message: '操作成功!'});
  289. this.goBack();
  290. } else {
  291. this.$message({message: response.data.msg,type: 'error'});
  292. }
  293. loading.close();
  294. },response => {
  295. loading.close();
  296. });
  297. }
  298. else {
  299. console.log('error submit!!');
  300. return false;
  301. }
  302. });
  303. },
  304. addList() {
  305. if(this.form.calculate_type==1) {
  306. this.piece.push(
  307. {areas:"",area_ids:"",province_ids:[],first_piece:this.form.first_piece,first_piece_price:this.form.first_piece_price,another_piece:this.form.another_piece,another_piece_price:this.form.another_piece_price}
  308. )
  309. }
  310. else {
  311. console.log(this.weight)
  312. this.weight.push(
  313. {areas:"",area_ids:"",province_ids:[],first_weight:this.form.first_weight,first_weight_price:this.form.first_weight_price,another_weight:this.form.another_weight,another_weight_price:this.form.another_weight_price}
  314. )
  315. }
  316. },
  317. delList(name,index) {
  318. if(name == "weight") {
  319. this.weight.splice(index,1);
  320. }
  321. else if(name == 'piece') {
  322. this.piece.splice(index,1);
  323. }
  324. },
  325. handleClose(area) {
  326. this.form.areas.splice(this.form.areas.indexOf(area), 1);
  327. },
  328. openVisible(name,index) {
  329. this.centerDialogVisible = true;
  330. this.showVisible = true;
  331. this.chooseName = name;
  332. this.chooseIndex = index;
  333. this.chooseItem = {};
  334. if(name == "weight") {
  335. this.chooseItem = JSON.parse(JSON.stringify(this.weight[index]));
  336. this.chooseItem.area_ids = this.weight[index].area_ids.split(";");
  337. this.chooseItem.area_ids.forEach((item,index) => {
  338. this.chooseItem.area_ids[index] = Number(item)
  339. });
  340. this.chooseItem.areas = this.weight[index].areas.split(";");
  341. }
  342. else if(name == "piece") {
  343. this.chooseItem = JSON.parse(JSON.stringify(this.piece[index]));
  344. this.chooseItem.area_ids = this.piece[index].area_ids.split(";");
  345. this.chooseItem.area_ids.forEach((item,index) => {
  346. this.chooseItem.area_ids[index] = Number(item)
  347. });
  348. // this.chooseItem.area_ids = this.piece[index].area_ids.split(";");
  349. this.chooseItem.areas = this.piece[index].areas.split(";");
  350. }
  351. console.log(this.chooseItem)
  352. },
  353. loadNode(node, resolve) {
  354. this.loading = true;
  355. if (!node.data.id) {
  356. //省份
  357. node.data.id = 0;
  358. this.$http.get("{!! yzWebUrl('area.list', ['parent_id'=> 0]) !!}").then(response => {
  359. response.data.data.forEach(function (province) {
  360. province.isLeaf = false;
  361. });
  362. resolve(response.data.data);
  363. this.loading = false;
  364. }, response => {
  365. console.log(response);
  366. });
  367. } else {
  368. //城市
  369. this.$http.get("{!! yzWebUrl('area.list', ['parent_id'=> '']) !!}" + node.data.id).then(response => {
  370. //城市没有子节点
  371. response.data.data.forEach(function (city) {
  372. city.isLeaf = true;
  373. })
  374. resolve(response.data.data);
  375. // 载入数据后,刷新已选中
  376. this.loading = false;
  377. }, response => {
  378. console.log(response);
  379. });
  380. }
  381. },
  382. checkAreas(node,checked,children) {
  383. if(node.isLeaf){
  384. return;
  385. }
  386. if(checked){
  387. if(!this.chooseItem.province_ids) {
  388. this.chooseItem.province_ids = [];
  389. }
  390. this.chooseItem.province_ids.push(node.id)
  391. }
  392. },
  393. saveAreas() {
  394. let areas = [];
  395. let area_ids = [];
  396. let province_ids = [];
  397. this.$refs.addressTree.getCheckedNodes().forEach(function (node) {
  398. if (node.level == 1) {
  399. province_ids.push(node.id);
  400. } else if (node.level == 2) {
  401. area_ids.push(node.id);
  402. areas.push(node.areaname)
  403. }
  404. });
  405. this.$refs.addressTree.getHalfCheckedNodes().forEach(function (node) {
  406. if (node.level == 1) {
  407. province_ids.push(node.id);
  408. }
  409. });
  410. if(this.chooseName == "weight") {
  411. this.weight[this.chooseIndex].area_ids = area_ids.join(";");
  412. this.weight[this.chooseIndex].areas = areas.join(";");
  413. this.weight[this.chooseIndex].province_ids = province_ids;
  414. }
  415. else if(this.chooseName == "piece") {
  416. this.piece[this.chooseIndex].area_ids = area_ids.join(";");
  417. this.piece[this.chooseIndex].areas = areas.join(";");
  418. this.piece[this.chooseIndex].province_ids = province_ids;
  419. }
  420. console.log(this.weight)
  421. console.log(this.piece)
  422. this.centerDialogVisible = false
  423. this.showVisible = false;
  424. },
  425. beforeClose() {
  426. this.centerDialogVisible = false;
  427. this.showVisible = false;
  428. },
  429. goBack() {
  430. history.go(-1)
  431. }
  432. },
  433. })
  434. </script>
  435. @endsection