success_edit.html 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  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: 100%;
  7. background: #fff;
  8. }
  9. .layui-icon {
  10. font-size: 20px !important;
  11. line-height: 38px;
  12. }
  13. .layui-tab {
  14. padding: 0px;
  15. height: 100%;
  16. }
  17. .layui-tab-card {
  18. border: none;
  19. box-shadow: none;
  20. }
  21. .upload-img .area i {
  22. font-size: 50px;
  23. color: #009688;
  24. }
  25. /*附件上传样式*/
  26. .imageDiv {
  27. display: inline-block;
  28. width: 140px;
  29. height: 125px;
  30. -webkit-box-sizing: border-box;
  31. -moz-box-sizing: border-box;
  32. box-sizing: border-box;
  33. border: 1px dashed darkgray;
  34. background: #f8f8f8;
  35. position: relative;
  36. overflow: hidden;
  37. margin-left: 5px;
  38. margin-bottom: 3px;
  39. }
  40. .imageDiv div {
  41. width: 100%;
  42. height: 100%;
  43. position: absolute;
  44. top: 0px;
  45. background-color: #e6e6e600;
  46. }
  47. .imageDiv div i {
  48. display: none;
  49. font-size: 31px;
  50. position: absolute;
  51. top: 37%;
  52. left: 40%;
  53. }
  54. .imageDiv div:hover {
  55. background-color: #e6e6e680;
  56. }
  57. .imageDiv div:hover i {
  58. display: block;
  59. cursor: pointer;
  60. }
  61. .imgs {
  62. width: 86%;
  63. float: left;
  64. margin-top: -1%;
  65. margin-left: -1%;
  66. }
  67. .labels {
  68. display: block;
  69. float: left;
  70. height: 4%;
  71. }
  72. .text-detail {
  73. margin-top: 40px;
  74. text-align: center;
  75. }
  76. .text-detail>span {
  77. font-size: 40px;
  78. }
  79. .addImages {
  80. display: inline-block;
  81. width: 140px;
  82. height: 125px;
  83. -webkit-box-sizing: border-box;
  84. -moz-box-sizing: border-box;
  85. box-sizing: border-box;
  86. border: 1px dashed darkgray;
  87. background: #f8f8f8;
  88. position: relative;
  89. overflow: hidden;
  90. margin-left: 5px;
  91. margin-bottom: 3px;
  92. }
  93. /*问题图片样式*/
  94. .imgDiv {
  95. display: inline-block;
  96. width: 120px;
  97. height: 105px;
  98. -webkit-box-sizing: border-box;
  99. -moz-box-sizing: border-box;
  100. box-sizing: border-box;
  101. border: 1px dashed darkgray;
  102. background: #f8f8f8;
  103. position: relative;
  104. overflow: hidden;
  105. margin-left: 5px;
  106. margin-bottom: 3px;
  107. }
  108. .imgDiv div i {
  109. position: absolute;
  110. bottom: 71px;
  111. right: 0px;
  112. z-index: 2;
  113. padding: 0 !important;
  114. margin: 0;
  115. }
  116. #uploadimg {
  117. position: absolute;
  118. bottom: 0px;
  119. right: 8px;
  120. z-index: 2;
  121. padding: 0 !important;
  122. margin: 0;
  123. }
  124. .xm-label-block {
  125. background-color: #249efb !important;
  126. }
  127. .layui-tab-card>.layui-tab-title {
  128. background-color: #fff;
  129. }
  130. .layui-tab-card>.layui-tab-title .layui-this {
  131. background-color: #249EFB !important;
  132. color: #fff;
  133. }
  134. .layui-tab-card>.layui-tab-title .layui-this:after {
  135. border-bottom: none;
  136. border: none;
  137. }
  138. .layui-tab-title li {
  139. background-color: #F2F2F2;
  140. margin: 0px 5px !important;
  141. }
  142. xm-select {
  143. width: 99% !important;
  144. min-height: 40px !important;
  145. line-height: 40px !important;
  146. }
  147. xm-select .xm-body .xm-option .xm-option-icon {
  148. display: none !important;
  149. }
  150. /* .xm-icon-close:before {
  151. display: none !important;
  152. } */
  153. xm-select>.xm-label.auto-row .xm-label-block>span {
  154. width: auto !important;
  155. }
  156. xm-select>.xm-label .xm-label-block {
  157. margin: 4px 5px 2px 0 !important;
  158. }
  159. .font18 {
  160. font-size: 16px;
  161. }
  162. .layui-form-item .layui-input-inline {
  163. width: 100% !important;
  164. margin-right: 0;
  165. }
  166. .layui-form-select {
  167. width: 100%;
  168. }
  169. .layui-tab {
  170. margin: 0;
  171. }
  172. .mdt20 {
  173. margin-top: 20px
  174. }
  175. .layui-form-label {
  176. line-height: 40px !important;
  177. width: auto;
  178. padding: 0;
  179. }
  180. .layui-select-title input {
  181. height: 40px !important;
  182. line-height: 40px;
  183. }
  184. .mdb0 {
  185. margin-bottom: 0 !important;
  186. }
  187. #isshowlabel,
  188. .cate01,
  189. .cate02,
  190. .cate03 {
  191. display: none;
  192. }
  193. .borxian {
  194. width: 6px;
  195. height: 20px;
  196. background: #28A1FF;
  197. border-radius: 2px 2px 2px 2px;
  198. display: inline-block;
  199. margin-right: 5px;
  200. vertical-align: -16%;
  201. }
  202. .layui-input-block {
  203. margin-left: 0;
  204. }
  205. .word_list_box {
  206. width: 100%;
  207. height: 300px;
  208. border: 1px solid #EEEEEE;
  209. margin-bottom: 20px;
  210. box-sizing: border-box;
  211. padding: 10px;
  212. overflow-y: auto;
  213. }
  214. /* 设置滚动条的样式 */
  215. .word_list_box::-webkit-scrollbar {
  216. width: 2px;
  217. }
  218. /* 滚动槽 */
  219. .word_list_box::-webkit-scrollbar-track {
  220. -webkit-box-shadow: inset006pxrgba(0, 0, 0, 0.3);
  221. border-radius: 10px;
  222. }
  223. /* 滚动条滑块 */
  224. .word_list_box::-webkit-scrollbar-thumb {
  225. background: rgba(0, 0, 0, 0.3);
  226. -webkit-box-shadow: inset006pxrgba(0, 0, 0, 0.5);
  227. }
  228. .float_left {
  229. float: left;
  230. }
  231. .mtcelter {
  232. height: 100px;
  233. line-height: 100px;
  234. width: 80px;
  235. }
  236. .flex-row {
  237. display: flex;
  238. }
  239. .flex-sub {
  240. flex: 1;
  241. }
  242. .left_ask {
  243. width: 100%;
  244. height: auto;
  245. overflow: hidden;
  246. box-sizing: border-box;
  247. padding: 10px 0px;
  248. }
  249. .left_ask_avatar {
  250. width: 34px;
  251. height: 34px;
  252. float: left;
  253. }
  254. .left_ask_avatar>img {
  255. width: 100%;
  256. height: 100%;
  257. }
  258. .left_ask_content {
  259. float: left;
  260. max-width: 80%;
  261. min-height: 34px;
  262. background-color: #EFEFEF;
  263. margin-left: 10px;
  264. box-sizing: border-box;
  265. padding: 8px 5px;
  266. display: flex;
  267. align-items: center;
  268. position: relative;
  269. }
  270. .right_answer {
  271. width: 100%;
  272. height: auto;
  273. overflow: hidden;
  274. box-sizing: border-box;
  275. padding: 10px 0px;
  276. }
  277. .right_answer_avatar {
  278. width: 34px;
  279. height: 34px;
  280. float: right;
  281. }
  282. .right_answer_avatar>img {
  283. width: 100%;
  284. height: 100%;
  285. }
  286. .right_answer_content {
  287. float: right;
  288. max-width: 80%;
  289. min-height: 34px;
  290. background-color: #EFEFEF;
  291. margin-right: 10px;
  292. box-sizing: border-box;
  293. padding: 8px 5px;
  294. display: flex;
  295. /* align-items: center; */
  296. justify-content: flex-end;
  297. background-color: #95EC6A;
  298. position: relative;
  299. flex-direction: column;
  300. }
  301. .lay-l-close {
  302. position: absolute;
  303. top: 50%;
  304. right: -30px;
  305. transform: translateY(-50%);
  306. color: red;
  307. cursor: pointer;
  308. }
  309. .lay-l-edit {
  310. position: absolute;
  311. top: 50%;
  312. right: -55px;
  313. transform: translateY(-50%);
  314. color: #249EFB;
  315. cursor: pointer;
  316. }
  317. .lay-r-close {
  318. position: absolute;
  319. top: 50%;
  320. left: -30px;
  321. transform: translateY(-50%);
  322. color: red;
  323. cursor: pointer;
  324. }
  325. .lay-r-edit {
  326. position: absolute;
  327. top: 50%;
  328. left: -55px;
  329. transform: translateY(-50%);
  330. color: #249EFB;
  331. cursor: pointer;
  332. }
  333. .noneData {
  334. width: 100%;
  335. height: 100%;
  336. display: flex;
  337. justify-content: center;
  338. align-items: center;
  339. color: #999999;
  340. }
  341. #uploadimg,#edituploadimg {
  342. position: absolute;
  343. bottom: 0px;
  344. right: 8px;
  345. z-index: 2;
  346. padding: 0 !important;
  347. margin: 0;
  348. }
  349. .addimgDiv {
  350. display: inline-block;
  351. width: 60px;
  352. height: 52px;
  353. margin-right: 8px;
  354. margin-top: 10px;
  355. overflow: hidden;
  356. position: relative;
  357. }
  358. .addimgDiv img {
  359. display: block;
  360. width: 100%;
  361. height: 100%;
  362. }
  363. .addimgDiv div i {
  364. position: absolute;
  365. right: -1px;
  366. top: -9px;
  367. z-index: 2;
  368. padding: 0 !important;
  369. margin: 0;
  370. }
  371. .answerbox{
  372. display: block;
  373. padding: 20px;
  374. }
  375. .answerbox textarea{
  376. display: block;
  377. width: 100%;
  378. height:150px;
  379. resize:none;
  380. border: 1px solid #e6e6e6;
  381. color: #333;
  382. padding: 6px 10px;
  383. box-sizing: border-box;
  384. }
  385. .editext{
  386. width: 410px;
  387. display: block;
  388. position: relative;
  389. }
  390. </style>
  391. <body>
  392. <form class="layui-form" id="admin" enctype="multipart/form-data">
  393. <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 15px;">
  394. <div class="layui-form-item" style="margin:0 auto; width:97%;">
  395. <div class="layui-tab layui-tab-card">
  396. <div class="layui-tab-content" style="padding:0;overflow: hidden;">
  397. <div class="layui-tab-item layui-show" style="width:63%;float:left;border-right: 1px dashed #ccc;">
  398. <p class="font18"><span class="borxian"></span>基础信息</p>
  399. <div style="width:95%;margin-top:20px">
  400. <div class="layui-form-item">
  401. <div class="layui-input-block">
  402. <input type="text" name="title" value="{$data.title}" required lay-verify="required"
  403. placeholder="请输入标题" autocomplete="off" class="layui-input">
  404. </div>
  405. </div>
  406. <div class="word_list_box">
  407. <div class="noneData">话术内容展示</div>
  408. </div>
  409. <div class="layui-form-item flex-row">
  410. <div class="layui-input-block float_left flex-sub">
  411. <input type="text" placeholder="请输入问题" id="ask_content" autocomplete="off" class="layui-input">
  412. </div>
  413. <div class="layui-btn float_left" id="ask_upload" style="width: 80px;">上传</div>
  414. </div>
  415. <div class="layui-form-item layui-form-text flex-row">
  416. <div class="layui-input-block float_left flex-sub">
  417. <textarea style="resize:none;" id="answer_content" placeholder="请输入回答内容"
  418. class="layui-textarea"></textarea>
  419. <div class="layui-form-mid layui-word-aux" id="uploadimg"><i class="layui-icon">&#xe64a;</i></div>
  420. </div>
  421. <div class="layui-btn float_left mtcelter" id="answer_upload">上传</div>
  422. </div>
  423. <div style="margin-top: -10px;margin-bottom: 5px;"><i style="color: red;margin-right:5px;">*</i>建议上传封面图宽高比例1:1,图片大小不超过1M</div>
  424. <div class="layui-input-block" id="imgArray" style="display: none;"></div>
  425. </div>
  426. </div>
  427. <div style="width:34%;float:right;">
  428. <p class="font18"><span class="borxian"></span>设置场景</p>
  429. <div class="layui-form-item mdt20 mdb0">
  430. <label class="layui-form-label"><span style="color:red">*</span>所属场景</label>
  431. <p style="clear:both"></p>
  432. <div class="layui-input-inline">
  433. <select name="cate1" lay-filter="type" id="type" lay-verify="required">
  434. <option value="">请选择所属场景</option>
  435. {volist name="cate" id="t"}
  436. <option value="{$t.id}" id="{$t.id}" {if $t.id eq $data.cate1}selected{/if}>{$t.name}</option>
  437. {/volist}
  438. </select>
  439. </div>
  440. </div>
  441. <div class="layui-form-item mdt20 mdb0" id="isshowlabel">
  442. <label class="layui-form-label" style="line-height:33px !important; font-size: 14px;">二级分类 <span
  443. class="cate01">已选择<a id="dataCounts">0</a>个</span></label>
  444. <p style="clear:both"></p>
  445. <div class="layui-input-block">
  446. <div id="label"></div>
  447. </div>
  448. </div>
  449. <div class="layui-form-item mdt20 mdb0">
  450. <label class="layui-form-label" style="line-height:33px !important; font-size: 14px;">适用部门 <span
  451. class="cate02">已选择<a id="dataCounts1">0</a>个</span></label>
  452. <p style="clear:both"></p>
  453. <div class="layui-input-block">
  454. <div id="label1"></div>
  455. </div>
  456. </div>
  457. <div class="layui-form-item mdt20 mdb0">
  458. <label class="layui-form-label" style="line-height:33px !important; font-size: 14px;">房屋类型 <span
  459. class="cate03">已选择<a id="dataCounts2">0</a>个</span></label>
  460. <p style="clear:both"></p>
  461. <div class="layui-input-block">
  462. <div id="label2"></div>
  463. </div>
  464. </div>
  465. </div>
  466. </div>
  467. </div>
  468. </div>
  469. <div class="layui-form-item layui-hide">
  470. <input type="button" lay-submit lay-filter="talkskill-submit" id="talkskill-submit" value="确认添加">
  471. <input type="button" lay-submit lay-filter="talkskill-edit" id="talkskill-edit" value="确认编辑">
  472. </div>
  473. </div>
  474. </form>
  475. </body>
  476. {/block} {block name="js"}
  477. <script src="__STATIC__/layui/layui/lay/modules/xm-select.js" type="text/javascript" charset="utf-8"></script>
  478. <script type="text/html" id="editanswerbox">
  479. <div class="answerbox">
  480. <div class="editext">
  481. <textarea style="resize:none;"></textarea>
  482. <div class="layui-form-mid layui-word-aux" id="edituploadimg"><i class="layui-icon">&#xe64a;</i></div>
  483. </div>
  484. <div style="margin-top: 5px;"><i style="color: red;margin-right:5px;">*</i>建议上传封面图宽高比例1:1,图片大小不超过1M</div>
  485. <div class="layui-input-block" id="editimgArray" style="display:none;">
  486. </div>
  487. </div>
  488. </script>
  489. <script>
  490. layui.config({
  491. base: '__LAYUI__/',
  492. urlbase: '/sys'
  493. }).extend({
  494. index: 'lib/index'
  495. }).use(['index', 'form', 'upload'], function () {
  496. var $ = layui.$,
  497. upload = layui.upload,
  498. form = layui.form,
  499. images,
  500. files,
  501. wordlist = [],
  502. wordimgs = [],
  503. editimgarr = [];
  504. //话术添加
  505. var clickRepeatedly = false; //防止重复点击
  506. form.on('submit(talkskill-submit)', function (data) {
  507. if(clickRepeatedly == true) return false;
  508. clickRepeatedly = true;
  509. if (!wordlist.length) {
  510. layer.msg('请添加话术内容', {
  511. anim: 6, time: 800
  512. });
  513. clickRepeatedly = false;
  514. return;
  515. }
  516. var index = parent.layer.getFrameIndex(window.name);
  517. var formData = new FormData(data.form);
  518. var load = layer.load(1, {shade: [0.5, '#fff']});
  519. formData.delete('images_data');
  520. let t = 0;
  521. wordlist.forEach((v, i) => {
  522. if (v.id) {
  523. formData.append(`content[${i}][type]`, v.type);
  524. formData.append(`content[${i}][content]`, v.content);
  525. formData.append(`content[${i}][id]`, v.id);
  526. } else {
  527. formData.append(`content[${i}][type]`, v.type);
  528. formData.append(`content[${i}][content]`, v.content)
  529. }
  530. if (v.type == 1) {
  531. if (wordimgs[t]) {
  532. formData.delete(`img_${i}[]`);
  533. formData.delete(`imgnew_${i}[]`);
  534. for (let j = 0; j < wordimgs[t].length; j++) {
  535. if (wordimgs[t][j].toString().substr(0, 10) == 'Talkskill/') {
  536. formData.append(`img_${i}[]`, wordimgs[t][j]);
  537. } else {
  538. formData.append(`imgnew_${i}[]`, wordimgs[t][j]);
  539. }
  540. }
  541. } else if (editimgarr[t]) {
  542. formData.delete(`imgnew_${i}[]`);
  543. if (editimgarr[t]) {
  544. for (let j = 0; j < editimgarr[t].length; j++) {
  545. formData.append(`imgnew_${i}[]`, editimgarr[t][j]);
  546. }
  547. }
  548. }
  549. t++;
  550. }
  551. })
  552. formData.append("id", "{$data.id}")
  553. $.ajax({
  554. url: '{:url("talkskill/success_edit")}',
  555. type: 'post',
  556. data: formData,
  557. dataType: 'json',
  558. processData: false,
  559. contentType: false,
  560. success: function (res) {
  561. if (res.code === 0) {
  562. layer.msg(res.msg, {
  563. anim: 0, time: 800
  564. }, function () {
  565. parent.layui.table.reload('talkskill-table');
  566. parent.layer.close(index);
  567. });
  568. } else {
  569. layer.close(load);
  570. layer.msg(res.msg, {
  571. anim: 6, time: 800
  572. });
  573. }
  574. clickRepeatedly = false;
  575. }
  576. });
  577. });
  578. $('.layui-layer-btn').css({ "boxShadow": "0 0 5px #000" });
  579. var options = {
  580. el: '#label',
  581. name: 'cate2',
  582. autoRow: true,
  583. tips: '请选择所属场景',
  584. data: [],
  585. on: function (data) {
  586. var arr = data.arr;
  587. if (arr.length > 0) {
  588. $('.cate01').show();
  589. $('#dataCounts').html(arr.length);
  590. } else {
  591. $('.cate01').hide();
  592. }
  593. }
  594. };
  595. var options1 = {
  596. el: '#label1',
  597. name: 'user_cate',
  598. autoRow: true,
  599. tips: '请选择适用部门',
  600. data: [],
  601. on: function (data) {
  602. var arr = data.arr;
  603. if (arr.length > 0) {
  604. $('.cate02').show();
  605. $('#dataCounts1').html(arr.length);
  606. } else {
  607. $('.cate02').hide();
  608. }
  609. }
  610. };
  611. var options2 = {
  612. el: '#label2',
  613. name: 'house_type',
  614. autoRow: true,
  615. tips: '请选择房屋类型',
  616. data: [],
  617. on: function (data) {
  618. var arr = data.arr;
  619. if (arr.length > 0) {
  620. $('.cate03').show();
  621. $('#dataCounts2').html(arr.length);
  622. } else {
  623. $('.cate03').hide();
  624. }
  625. }
  626. };
  627. $('#ask_upload').click(function () {
  628. let val = $('#ask_content').val();
  629. val = $.trim(val);
  630. if (!val) {
  631. layer.msg('请输入问题', {
  632. anim: 6, time: 800
  633. });
  634. return;
  635. }
  636. wordlist.push({ type: '0', content: val });
  637. renderWordlistHtml(wordlist);
  638. $('#ask_content').val('');
  639. setTimeout(() => {
  640. var scrollHeight = $('.word_list_box').prop("scrollHeight");
  641. $('.word_list_box').scrollTop(scrollHeight, 200);
  642. }, 600)
  643. })
  644. $('#answer_upload').click(function () {
  645. let val = $('#answer_content').val();
  646. val = $.trim(val);
  647. if (!val && (!images || JSON.stringify(images) === '{}')) {
  648. layer.msg('请输入回答', {
  649. anim: 6, time: 800
  650. });
  651. return;
  652. }
  653. var img = [];
  654. for (var i in $('#imgArray .imgDiv img')) {
  655. if ($('#imgArray .imgDiv img')[i].src) {
  656. img.push($('#imgArray .imgDiv img')[i].src);
  657. }
  658. }
  659. if (!!images) {
  660. let arr = [];
  661. for (var t in images) {
  662. arr.push(images[t])
  663. }
  664. editimgarr.push(arr);
  665. } else {
  666. editimgarr.push('');
  667. }
  668. for (let x in images) {
  669. delete images[x];
  670. }
  671. $('#imgArray').html('');
  672. wordlist.push({ type: '1', content: val, img: img });
  673. renderWordlistHtml(wordlist);
  674. $('#answer_content').val('');
  675. setTimeout(() => {
  676. var scrollHeight = $('.word_list_box').prop("scrollHeight");
  677. $('.word_list_box').scrollTop(scrollHeight, 200);
  678. }, 600)
  679. })
  680. function renderWordlistHtml(data) {
  681. let w = 0;
  682. let htmls = data.map((item, index) => {
  683. item.content = item.content.replace(/^(\s|&quot;)+|(\s|&quot;)+$/g, '');
  684. if (item.type == '0') {
  685. return `<div class="left_ask">
  686. <div class="left_ask_avatar">
  687. <img src="__STATIC__/img/ask_icon.png" alt="">
  688. </div>
  689. <div class="left_ask_content">
  690. <pre class="txt">${item.content}</pre>
  691. <i data-index="${index}" class="layui-icon layui-icon-delete lay-l-close"></i>
  692. <i data-index="${index}" class="layui-icon layui-icon-edit lay-l-edit"></i>
  693. </div>
  694. </div>`;
  695. } else {
  696. let imgstr = "";
  697. for (let i = 0; i < item.img.length; i++) {
  698. imgstr += '<div class="addimgDiv" data-id="' + i + '"><img src="' + item.img[i] + '" class="layui-upload-img" width="100%" height="100%" onclick="previewImg(this)"><div><i data-index="' + w + '" data-id="' + i + '" class="layui-icon layui-icon-closeimg layui-icon-close-fill"></i></div></div>';
  699. }
  700. w++;
  701. return `<div class="right_answer">
  702. <div class="right_answer_avatar">
  703. <img src="__STATIC__/img/answer_icon.png" alt="">
  704. </div>
  705. <div class="right_answer_content">
  706. <pre>${item.content}</pre>
  707. <i data-index="${index}" class="layui-icon layui-icon-delete lay-r-close"></i>
  708. <i data-index="${index}" class="layui-icon layui-icon-edit lay-r-edit"></i>
  709. <div data-index="${index}" class="right_answer_img" style="display: block;width: 100%;flex-shrink: 0;">${imgstr}</div>
  710. </div>
  711. </div>`;
  712. }
  713. }).join('');
  714. $('.word_list_box').html(htmls);
  715. setTimeout(() => {
  716. //删除图片
  717. $('.layui-icon-closeimg').click(function () {
  718. var that = this;
  719. let index = $(this).prop('dataset').index;
  720. let i = $(this).prop('dataset').id;
  721. var imgDiv = $(that).closest('.addimgDiv');
  722. let img1 = $(that).closest('.right_answer_img');
  723. if (wordimgs[index]) {
  724. if (wordimgs[index][i]) {
  725. wordimgs[index].splice(i, 1);
  726. } else {
  727. editimgarr[index].splice(i - wordimgs[index].length + 1, 1);
  728. }
  729. } else {
  730. editimgarr[index].splice(i, 1);
  731. }
  732. imgDiv.remove();
  733. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  734. });
  735. $('.lay-l-close').click(function () {
  736. let index = $(this).prop('dataset').index;
  737. wordlist.splice(index, 1);
  738. renderWordlistHtml(wordlist);
  739. })
  740. $('.lay-r-close').click(function () {
  741. let index = $(this).prop('dataset').index;
  742. wordlist.splice(index, 1);
  743. renderWordlistHtml(wordlist);
  744. })
  745. $('.lay-l-edit').click(function () {
  746. let idx = $(this).prop('dataset').index;
  747. layer.prompt({
  748. formType: 2,
  749. title: ['编辑问题内容', 'color:#333333;background-color:#D8E6F1;'],
  750. area: ['400px', '150px']
  751. }, function (value, index, elem) {
  752. var value = $.trim(value);
  753. if (value == '') {
  754. layer.msg('请输入内容', { anim: 6 });
  755. return false;
  756. }
  757. wordlist[idx].content = value;
  758. renderWordlistHtml(wordlist);
  759. layer.close(index); //再执行关闭
  760. });
  761. form.render();
  762. })
  763. $('.lay-r-edit').click(function () {
  764. let that = this;
  765. let idx = $(this).prop('dataset').index;
  766. let h = -1;
  767. for (let i in wordlist) {
  768. if (wordlist[i].type == 1) {
  769. h++;
  770. if (idx == i) {
  771. break;
  772. }
  773. }
  774. }
  775. let editimages = wordimgs[h] ? wordimgs[h].concat([]) : editimgarr[h] ? editimgarr[h].concat([]) : [];
  776. let images9;
  777. layer.open({
  778. type: 1,
  779. title: ['编辑回答内容', 'color:#333333;background-color:#D8E6F1;'],
  780. area: '450px',
  781. resize: false,
  782. btn: ['确定', '取消'],
  783. fixed: false, //不固定
  784. content: $('#editanswerbox').html(),
  785. success: function (layero, index) {
  786. for (let x in images9) {
  787. delete images9[x];
  788. }
  789. $('.editext textarea').val($(that).siblings('pre').text());
  790. if (!!$(that).siblings('.right_answer_img').html()) {
  791. $('#editimgArray').show();
  792. $('#editimgArray').html($(that).siblings('.right_answer_img').html());
  793. setTimeout(() => {
  794. $('.layui-icon-closeimg').click(function () {
  795. var that = this;
  796. let i = $(this).prop('dataset').id;
  797. var imgDiv = $(that).closest('.addimgDiv');
  798. let img1 = $(that).closest('.right_answer_img');
  799. editimages.splice(i, 1);
  800. imgDiv.remove();
  801. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  802. });
  803. }, 500);
  804. }
  805. //回答图片上传
  806. upload.render({
  807. elem: '#edituploadimg',
  808. accept: 'images',
  809. url: '/upload/',
  810. exts: 'jpg|png|bmp|jpeg|JPG|PNG|BMP|JPEG',
  811. field: 'images_data',
  812. size: 1 * 1024,
  813. auto: false,
  814. multiple: true,
  815. choose: function (obj) {
  816. images9 = obj.pushFile();
  817. $('#editimgArray').show();
  818. length = editimages.length;
  819. obj.preview(function (index, file, result) {
  820. length++;
  821. if (length > 9) {
  822. layer.msg('最多上传九张图片');
  823. } else {
  824. editimages.push(file);
  825. $('#editimgArray').append('<div class="addimgDiv" data-id="' + index + '"><img src="' + result + '" alt="' + file.name + '" class="layui-upload-img" width="100%" height="100%" onclick="previewImg(this)"><div><i data-id="' + (length - 1) + '" class="layui-icon layui-icon-closeimg1 layui-icon-close-fill"></i></div></div>');
  826. }
  827. });
  828. setTimeout(() => {
  829. //删除图片
  830. $('.layui-icon-closeimg1').click(function () {
  831. var that = this;
  832. let i = $(this).prop('dataset').id;
  833. var imgDiv = $(that).closest('.addimgDiv');
  834. let img1 = $(that).closest('.right_answer_img');
  835. editimages.splice(i, 1);
  836. if (id = imgDiv.data('id')) {
  837. delete images9[id];
  838. }
  839. imgDiv.remove();
  840. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  841. });
  842. }, 500);
  843. }
  844. });
  845. },
  846. yes: function (index, layero) {
  847. //do something
  848. var value = $.trim($('.editext textarea').val());
  849. if (value == '') {
  850. layer.msg('请输入内容', { anim: 6 });
  851. return false;
  852. }
  853. wordlist[idx].content = value;
  854. if (wordimgs[h]) {
  855. wordimgs[h] = editimages;
  856. } else {
  857. editimgarr[h] = editimages;
  858. }
  859. let arr = [];
  860. for (let i = 0; i < $('#editimgArray img').length; i++) {
  861. arr.push($('#editimgArray img')[i].src);
  862. }
  863. wordlist[idx].img = arr;
  864. renderWordlistHtml(wordlist);
  865. layer.close(index); //如果设定了yes回调,需进行手工关闭
  866. },
  867. end: function (index, layero) {
  868. for (let x in images9) {
  869. delete images9[x];
  870. }
  871. layer.close(index)
  872. return false;
  873. }
  874. });
  875. form.render();
  876. })
  877. }, 500)
  878. }
  879. var label = xmSelect.render(options);
  880. var label1 = xmSelect.render(options1);
  881. var label2 = xmSelect.render(options2);
  882. $(function () {
  883. let arr1 = [];
  884. {volist name = "data.content" id = "vo" }
  885. var type = "{$vo.type}"
  886. var content = "{$vo.content}"
  887. var id = "{$vo.id}"
  888. var img = [], imgarr = [];
  889. {empty name = "vo.img" }
  890. if (type == 1) {
  891. let arr = [];
  892. wordimgs.push(arr);
  893. editimgarr.push(arr);
  894. }
  895. {else /}
  896. {volist name = "vo.img" id = "m" }
  897. img.push("{$m}");
  898. imgarr.push('https://' + '{$oss_bindurl}' + '/' + "{$m}");
  899. {/volist}
  900. wordimgs[wordimgs.length] = img;
  901. editimgarr.push(arr1);
  902. {/empty}
  903. wordlist.push({ type: type, content: content, id: id, img: imgarr });
  904. {/volist}
  905. renderWordlistHtml(wordlist);
  906. let cate1Id = "{$data.cate1}";
  907. let cate2_ids = "{$data.cate2}";
  908. let house_type_ids = "{$data.house_type}";
  909. let user_cate_ids = "{$data.user_cate}";
  910. let cate2_ids_arr = cate2_ids.split(',');
  911. let house_type_ids_arr = house_type_ids.split(',');
  912. let user_cate_ids_arr = user_cate_ids.split(',');
  913. if (cate1Id) {
  914. $('#isshowlabel').show();
  915. }
  916. selectdata("{:url('talkskill/dictionary_list')}", label, 4, cate1Id, cate2_ids_arr);
  917. selectdata("{:url('talkskill/dictionary_list')}", label1, 3, 0, user_cate_ids_arr);
  918. selectdata("{:url('talkskill/dictionary_list')}", label2, 2, 0, house_type_ids_arr);
  919. });
  920. form.on('select(type)', function (data) {
  921. $('#isshowlabel').show();
  922. selectdata("{:url('talkskill/dictionary_list')}", label, 4, $(data.elem).find('option:selected').attr('id'));
  923. })
  924. function selectdata(url, index, type, id, ids) {
  925. setTimeout(function () {
  926. $.ajax({
  927. type: "get",
  928. url: url,
  929. dataType: 'json',
  930. data: {
  931. type: type,
  932. pid: id,
  933. page: 1,
  934. limit: 10000
  935. },
  936. success: function (data) {
  937. index.update({ data: handleData(data.data, ids) });
  938. }
  939. });
  940. }, 100);
  941. }
  942. function handleData(data, ids) {
  943. return data.map(v => {
  944. return { name: v.name, value: v.id, id: v.id, selected: ids ? (ids.indexOf(`${v.id}`) > -1) : false };
  945. })
  946. }
  947. var addtslabel = function () {
  948. layer.prompt({
  949. title: ['话术场景添加', 'color:#333333;background-color:#D8E6F1;'],
  950. }, function (value, index, elem) {
  951. $.post('{:url("talkskill/add_talkskill_label")}', {
  952. value: value
  953. }, function (res) {
  954. if (res.code == 0) {
  955. $(function () {
  956. selectdata();
  957. });
  958. layer.msg(res.msg, { anim: 0, time: 800 }, function () {
  959. layer.close(index); //再执行关闭
  960. });
  961. } else {
  962. layer.msg(res.msg, { anim: 6 });
  963. }
  964. });
  965. });
  966. }
  967. //添加分类
  968. $('#cate-add').on('click', function () {
  969. addcate();
  970. });
  971. var addcate = function () {
  972. layer.prompt({
  973. title: ['添加适用部门', 'color:#333333;background-color:#D8E6F1;'],
  974. }, function (value, index, elem) {
  975. var value = $.trim(value);
  976. if (value == '') {
  977. layer.msg('请输入名称', { anim: 6 });
  978. return false;
  979. }
  980. if (value.length > 6) {
  981. layer.msg('名称超长', { anim: 6 });
  982. return false;
  983. }
  984. $.post('{:url("talkskill/person_add")}', {
  985. 'name': value
  986. }, function (res) {
  987. if (res.code == 0) {
  988. $('#type').append("<option selected value='" + value + "' id='" + res.id + "'>" + value + "</option>")
  989. form.render();
  990. layer.msg(res.msg, {
  991. anim: 0, time: 800
  992. }, function () {
  993. layer.close(index); //再执行关闭
  994. });
  995. } else {
  996. layer.msg(res.msg, {
  997. anim: 6, time: 800
  998. });
  999. }
  1000. });
  1001. });
  1002. form.render();
  1003. }
  1004. //回答图片上传
  1005. upload.render({
  1006. elem: '#uploadimg',
  1007. accept: 'images',
  1008. url: '/upload/',
  1009. exts: 'jpg|png|bmp|jpeg|JPG|PNG|BMP|JPEG',
  1010. field: 'images_data',
  1011. size: 1 * 1024,
  1012. auto: false,
  1013. multiple: true,
  1014. choose: function (obj) {
  1015. images = obj.pushFile();
  1016. length = $('.imgDiv').length;
  1017. // console.log(images)
  1018. obj.preview(function (index, file, result) {
  1019. length++;
  1020. if (length > 9) {
  1021. layer.msg('最多上传九张图片');
  1022. delete images[index];
  1023. } else {
  1024. $('#imgArray').css('display', 'block');
  1025. $('#imgArray').prepend('<div class="imgDiv" data-id="' + index + '"><img src="' + result + '" alt="' + file.name + '" class="layui-upload-img" width="100%" height="100%" onclick="previewImg(this)"><div><i class="layui-icon layui-icon-close-fill"></i></div></div>');
  1026. }
  1027. });
  1028. }
  1029. });
  1030. //删除图片
  1031. $('#imgArray').on('click', 'i', function () {
  1032. var that = this;
  1033. var imgDiv = $(that).closest('.imgDiv');
  1034. if (id = imgDiv.data('id')) {
  1035. delete images[id];
  1036. }
  1037. imgDiv.remove();
  1038. if ($('#imgArray').html().trim().length == 0) $('#imgArray').css('display', 'none');
  1039. });
  1040. });
  1041. //放大图片
  1042. function previewImg(obj) {
  1043. var imgHtml = "<img src='" + obj.src + "' width='100%' height='100%' />";
  1044. layer.open({
  1045. type: 1,
  1046. title: false,
  1047. closeBtn: 0,
  1048. area: ['auto', '80%'],
  1049. skin: 'layui-layer-nobg', //没有背景色
  1050. shadeClose: true,
  1051. content: imgHtml
  1052. });
  1053. }
  1054. </script>
  1055. {/block}