add.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. {extend name="public/container"}
  2. {block name="content"}
  3. <style>
  4. .red {
  5. color: red;
  6. }
  7. </style>
  8. <div class="layui-fluid">
  9. <div class="layui-row layui-col-space15" id="app" v-cloak="">
  10. <div class="layui-col-md12">
  11. <div class="layui-card">
  12. <div class="layui-card-body">
  13. <form class="layui-form" @submit.stop>
  14. <div class="layui-form-item">
  15. <label class="layui-form-label">模板名称<i class="red">*</i></label>
  16. <div class="layui-input-block">
  17. <input type="text" name="name" v-model="formData.name" placeholder="请输入模板名称"
  18. class="layui-input" lay-verify="required">
  19. </div>
  20. </div>
  21. <div class="layui-form-item">
  22. <label class="layui-form-label">计费方式</label>
  23. <div class="layui-input-block">
  24. <input type="radio" name="type" v-model="formData.type"
  25. :checked="formData.type == 1 ? true : false" value="1" title="按件数"
  26. lay-filter="type">
  27. <input type="radio" name="type" v-model="formData.type"
  28. :checked="formData.type == 2 ? true : false" value="2" title="按重量"
  29. lay-filter="type">
  30. <input type="radio" name="type" v-model="formData.type"
  31. :checked="formData.type == 3 ? true : false" value="3" title="按体积"
  32. lay-filter="type">
  33. </div>
  34. </div>
  35. <div class="layui-form-item">
  36. <label class="layui-form-label">配送区域及运费</label>
  37. <div class="layui-input-block">
  38. <table class="layui-table">
  39. <colgroup>
  40. <col width="150">
  41. <col width="200">
  42. <col>
  43. </colgroup>
  44. <thead>
  45. <tr>
  46. <th>可配送区域<i class="red">*</i></th>
  47. <th v-if="formData.type == 1">首件<i class="red">*</i></th>
  48. <th v-else-if="formData.type == 2">首件重量(KG)<i class="red">*</i></th>
  49. <th v-else>首件体积(m³)<i class="red">*</i></th>
  50. <th>运费(元)<i class="red">*</i></th>
  51. <th v-if="formData.type == 1">续件<i class="red">*</i></th>
  52. <th v-else-if="formData.type == 2">续件重量(KG)<i class="red">*</i></th>
  53. <th v-else>续件体积(m³)<i class="red">*</i></th>
  54. <th>续费(元)<i class="red">*</i></th>
  55. <th>操作</th>
  56. </tr>
  57. </thead>
  58. <tbody id="region">
  59. <tr v-for="(item,index) in templateList">
  60. <td>
  61. <input type="text" class="layui-input" :value="item.regionName" readonly>
  62. </td>
  63. <td>
  64. <input type="number" v-model="item.first" class="layui-input"
  65. lay-verify="required">
  66. </td>
  67. <td>
  68. <input type="number" v-model="item.price" class="layui-input"
  69. lay-verify="required">
  70. </td>
  71. <td>
  72. <input type="number" v-model="item.continue" class="layui-input"
  73. lay-verify="required">
  74. </td>
  75. <td>
  76. <input type="number" v-model="item.continue_price" class="layui-input"
  77. lay-verify="required">
  78. </td>
  79. <td style="width:100px;" v-if="item.regionName != '默认全国' ">
  80. <!-- <button type="button" class="layui-btn layui-btn-sm layui-btn-info">修改</button>-->
  81. <button type="button" class="layui-btn layui-btn-sm layui-btn-danger"
  82. @click="del(1,index)">删除
  83. </button>
  84. </td>
  85. <td style="width:100px;" v-else></td>
  86. </tr>
  87. </tbody>
  88. </table>
  89. </div>
  90. </div>
  91. <div class="layui-form-item" style="margin-top: 10px">
  92. <div class="layui-input-block">
  93. <button class="layui-btn layui-btn-sm" @click="open(1)" type="button">
  94. 单独添加配送区域
  95. </button>
  96. </div>
  97. </div>
  98. <div class="layui-form-item">
  99. <label class="layui-form-label">指定包邮</label>
  100. <div class="layui-input-block">
  101. <input type="radio" name="appoint_check"
  102. :checked="formData.appoint_check == 1 ? true : false"
  103. v-model="formData.appoint_check" value="1" title="开启" lay-filter="appoint_check">
  104. <input type="radio" name="appoint_check"
  105. :checked="formData.appoint_check == 0 ? true : false"
  106. v-model="formData.appoint_check" value="0" title="关闭" lay-filter="appoint_check">
  107. </div>
  108. </div>
  109. <div v-show="formData.appoint_check == 1">
  110. <div class="layui-form-item">
  111. <label class="layui-form-label"></label>
  112. <div class="layui-input-block">
  113. <table class="layui-table">
  114. <colgroup>
  115. <col width="150">
  116. <col width="200">
  117. <col>
  118. </colgroup>
  119. <thead>
  120. <tr>
  121. <th>选择地区<i class="red">*</i></th>
  122. <th v-if="formData.type == 1">包邮件数<i class="red">*</i></th>
  123. <th v-else-if="formData.type == 2">包邮重量(KG)<i class="red">*</i></th>
  124. <th v-else>包邮体积(m³)<i class="red">*</i></th>
  125. <th>包邮金额(元)<i class="red">*</i></th>
  126. <th>操作</th>
  127. </tr>
  128. </thead>
  129. <tbody>
  130. <tr v-for="(item,index) in appointList">
  131. <td><input type="text" class="layui-input"
  132. :value="item.placeName"
  133. readonly></td>
  134. <td><input type="number" autocomplete="off" class="layui-input"
  135. v-model="item.a_num"></td>
  136. <td><input type="number" autocomplete="off" class="layui-input"
  137. v-model="item.a_price"></td>
  138. <td>
  139. <!-- <button type="button" class="layui-btn layui-btn-sm layui-btn-info">修改</button>-->
  140. <button type="button" class="layui-btn layui-btn-sm layui-btn-danger"
  141. @click="del(2,index)">删除
  142. </button>
  143. </td>
  144. </tr>
  145. <tr v-if="appointList.length <= 0">
  146. <td colspan="5" style="text-align: center;">暂无</td>
  147. </tr>
  148. </tbody>
  149. </table>
  150. </div>
  151. </div>
  152. <div class="layui-form-item" style="margin-top: 10px">
  153. <div class="layui-input-block">
  154. <button class="layui-btn layui-btn-sm" @click="open(2)" type="button">
  155. 单独指定包邮区域
  156. </button>
  157. </div>
  158. </div>
  159. </div>
  160. <div class="layui-form-item">
  161. <label class="layui-form-label">是否到付</label>
  162. <div class="layui-input-block">
  163. <input type="radio" name="collect_on_delivery" v-model="formData.collect_on_delivery"
  164. :checked="formData.collect_on_delivery == 0 ? true : false" value="0" title="否"
  165. lay-filter="collect_on_delivery">
  166. <input type="radio" name="collect_on_delivery" v-model="formData.collect_on_delivery"
  167. :checked="formData.collect_on_delivery == 1 ? true : false" value="1" title="是"
  168. lay-filter="collect_on_delivery">
  169. </div>
  170. </div>
  171. <div class="layui-form-item" style="margin-top: 10px">
  172. <label class="layui-form-label">排序</label>
  173. <div class="layui-input-block">
  174. <input type="number" name="sort" v-model="formData.sort" placeholder="请输入值越大越靠前"
  175. class="layui-input">
  176. </div>
  177. </div>
  178. <div class="layui-form-item" style="margin-top: 10px">
  179. <div class="layui-input-block">
  180. <button class="layui-btn" type="button" @click="handleSubmit">{{id ? '立即修改':'立即提交'}}
  181. </button>
  182. </div>
  183. </div>
  184. </form>
  185. </div>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  191. <script>
  192. var id = {$id};
  193. require(['vue'], function (Vue) {
  194. new Vue({
  195. el: "#app",
  196. data: {
  197. selectCityList: [],
  198. selectTypeCityList: [],
  199. templateList: [
  200. {
  201. region: [
  202. {
  203. name: '默认全国',
  204. city_id: 0,
  205. }
  206. ],
  207. regionName: "默认全国",
  208. first: 0,
  209. price: 0,
  210. 'continue': 0,
  211. continue_price: 0,
  212. action: true,
  213. }
  214. ],
  215. appointList: [],
  216. id: id,
  217. formData: {
  218. type: 1,
  219. sort: 0,
  220. name: '',
  221. appoint_check: 0,
  222. collect_on_delivery: 0,
  223. },
  224. },
  225. watch: {
  226. 'formData.appoint_check': function (n) {
  227. console.log(n);
  228. }
  229. },
  230. methods: {
  231. getTemplateInfo: function () {
  232. if (!this.id) return;
  233. var that = this;
  234. layList.baseGet(layList.Url({a: 'edit', q: {id: this.id}}), function (res) {
  235. that.$set(that, 'appointList', res.data.appointList || []);
  236. that.$set(that, 'templateList', res.data.templateList || []);
  237. if (!that.templateList.length) {
  238. that.$set(that, 'templateList', [
  239. {
  240. region: [
  241. {
  242. name: '默认全国',
  243. city_id: 0,
  244. }
  245. ],
  246. regionName: "默认全国",
  247. first: 0,
  248. price: 0,
  249. 'continue': 0,
  250. continue_price: 0,
  251. action: true,
  252. }
  253. ]);
  254. } else {
  255. if (that.templateList[0].region === undefined) {
  256. that.$set(that.templateList[0], 'region', [{name: '默认全国', city_id: 0}]);
  257. that.$set(that.templateList[0], 'regionName', '默认全国');
  258. }
  259. }
  260. that.formData = res.data.formData;
  261. that.render();
  262. }, function (res) {
  263. return layList.msg(res.msg);
  264. })
  265. },
  266. del: function (type, index) {
  267. switch (type) {
  268. case 1:
  269. this.templateList.splice(index, 1);
  270. break;
  271. case 2:
  272. this.appointList.splice(index, 1);
  273. break;
  274. }
  275. },
  276. open: function (type, edit) {
  277. if (edit == undefined) edit = 0;
  278. switch (type) {
  279. case 1:
  280. this.createFrame('单独添加配送区域', layList.Url({a: 'city', p: {type: 1, isedit: edit}}));
  281. break;
  282. case 2:
  283. this.createFrame('单独指定包邮区域', layList.Url({a: 'city', p: {type: 2, isedit: edit}}));
  284. break;
  285. }
  286. },
  287. createFrame: function (title, src, opt) {
  288. opt === undefined && (opt = {});
  289. return layer.open({
  290. type: 2,
  291. title: title,
  292. area: [(opt.w || 1000) + 'px', (opt.h || 700) + 'px'],
  293. fixed: false, //不固定
  294. maxmin: true,
  295. moveOut: false,//true 可以拖出窗外 false 只能在窗内拖
  296. anim: 5,//出场动画 isOutAnim bool 关闭动画
  297. offset: 'auto',//['100px','100px'],//'auto',//初始位置 ['100px','100px'] t[ 上 左]
  298. shade: 0,//遮罩
  299. resize: true,//是否允许拉伸
  300. content: src,//内容
  301. move: '.layui-layer-title'
  302. });
  303. },
  304. render: function () {
  305. var that = this, radioRule = ['appoint_check', 'type', 'collect_on_delivery'];
  306. that.$nextTick(function () {
  307. layList.form.render();
  308. radioRule.map(function (val) {
  309. layList.form.on('radio(' + val + ')', function (res) {
  310. that.formData[val] = res.value;
  311. });
  312. })
  313. })
  314. },
  315. selectCity: function (data, type) {
  316. var cityName = data.map(function (item) {
  317. return item.name;
  318. }).join(';');
  319. switch (type) {
  320. case 1:
  321. this.templateList.push({
  322. region: data,
  323. regionName: cityName,
  324. first: 0,
  325. price: 0,
  326. 'continue': 0,
  327. continue_price: 0
  328. });
  329. break;
  330. case 2:
  331. this.appointList.push({
  332. place: data,
  333. placeName: cityName,
  334. a_num: 0,
  335. a_price: 0
  336. });
  337. break;
  338. }
  339. },
  340. handleSubmit: function () {
  341. var that = this;
  342. for (var i = 0; i < that.templateList.length; i++) {
  343. if (!that.templateList[i].first) {
  344. return layList.msg('请填写首件数量');
  345. }
  346. if (that.templateList[i].continue <= 0) {
  347. return layList.msg('请填写续件数量');
  348. }
  349. }
  350. layList.basePost(layList.Url({a: 'save', p: {id: this.id}}), {
  351. appoint_info: that.appointList,
  352. region_info: that.templateList,
  353. sort: that.formData.sort,
  354. type: that.formData.type,
  355. name: that.formData.name,
  356. appoint: that.formData.appoint_check,
  357. collect_on_delivery: that.formData.collect_on_delivery,
  358. }, function (res) {
  359. layList.msg(res.msg, function () {
  360. parent.layer.close(parent.layer.getFrameIndex(window.name));
  361. parent.$(".J_iframe:visible")[0].contentWindow.location.reload();
  362. });
  363. });
  364. }
  365. },
  366. mounted: function () {
  367. this.getTemplateInfo();
  368. if (!this.id) this.render();
  369. window.selectCity = this.selectCity;
  370. }
  371. })
  372. })
  373. </script>
  374. {/block}