success_add.html 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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" required lay-verify="required" placeholder="请输入标题"
  403. 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}">{$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. //话术添加
  504. var clickRepeatedly = false; //防止重复点击
  505. form.on('submit(talkskill-submit)', function (data) {
  506. if(clickRepeatedly == true) return false;
  507. clickRepeatedly = true;
  508. if (!wordlist.length) {
  509. layer.msg('请添加话术内容', {
  510. anim: 6, time: 800
  511. });
  512. clickRepeatedly = false;
  513. return;
  514. }
  515. var index = parent.layer.getFrameIndex(window.name);
  516. var formData = new FormData(data.form);
  517. var load = layer.load(1, {shade: [0.5, '#fff']});
  518. formData.delete('images_data');
  519. let t = 0;
  520. wordlist.forEach((v, i) => {
  521. formData.append(`content[${i}][type]`, v.type);
  522. formData.append(`content[${i}][content]`, v.content)
  523. if (v.type == 1) {
  524. if (wordimgs) {
  525. formData.delete(`images_${i}[]`);
  526. if (wordimgs[t]) {
  527. for (let j = 0; j < wordimgs[t].length; j++) {
  528. formData.append(`images_${i}[]`, wordimgs[t][j]);
  529. }
  530. }
  531. t++;
  532. }
  533. }
  534. })
  535. $.ajax({
  536. url: '{:url("talkskill/success_add")}',
  537. type: 'post',
  538. data: formData,
  539. dataType: 'json',
  540. processData: false,
  541. contentType: false,
  542. success: function (res) {
  543. if (res.code === 0) {
  544. layer.msg(res.msg, {
  545. anim: 0, time: 800
  546. }, function () {
  547. parent.layui.table.reload('talkskill-table');
  548. parent.layer.close(index);
  549. });
  550. } else {
  551. layer.close(load);
  552. layer.msg(res.msg, {
  553. anim: 6, time: 800
  554. });
  555. }
  556. clickRepeatedly = false;
  557. }
  558. });
  559. });
  560. $('.layui-layer-btn').css({ "boxShadow": "0 0 5px #000" });
  561. var options = {
  562. el: '#label',
  563. name: 'cate2',
  564. autoRow: true,
  565. tips: '请选择所属场景',
  566. data: [],
  567. on: function (data) {
  568. var arr = data.arr;
  569. if (arr.length > 0) {
  570. $('.cate01').show();
  571. $('#dataCounts').html(arr.length);
  572. } else {
  573. $('.cate01').hide();
  574. }
  575. }
  576. };
  577. var options1 = {
  578. el: '#label1',
  579. name: 'user_cate',
  580. autoRow: true,
  581. tips: '请选择适用部门',
  582. data: [],
  583. on: function (data) {
  584. var arr = data.arr;
  585. if (arr.length > 0) {
  586. $('.cate02').show();
  587. $('#dataCounts1').html(arr.length);
  588. } else {
  589. $('.cate02').hide();
  590. }
  591. }
  592. };
  593. var options2 = {
  594. el: '#label2',
  595. name: 'house_type',
  596. autoRow: true,
  597. tips: '请选择房屋类型',
  598. data: [],
  599. on: function (data) {
  600. var arr = data.arr;
  601. if (arr.length > 0) {
  602. $('.cate03').show();
  603. $('#dataCounts2').html(arr.length);
  604. } else {
  605. $('.cate03').hide();
  606. }
  607. }
  608. };
  609. $('#ask_upload').click(function () {
  610. let val = $('#ask_content').val();
  611. val = $.trim(val);
  612. if (!val) {
  613. layer.msg('请输入问题', {
  614. anim: 6, time: 800
  615. });
  616. return;
  617. }
  618. wordlist.push({ type: '0', content: val });
  619. renderWordlistHtml(wordlist);
  620. $('#ask_content').val('');
  621. setTimeout(() => {
  622. var scrollHeight = $('.word_list_box').prop("scrollHeight");
  623. $('.word_list_box').scrollTop(scrollHeight, 200);
  624. }, 600)
  625. })
  626. $('#answer_upload').click(function () {
  627. let val = $('#answer_content').val();
  628. val = $.trim(val);
  629. if (!val && (!images || JSON.stringify(images) === '{}')) {
  630. layer.msg('请输入回答', {
  631. anim: 6, time: 800
  632. });
  633. return;
  634. }
  635. var img = [];
  636. for (var i in $('#imgArray .imgDiv img')) {
  637. if ($('#imgArray .imgDiv img')[i].src) {
  638. let obj = {
  639. src: $('#imgArray .imgDiv img')[i].src,
  640. }
  641. img.push(obj);
  642. }
  643. }
  644. if (!!images) {
  645. let arr = [];
  646. for (var t in images) {
  647. arr.push(images[t])
  648. }
  649. wordimgs.push(arr);
  650. } else {
  651. wordimgs.push('');
  652. }
  653. for (let x in images) {
  654. delete images[x];
  655. }
  656. $('#imgArray').html('');
  657. wordlist.push({ type: '1', content: val, img: img });
  658. renderWordlistHtml(wordlist);
  659. $('#answer_content').val('');
  660. setTimeout(() => {
  661. var scrollHeight = $('.word_list_box').prop("scrollHeight");
  662. $('.word_list_box').scrollTop(scrollHeight, 200);
  663. }, 600)
  664. })
  665. function renderWordlistHtml(data) {
  666. let w = 0;
  667. let htmls = data.map((item, index) => {
  668. item.content = item.content.replace(/^(\s|&quot;)+|(\s|&quot;)+$/g, '');
  669. if (item.type == '0') {
  670. return `<div class="left_ask">
  671. <div class="left_ask_avatar">
  672. <img src="__STATIC__/img/ask_icon.png" alt="">
  673. </div>
  674. <div class="left_ask_content">
  675. <pre class="txt">${item.content}</pre>
  676. <i data-index="${index}" class="layui-icon layui-icon-delete lay-l-close"></i>
  677. <i data-index="${index}" class="layui-icon layui-icon-edit lay-l-edit"></i>
  678. </div>
  679. </div>`;
  680. } else {
  681. let imgstr = "";
  682. for (let i = 0; i < item.img.length; i++) {
  683. imgstr += '<div class="addimgDiv" data-id="' + i + '"><img src="' + item.img[i].src + '" 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>';
  684. }
  685. w++;
  686. return `<div class="right_answer">
  687. <div class="right_answer_avatar">
  688. <img src="__STATIC__/img/answer_icon.png" alt="">
  689. </div>
  690. <div class="right_answer_content">
  691. <pre>${item.content}</pre>
  692. <i data-index="${index}" class="layui-icon layui-icon-delete lay-r-close"></i>
  693. <i data-index="${index}" class="layui-icon layui-icon-edit lay-r-edit"></i>
  694. <div data-index="${index}" class="right_answer_img" style="display: block;width: 100%;flex-shrink: 0;">${imgstr}</div>
  695. </div>
  696. </div>`;
  697. }
  698. }).join('');
  699. $('.word_list_box').html(htmls);
  700. setTimeout(() => {
  701. //删除图片
  702. $('.layui-icon-closeimg').click(function () {
  703. var that = this;
  704. let index = $(this).prop('dataset').index;
  705. let i = $(this).prop('dataset').id;
  706. var imgDiv = $(that).closest('.addimgDiv');
  707. let img1 = $(that).closest('.right_answer_img');
  708. wordimgs[index].splice(i, 1);
  709. imgDiv.remove();
  710. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  711. });
  712. $('.lay-l-close').click(function () {
  713. let index = $(this).prop('dataset').index;
  714. wordlist.splice(index, 1);
  715. renderWordlistHtml(wordlist);
  716. })
  717. $('.lay-r-close').click(function () {
  718. let index = $(this).prop('dataset').index;
  719. wordlist.splice(index, 1);
  720. renderWordlistHtml(wordlist);
  721. })
  722. $('.lay-l-edit').click(function () {
  723. let idx = $(this).prop('dataset').index;
  724. layer.prompt({
  725. formType: 2,
  726. title: ['编辑问题内容', 'color:#333333;background-color:#D8E6F1;'],
  727. area: ['400px', '150px']
  728. }, function (value, index, elem) {
  729. var value = $.trim(value);
  730. if (value == '') {
  731. layer.msg('请输入内容', { anim: 6 });
  732. return false;
  733. }
  734. wordlist[idx].content = value;
  735. renderWordlistHtml(wordlist);
  736. layer.close(index); //再执行关闭
  737. });
  738. form.render();
  739. })
  740. $('.lay-r-edit').click(function () {
  741. let that = this;
  742. let idx = $(this).prop('dataset').index;
  743. let h = -1;
  744. for (let i in wordlist) {
  745. if (wordlist[i].type == 1) {
  746. h++;
  747. if (idx == i) {
  748. break;
  749. }
  750. }
  751. }
  752. var editimages = wordimgs[h] ? wordimgs[h].concat([]) : [];
  753. let images9;
  754. layer.open({
  755. type: 1,
  756. title: ['编辑回答内容', 'color:#333333;background-color:#D8E6F1;'],
  757. area: '450px',
  758. resize: false,
  759. btn: ['确定', '取消'],
  760. fixed: false, //不固定
  761. content: $('#editanswerbox').html(),
  762. success: function (layero, index) {
  763. for (let x in images9) {
  764. delete images9[x];
  765. }
  766. $('.editext textarea').val($(that).siblings('pre').text());
  767. if (!!$(that).siblings('.right_answer_img').html()) {
  768. $('#editimgArray').show();
  769. $('#editimgArray').html($(that).siblings('.right_answer_img').html());
  770. $('.layui-icon-closeimg').click(function () {
  771. var that = this;
  772. let i = $(this).prop('dataset').id;
  773. var imgDiv = $(that).closest('.addimgDiv');
  774. let img1 = $(that).closest('.right_answer_img');
  775. editimages.splice(i, 1);
  776. imgDiv.remove();
  777. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  778. });
  779. }
  780. //回答图片上传
  781. upload.render({
  782. elem: '#edituploadimg',
  783. accept: 'images',
  784. url: '/upload/',
  785. exts: 'jpg|png|bmp|jpeg|JPG|PNG|BMP|JPEG',
  786. field: 'images_data',
  787. size: 1 * 1024,
  788. auto: false,
  789. multiple: true,
  790. choose: function (obj) {
  791. images9 = obj.pushFile();
  792. $('#editimgArray').show();
  793. length = editimages.length;
  794. obj.preview(function (index, file, result) {
  795. length++;
  796. if (length > 9) {
  797. layer.msg('最多上传九张图片');
  798. } else {
  799. editimages.push(file);
  800. $('#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>');
  801. }
  802. });
  803. setTimeout(() => {
  804. //删除图片
  805. $('.layui-icon-closeimg1').click(function () {
  806. var that = this;
  807. let i = $(this).prop('dataset').id;
  808. var imgDiv = $(that).closest('.addimgDiv');
  809. let img1 = $(that).closest('.right_answer_img');
  810. editimages.splice(i, 1);
  811. if (id = imgDiv.data('id')) {
  812. delete images9[id];
  813. }
  814. imgDiv.remove();
  815. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  816. });
  817. }, 500);
  818. }
  819. });
  820. },
  821. yes: function (index, layero) {
  822. //do something
  823. var value = $.trim($('.editext textarea').val());
  824. if (value == '') {
  825. layer.msg('请输入内容', { anim: 6 });
  826. return false;
  827. }
  828. wordlist[idx].content = value;
  829. for (let x in images9) {
  830. delete images9[x];
  831. }
  832. wordimgs[h] = editimages;
  833. let arr = [];
  834. for (let i = 0; i < $('#editimgArray img').length; i++) {
  835. let obj = {
  836. src: $('#editimgArray img')[i].src,
  837. }
  838. arr.push(obj);
  839. }
  840. wordlist[idx].img = arr;
  841. renderWordlistHtml(wordlist);
  842. layer.close(index); //如果设定了yes回调,需进行手工关闭
  843. },
  844. end: function (index, layero) {
  845. for (let x in images9) {
  846. delete images9[x];
  847. }
  848. layer.close(index)
  849. return false;
  850. }
  851. });
  852. form.render();
  853. })
  854. }, 500)
  855. }
  856. var label = xmSelect.render(options);
  857. var label1 = xmSelect.render(options1);
  858. var label2 = xmSelect.render(options2);
  859. $(function () {
  860. selectdata("{:url('talkskill/dictionary_list')}", label1, 3, 0);
  861. selectdata("{:url('talkskill/dictionary_list')}", label2, 2, 0);
  862. });
  863. form.on('select(type)', function (data) {
  864. $('#isshowlabel').show();
  865. selectdata("{:url('talkskill/dictionary_list')}", label, 4, $(data.elem).find('option:selected').attr('id'));
  866. })
  867. function selectdata(url, index, type, id) {
  868. setTimeout(function () {
  869. $.ajax({
  870. type: "get",
  871. url: url,
  872. dataType: 'json',
  873. data: {
  874. type: type,
  875. pid: id,
  876. page: 1,
  877. limit: 10000
  878. },
  879. success: function (data) {
  880. index.update({ data: handleData(data.data) })
  881. }
  882. });
  883. }, 100);
  884. }
  885. function handleData(data) {
  886. return data.map(v => {
  887. return { name: v.name, value: v.id, id: v.id };
  888. })
  889. }
  890. var addtslabel = function () {
  891. layer.prompt({
  892. title: ['话术场景添加', 'color:#333333;background-color:#D8E6F1;'],
  893. }, function (value, index, elem) {
  894. $.post('{:url("talkskill/add_talkskill_label")}', {
  895. value: value
  896. }, function (res) {
  897. if (res.code == 0) {
  898. $(function () {
  899. selectdata();
  900. });
  901. layer.msg(res.msg, { anim: 0, time: 800 }, function () {
  902. layer.close(index); //再执行关闭
  903. });
  904. } else {
  905. layer.msg(res.msg, { anim: 6 });
  906. }
  907. });
  908. });
  909. }
  910. //添加分类
  911. $('#cate-add').on('click', function () {
  912. addcate();
  913. });
  914. var addcate = function () {
  915. layer.prompt({
  916. title: ['添加适用部门', 'color:#333333;background-color:#D8E6F1;'],
  917. }, function (value, index, elem) {
  918. var value = $.trim(value);
  919. if (value == '') {
  920. layer.msg('请输入名称', { anim: 6 });
  921. return false;
  922. }
  923. if (value.length > 6) {
  924. layer.msg('名称超长', { anim: 6 });
  925. return false;
  926. }
  927. $.post('{:url("talkskill/person_add")}', {
  928. 'name': value
  929. }, function (res) {
  930. if (res.code == 0) {
  931. $('#type').append("<option selected value='" + value + "' id='" + res.id + "'>" + value + "</option>")
  932. form.render();
  933. layer.msg(res.msg, {
  934. anim: 0, time: 800
  935. }, function () {
  936. layer.close(index); //再执行关闭
  937. });
  938. } else {
  939. layer.msg(res.msg, {
  940. anim: 6, time: 800
  941. });
  942. }
  943. });
  944. });
  945. form.render();
  946. }
  947. //回答图片上传
  948. upload.render({
  949. elem: '#uploadimg',
  950. accept: 'images',
  951. url: '/upload/',
  952. exts: 'jpg|png|bmp|jpeg|JPG|PNG|BMP|JPEG',
  953. field: 'images_data',
  954. size: 1 * 1024,
  955. auto: false,
  956. multiple: true,
  957. choose: function (obj) {
  958. images = obj.pushFile();
  959. length = $('.imgDiv').length;
  960. // console.log(images)
  961. obj.preview(function (index, file, result) {
  962. length++;
  963. if (length > 9) {
  964. layer.msg('最多上传九张图片');
  965. delete images[index];
  966. } else {
  967. $('#imgArray').css('display', 'block');
  968. $('#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>');
  969. }
  970. });
  971. }
  972. });
  973. //删除图片
  974. $('#imgArray').on('click', 'i', function () {
  975. var that = this;
  976. var imgDiv = $(that).closest('.imgDiv');
  977. if (id = imgDiv.data('id')) {
  978. delete images[id];
  979. }
  980. imgDiv.remove();
  981. if ($('#imgArray').html().trim().length == 0) $('#imgArray').css('display', 'none');
  982. });
  983. });
  984. //放大图片
  985. function previewImg(obj) {
  986. var imgHtml = "<img src='" + obj.src + "' width='100%' height='100%' />";
  987. layer.open({
  988. type: 1,
  989. title: false,
  990. closeBtn: 0,
  991. area: ['auto', '80%'],
  992. skin: 'layui-layer-nobg', //没有背景色
  993. shadeClose: true,
  994. content: imgHtml
  995. });
  996. }
  997. </script>
  998. {/block}