index.html 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. {extend name="public/layout" /} {block name="title"}装修案例列表{/block} {block name="body"}
  2. <style type="text/css">
  3. html,
  4. body {
  5. display: block;
  6. min-width: 1000px;
  7. overflow: hidden;
  8. }
  9. .layui-fluid {
  10. display: block;
  11. box-shadow: 0 0 4px 0 #B6CADE;
  12. border-radius: 5px;
  13. margin: 15px;
  14. background-color: #ffffff;
  15. box-sizing: border-box;
  16. }
  17. .wzh-header-tab {
  18. width: 97.5%;
  19. height: 50px;
  20. background-color: #fff;
  21. margin: 20px auto 20px;
  22. border-radius: 6px;
  23. }
  24. .wzh-header-ul {
  25. width: 100%;
  26. height: 100%;
  27. display: flex;
  28. align-items: center;
  29. box-sizing: border-box;
  30. padding: 0px 10px;
  31. }
  32. .wzh-header-ul>li {
  33. width: 100px;
  34. float: left;
  35. text-align: center;
  36. cursor: pointer;
  37. }
  38. .wzh-header-ul>li>a {
  39. display: block;
  40. }
  41. .wzh-active {
  42. color: #249EFB;
  43. position: relative;
  44. }
  45. .wzh-active::after {
  46. content: ' ';
  47. width: 50px;
  48. height: 4px;
  49. background-color: #249EFB;
  50. border-radius: 2px;
  51. position: absolute;
  52. bottom: -10px;
  53. left: 50%;
  54. transform: translateX(-50%);
  55. }
  56. .wzh-remind {
  57. width: 97.5%;
  58. height: auto;
  59. overflow: hidden;
  60. margin: 20px auto 20px;
  61. }
  62. .wzh-remind>div {
  63. width: 100%;
  64. height: 46px;
  65. background-color: #F0F8FF;
  66. color: #0567B4;
  67. font-size: 14px;
  68. line-height: 46px;
  69. box-sizing: border-box;
  70. padding: 0px 10px;
  71. }
  72. .layui-card-box {
  73. width: 100%;
  74. min-height: 85vh;
  75. margin: 0px auto 10px;
  76. box-sizing: border-box;
  77. display: flex;
  78. align-items: center;
  79. }
  80. .layui-left-box {
  81. width: 180px;
  82. height: 100vh;
  83. background-color: #fff;
  84. box-sizing: border-box;
  85. padding: 10px 15px;
  86. }
  87. .layui-right-box {
  88. flex: 1;
  89. height: 100vh;
  90. background-color: #fff;
  91. margin-left: 20px;
  92. box-sizing: border-box;
  93. padding: 20px 30px;
  94. overflow-y: auto;
  95. overflow-x: hidden;
  96. }
  97. .layui-left-add-plan {
  98. width: 100%;
  99. height: 35px;
  100. display: flex;
  101. align-items: center;
  102. cursor: pointer;
  103. }
  104. .add-plan-icon {
  105. display: inline-block;
  106. width: 20px;
  107. height: 20px;
  108. background-color: #B0C4D4;
  109. display: flex;
  110. justify-content: center;
  111. align-items: center;
  112. border-radius: 3px;
  113. margin-right: 6px;
  114. }
  115. .plan-item-box {
  116. width: 100%;
  117. height: 35px;
  118. line-height: 35px;
  119. cursor: pointer;
  120. box-sizing: border-box;
  121. padding-left: 10px;
  122. position: relative;
  123. overflow: hidden;
  124. white-space: nowrap;
  125. text-overflow: ellipsis;
  126. }
  127. .right-tips {
  128. width: 100%;
  129. height: 20px;
  130. line-height: 20px;
  131. display: flex;
  132. align-items: center;
  133. }
  134. .right-tips>span {
  135. display: inline-block;
  136. width: 5px;
  137. height: 20px;
  138. background-color: #249EFB;
  139. border-radius: 2px;
  140. margin-right: 8px;
  141. }
  142. .choose-chat {
  143. box-sizing: border-box;
  144. padding: 10px 15px;
  145. margin: 10px 0px;
  146. }
  147. .right-btn {
  148. box-sizing: border-box;
  149. padding: 10px 0px 10px 0px;
  150. margin-top: 10px;
  151. }
  152. .set-action {
  153. box-sizing: border-box;
  154. width: 90%;
  155. min-height: 320px;
  156. background-color: #F8F8F8;
  157. margin: 20px 0px 0px;
  158. padding: 10px 20px;
  159. display: flex;
  160. }
  161. .action-remind {
  162. width: 300px;
  163. }
  164. .action-remind>div {
  165. width: 100%;
  166. height: 32px;
  167. line-height: 32px;
  168. display: flex;
  169. align-items: center;
  170. }
  171. .action-remind>div>label {
  172. margin-left: 6px;
  173. }
  174. .chat-check>div {
  175. width: 100%;
  176. height: 32px;
  177. line-height: 32px;
  178. display: flex;
  179. align-items: center;
  180. }
  181. .chat-check>div>label {
  182. margin-left: 6px;
  183. }
  184. .field_box_style {
  185. width: 100%;
  186. height: auto;
  187. overflow: hidden;
  188. padding: 10px 0px;
  189. }
  190. .field_title_box {
  191. width: 100%;
  192. display: flex;
  193. align-items: center;
  194. }
  195. .field_label {
  196. display: inline-block;
  197. border-left: 4px solid #249EFB;
  198. padding-left: 7px;
  199. height: 16px;
  200. line-height: 16px;
  201. }
  202. .flex {
  203. display: flex;
  204. }
  205. .align-center {
  206. align-items: center;
  207. }
  208. .mr10 {
  209. margin-right: 10px;
  210. }
  211. .ml0 {
  212. margin-left: 0px !important;
  213. }
  214. .p10 {
  215. margin-top: 15px;
  216. padding: 20px 15px 10px 15px;
  217. background-color: #F8F8F8;
  218. }
  219. .red-font {
  220. color: red;
  221. }
  222. .mlr10 {
  223. margin: 0px 10px;
  224. }
  225. .layui-form-switch {
  226. margin-top: 0px !important;
  227. }
  228. .field_edit {
  229. color: #249EFB;
  230. cursor: pointer;
  231. }
  232. .layui-form-onswitch {
  233. border-color: #249EFB;
  234. background-color: #249EFB;
  235. }
  236. .layui-form-radio>i:hover,
  237. .layui-form-radioed>i {
  238. color: #249EFB;
  239. }
  240. .field_delete {
  241. color: red;
  242. cursor: pointer;
  243. }
  244. .mt10 {
  245. margin-top: 10px;
  246. }
  247. .active_style {
  248. background-color: #f5f5f5;
  249. }
  250. .flex-wrap {
  251. flex-wrap: wrap;
  252. }
  253. .mtbr10 {
  254. margin: 5px 10px 5px 0px;
  255. }
  256. .p-operate-box {
  257. position: absolute;
  258. top: 0px;
  259. right: -5px;
  260. padding: 2px;
  261. display: none;
  262. background-color: #fff;
  263. }
  264. .plan-item-box:hover .p-operate-box {
  265. display: flex;
  266. }
  267. .mt20 {
  268. margin-top: 20px;
  269. }
  270. .layui-form-switch {
  271. transform: scale(0.8, 0.8);
  272. }
  273. .ml50 {
  274. margin-left: 47px;
  275. }
  276. </style>
  277. <body>
  278. <!-- <div class="wzh-header-tab">
  279. <ul class="wzh-header-ul">
  280. <li class="wzh-active">客户画像</li>
  281. </ul>
  282. </div> -->
  283. <div class="layui-card-box">
  284. <div class="layui-left-box">
  285. <div class="layui-left-add-plan">
  286. <span class="add-plan-icon">
  287. <i class="layui-icon layui-icon-addition" style="color:#fff;"></i>
  288. </span>
  289. <span>添加画像</span>
  290. </div>
  291. <div class="h_tab_box">
  292. {volist name="list" id="vo"}
  293. <div class="plan-item-box" title="{$vo.name}" data-id="{$vo.id}">
  294. {$vo.name}
  295. <span class="p-operate-box">
  296. {if $vo.isedit == 0}
  297. <i data-id="{$vo.id}" data-name="{$vo.name}" class="layui-icon layui-icon-edit"
  298. style="color: #249EFB;"></i>
  299. {/if}
  300. {if $vo.isdel == 0}
  301. <i data-id="{$vo.id}" class="layui-icon layui-icon-delete lay-del-p" style="color: red;"></i>
  302. {/if}
  303. </span>
  304. </div>
  305. {/volist}
  306. </div>
  307. </div>
  308. <div class="layui-right-box">
  309. <div class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue" id="add_field_btn">
  310. <i class="layui-icon layui-icon-addition"></i>
  311. 添加
  312. </div>
  313. <div class="field_box_style">
  314. </div>
  315. </div>
  316. </div>
  317. </body>
  318. {/block} {block name="js"}
  319. <script>
  320. layui.config({
  321. base: '__LAYUI__/',
  322. urlbase: '/sys'
  323. }).extend({
  324. index: 'lib/index' //主入口模块
  325. }).use(['index', 'table', 'element', 'laydate'], function () {
  326. var $ = layui.$,
  327. form = layui.form,
  328. element = layui.element,
  329. laydate = layui.laydate,
  330. table = layui.table,
  331. curId = '',
  332. editId = null,
  333. fieldlist = [];
  334. $('.h_tab_box div').click(function () {
  335. $(this).addClass('active_style').siblings().removeClass("active_style");
  336. curId = $(this).prop('dataset').id;
  337. localStorage.setItem('CUR_FIELD_VAL',curId);
  338. requestListApi(curId);
  339. })
  340. let c_show_id = localStorage.getItem('CUR_FIELD_VAL');
  341. if (c_show_id) {
  342. $('.plan-item-box').each(function() {
  343. if ($(this).prop('dataset').id == c_show_id) {
  344. curId = c_show_id;
  345. $(this).addClass('active_style').siblings().removeClass("active_style");
  346. requestListApi(curId);
  347. }
  348. })
  349. } else {
  350. $('.plan-item-box').eq(0).addClass('active_style')
  351. curId = $('.plan-item-box').eq(0).prop('dataset').id;
  352. requestListApi(curId);
  353. }
  354. $('.layui-icon-edit').click(function () {
  355. let props = $(this).prop('dataset');
  356. if (!props.name) {
  357. return false;
  358. }
  359. layer.prompt({ value: props.name, title: ['编辑画像', 'color:#333333;background-color:#D8E6F1;'], }, function (value, index, elem) {
  360. editClientContentApi(value, props.id);
  361. layer.close(index);
  362. });
  363. })
  364. $('.lay-del-p').click(function (e) {
  365. let props = $(this).prop('dataset');
  366. layer.confirm('确定删除当前客户画像?', { title: ['信息', 'color:#333333;background-color:#D8E6F1;'], }, function (index) {
  367. deleteFirstLevel(props.id);
  368. });
  369. return false;
  370. })
  371. function requestListApi(id) {
  372. $.ajax({
  373. url: "{:url('customer_new_portrait/index')}",
  374. data: {
  375. pid: id
  376. },
  377. type: 'post',
  378. dataType: 'json',
  379. success: function (res) {
  380. if (res.code == 0) {
  381. fieldlist = res.data;
  382. renderlistHtml(res.data);
  383. } else {
  384. layer.msg(res.msg)
  385. }
  386. }
  387. });
  388. }
  389. function deleteFiledApi(id) {
  390. $.ajax({
  391. url: "{:url('customer_new_portrait/del_field')}",
  392. data: {
  393. id: id
  394. },
  395. type: 'post',
  396. dataType: 'json',
  397. success: function (res) {
  398. if (res.code == 0) {
  399. layer.msg(res.msg, {
  400. anim: 0
  401. }, function () {
  402. requestListApi(curId);
  403. })
  404. } else {
  405. layer.msg(res.msg)
  406. }
  407. }
  408. });
  409. }
  410. function deleteFirstLevel(id) {
  411. $.ajax({
  412. url: "{:url('customer_new_portrait/del_field')}",
  413. data: {
  414. id: id
  415. },
  416. type: 'post',
  417. dataType: 'json',
  418. success: function (res) {
  419. if (res.code == 0) {
  420. layer.msg(res.msg, {
  421. anim: 0
  422. }, function () {
  423. location.reload();
  424. })
  425. } else {
  426. layer.msg(res.msg)
  427. }
  428. }
  429. });
  430. }
  431. function addClientContentApi(name) {
  432. $.ajax({
  433. url: "{:url('customer_new_portrait/add_top_field')}",
  434. data: {
  435. name: name
  436. },
  437. type: 'post',
  438. dataType: 'json',
  439. success: function (res) {
  440. if (res.code == 0) {
  441. layer.msg(res.msg, {
  442. anim: 0
  443. }, function () {
  444. location.reload();
  445. })
  446. } else {
  447. layer.msg(res.msg)
  448. }
  449. }
  450. });
  451. }
  452. function editClientContentApi(name, id) {
  453. $.ajax({
  454. url: "{:url('customer_new_portrait/edit_top_field')}",
  455. data: {
  456. name: name,
  457. id: id
  458. },
  459. type: 'post',
  460. dataType: 'json',
  461. success: function (res) {
  462. if (res.code == 0) {
  463. layer.msg(res.msg, {
  464. anim: 0
  465. }, function () {
  466. location.reload();
  467. })
  468. } else {
  469. layer.msg(res.msg)
  470. }
  471. }
  472. });
  473. }
  474. function setFieldStatusApi(status, id,field='status',refresh) {
  475. $.ajax({
  476. url: "{:url('customer_new_portrait/set_show')}",
  477. data: {
  478. status: status,
  479. id: id,
  480. field: field
  481. },
  482. type: 'post',
  483. dataType: 'json',
  484. success: function (res) {
  485. if (res.code == 0) {
  486. if (!refresh) {
  487. layer.msg(res.msg, {
  488. anim: 0
  489. })
  490. }
  491. } else {
  492. layer.msg(res.msg);
  493. setTimeout(() => {
  494. location.reload();
  495. },1000)
  496. }
  497. }
  498. });
  499. }
  500. function renderlistHtml(list) {
  501. let liveVal = list.filter(g => g.name == '直播情况')[0];
  502. let htmls = list.map((item, index) => {
  503. return `<form class="layui-form mt20" action="">
  504. <div class="field_title_box">
  505. <span class="field_label">${item.name}</span>
  506. <span data-id="${item.id}" data-index="${index}" class="mlr10 field_edit ${item.isedit == 1 ? 'layui-hide' : ''}">
  507. <i class="layui-icon layui-icon-edit"></i>
  508. <span>编辑</span>
  509. </span>
  510. <span data-id="${item.id}" class="mr10 field_delete ${item.isdel == 1 ? 'layui-hide' : ''}">
  511. <i data-id="${item.id}" class="layui-icon layui-icon-delete red-font"></i>
  512. <span data-id="${item.id}">删除</span>
  513. </span>
  514. <span style="${(item.isdel == 1 && item.isedit == 1) ? "margin-left:10px;" : ''}" class="${item.is_status == 1 ? 'layui-hide' : ''}">
  515. <input data-id="${item.id}" data-name="${item.name}" id="lay-switch-${item.id}" type="checkbox" lay-filter="status" name="status" value="${item.status}" ${item.status == 0 ? 'checked' : ''} lay-skin="switch" lay-text="开启|关闭">
  516. </span>
  517. <span class="${(item.keyname == 'name' || item.keyname == 'phone' || item.keyname == 'sex'||((item.keyname=='live_broadcast_business'||item.keyname=='live_broadcast_design')||item.keyname=='live_broadcast_personnel')&&liveVal.isadd == 0)? 'layui-hide' : ''}">
  518. <!-- <input data-id="${item.id}" data-must="${item.is_must}" data-name="${item.name}" id="lay-switch-${item.id}" type="checkbox" lay-filter="isadd" name="isadd" value="${item.isadd}" ${item.isadd == 1 ? 'checked' : ''} lay-skin="switch" lay-text="客户报备|客户报备"> -->
  519. </span>
  520. <span class="${(item.keyname == 'phone')? 'layui-hide' : ''}">
  521. <input data-id="${item.id}" data-name="${item.name}" id="lay-switch-${item.id}" type="checkbox" lay-filter="is_must" name="is_must" value="${item.is_must}" ${item.is_must == 0 ? 'checked' : ''} lay-skin="switch" lay-text="必填|必填">
  522. </span>
  523. </div>
  524. <input type="hidden" name="id" value="${item.id}" />
  525. <div class="p10 edit_content_box ${item.id == editId ? '' : 'layui-hide'}">
  526. <div class="layui-form-item">
  527. <div class="layui-input-block ml0">
  528. <input type="text" value="${item.name}" name="name" placeholder="请输入标题"
  529. autocomplete="off" class="layui-input" style="width:260px;" required lay-verify="required">
  530. </div>
  531. </div>
  532. <div class="layui-form-item flex align-center">
  533. <span class="mr10">填写方式</span>
  534. <div class="layui-input-block ml0">
  535. <input data-index="${index}" data-id="${item.id}" disabled="${item.isedit_type==1}" type="radio" name="type" lay-filter="type" value="1" title="输入框" ${item.type == 1 ? 'checked' : ''}>
  536. <input data-index="${index}" data-id="${item.id}" disabled="${item.isedit_type==1}" type="radio" name="type" lay-filter="type" value="2" title="数字框" ${item.type == 2 ? 'checked' : ''}>
  537. <input data-index="${index}" data-id="${item.id}" disabled="${item.isedit_type==1}" type="radio" name="type" lay-filter="type" value="3" title="单选框" ${item.type == 3 ? 'checked' : ''}>
  538. <input data-index="${index}" data-id="${item.id}" disabled="${item.isedit_type==1}" type="radio" name="type" lay-filter="type" value="4" title="多选框" ${item.type == 4 ? 'checked' : ''}>
  539. <input data-index="${index}" data-id="${item.id}" disabled="${item.isedit_type==1}" type="radio" name="type" lay-filter="type" value="5" title="日期" ${item.type == 5 ? 'checked' : ''}>
  540. <input data-index="${index}" data-id="${item.id}" disabled="${item.isedit_type==1}" type="radio" name="type" lay-filter="type" value="6" title="图片上传" ${item.type == 6 ? 'checked' : ''}>
  541. </div>
  542. <input type="hidden" name="oldType" value="${item.type}" />
  543. </div>
  544. <div class="layui-form-item ${item.type == 2 ? '' : 'layui-hide'} flex align-center unity_box_${item.id}">
  545. <span class="mr10">单位&nbsp;&nbsp;</span>
  546. <div class="layui-input-block ml0">
  547. <input type="text" value="${item.unity || ''}" name="unity" placeholder="请输入单位"
  548. autocomplete="off" class="layui-input" style="width:260px;">
  549. </div>
  550. </div>
  551. <div class="layui-form-item select-list-box-${item.id} flex flex-wrap align-center ${item.type == 3 || item.type == 4 ? '' : 'layui-hide'}">
  552. ${!!item.select ? item.select.map((sItem, sIndex) => {
  553. return `<div class="flex align-center mtbr10 select-item-box-${item.id}">
  554. <span class="mr10">选项${sIndex + 1}</span>
  555. <input data-type="input" data-idx="${index}" data-index="${sIndex}" type="text" name="select[${sIndex}][name]" required lay-verify="required" value="${sItem.name}" placeholder="请输入标题" autocomplete="off"
  556. class="layui-input select_input_content mr10" style="width:150px;">
  557. <input type="hidden" name="select[${sIndex}][id]" value="${sItem.id}" />
  558. <i data-id="${item.id}" data-curid="${sItem.id}" data-idx="${index}" data-index="${sIndex}" class="layui-icon layui-icon-delete red-font"></i>
  559. </div>`
  560. }).join('') : ''
  561. }
  562. <div data-id="${item.id}" data-index="${index}" class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue add-select-btn add-select-btn-${item.id}">
  563. +添加
  564. </div>
  565. </div>
  566. <div class="layui-form-item">
  567. <div class="layui-input-block ml50">
  568. <div type="button" class="layui-btn layui-btn-sm" lay-submit lay-filter="layuiadmin-field-submit-${item.id}">保存</div>
  569. </div>
  570. </div>
  571. </div>
  572. </form>`
  573. }).join('')
  574. $('.field_box_style').html(htmls);
  575. setTimeout(() => {
  576. $('.field_delete').click(function () {
  577. let id = $(this).prop('dataset').id;
  578. layer.confirm('确定删除当前字段?', { title: ['信息', 'color:#333333;background-color:#D8E6F1;'], }, function (index) {
  579. deleteFiledApi(id);
  580. });
  581. })
  582. $('.field_edit').click(function () {
  583. let index = $(this).prop('dataset').index;
  584. editId = $(this).prop('dataset').id;
  585. $('.edit_content_box').eq(parseInt(index)).toggleClass('layui-hide');
  586. $('.edit_content_box').each(function (item) {
  587. if (item != index) {
  588. $(this).addClass('layui-hide');
  589. }
  590. })
  591. })
  592. form.on('switch(status)', function (e) {
  593. let id = $(this).prop('dataset').id;
  594. let name = $(this).prop('dataset').name;
  595. var switchVal = $(`#lay-switch-${id}`).val();
  596. let val = switchVal ? '0' : '1';
  597. setFieldStatusApi(val, id);
  598. if (name == '直播情况') {
  599. let liveBroadcast = fieldlist.filter(v => v.keyname=='live_broadcast_business'||v.keyname=='live_broadcast_design'||v.keyname=='live_broadcast_personnel'||v.keyname=='live_broadcast_date');
  600. if (switchVal==1) {
  601. let ids = liveBroadcast.filter(v=>v.status==1).map(v=>v.id).join(',');
  602. setFieldStatusApi(0, ids);
  603. }
  604. if (switchVal==0) {
  605. let ids = liveBroadcast.filter(v=>v.status==0).map(v=>v.id).join(',');
  606. setFieldStatusApi(1, ids);
  607. }
  608. }
  609. })
  610. form.on('switch(isadd)', function (e) {
  611. let id = $(this).prop('dataset').id;
  612. let name = $(this).prop('dataset').name;
  613. let must = $(this).prop('dataset').must;
  614. var switchVal = $(this).val();
  615. let val = switchVal == 0 ? 1 : 0;
  616. if (name == '直播情况') {
  617. let liveBroadcast = fieldlist.filter(v => v.name=='业务直播人员'||v.name=='设计直播人员'||v.name=='直播人员');
  618. liveBroadcast.forEach(k => {
  619. setFieldStatusApi(val, k.id,'isadd', true);
  620. });
  621. }
  622. if (switchVal == 1 && must == 0) {
  623. setFieldStatusApi(val, id,'is_must');
  624. }
  625. setFieldStatusApi(val, id,'isadd');
  626. })
  627. form.on('switch(is_must)', function (e) {
  628. let id = $(this).prop('dataset').id;
  629. let name = $(this).prop('dataset').name;
  630. var switchVal = $(this).val();
  631. let val = switchVal == 0 ? 1 : 0;
  632. setFieldStatusApi(val, id,'is_must');
  633. })
  634. form.on('radio(type)', function (e) {
  635. let id = $(this).prop('dataset').id;
  636. let index = parseInt($(this).prop('dataset').index);
  637. if (e.value == 2) {
  638. $(`.unity_box_${id}`).removeClass('layui-hide');
  639. $(`.select-list-box-${id}`).html('');
  640. } else if (e.value == 3 || e.value == 4) {
  641. $(`.unity_box_${id}`).addClass('layui-hide');
  642. $(`.select-list-box-${id}`).removeClass('layui-hide');
  643. renderSelectItemHtml(fieldlist[index].select || [], `select-list-box-${id}`, id, index);
  644. } else {
  645. $(`.select-list-box-${id}`).html('');
  646. $(`.select-list-box-${id}`).addClass('layui-hide');
  647. $(`.unity_box_${id}`).addClass('layui-hide');
  648. }
  649. })
  650. $('.add-select-btn').click(function () {
  651. let id = $(this).prop('dataset').id;
  652. let idx = $(this).prop('dataset').index;
  653. let index = $(`.select-item-box-${id}`).length;
  654. if (index > 0) {
  655. fieldlist[parseInt(idx)].select.push({ name: '', id: '', pid: id });
  656. } else {
  657. fieldlist[parseInt(idx)].select = [];
  658. fieldlist[parseInt(idx)].select.push({ name: '', id: '', pid: id });
  659. }
  660. renderSelectItemHtml(fieldlist[parseInt(idx)].select, `select-list-box-${id}`, id, idx);
  661. })
  662. $('.layui-icon-delete').click(function () {
  663. let id = $(this).prop('dataset').id;
  664. let index = $(this).prop('dataset').index;
  665. let idx = $(this).prop('dataset').idx;
  666. let curid = $(this).prop('dataset').curid;
  667. layer.confirm('确定删除当前选项?', { title: ['信息', 'color:#333333;background-color:#D8E6F1;'], }, function (cdx) {
  668. layer.close(cdx)
  669. if (id && index && idx) {
  670. if (curid) {
  671. let = loadingIndex = layer.load('Loading...', {
  672. shade: [0.6,'#000'] //0.1透明度的白色背景
  673. });
  674. $.ajax({
  675. url: "{:url('customer_new_portrait/del_select_opt')}",
  676. data: {
  677. id: curid,
  678. pid: id
  679. },
  680. type: 'post',
  681. dataType: 'json',
  682. success: function (res) {
  683. layer.close(loadingIndex);
  684. if (res.code == 0) {
  685. layer.msg('删除成功,当前选项未使用');
  686. fieldlist[parseInt(idx)].select.splice(parseInt(index), 1);
  687. renderSelectItemHtml(fieldlist[parseInt(idx)].select, `select-list-box-${id}`, id, idx);
  688. } else {
  689. layer.msg(res.msg)
  690. }
  691. }
  692. });
  693. } else {
  694. fieldlist[parseInt(idx)].select.splice(parseInt(index), 1);
  695. renderSelectItemHtml(fieldlist[parseInt(idx)].select, `select-list-box-${id}`, id, idx);
  696. }
  697. }
  698. })
  699. })
  700. $('.select_input_content').change(function () {
  701. let props = $(this).prop('dataset');
  702. if (props.type && (props.type == 'input')) {
  703. fieldlist[parseInt(props.idx)].select[parseInt(props.index)].name = $(this).val();
  704. }
  705. })
  706. /* 监听提交 */
  707. list.forEach(item => {
  708. form.on(`submit(layuiadmin-field-submit-${item.id})`, function (obj) {
  709. var formData = new FormData(obj.form);
  710. if (obj.field.oldType != obj.field.type) {
  711. layer.confirm('更改填写方式,会导致之前填写的信息丢失,您确认更改吗?', { title: ['信息', 'color:#333333;background-color:#D8E6F1;'], }, function (index) {
  712. formData.delete('oldType');
  713. formData.set('type', obj.field.type);
  714. if (obj.field.type != 3 && obj.field.type != 4) {
  715. formData.append('select', '');
  716. if (obj.field.type != 2) {
  717. formData.set('unity', '');
  718. }
  719. } else {
  720. formData.set('unity', '');
  721. let isSubmit = false;
  722. Object.keys(obj.field).forEach(v => {
  723. if (!obj.field[v] && (v.indexOf('id') < 0) && v != 'unity') {
  724. isSubmit = true;
  725. }
  726. })
  727. if (isSubmit || Object.keys(obj.field).indexOf('select[0][name]') < 0) {
  728. layer.msg('请填写选项', {
  729. icon: 5,
  730. anim: 6,
  731. time: 2000
  732. });
  733. return false;
  734. }
  735. }
  736. $.ajax({
  737. url: '{:url("customer_new_portrait/edit_field")}',
  738. type: 'post',
  739. data: formData,
  740. dataType: 'json',
  741. processData: false,
  742. contentType: false,
  743. success: function (res) {
  744. if (res.code == 0) {
  745. layer.msg(res.msg, {
  746. anim: 0,
  747. }, function () {
  748. location.reload();
  749. });
  750. } else {
  751. layer.msg(res.msg, {
  752. icon: 5,
  753. anim: 6,
  754. time: 2000
  755. });
  756. }
  757. }
  758. });
  759. });
  760. } else {
  761. formData.delete('oldType');
  762. formData.set('type', obj.field.type);
  763. if (obj.field.type != 3 && obj.field.type != 4) {
  764. formData.append('select', '');
  765. if (obj.field.type != 2) {
  766. formData.set('unity', '');
  767. }
  768. } else {
  769. formData.set('unity', '');
  770. let isSubmit = false;
  771. Object.keys(obj.field).forEach(v => {
  772. if (!obj.field[v] && (v.indexOf('id') < 0) && v != 'unity') {
  773. isSubmit = true;
  774. }
  775. })
  776. if (isSubmit || Object.keys(obj.field).indexOf('select[0][name]') < 0) {
  777. layer.msg('请填写选项', {
  778. icon: 5,
  779. anim: 6,
  780. time: 2000
  781. });
  782. return false;
  783. }
  784. }
  785. $.ajax({
  786. url: '{:url("customer_new_portrait/edit_field")}',
  787. type: 'post',
  788. data: formData,
  789. dataType: 'json',
  790. processData: false,
  791. contentType: false,
  792. success: function (res) {
  793. if (res.code == 0) {
  794. layer.msg(res.msg, {
  795. anim: 0,
  796. }, function () {
  797. location.reload();
  798. });
  799. } else {
  800. layer.msg(res.msg, {
  801. icon: 5,
  802. anim: 6,
  803. time: 2000
  804. });
  805. }
  806. }
  807. });
  808. }
  809. });
  810. });
  811. form.render();
  812. }, 500)
  813. }
  814. function renderSelectItemHtml(arry = [], dom, id, idx) {
  815. let htmls = arry.map((item, index) => {
  816. return `<div class="flex align-center mtbr10 select-item-box-${id}">
  817. <span class="mr10">选项${index + 1}</span>
  818. <input data-type="input" data-idx="${idx}" data-index="${index}" type="text" name="select[${index}][name]" value="${item.name}" placeholder="请输入标题" autocomplete="off"
  819. class="layui-input select_input_content mr10" style="width:150px;">
  820. <input type="hidden" name="select[${index}][id]" value="${item.id || ''}" />
  821. <i data-id="${id}" data-curid="${item.id}" data-idx="${idx}" data-index="${index}" class="layui-icon layui-icon-delete red-font"></i>
  822. </div>`;
  823. }).join('');
  824. let htmls1 = `${htmls}
  825. <div data-id="${id}" data-index="${idx}" class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue add-select-btn add-select-btn-${id}">
  826. +添加
  827. </div>`
  828. $(`.${dom}`).html(htmls1);
  829. setTimeout(() => {
  830. $('.select_input_content').change(function () {
  831. let props = $(this).prop('dataset');
  832. if (props.type && (props.type == 'input')) {
  833. fieldlist[parseInt(props.idx)].select[parseInt(props.index)].name = $(this).val();
  834. }
  835. })
  836. $('.add-select-btn').click(function () {
  837. let id = $(this).prop('dataset').id;
  838. let idx = $(this).prop('dataset').index;
  839. let index = $(`.select-item-box-${id}`).length;
  840. if (index > 0) {
  841. fieldlist[parseInt(idx)].select.push({ name: '', id: '', pid: id });
  842. } else {
  843. fieldlist[parseInt(idx)].select = [];
  844. fieldlist[parseInt(idx)].select.push({ name: '', id: '', pid: id });
  845. }
  846. renderSelectItemHtml(fieldlist[parseInt(idx)].select, `select-list-box-${id}`, id, idx);
  847. })
  848. $('.layui-icon-delete').click(function () {
  849. let id = $(this).prop('dataset').id;
  850. let index = $(this).prop('dataset').index;
  851. let idx = $(this).prop('dataset').idx;
  852. let curid = $(this).prop('dataset').curid;
  853. layer.confirm('确定删除当前选项?', { title: ['信息', 'color:#333333;background-color:#D8E6F1;'], }, function (cdx) {
  854. layer.close(cdx);
  855. if (id && index && idx) {
  856. if (curid) {
  857. let loadingIndex = layer.load('Loading...', {
  858. shade: [0.6,'#000'] //0.1透明度的白色背景
  859. });
  860. $.ajax({
  861. url: "{:url('customer_new_portrait/del_select_opt')}",
  862. data: {
  863. id: curid,
  864. pid: id
  865. },
  866. type: 'post',
  867. dataType: 'json',
  868. success: function (res) {
  869. layer.close(loadingIndex);
  870. if (res.code == 0) {
  871. layer.msg('删除成功,当前选项未使用');
  872. fieldlist[parseInt(idx)].select.splice(parseInt(index), 1);
  873. renderSelectItemHtml(fieldlist[parseInt(idx)].select, `select-list-box-${id}`, id, idx);
  874. } else {
  875. layer.msg(res.msg)
  876. }
  877. }
  878. });
  879. } else {
  880. fieldlist[parseInt(idx)].select.splice(parseInt(index), 1);
  881. renderSelectItemHtml(fieldlist[parseInt(idx)].select, `select-list-box-${id}`, id, idx);
  882. }
  883. }
  884. })
  885. })
  886. }, 300)
  887. }
  888. $('.layui-left-add-plan').click(function () {
  889. layer.prompt({ title: ['添加画像', 'color:#333333;background-color:#D8E6F1;'], }, function (value, index, elem) {
  890. addClientContentApi(value);
  891. layer.close(index);
  892. });
  893. })
  894. $('#add_field_btn').click(function () {
  895. layer.open({
  896. type: 2,
  897. title: ['添加客户画像字段', 'color:#333333;background-color:#D8E6F1;'],
  898. content: '{:url("customer_new_portrait/add_field")}?pid=' + curId,
  899. resize: false,
  900. area: ['60%', '70%'],
  901. // btn: ['确认提交', '取消'],
  902. yes: function (index, layero) {
  903. //点击确认触发 iframe 内容中的按钮提交
  904. // var submit = layero.find('iframe').contents().find("#layuiadmin-field-submit");
  905. // submit.click();
  906. },
  907. end: function () {
  908. requestListApi(curId);
  909. }
  910. });
  911. })
  912. });
  913. </script>
  914. {/block}