chosen_add_new.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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" placeholder="请输入标题" autocomplete="off" class="layui-input">
  405. </div>
  406. </div>
  407. <div class="word_list_box">
  408. <div class="noneData">话术内容展示</div>
  409. </div>
  410. <div class="layui-form-item flex-row">
  411. <div class="layui-input-block float_left flex-sub">
  412. <input type="text" placeholder="请输入问题" id="ask_content" autocomplete="off" class="layui-input">
  413. </div>
  414. <div class="layui-btn float_left" id="ask_upload" style="width: 80px;">上传</div>
  415. </div>
  416. <div class="layui-form-item layui-form-text flex-row">
  417. <div class="layui-input-block float_left flex-sub">
  418. <textarea style="resize:none;" id="answer_content" placeholder="请输入回答内容"
  419. class="layui-textarea"></textarea>
  420. <div class="layui-form-mid layui-word-aux" id="uploadimg"><i class="layui-icon">&#xe64a;</i></div>
  421. </div>
  422. <div class="layui-btn float_left mtcelter" id="answer_upload">上传</div>
  423. </div>
  424. <div style="margin-top: -10px;margin-bottom: 5px;"><i style="color: red;margin-right:5px;">*</i>建议上传封面图宽高比例1:1,图片大小不超过1M</div>
  425. <div class="layui-input-block" id="imgArray" style="display: none;"></div>
  426. </div>
  427. </div>
  428. <div style="width:34%;float:right;">
  429. <p class="font18"><span class="borxian"></span>设置场景</p>
  430. <div class="layui-form-item mdt20 mdb0" id="isshowlabel">
  431. <label class="layui-form-label" style="line-height:33px !important; font-size: 14px;"><span
  432. style="color:red">*</span>二级分类 <span class="cate01">已选择<a id="dataCounts">0</a>个</span></label>
  433. <p style="clear:both"></p>
  434. <div class="layui-input-block">
  435. <div id="label"></div>
  436. </div>
  437. </div>
  438. <div class="layui-form-item mdt20 mdb0">
  439. <label class="layui-form-label" style="line-height:33px !important; font-size: 14px;">适用部门 <span
  440. class="cate02">已选择<a id="dataCounts1">0</a>个</span></label>
  441. <p style="clear:both"></p>
  442. <div class="layui-input-block">
  443. <div id="label1"></div>
  444. </div>
  445. </div>
  446. <div class="layui-form-item mdt20 mdb0">
  447. <label class="layui-form-label" style="line-height:33px !important; font-size: 14px;">房屋类型 <span
  448. class="cate03">已选择<a id="dataCounts2">0</a>个</span></label>
  449. <p style="clear:both"></p>
  450. <div class="layui-input-block">
  451. <div id="label2"></div>
  452. </div>
  453. </div>
  454. </div>
  455. </div>
  456. </div>
  457. </div>
  458. <div class="layui-form-item layui-hide">
  459. <input type="button" lay-submit lay-filter="talkskill-submit" id="talkskill-submit" value="确认添加">
  460. <input type="button" lay-submit lay-filter="talkskill-edit" id="talkskill-edit" value="确认编辑">
  461. </div>
  462. </div>
  463. </form>
  464. </body>
  465. {/block} {block name="js"}
  466. <script src="__STATIC__/layui/layui/lay/modules/xm-select.js" type="text/javascript" charset="utf-8"></script>
  467. <script type="text/html" id="editanswerbox">
  468. <div class="answerbox">
  469. <div class="editext">
  470. <textarea style="resize:none;"></textarea>
  471. <div class="layui-form-mid layui-word-aux" id="edituploadimg"><i class="layui-icon">&#xe64a;</i></div>
  472. </div>
  473. <div style="margin-top: 5px;"><i style="color: red;margin-right:5px;">*</i>建议上传封面图宽高比例1:1,图片大小不超过1M</div>
  474. <div class="layui-input-block" id="editimgArray" style="display:none;">
  475. </div>
  476. </div>
  477. </script>
  478. <script>
  479. layui.config({
  480. base: '__LAYUI__/',
  481. urlbase: '/sys'
  482. }).extend({
  483. index: 'lib/index'
  484. }).use(['index', 'form', 'upload'], function () {
  485. var $ = layui.$,
  486. upload = layui.upload,
  487. form = layui.form,
  488. images,
  489. files,
  490. wordlist = [],
  491. wordimgs = [];
  492. //话术添加
  493. var clickRepeatedly = false; //防止重复点击
  494. form.on('submit(talkskill-submit)', function (data) {
  495. if(clickRepeatedly == true) return false;
  496. clickRepeatedly = true;
  497. if (!wordlist.length) {
  498. layer.msg('请添加话术内容', {
  499. anim: 6, time: 800
  500. });
  501. clickRepeatedly = false;
  502. return;
  503. }
  504. var index = parent.layer.getFrameIndex(window.name);
  505. var formData = new FormData(data.form);
  506. var load = layer.load(1, {shade: [0.5, '#fff']});
  507. formData.delete('images_data');
  508. let cate1_id = "{$id}";
  509. let t = 0;
  510. formData.append("cate1", cate1_id);
  511. wordlist.forEach((v, i) => {
  512. formData.append(`content[${i}][type]`, v.type);
  513. formData.append(`content[${i}][content]`, v.content)
  514. if (v.type == 1) {
  515. if (wordimgs) {
  516. formData.delete(`images_${i}[]`);
  517. if (wordimgs[t]) {
  518. for (let j = 0; j < wordimgs[t].length; j++) {
  519. formData.append(`images_${i}[]`, wordimgs[t][j]);
  520. }
  521. }
  522. t++;
  523. }
  524. }
  525. })
  526. $.ajax({
  527. url: '{:url("talkskill/chosen_add")}',
  528. type: 'post',
  529. data: formData,
  530. dataType: 'json',
  531. processData: false,
  532. contentType: false,
  533. success: function (res) {
  534. if (res.code === 0) {
  535. layer.msg(res.msg, {
  536. anim: 0, time: 800
  537. }, function () {
  538. parent.layui.table.reload('label-table');
  539. parent.layer.close(index);
  540. });
  541. } else {
  542. layer.close(load);
  543. layer.msg(res.msg, {
  544. anim: 6, time: 800
  545. });
  546. }
  547. clickRepeatedly = false;
  548. }
  549. });
  550. });
  551. $('.layui-layer-btn').css({ "boxShadow": "0 0 5px #000" });
  552. var options = {
  553. el: '#label',
  554. name: 'cate2',
  555. autoRow: true,
  556. tips: '请选择所属场景',
  557. data: [],
  558. layVerify: 'required',
  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. wordimgs.splice(index, 1);
  713. renderWordlistHtml(wordlist);
  714. })
  715. $('.lay-l-edit').click(function () {
  716. let idx = $(this).prop('dataset').index;
  717. layer.prompt({
  718. formType: 2,
  719. title: ['编辑问题内容', 'color:#333333;background-color:#D8E6F1;'],
  720. area: ['400px', '150px']
  721. }, function (value, index, elem) {
  722. var value = $.trim(value);
  723. if (value == '') {
  724. layer.msg('请输入内容', { anim: 6 });
  725. return false;
  726. }
  727. wordlist[idx].content = value;
  728. renderWordlistHtml(wordlist);
  729. layer.close(index); //再执行关闭
  730. });
  731. form.render();
  732. })
  733. $('.lay-r-edit').click(function () {
  734. let that = this;
  735. let idx = $(this).prop('dataset').index;
  736. let h = -1;
  737. for (let i in wordlist) {
  738. if (wordlist[i].type == 1) {
  739. h++;
  740. if (idx == i) {
  741. break;
  742. }
  743. }
  744. }
  745. var editimages = wordimgs[h] ? wordimgs[h].concat([]) : [];
  746. let images9;
  747. layer.open({
  748. type: 1,
  749. title: ['编辑回答内容', 'color:#333333;background-color:#D8E6F1;'],
  750. area: '450px',
  751. resize: false,
  752. btn: ['确定', '取消'],
  753. fixed: false, //不固定
  754. content: $('#editanswerbox').html(),
  755. success: function (layero, index) {
  756. for (let x in images9) {
  757. delete images9[x];
  758. }
  759. $('.editext textarea').val($(that).siblings('pre').text());
  760. if (!!$(that).siblings('.right_answer_img').html()) {
  761. $('#editimgArray').show();
  762. $('#editimgArray').html($(that).siblings('.right_answer_img').html());
  763. setTimeout(() => {
  764. $('.layui-icon-closeimg').click(function () {
  765. var that = this;
  766. let i = $(this).prop('dataset').id;
  767. var imgDiv = $(that).closest('.addimgDiv');
  768. let img1 = $(that).closest('.right_answer_img');
  769. editimages.splice(i, 1);
  770. imgDiv.remove();
  771. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  772. });
  773. }, 500);
  774. }
  775. //回答图片上传
  776. upload.render({
  777. elem: '#edituploadimg',
  778. accept: 'images',
  779. url: '/upload/',
  780. exts: 'jpg|png|bmp|jpeg|JPG|PNG|BMP|JPEG',
  781. field: 'images_data',
  782. size: 1 * 1024,
  783. auto: false,
  784. multiple: true,
  785. choose: function (obj) {
  786. images9 = obj.pushFile();
  787. $('#editimgArray').show();
  788. length = editimages.length;
  789. obj.preview(function (index, file, result) {
  790. length++;
  791. if (length > 9) {
  792. layer.msg('最多上传九张图片');
  793. } else {
  794. editimages.push(file);
  795. $('#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>');
  796. }
  797. });
  798. setTimeout(() => {
  799. //删除图片
  800. $('.layui-icon-closeimg1').click(function () {
  801. var that = this;
  802. let i = $(this).prop('dataset').id;
  803. var imgDiv = $(that).closest('.addimgDiv');
  804. let img1 = $(that).closest('.right_answer_img');
  805. editimages.splice(i, 1);
  806. if (id = imgDiv.data('id')) {
  807. delete images9[id];
  808. }
  809. imgDiv.remove();
  810. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  811. });
  812. }, 500);
  813. }
  814. });
  815. },
  816. yes: function (index, layero) {
  817. var value = $.trim($('.editext textarea').val());
  818. if (value == '') {
  819. layer.msg('请输入内容', { anim: 6 });
  820. return false;
  821. }
  822. wordlist[idx].content = value;
  823. for (let x in images9) {
  824. delete images9[x];
  825. }
  826. wordimgs[h] = editimages;
  827. let arr = [];
  828. for (let i = 0; i < $('#editimgArray img').length; i++) {
  829. let obj = {
  830. src: $('#editimgArray img')[i].src,
  831. }
  832. arr.push(obj);
  833. }
  834. wordlist[idx].img = arr;
  835. renderWordlistHtml(wordlist);
  836. layer.close(index); //如果设定了yes回调,需进行手工关闭
  837. },
  838. end: function (index, layero) {
  839. for (let x in images9) {
  840. delete images9[x];
  841. }
  842. layer.close(index)
  843. return false;
  844. }
  845. });
  846. form.render();
  847. })
  848. }, 500)
  849. }
  850. var label = xmSelect.render(options);
  851. var label1 = xmSelect.render(options1);
  852. var label2 = xmSelect.render(options2);
  853. $(function () {
  854. let cate1_id = "{$id}";
  855. $('#isshowlabel').show();
  856. selectdata("{:url('talkskill/dictionary_list')}", label, 4, cate1_id);
  857. selectdata("{:url('talkskill/dictionary_list')}", label1, 3, 0);
  858. selectdata("{:url('talkskill/dictionary_list')}", label2, 2, 0);
  859. });
  860. form.on('select(type)', function (data) {
  861. $('#isshowlabel').show();
  862. selectdata("{:url('talkskill/dictionary_list')}", label, 4, $(data.elem).find('option:selected').attr('id'));
  863. })
  864. function selectdata(url, index, type, id) {
  865. setTimeout(function () {
  866. $.ajax({
  867. type: "get",
  868. url: url,
  869. dataType: 'json',
  870. data: {
  871. type: type,
  872. pid: id,
  873. page: 1,
  874. limit: 10000
  875. },
  876. success: function (data) {
  877. index.update({ data: handleData(data.data) })
  878. }
  879. });
  880. }, 100);
  881. }
  882. function handleData(data) {
  883. return data.map(v => {
  884. return { name: v.name, value: v.id, id: v.id };
  885. })
  886. }
  887. var addtslabel = function () {
  888. layer.prompt({
  889. title: ['话术场景添加', 'color:#333333;background-color:#D8E6F1;'],
  890. }, function (value, index, elem) {
  891. $.post('{:url("talkskill/add_talkskill_label")}', {
  892. value: value
  893. }, function (res) {
  894. if (res.code == 0) {
  895. $(function () {
  896. selectdata();
  897. });
  898. layer.msg(res.msg, { anim: 0, time: 800 }, function () {
  899. layer.close(index); //再执行关闭
  900. });
  901. } else {
  902. layer.msg(res.msg, { anim: 6 });
  903. }
  904. });
  905. });
  906. }
  907. //添加分类
  908. $('#cate-add').on('click', function () {
  909. addcate();
  910. });
  911. var addcate = function () {
  912. layer.prompt({
  913. title: ['添加适用部门', 'color:#333333;background-color:#D8E6F1;'],
  914. }, function (value, index, elem) {
  915. var value = $.trim(value);
  916. if (value == '') {
  917. layer.msg('请输入名称', { anim: 6 });
  918. return false;
  919. }
  920. if (value.length > 6) {
  921. layer.msg('名称超长', { anim: 6 });
  922. return false;
  923. }
  924. $.post('{:url("talkskill/person_add")}', {
  925. 'name': value
  926. }, function (res) {
  927. if (res.code == 0) {
  928. $('#type').append("<option selected value='" + value + "' id='" + res.id + "'>" + value + "</option>")
  929. form.render();
  930. layer.msg(res.msg, {
  931. anim: 0, time: 800
  932. }, function () {
  933. layer.close(index); //再执行关闭
  934. });
  935. } else {
  936. layer.msg(res.msg, {
  937. anim: 6, time: 800
  938. });
  939. }
  940. });
  941. });
  942. form.render();
  943. }
  944. //回答图片上传
  945. upload.render({
  946. elem: '#uploadimg',
  947. accept: 'images',
  948. url: '/upload/',
  949. exts: 'jpg|png|bmp|jpeg|JPG|PNG|BMP|JPEG',
  950. field: 'images_data',
  951. size: 1 * 1024,
  952. auto: false,
  953. multiple: true,
  954. choose: function (obj) {
  955. images = obj.pushFile();
  956. length = $('.imgDiv').length;
  957. // console.log(images)
  958. obj.preview(function (index, file, result) {
  959. length++;
  960. if (length > 9) {
  961. layer.msg('最多上传九张图片');
  962. delete images[index];
  963. } else {
  964. $('#imgArray').css('display', 'block');
  965. $('#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>');
  966. }
  967. });
  968. }
  969. });
  970. //删除图片
  971. $('#imgArray').on('click', 'i', function () {
  972. var that = this;
  973. var imgDiv = $(that).closest('.imgDiv');
  974. if (id = imgDiv.data('id')) {
  975. delete images[id];
  976. }
  977. imgDiv.remove();
  978. if ($('#imgArray').html().trim().length == 0) $('#imgArray').css('display', 'none');
  979. });
  980. });
  981. //放大图片
  982. function previewImg(obj) {
  983. var imgHtml = "<img src='" + obj.src + "' width='100%' height='100%' />";
  984. layer.open({
  985. type: 1,
  986. title: false,
  987. closeBtn: 0,
  988. area: ['auto', '80%'],
  989. skin: 'layui-layer-nobg', //没有背景色
  990. shadeClose: true,
  991. content: imgHtml
  992. });
  993. }
  994. </script>
  995. {/block}