add.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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" style="margin-top: 10px">
  161. <label class="layui-form-label">排序</label>
  162. <div class="layui-input-block">
  163. <input type="number" name="sort" v-model="formData.sort" placeholder="请输入值越大越靠前"
  164. class="layui-input">
  165. </div>
  166. </div>
  167. <div class="layui-form-item" style="margin-top: 10px">
  168. <div class="layui-input-block">
  169. <button class="layui-btn" type="button" @click="handleSubmit">{{id ? '立即修改':'立即提交'}}
  170. </button>
  171. </div>
  172. </div>
  173. </form>
  174. </div>
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. <script src="{__ADMIN_PATH}js/layuiList.js"></script>
  180. <script>
  181. var id = {$id};
  182. require(['vue'], function (Vue) {
  183. new Vue({
  184. el: "#app",
  185. data: {
  186. selectCityList: [],
  187. selectTypeCityList: [],
  188. templateList: [
  189. {
  190. region: [
  191. {
  192. name: '默认全国',
  193. city_id: 0,
  194. }
  195. ],
  196. regionName: "默认全国",
  197. first: 0,
  198. price: 0,
  199. 'continue': 0,
  200. continue_price: 0,
  201. action: true,
  202. }
  203. ],
  204. appointList: [],
  205. id: id,
  206. formData: {
  207. type: 1,
  208. sort: 0,
  209. name: '',
  210. appoint_check: 0,
  211. },
  212. },
  213. watch: {
  214. 'formData.appoint_check': function (n) {
  215. console.log(n);
  216. }
  217. },
  218. methods: {
  219. getTemplateInfo: function () {
  220. if (!this.id) return;
  221. var that = this;
  222. layList.baseGet(layList.Url({a: 'edit', q: {id: this.id}}), function (res) {
  223. that.$set(that, 'appointList', res.data.appointList || []);
  224. that.$set(that, 'templateList', res.data.templateList || []);
  225. if (!that.templateList.length) {
  226. that.$set(that, 'templateList', [
  227. {
  228. region: [
  229. {
  230. name: '默认全国',
  231. city_id: 0,
  232. }
  233. ],
  234. regionName: "默认全国",
  235. first: 0,
  236. price: 0,
  237. 'continue': 0,
  238. continue_price: 0,
  239. action: true,
  240. }
  241. ]);
  242. } else {
  243. if (that.templateList[0].region === undefined) {
  244. that.$set(that.templateList[0], 'region', [{name: '默认全国', city_id: 0}]);
  245. that.$set(that.templateList[0], 'regionName', '默认全国');
  246. }
  247. }
  248. that.formData = res.data.formData;
  249. that.render();
  250. }, function (res) {
  251. return layList.msg(res.msg);
  252. })
  253. },
  254. del: function (type, index) {
  255. switch (type) {
  256. case 1:
  257. this.templateList.splice(index, 1);
  258. break;
  259. case 2:
  260. this.appointList.splice(index, 1);
  261. break;
  262. }
  263. },
  264. open: function (type, edit) {
  265. if (edit == undefined) edit = 0;
  266. switch (type) {
  267. case 1:
  268. this.createFrame('单独添加配送区域', layList.Url({a: 'city', p: {type: 1, isedit: edit}}));
  269. break;
  270. case 2:
  271. this.createFrame('单独指定包邮区域', layList.Url({a: 'city', p: {type: 2, isedit: edit}}));
  272. break;
  273. }
  274. },
  275. createFrame: function (title, src, opt) {
  276. opt === undefined && (opt = {});
  277. return layer.open({
  278. type: 2,
  279. title: title,
  280. area: [(opt.w || 1000) + 'px', (opt.h || 700) + 'px'],
  281. fixed: false, //不固定
  282. maxmin: true,
  283. moveOut: false,//true 可以拖出窗外 false 只能在窗内拖
  284. anim: 5,//出场动画 isOutAnim bool 关闭动画
  285. offset: 'auto',//['100px','100px'],//'auto',//初始位置 ['100px','100px'] t[ 上 左]
  286. shade: 0,//遮罩
  287. resize: true,//是否允许拉伸
  288. content: src,//内容
  289. move: '.layui-layer-title'
  290. });
  291. },
  292. render: function () {
  293. var that = this, radioRule = ['appoint_check', 'type'];
  294. that.$nextTick(function () {
  295. layList.form.render();
  296. radioRule.map(function (val) {
  297. layList.form.on('radio(' + val + ')', function (res) {
  298. that.formData[val] = res.value;
  299. });
  300. })
  301. })
  302. },
  303. selectCity: function (data, type) {
  304. var cityName = data.map(function (item) {
  305. return item.name;
  306. }).join(';');
  307. switch (type) {
  308. case 1:
  309. this.templateList.push({
  310. region: data,
  311. regionName: cityName,
  312. first: 0,
  313. price: 0,
  314. 'continue': 0,
  315. continue_price: 0
  316. });
  317. break;
  318. case 2:
  319. this.appointList.push({
  320. place: data,
  321. placeName: cityName,
  322. a_num: 0,
  323. a_price: 0
  324. });
  325. break;
  326. }
  327. },
  328. handleSubmit: function () {
  329. var that = this;
  330. for (var i = 0; i < that.templateList.length; i++) {
  331. if (!that.templateList[i].first) {
  332. return layList.msg('请填写首件数量');
  333. }
  334. if (that.templateList[i].continue <= 0) {
  335. return layList.msg('请填写续件数量');
  336. }
  337. }
  338. layList.basePost(layList.Url({a: 'save', p: {id: this.id}}), {
  339. appoint_info: that.appointList,
  340. region_info: that.templateList,
  341. sort: that.formData.sort,
  342. type: that.formData.type,
  343. name: that.formData.name,
  344. appoint: that.formData.appoint_check,
  345. }, function (res) {
  346. layList.msg(res.msg, function () {
  347. parent.layer.close(parent.layer.getFrameIndex(window.name));
  348. parent.$(".J_iframe:visible")[0].contentWindow.location.reload();
  349. });
  350. });
  351. }
  352. },
  353. mounted: function () {
  354. this.getTemplateInfo();
  355. if (!this.id) this.render();
  356. window.selectCity = this.selectCity;
  357. }
  358. })
  359. })
  360. </script>
  361. {/block}