add_change.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>新增经销商</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  10. <meta name="apple-mobile-web-app-capable" content="yes">
  11. <meta name="format-detection" content="telephone=no">
  12. <script type="text/javascript"
  13. src="https://webapi.amap.com/maps?v=1.4.15&key=388e4a971a8fb8d616e4a85d7deff144"></script>
  14. <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css" />
  15. <link rel="stylesheet" type="text/css" href="../../css/common.css" />
  16. <style type="text/css">
  17. .ui-required:before {
  18. content: "*";
  19. color: red;
  20. vertical-align: middle;
  21. }
  22. #roleSelectViwe .layui-form-item {
  23. margin-bottom: 0
  24. }
  25. #roleSelectViwe .layui-input-inline {
  26. width: calc(100% - 110px);
  27. margin-right: 0;
  28. }
  29. .region {
  30. padding-left: 10px;
  31. height: 38px;
  32. line-height: 38px;
  33. background-color: #fff;
  34. border-radius: 2px;
  35. border: 1px solid #e6e6e6;
  36. width: 100% !important;
  37. width: calc(100% - 132px) !important;
  38. }
  39. .userTip {
  40. color: #666;
  41. font-size: 12px;
  42. }
  43. .userTip b {
  44. color: #333;
  45. }
  46. .amap {
  47. width: 658px;
  48. height: 300px;
  49. margin-left: 110px;
  50. }
  51. </style>
  52. <script type="text/html" id="typeHtmlTpl">
  53. <option value="">请选择</option>
  54. {{# if(!d.list){d.list = []}; layui.each(d.list, function(index, item){ }}
  55. <option value="{{item.guid}}">{{item.roleName}}</option>
  56. {{# }); }}
  57. </script>
  58. </head>
  59. <body>
  60. <form class="layui-form" action="" lay-filter="addForm" style="padding: 20px 20px 0 0">
  61. <h3 style="font-size:16px;margin:10px 20px 10px 20px;padding:10px 6px;border-bottom:1px dashed #ddd;">经销商信息</h3>
  62. <div class="layui-form-item">
  63. <label class="layui-form-label ui-required">经销商编码</label>
  64. <div class="layui-input-block">
  65. <input type="text" name="dealerCode" maxlength="32" lay-verify="required" placeholder="请输入经销商编码"
  66. autocomplete="off" class="layui-input" readonly="readonly">
  67. </div>
  68. </div>
  69. <div class="layui-form-item">
  70. <label class="layui-form-label ui-required">经销商名称</label>
  71. <div class="layui-input-block">
  72. <input type="text" name="dealerName" maxlength="32" lay-verify="required" placeholder="请输入经销商名称"
  73. autocomplete="off" class="layui-input">
  74. </div>
  75. </div>
  76. <div class="layui-form-item">
  77. <label class="layui-form-label ui-required">联系方式</label>
  78. <div class="layui-input-block">
  79. <input type="text" name="linkPhone" maxlength="11" lay-verify="required" placeholder="请输入联系电话"
  80. autocomplete="off" class="layui-input">
  81. </div>
  82. </div>
  83. <div class="layui-form-item">
  84. <label class="layui-form-label">备注说明</label>
  85. <div class="layui-input-block">
  86. <textarea type="text" name="remark" maxlength="200" autocomplete="off" class="layui-textarea"></textarea>
  87. </div>
  88. </div>
  89. <h3 style="font-size:16px;margin:10px 20px 10px 20px;padding:10px 6px;border-bottom:1px dashed #ddd;">地理位置标记</h3>
  90. <div class="layui-form-item">
  91. <label class="layui-form-label ui-required">产地地址</label>
  92. <div id="address" class="layui-input-block">
  93. </div>
  94. </div>
  95. <div class="layui-form-item">
  96. <div class="amap" id="container"></div>
  97. </div>
  98. <div class="layui-form-item layui-layer-btn">
  99. <div class="layui-input-block">
  100. <button type="reset" class="layui-btn layui-btn-primary" id="closeWin">取消</button>
  101. <button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
  102. </div>
  103. </div>
  104. </form>
  105. <script type="text/javascript">
  106. function loadJS(url) {
  107. document.write("<script src='" + url + "?ver=" + new Date().getTime() + "'><\/script>")
  108. }
  109. loadJS("../../layui/layui.js");
  110. loadJS("../../js/ajaxhook.min.js");
  111. loadJS("../../js/config.js");
  112. </script>
  113. <script type="text/javascript">
  114. layui.config({
  115. base: "../../js/layuiPlugins/"
  116. }).use(["form", 'layer', 'laytpl', 'jquery', 'cascade'], function () {
  117. var form = layui.form,
  118. layer = layui.layer,
  119. laytpl = layui.laytpl,
  120. cascade = layui.cascade,
  121. $ = layui.jquery;
  122. var funcName = "dealer";
  123. var formData = {
  124. guid: (JSON.stringify(location.searchObj()) != "{}") ? location.searchObj().guid || null : null, //带参传入ID
  125. roleTableDataId: "roleDataList", //数据ID
  126. current: {
  127. latitudeLongitude: ''
  128. }, //当前表单数据
  129. select_data: "select_" + funcName, //查询用户
  130. selectPId_dealer: "selectPId_" + funcName,
  131. save_data: (location.searchObj().guid ? 'edit' : 'add') + '_' + funcName, //查询用户
  132. formLayFilter: "addForm", //表单容器
  133. closeModal: function () { //关闭当前窗口
  134. parent.layer.close(parent.layer.getFrameIndex(window.name));
  135. }
  136. };
  137. //高德地图初始化
  138. var marker, map = new AMap.Map('container', {
  139. zoom: 11,//级别
  140. viewMode: '3D'//使用3D视图
  141. });
  142. AMap.plugin('AMap.ToolBar', function () {
  143. var toolbar = new AMap.ToolBar();
  144. map.addControl(toolbar)
  145. })
  146. //点击标记地图点
  147. map.on('click', function (e) {
  148. clearMarker();
  149. let lnglat = [e.lnglat.getLng(), e.lnglat.getLat()]
  150. marker = new AMap.Marker({
  151. icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  152. position: lnglat,
  153. offset: new AMap.Pixel(-13, -30)
  154. });
  155. marker.setMap(map);
  156. formData.current.latitudeLongitude = lnglat.toString()
  157. });
  158. //设置标记点
  159. function setMarker(lnglat) {
  160. marker = new AMap.Marker({
  161. icon: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  162. position: lnglat,
  163. offset: new AMap.Pixel(-13, -30)
  164. });
  165. marker.setMap(map);
  166. }
  167. //清空坐标点
  168. function clearMarker() {
  169. if (marker) {
  170. marker.setMap(null);
  171. marker = null;
  172. }
  173. }
  174. //类型下拉列表模板
  175. function typeTpl(obj) {
  176. laytpl(typeHtmlTpl.innerHTML).render(obj, function (html) {
  177. $(obj.elem).html(html);
  178. form.render();
  179. });
  180. }
  181. //初始化
  182. formData.main = function () {
  183. var _this = this;
  184. if (this.guid) {
  185. _this.getCurrent(_this.guid); //获取并初始化表单角色信息
  186. } else {
  187. _this.initialization();
  188. }
  189. if (location.searchObj().event == "view") {
  190. var el = document.getElementsByTagName("INPUT");
  191. for (var i = 0; i < el.length; i++) {
  192. el[i].readOnly = true;
  193. }
  194. el = document.getElementsByTagName("textarea");
  195. for (var i = 0; i < el.length; i++) {
  196. el[i].disabled = true;
  197. }
  198. el = document.getElementsByTagName("checkbox");
  199. for (var i = 0; i < el.length; i++) {
  200. el[i].disabled = true;
  201. }
  202. el = document.getElementsByTagName("button");
  203. for (var i = 0; i < el.length; i++) {
  204. if (el[i].innerText.replace(" ", "") == "保存") {
  205. el[i].style.display = "none";
  206. }
  207. }
  208. }
  209. return this;
  210. };
  211. //初始化
  212. formData.initialization = function () {
  213. var _this = this;
  214. //坐标设定
  215. if (!(formData.current.latitudeLongitude === "")) {
  216. let mapMark = formData.current.latitudeLongitude.split(",")
  217. setMarker(mapMark);
  218. }
  219. //新增->初始化编码
  220. if (!formData.current.dealerCode) {
  221. formData.getProductId();
  222. }
  223. //初始化地区
  224. cascade.render({
  225. elem: "#address",
  226. hostParm: {
  227. idName: 'parentId'
  228. },
  229. url: {
  230. provinceId: 'areaSearch',
  231. cityId: 'areaSearch',
  232. countyId: 'areaSearch'
  233. },
  234. listParamName: {
  235. valueName: 'code',
  236. name: 'name'
  237. },
  238. width: {
  239. provinceId: '8em',
  240. cityId: '8em',
  241. countyId: '8em',
  242. townId: '8em'
  243. }
  244. }).val({
  245. provinceId: this.current.provinceId,
  246. cityId: this.current.cityId,
  247. countyId: this.current.countyId
  248. });
  249. //监听提交
  250. form.on('submit(formDemo)', function (obj) {
  251. //必须return false;
  252. return _this.fusionData(obj.field).submitInfo(); //获取选中权限变数组,提交变化===下拉
  253. });
  254. //关闭窗口
  255. $("#closeWin").on("click", function () {
  256. _this.closeModal();
  257. });
  258. return _this;
  259. };
  260. //创建新的编码
  261. formData.getProductId = function () {
  262. var _this = this;
  263. $.ajax({
  264. url: this.selectPId_dealer,
  265. method: 'get',
  266. success: function (res) {
  267. _this.current.dealerCode = res.data[0].dealerCode;
  268. form.val(_this.formLayFilter, _this.current);
  269. }
  270. });
  271. }
  272. //获取当前信息
  273. formData.getCurrent = function (id) {
  274. var _this = this;
  275. $.ajax({
  276. url: this.select_data,
  277. method: 'get',
  278. data: {
  279. guid: id || this.guid //当前ID
  280. },
  281. success: function (res) {
  282. _this.current = res.data[0];
  283. _this.initialization().formVal();
  284. }
  285. });
  286. return _this;
  287. };
  288. //表单赋值
  289. formData.formVal = function () {
  290. var _this = this;
  291. form.val(this.formLayFilter, this.current);
  292. return this;
  293. };
  294. //合并表单内容
  295. formData.fusionData = function (obj) {
  296. this.current = $.extend(this.current, obj);
  297. if (this.current.guid) {
  298. delete this.current.password;
  299. }
  300. return this;
  301. };
  302. //提交新增修改
  303. formData.submitInfo = function () {
  304. var _this = this;
  305. if (!this.current.countyId || this.current.countyId == "") {
  306. layer.msg("必须选择省市县地址");
  307. return false;
  308. }
  309. this.current.fkPostionId = this.current.countyId;
  310. $.ajax({
  311. type: 'POST',
  312. url: this.save_data,//+'?userId='+this.guid
  313. data: JSON.stringify(this.current),
  314. contentType: 'application/json',
  315. success: function (res) {
  316. if (!(res.code - 0)) {
  317. parent.layer.msg(res.msg, {
  318. icon: 1
  319. });
  320. _this.closeModal();
  321. } else {
  322. layer.msg(res.msg, {
  323. icon: 2
  324. });
  325. }
  326. }
  327. });
  328. return false;
  329. };
  330. formData.main();
  331. //验证规则
  332. form.verify({
  333. nickname: function (value) {
  334. if (!new RegExp("^[a-zA-Z][a-zA-Z0-9_]*$").test(value)) {
  335. return '账号必须以英文字母开头,只能包含英文字母、数字、下划线';
  336. }
  337. if (/(^\_)|(\__)|(\_+$)/.test(value)) {
  338. return '账号首尾不能出现下划线\'_\'';
  339. }
  340. },
  341. checkName: function (value) {
  342. },
  343. phoneNumber: function (value) {
  344. if (value) {
  345. if (!(/^1[3|4|5|7|8]\d{9}$/).test(value)) {
  346. return '请输入正确的手机号码';
  347. }
  348. }
  349. return false;
  350. },
  351. password: function (value) {
  352. if (location.searchObj().guid) {
  353. if (value) {
  354. if (!(/^[\S]{6,12}$/).test(value)) {
  355. return '密码必须6到12位,且不能出现空格';
  356. }
  357. }
  358. return false;
  359. }
  360. if (!(/^[\S]{6,12}$/).test(value)) {
  361. return '密码必须6到12位,且不能出现空格';
  362. }
  363. },
  364. resspaword: function (value) {
  365. var pass = $('#L_pass').val();
  366. if (value != pass) {
  367. return '两次密码不一致';
  368. }
  369. },
  370. ageLength: [
  371. /^[0-9]{0,2}$/,
  372. '年龄必须0到2位,且只能是数字'
  373. ],
  374. jobLength: [
  375. /^[a-z\A-Z\u4e00-\u9fa5_]{0,10}$/,
  376. '职务必须是0-10位,且不包含特殊字符与数字'
  377. ],
  378. workUnit: [
  379. /^[0-9\a-z\A-Z\u4e00-\u9fa5_]{0,25}$/,
  380. '工作单位必须是0-25位,且不包含特殊字符'
  381. ],
  382. vcode: [
  383. /^[\w]{4,5}$/,
  384. '验证码不符合规则'
  385. ]
  386. });
  387. });
  388. </script>
  389. </body>
  390. </html>