chosen_add.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086
  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,#edituploadimg {
  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. justify-content: flex-end;
  296. background-color: #95EC6A;
  297. position: relative;
  298. flex-direction: column;
  299. }
  300. .lay-l-close {
  301. position: absolute;
  302. top: 50%;
  303. right: -30px;
  304. transform: translateY(-50%);
  305. color: red;
  306. cursor: pointer;
  307. }
  308. .lay-l-edit {
  309. position: absolute;
  310. top: 50%;
  311. right: -55px;
  312. transform: translateY(-50%);
  313. color: #249EFB;
  314. cursor: pointer;
  315. }
  316. .lay-r-close {
  317. position: absolute;
  318. top: 50%;
  319. left: -30px;
  320. transform: translateY(-50%);
  321. color: red;
  322. cursor: pointer;
  323. }
  324. .lay-r-edit {
  325. position: absolute;
  326. top: 50%;
  327. left: -55px;
  328. transform: translateY(-50%);
  329. color: #249EFB;
  330. cursor: pointer;
  331. }
  332. .noneData {
  333. width: 100%;
  334. height: 100%;
  335. display: flex;
  336. justify-content: center;
  337. align-items: center;
  338. color: #999999;
  339. }
  340. #uploadimg,#edituploadimg {
  341. position: absolute;
  342. bottom: 0px;
  343. right: 8px;
  344. z-index: 2;
  345. padding: 0 !important;
  346. margin: 0;
  347. }
  348. .addimgDiv {
  349. display: inline-block;
  350. width: 60px;
  351. height: 52px;
  352. margin-right: 8px;
  353. margin-top: 10px;
  354. overflow: hidden;
  355. position: relative;
  356. }
  357. .addimgDiv img {
  358. display: block;
  359. width: 100%;
  360. height: 100%;
  361. }
  362. .addimgDiv div i {
  363. position: absolute;
  364. right: -1px;
  365. top: -9px;
  366. z-index: 2;
  367. padding: 0 !important;
  368. margin: 0;
  369. }
  370. .answerbox{
  371. display: block;
  372. padding: 20px;
  373. }
  374. .answerbox textarea{
  375. display: block;
  376. width: 100%;
  377. height:150px;
  378. resize:none;
  379. border: 1px solid #e6e6e6;
  380. color: #333;
  381. padding: 6px 10px;
  382. box-sizing: border-box;
  383. }
  384. .editext{
  385. width: 410px;
  386. display: block;
  387. position: relative;
  388. }
  389. </style>
  390. <body>
  391. <form class="layui-form" id="admin" enctype="multipart/form-data">
  392. <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 15px;">
  393. <div class="layui-form-item" style="margin:0 auto; width:97%;">
  394. <div class="layui-tab layui-tab-card">
  395. <div class="layui-tab-content" style="padding:0;overflow: hidden;">
  396. <div class="layui-tab-item layui-show" style="width:63%;float:left;border-right: 1px dashed #ccc;">
  397. <p class="font18"><span class="borxian"></span>基础信息</p>
  398. <div style="width:95%;margin-top:20px">
  399. <div class="layui-form-item">
  400. <div class="layui-input-block">
  401. <input type="text" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input">
  402. </div>
  403. </div>
  404. <div class="word_list_box">
  405. <div class="noneData">话术内容展示</div>
  406. </div>
  407. <div class="layui-form-item flex-row">
  408. <div class="layui-input-block float_left flex-sub">
  409. <input type="text" placeholder="请输入问题" id="ask_content" autocomplete="off" class="layui-input">
  410. </div>
  411. <div class="layui-btn float_left" id="ask_upload" style="width: 80px;">上传</div>
  412. </div>
  413. <div class="layui-form-item layui-form-text flex-row">
  414. <div class="layui-input-block float_left flex-sub">
  415. <textarea style="resize:none;" id="answer_content" placeholder="请输入回答内容"
  416. class="layui-textarea"></textarea>
  417. <div class="layui-form-mid layui-word-aux" id="uploadimg"><i class="layui-icon">&#xe64a;</i></div>
  418. </div>
  419. <div class="layui-btn float_left mtcelter" id="answer_upload">上传</div>
  420. </div>
  421. <div style="margin-top: -10px;margin-bottom: 5px;"><i style="color: red;margin-right:5px;">*</i>建议上传封面图宽高比例1:1,图片大小不超过1M</div>
  422. <div class="layui-input-block" id="imgArray" style="display: none;"></div>
  423. </div>
  424. </div>
  425. <div style="width:34%;float:right;">
  426. <p class="font18"><span class="borxian"></span>设置场景</p>
  427. <div class="layui-form-item mdt20 mdb0">
  428. <label class="layui-form-label"><span style="color:red">*</span>所属场景</label>
  429. <p style="clear:both"></p>
  430. <div class="layui-input-inline">
  431. <select name="cate1" lay-filter="type" id="type" lay-verify="required">
  432. <option value="">请选择所属场景</option>
  433. {volist name="cate" id="t"}
  434. <option value="{$t.id}" id="{$t.id}">{$t.name}</option>
  435. {/volist}
  436. </select>
  437. </div>
  438. </div>
  439. <div class="layui-form-item mdt20 mdb0" id="isshowlabel">
  440. <label class="layui-form-label" style="line-height:33px !important; font-size: 14px;"><span
  441. style="color:red">*</span>二级分类 <span class="cate01">已选择<a id="dataCounts">0</a>个</span></label>
  442. <p style="clear:both"></p>
  443. <div class="layui-input-block">
  444. <div id="label"></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="cate02">已选择<a id="dataCounts1">0</a>个</span></label>
  450. <p style="clear:both"></p>
  451. <div class="layui-input-block">
  452. <div id="label1"></div>
  453. </div>
  454. </div>
  455. <div class="layui-form-item mdt20 mdb0">
  456. <label class="layui-form-label" style="line-height:33px !important; font-size: 14px;">房屋类型 <span
  457. class="cate03">已选择<a id="dataCounts2">0</a>个</span></label>
  458. <p style="clear:both"></p>
  459. <div class="layui-input-block">
  460. <div id="label2"></div>
  461. </div>
  462. </div>
  463. </div>
  464. </div>
  465. </div>
  466. </div>
  467. <div class="layui-form-item layui-hide">
  468. <input type="button" lay-submit lay-filter="talkskill-submit" id="talkskill-submit" value="确认添加">
  469. <input type="button" lay-submit lay-filter="talkskill-edit" id="talkskill-edit" value="确认编辑">
  470. </div>
  471. </div>
  472. </form>
  473. </body>
  474. {/block} {block name="js"}
  475. <script src="__STATIC__/layui/layui/lay/modules/xm-select.js" type="text/javascript" charset="utf-8"></script>
  476. <script type="text/html" id="editanswerbox">
  477. <div class="answerbox">
  478. <div class="editext">
  479. <textarea style="resize:none;"></textarea>
  480. <div class="layui-form-mid layui-word-aux" id="edituploadimg"><i class="layui-icon">&#xe64a;</i></div>
  481. </div>
  482. <div style="margin-top: 5px;"><i style="color: red;margin-right:5px;">*</i>建议上传封面图宽高比例1:1,图片大小不超过1M</div>
  483. <div class="layui-input-block" id="editimgArray" style="display:none;">
  484. </div>
  485. </div>
  486. </script>
  487. <script>
  488. layui.config({
  489. base: '__LAYUI__/',
  490. urlbase: '/sys'
  491. }).extend({
  492. index: 'lib/index'
  493. }).use(['index', 'form', 'upload'], function () {
  494. var $ = layui.$,
  495. upload = layui.upload,
  496. form = layui.form,
  497. images,
  498. files,
  499. wordlist = [],
  500. wordimgs=[];
  501. //话术添加
  502. var clickRepeatedly = false; //防止重复点击
  503. form.on('submit(talkskill-submit)', function (data) {
  504. if(clickRepeatedly == true) return false;
  505. clickRepeatedly = true;
  506. if (!wordlist.length) {
  507. layer.msg('请添加话术内容', {
  508. anim: 6, time: 800
  509. });
  510. clickRepeatedly = false;
  511. return;
  512. }
  513. var index = parent.layer.getFrameIndex(window.name);
  514. var formData = new FormData(data.form);
  515. var load = layer.load(1, {shade: [0.5, '#fff']});
  516. formData.delete('images_data');
  517. let t = 0;
  518. wordlist.forEach((v, i) => {
  519. formData.append(`content[${i}][type]`, v.type);
  520. formData.append(`content[${i}][content]`, v.content)
  521. if(v.type==1){
  522. if(wordimgs){
  523. formData.delete(`images_${i}[]`);
  524. if (wordimgs[t]) {
  525. for (let j=0;j< wordimgs[t].length;j++) {
  526. formData.append(`images_${i}[]`, wordimgs[t][j]);
  527. }
  528. }
  529. t++;
  530. }
  531. }
  532. })
  533. $.ajax({
  534. url: '{:url("talkskill/chosen_add")}',
  535. type: 'post',
  536. data: formData,
  537. dataType: 'json',
  538. processData: false,
  539. contentType: false,
  540. success: function (res) {
  541. if (res.code === 0) {
  542. layer.msg(res.msg, {
  543. anim: 0, time: 800
  544. }, function () {
  545. parent.layui.table.reload('label-table');
  546. parent.layer.close(index);
  547. });
  548. } else {
  549. layer.close(load);
  550. layer.msg(res.msg, {
  551. anim: 6, time: 800
  552. });
  553. }
  554. clickRepeatedly = false;
  555. }
  556. });
  557. });
  558. $('.layui-layer-btn').css({ "boxShadow": "0 0 5px #000" });
  559. var options = {
  560. el: '#label',
  561. name: 'cate2',
  562. autoRow: true,
  563. tips: '请选择所属场景',
  564. data: [],
  565. layVerify: 'required',
  566. on: function (data) {
  567. var arr = data.arr;
  568. if (arr.length > 0) {
  569. $('.cate01').show();
  570. $('#dataCounts').html(arr.length);
  571. } else {
  572. $('.cate01').hide();
  573. }
  574. }
  575. };
  576. var options1 = {
  577. el: '#label1',
  578. name: 'user_cate',
  579. autoRow: true,
  580. tips: '请选择适用部门',
  581. data: [],
  582. on: function (data) {
  583. var arr = data.arr;
  584. if (arr.length > 0) {
  585. $('.cate02').show();
  586. $('#dataCounts1').html(arr.length);
  587. } else {
  588. $('.cate02').hide();
  589. }
  590. }
  591. };
  592. var options2 = {
  593. el: '#label2',
  594. name: 'house_type',
  595. autoRow: true,
  596. tips: '请选择房屋类型',
  597. data: [],
  598. on: function (data) {
  599. var arr = data.arr;
  600. if (arr.length > 0) {
  601. $('.cate03').show();
  602. $('#dataCounts2').html(arr.length);
  603. } else {
  604. $('.cate03').hide();
  605. }
  606. }
  607. };
  608. $('#ask_upload').click(function () {
  609. let val = $('#ask_content').val();
  610. val = $.trim(val);
  611. if (!val) {
  612. layer.msg('请输入问题', {
  613. anim: 6, time: 800
  614. });
  615. return;
  616. }
  617. wordlist.push({ type: '0', content: val });
  618. renderWordlistHtml(wordlist);
  619. $('#ask_content').val('');
  620. setTimeout(() => {
  621. var scrollHeight = $('.word_list_box').prop("scrollHeight");
  622. $('.word_list_box').scrollTop(scrollHeight, 200);
  623. }, 600)
  624. })
  625. $('#answer_upload').click(function () {
  626. let val = $('#answer_content').val();
  627. val= $.trim(val);
  628. if (!val && (!images || JSON.stringify(images) === '{}')) {
  629. layer.msg('请输入回答', {
  630. anim: 6, time: 800
  631. });
  632. return;
  633. }
  634. var img = [];
  635. for (var i in $('#imgArray .imgDiv img')) {
  636. if ($('#imgArray .imgDiv img')[i].src) {
  637. let obj={
  638. src: $('#imgArray .imgDiv img')[i].src,
  639. }
  640. img.push(obj);
  641. }
  642. }
  643. if(!!images){
  644. let arr=[];
  645. for (var t in images) {
  646. arr.push(images[t])
  647. }
  648. wordimgs.push(arr);
  649. }else{
  650. wordimgs.push('');
  651. }
  652. for (let x in images) {
  653. delete images[x];
  654. }
  655. $('#imgArray').html('');
  656. wordlist.push({ type: '1', content: val, img: img });
  657. renderWordlistHtml(wordlist);
  658. $('#answer_content').val('');
  659. setTimeout(() => {
  660. var scrollHeight = $('.word_list_box').prop("scrollHeight");
  661. $('.word_list_box').scrollTop(scrollHeight, 200);
  662. }, 600)
  663. })
  664. function renderWordlistHtml(data) {
  665. let w = 0;
  666. let htmls = data.map((item, index) => {
  667. item.content = item.content.replace(/^(\s|&quot;)+|(\s|&quot;)+$/g, '');
  668. if (item.type == '0') {
  669. return `<div class="left_ask">
  670. <div class="left_ask_avatar">
  671. <img src="__STATIC__/img/ask_icon.png" alt="">
  672. </div>
  673. <div class="left_ask_content">
  674. <pre class="txt">${item.content}</pre>
  675. <i data-index="${index}" class="layui-icon layui-icon-delete lay-l-close"></i>
  676. <i data-index="${index}" class="layui-icon layui-icon-edit lay-l-edit"></i>
  677. </div>
  678. </div>`;
  679. } else {
  680. let imgstr = "";
  681. for (let i = 0; i < item.img.length; i++) {
  682. 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>';
  683. }
  684. w++;
  685. return `<div class="right_answer">
  686. <div class="right_answer_avatar">
  687. <img src="__STATIC__/img/answer_icon.png" alt="">
  688. </div>
  689. <div class="right_answer_content">
  690. <pre>${item.content}</pre>
  691. <i data-index="${index}" class="layui-icon layui-icon-delete lay-r-close"></i>
  692. <i data-index="${index}" class="layui-icon layui-icon-edit lay-r-edit"></i>
  693. <div data-index="${index}" class="right_answer_img" style="display: block;width: 100%;flex-shrink: 0;">${imgstr}</div>
  694. </div>
  695. </div>`;
  696. }
  697. }).join('');
  698. $('.word_list_box').html(htmls);
  699. setTimeout(() => {
  700. //删除图片
  701. $('.layui-icon-closeimg').click(function () {
  702. var that = this;
  703. let index = $(this).prop('dataset').index;
  704. let i = $(this).prop('dataset').id;
  705. var imgDiv = $(that).closest('.addimgDiv');
  706. let img1 = $(that).closest('.right_answer_img');
  707. wordimgs[index].splice(i, 1);
  708. imgDiv.remove();
  709. if ($(that).closest('.addimgDiv').html().trim().length == 0) $(that).closest('.addimgDiv').css('display', 'none');
  710. });
  711. $('.lay-l-close').click(function () {
  712. let index = $(this).prop('dataset').index;
  713. wordlist.splice(index, 1);
  714. renderWordlistHtml(wordlist);
  715. })
  716. $('.lay-r-close').click(function () {
  717. let index = $(this).prop('dataset').index;
  718. wordlist.splice(index, 1);
  719. wordimgs.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}