1
0

success_add_new.html 26 KB

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