chosen_edit.html 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  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}" placeholder="请输入标题" autocomplete="off"
  403. 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. style="color:red">*</span>二级分类 <span 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/chosen_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('label-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. layVerify: 'required',
  586. on: function (data) {
  587. var arr = data.arr;
  588. if (arr.length > 0) {
  589. $('.cate01').show();
  590. $('#dataCounts').html(arr.length);
  591. } else {
  592. $('.cate01').hide();
  593. }
  594. }
  595. };
  596. var options1 = {
  597. el: '#label1',
  598. name: 'user_cate',
  599. autoRow: true,
  600. tips: '请选择适用部门',
  601. data: [],
  602. on: function (data) {
  603. var arr = data.arr;
  604. if (arr.length > 0) {
  605. $('.cate02').show();
  606. $('#dataCounts1').html(arr.length);
  607. } else {
  608. $('.cate02').hide();
  609. }
  610. }
  611. };
  612. var options2 = {
  613. el: '#label2',
  614. name: 'house_type',
  615. autoRow: true,
  616. tips: '请选择房屋类型',
  617. data: [],
  618. on: function (data) {
  619. var arr = data.arr;
  620. if (arr.length > 0) {
  621. $('.cate03').show();
  622. $('#dataCounts2').html(arr.length);
  623. } else {
  624. $('.cate03').hide();
  625. }
  626. }
  627. };
  628. $('#ask_upload').click(function () {
  629. let val = $('#ask_content').val();
  630. val = $.trim(val);
  631. if (!val) {
  632. layer.msg('请输入问题', {
  633. anim: 6, time: 800
  634. });
  635. return;
  636. }
  637. wordlist.push({ type: '0', content: val });
  638. renderWordlistHtml(wordlist);
  639. $('#ask_content').val('');
  640. setTimeout(() => {
  641. var scrollHeight = $('.word_list_box').prop("scrollHeight");
  642. $('.word_list_box').scrollTop(scrollHeight, 200);
  643. }, 600)
  644. })
  645. $('#answer_upload').click(function () {
  646. let val = $('#answer_content').val();
  647. val = $.trim(val);
  648. if (!val && (!images || JSON.stringify(images) === '[]')) {
  649. layer.msg('请输入回答', {
  650. anim: 6, time: 800
  651. });
  652. return;
  653. }
  654. var img = [];
  655. for (var i in $('#imgArray .imgDiv img')) {
  656. if ($('#imgArray .imgDiv img')[i].src) {
  657. img.push($('#imgArray .imgDiv img')[i].src);
  658. }
  659. }
  660. if (!!images) {
  661. let arr = [];
  662. for (var t in images) {
  663. arr.push(images[t])
  664. }
  665. editimgarr.push(arr);
  666. } else {
  667. editimgarr.push('');
  668. }
  669. for (let x in images) {
  670. delete images[x];
  671. }
  672. $('#imgArray').html('');
  673. wordlist.push({ type: '1', content: val, img: img });
  674. renderWordlistHtml(wordlist);
  675. $('#answer_content').val('');
  676. setTimeout(() => {
  677. var scrollHeight = $('.word_list_box').prop("scrollHeight");
  678. $('.word_list_box').scrollTop(scrollHeight, 200);
  679. }, 600)
  680. })
  681. function renderWordlistHtml(data) {
  682. let w = 0;
  683. let htmls = data.map((item, index) => {
  684. item.content = item.content.replace(/^(\s|&quot;)+|(\s|&quot;)+$/g, '');
  685. if (item.type == '0') {
  686. return `<div class="left_ask">
  687. <div class="left_ask_avatar">
  688. <img src="__STATIC__/img/ask_icon.png" alt="">
  689. </div>
  690. <div class="left_ask_content">
  691. <pre class="txt">${item.content}</pre>
  692. <i data-index="${index}" class="layui-icon layui-icon-delete lay-l-close"></i>
  693. <i data-index="${index}" class="layui-icon layui-icon-edit lay-l-edit"></i>
  694. </div>
  695. </div>`;
  696. } else {
  697. let imgstr = "";
  698. for (let i = 0; i < item.img.length; i++) {
  699. 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>';
  700. }
  701. w++;
  702. return `<div class="right_answer">
  703. <div class="right_answer_avatar">
  704. <img src="__STATIC__/img/answer_icon.png" alt="">
  705. </div>
  706. <div class="right_answer_content">
  707. <pre>${item.content}</pre>
  708. <i data-index="${index}" class="layui-icon layui-icon-delete lay-r-close"></i>
  709. <i data-index="${index}" class="layui-icon layui-icon-edit lay-r-edit"></i>
  710. <div data-index="${index}" class="right_answer_img" style="display: block;width: 100%;flex-shrink: 0;">${imgstr}</div>
  711. </div>
  712. </div>`;
  713. }
  714. }).join('');
  715. $('.word_list_box').html(htmls);
  716. setTimeout(() => {
  717. //删除图片
  718. $('.layui-icon-closeimg').click(function () {
  719. var that = this;
  720. let index = $(this).prop('dataset').index;
  721. let i = $(this).prop('dataset').id;
  722. var imgDiv = $(that).closest('.addimgDiv');
  723. let img1 = $(that).closest('.right_answer_img');
  724. if(wordimgs[index]){
  725. if(wordimgs[index][i]){
  726. wordimgs[index].splice(i, 1);
  727. }else{
  728. editimgarr[index].splice(i- wordimgs[index].length+1, 1);
  729. }
  730. }else{
  731. editimgarr[index].splice(i, 1);
  732. }
  733. imgDiv.remove();
  734. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  735. });
  736. $('.lay-l-close').click(function () {
  737. let index = $(this).prop('dataset').index;
  738. wordlist.splice(index, 1);
  739. renderWordlistHtml(wordlist);
  740. })
  741. $('.lay-r-close').click(function () {
  742. let index = $(this).prop('dataset').index;
  743. wordlist.splice(index, 1);
  744. renderWordlistHtml(wordlist);
  745. })
  746. $('.lay-l-edit').click(function () {
  747. let idx = $(this).prop('dataset').index;
  748. layer.prompt({
  749. formType: 2,
  750. title: ['编辑问题内容', 'color:#333333;background-color:#D8E6F1;'],
  751. area: ['400px', '150px']
  752. }, function (value, index, elem) {
  753. var value = $.trim(value);
  754. if (value == '') {
  755. layer.msg('请输入内容', { anim: 6 });
  756. return false;
  757. }
  758. wordlist[idx].content = value;
  759. renderWordlistHtml(wordlist);
  760. layer.close(index); //再执行关闭
  761. });
  762. form.render();
  763. })
  764. $('.lay-r-edit').click(function () {
  765. let that = this;
  766. let idx = $(this).prop('dataset').index;
  767. let h = -1;
  768. for (let i in wordlist) {
  769. if (wordlist[i].type == 1) {
  770. h++;
  771. if (idx == i) {
  772. break;
  773. }
  774. }
  775. }
  776. let editimages = wordimgs[h] ? wordimgs[h].concat([]) : editimgarr[h]? editimgarr[h].concat([]):[];
  777. let images9;
  778. layer.open({
  779. type: 1,
  780. title: ['编辑回答内容', 'color:#333333;background-color:#D8E6F1;'],
  781. area: '450px',
  782. resize: false,
  783. btn: ['确定', '取消'],
  784. fixed: false, //不固定
  785. content: $('#editanswerbox').html(),
  786. success: function (layero, index) {
  787. for (let x in images9) {
  788. delete images9[x];
  789. }
  790. $('.editext textarea').val($(that).siblings('pre').text());
  791. if (!!$(that).siblings('.right_answer_img').html()) {
  792. $('#editimgArray').show();
  793. $('#editimgArray').html($(that).siblings('.right_answer_img').html());
  794. setTimeout(() => {
  795. $('.layui-icon-closeimg').click(function () {
  796. var that = this;
  797. let i = $(this).prop('dataset').id;
  798. var imgDiv = $(that).closest('.addimgDiv');
  799. let img1 = $(that).closest('.right_answer_img');
  800. editimages.splice(i, 1);
  801. imgDiv.remove();
  802. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  803. });
  804. }, 500);
  805. }
  806. //回答图片上传
  807. upload.render({
  808. elem: '#edituploadimg',
  809. accept: 'images',
  810. url: '/upload/',
  811. exts: 'jpg|png|bmp|jpeg|JPG|PNG|BMP|JPEG',
  812. field: 'images_data',
  813. size: 1 * 1024,
  814. auto: false,
  815. multiple: true,
  816. choose: function (obj) {
  817. images9 = obj.pushFile();
  818. $('#editimgArray').show();
  819. length = editimages.length;
  820. obj.preview(function (index, file, result) {
  821. length++;
  822. if (length > 9) {
  823. layer.msg('最多上传九张图片');
  824. } else {
  825. editimages.push(file);
  826. $('#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>');
  827. }
  828. });
  829. setTimeout(() => {
  830. //删除图片
  831. $('.layui-icon-closeimg1').click(function () {
  832. var that = this;
  833. let i = $(this).prop('dataset').id;
  834. var imgDiv = $(that).closest('.addimgDiv');
  835. let img1 = $(that).closest('.right_answer_img');
  836. editimages.splice(i, 1);
  837. if (id = imgDiv.data('id')) {
  838. delete images9[id];
  839. }
  840. imgDiv.remove();
  841. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  842. });
  843. }, 500);
  844. }
  845. });
  846. },
  847. yes: function (index, layero) {
  848. //do something
  849. var value = $.trim($('.editext textarea').val());
  850. if (value == '') {
  851. layer.msg('请输入内容', { anim: 6 });
  852. return false;
  853. }
  854. wordlist[idx].content = value;
  855. if(wordimgs[h]){
  856. wordimgs[h] = editimages;
  857. }else{
  858. editimgarr[h] = editimages;
  859. }
  860. let arr = [];
  861. for (let i = 0; i < $('#editimgArray img').length; i++) {
  862. arr.push($('#editimgArray img')[i].src);
  863. }
  864. wordlist[idx].img = arr;
  865. renderWordlistHtml(wordlist);
  866. layer.close(index); //如果设定了yes回调,需进行手工关闭
  867. },
  868. end: function (index, layero) {
  869. for (let x in images9) {
  870. delete images9[x];
  871. }
  872. layer.close(index)
  873. return false;
  874. }
  875. });
  876. form.render();
  877. })
  878. }, 500)
  879. }
  880. var label = xmSelect.render(options);
  881. var label1 = xmSelect.render(options1);
  882. var label2 = xmSelect.render(options2);
  883. form.on('select(type)', function (data) {
  884. $('#isshowlabel').show();
  885. selectdata("{:url('talkskill/dictionary_list')}", label, 4, $(data.elem).find('option:selected').attr('id'));
  886. })
  887. function selectdata(url, index, type, id, ids) {
  888. setTimeout(function () {
  889. $.ajax({
  890. type: "get",
  891. url: url,
  892. dataType: 'json',
  893. data: {
  894. type: type,
  895. pid: id,
  896. page: 1,
  897. limit: 10000
  898. },
  899. success: function (data) {
  900. index.update({ data: handleData(data.data, ids) });
  901. }
  902. });
  903. }, 100);
  904. }
  905. function handleData(data, ids) {
  906. return data.map(v => {
  907. return { name: v.name, value: v.id, id: v.id, selected: ids ? (ids.indexOf(`${v.id}`) > -1) : false};
  908. })
  909. }
  910. $(function () {
  911. let arr1 = [];
  912. {volist name="data.content" id="vo"}
  913. var type = "{$vo.type}"
  914. var content = "{$vo.content}"
  915. var id = "{$vo.id}"
  916. var img=[],imgarr=[];
  917. {empty name="vo.img"}
  918. if (type == 1){
  919. let arr=[];
  920. wordimgs.push(arr);
  921. editimgarr.push(arr);
  922. }
  923. {else/}
  924. {volist name = "vo.img" id = "m" }
  925. img.push("{$m}");
  926. imgarr.push('https://' + '{$oss_bindurl}' + '/' + "{$m}");
  927. {/volist}
  928. console.log(imgarr)
  929. wordimgs[wordimgs.length] = img;
  930. editimgarr.push(arr1);
  931. {/empty}
  932. wordlist.push({ type: type, content: content, id: id, img:imgarr });
  933. {/volist}
  934. renderWordlistHtml(wordlist);
  935. let cate1Id = "{$data.cate1}";
  936. let cate2_ids = "{$data.cate2}";
  937. let house_type_ids = "{$data.house_type}";
  938. let user_cate_ids = "{$data.user_cate}";
  939. let cate2_ids_arr = cate2_ids.split(',');
  940. let house_type_ids_arr = house_type_ids.split(',');
  941. let user_cate_ids_arr = user_cate_ids.split(',');
  942. if (cate1Id) {
  943. $('#isshowlabel').show();
  944. }
  945. selectdata("{:url('talkskill/dictionary_list')}", label, 4, cate1Id, cate2_ids_arr);
  946. selectdata("{:url('talkskill/dictionary_list')}", label1, 3, 0, user_cate_ids_arr);
  947. selectdata("{:url('talkskill/dictionary_list')}", label2, 2, 0, house_type_ids_arr);
  948. });
  949. var addtslabel = function () {
  950. layer.prompt({
  951. title: ['话术场景添加', 'color:#333333;background-color:#D8E6F1;'],
  952. }, function (value, index, elem) {
  953. $.post('{:url("talkskill/add_talkskill_label")}', {
  954. value: value
  955. }, function (res) {
  956. if (res.code == 0) {
  957. $(function () {
  958. selectdata();
  959. });
  960. layer.msg(res.msg, { anim: 0, time: 800 }, function () {
  961. layer.close(index); //再执行关闭
  962. });
  963. } else {
  964. layer.msg(res.msg, { anim: 6 });
  965. }
  966. });
  967. });
  968. }
  969. //添加分类
  970. $('#cate-add').on('click', function () {
  971. addcate();
  972. });
  973. var addcate = function () {
  974. layer.prompt({
  975. title: ['添加适用部门', 'color:#333333;background-color:#D8E6F1;'],
  976. }, function (value, index, elem) {
  977. var value = $.trim(value);
  978. if (value == '') {
  979. layer.msg('请输入名称', { anim: 6 });
  980. return false;
  981. }
  982. if (value.length > 6) {
  983. layer.msg('名称超长', { anim: 6 });
  984. return false;
  985. }
  986. $.post('{:url("talkskill/person_add")}', {
  987. 'name': value
  988. }, function (res) {
  989. if (res.code == 0) {
  990. $('#type').append("<option selected value='" + value + "' id='" + res.id + "'>" + value + "</option>")
  991. form.render();
  992. layer.msg(res.msg, {
  993. anim: 0, time: 800
  994. }, function () {
  995. layer.close(index); //再执行关闭
  996. });
  997. } else {
  998. layer.msg(res.msg, {
  999. anim: 6, time: 800
  1000. });
  1001. }
  1002. });
  1003. });
  1004. form.render();
  1005. }
  1006. //回答图片上传
  1007. upload.render({
  1008. elem: '#uploadimg',
  1009. accept: 'images',
  1010. url: '/upload/',
  1011. exts: 'jpg|png|bmp|jpeg|JPG|PNG|BMP|JPEG',
  1012. field: 'images_data',
  1013. size: 1 * 1024,
  1014. auto: false,
  1015. multiple: true,
  1016. choose: function (obj) {
  1017. images = obj.pushFile();
  1018. length = $('.imgDiv').length;
  1019. // console.log(images)
  1020. obj.preview(function (index, file, result) {
  1021. length++;
  1022. if (length > 9) {
  1023. layer.msg('最多上传九张图片');
  1024. delete images[index];
  1025. } else {
  1026. $('#imgArray').css('display', 'block');
  1027. $('#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>');
  1028. }
  1029. });
  1030. }
  1031. });
  1032. //删除图片
  1033. $('#imgArray').on('click', 'i', function () {
  1034. var that = this;
  1035. var imgDiv = $(that).closest('.imgDiv');
  1036. if (id = imgDiv.data('id')) {
  1037. delete images[id];
  1038. }
  1039. imgDiv.remove();
  1040. if ($('#imgArray').html().trim().length == 0) $('#imgArray').css('display', 'none');
  1041. });
  1042. //放大图片
  1043. function previewImg(obj) {
  1044. var imgHtml = "<img src='" + obj.src + "' width='100%' height='100%' />";
  1045. layer.open({
  1046. type: 1,
  1047. title: false,
  1048. closeBtn: 0,
  1049. area: ['auto', '80%'],
  1050. skin: 'layui-layer-nobg', //没有背景色
  1051. shadeClose: true,
  1052. content: imgHtml
  1053. });
  1054. }
  1055. });
  1056. </script>
  1057. {/block}