add.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <view>
  3. <view class="headerGetbg"></view>
  4. <view class="home-content">
  5. <form @submit="save">
  6. <view class="home-content-top">
  7. <view class="br box-pack-between" style="padding: 32rpx 0 25rpx 0;">
  8. <text>语音信息</text>
  9. <view class="flex-y-center" v-if="id">
  10. <view @click="del(info.id)" class="flex-y-center ft28" style="color: #999999;">
  11. <view class="iconfont iconshanchu list-icon"></view>
  12. <view class="ft30">删除</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view>
  17. <view class="box-pack-between ft28 item">
  18. <text>语音名称<text class="red">*</text></text>
  19. <view class="flex-center ft24">
  20. <input type="text" :value="info.name" placeholder="请填写语音名称" name="name" />
  21. </view>
  22. </view>
  23. </view>
  24. <view class="box-pack-between ft28 item">
  25. <view class="flex-y-center">首页播报<text class="red">*</text></view>
  26. <view class="flex-y-center">
  27. <view class="desc-content" v-for="(item,index) of zt_list" :key='index'>
  28. <view class="checklist-box" @click="choicezt(index)" :class="is_zt==index?'actt':''">
  29. <view class="radio__inner" :class="is_zt==index?'act_border':''">
  30. <view :class="is_zt==index?'is-default-checked':''"
  31. class="radio__inner-icon radio__inner-icon ">
  32. </view>
  33. </view>
  34. <text class="checklist-text">{{item}}</text>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view>
  40. <view class="box-pack-between ft28 item">
  41. <text>排序</text>
  42. <view class="flex-center ft24">
  43. <input type="number" :value="info.num" placeholder="请填写排序" name="num" />
  44. </view>
  45. </view>
  46. </view>
  47. <view class="" style="padding-bottom: 20rpx;">
  48. <view class="box-pack-between ft28 item">
  49. <text>添加语音<text class="red">*</text> </text>
  50. <view class="add-home flex-center ft24" @click="Uploads">
  51. 上传
  52. </view>
  53. </view>
  54. <view class="item-bg" v-if="arr.length>0">
  55. <view @click="bindfile(index)" class="box-pack-between mar64 flex-y-center" v-for="(item,index) of arr" :key='index'>
  56. <view class="flex-y-center flex-grow-1 pdr-20">
  57. {{item.name}}
  58. </view>
  59. <view class="iconfont iconshanchu1 item-del flex-center" @click.stop="delScene"
  60. :data-index='index'></view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="hg200rpx"></view>
  66. <view class="bottom-bar">
  67. <button form-type="submit" data-status="2" class="btn1 flex-center">
  68. 提交
  69. </button>
  70. </view>
  71. </form>
  72. </view>
  73. <uni-popup ref="popup" type="center">
  74. <view class="home">
  75. <view class="home-top box-pack-between">
  76. <view class="flex-y-center">
  77. <view class="rund flex-center" @click="choiceAll(index)">
  78. <icon type="success_no_circle" size="12" v-if="checkedAll" />
  79. </view>
  80. <text class="ft28">全选</text>
  81. </view>
  82. <view class="flex-y-center">
  83. <view class="btn flex-center" @click="Uploads">
  84. 上传素材
  85. </view>
  86. <view class="btn flex-center" style="background: #007AFF;" @click="config">
  87. 确定选中素材
  88. </view>
  89. </view>
  90. </view>
  91. <scroll-view scroll-y="true" style="height: 630rpx;">
  92. <view class="item-li flex-y-center" v-for="(item,index) of material_list" :key='index'>
  93. <view class="rund flex-center" @click="choice(index)">
  94. <icon type="success_no_circle" size="12" v-if="item.checked" />
  95. </view>
  96. <text @click="bindfile(index)">{{item.file_name}}</text>
  97. </view>
  98. </scroll-view>
  99. </view>
  100. </uni-popup>
  101. </view>
  102. </template>
  103. <script>
  104. export default {
  105. data() {
  106. return {
  107. checkedAll: false,
  108. arr: [],
  109. material_list: [],
  110. id: "",
  111. info: {},
  112. is_video: 1,
  113. URL: getApp().globalData.URL,
  114. zt_list: ["关闭", "开启"],
  115. is_zt: 0,
  116. }
  117. },
  118. onLoad(e) {
  119. if (e.id) {
  120. this.id = e.id;
  121. this.detail(e.id);
  122. uni.setNavigationBarTitle({
  123. title: "编辑语音"
  124. })
  125. }
  126. // this.material();
  127. },
  128. onShow() {
  129. var pages = getCurrentPages();
  130. var currPage = pages[pages.length - 1],
  131. is_video = currPage.data.is_video;
  132. console.log(is_video)
  133. if (is_video == 2) {
  134. currPage.setData({
  135. is_video: 1,
  136. })
  137. // this.material();
  138. }
  139. },
  140. methods: {
  141. choicezt(e) {
  142. this.is_zt = e;
  143. },
  144. bindfile(index) {
  145. uni.setStorageSync("audio-info", this.arr[index])
  146. uni.navigateTo({
  147. url: "./detail"
  148. })
  149. },
  150. choiceAll() {
  151. if (this.checkedAll) {
  152. this.material_list.forEach((v, i) => {
  153. v.checked = false;
  154. })
  155. this.checkedAll = false
  156. } else {
  157. this.material_list.forEach((v, i) => {
  158. v.checked = true;
  159. })
  160. this.checkedAll = true
  161. }
  162. },
  163. choice(index) {
  164. this.material_list[index].checked = !this.material_list[index].checked;
  165. let allArr = getData(this.material_list);
  166. this.checkedAll = this.material_list.length === allArr.length ? true : false;
  167. function getData(col) {
  168. return col
  169. .filter(item => item.checked)
  170. .map(item => item.id);
  171. }
  172. },
  173. Uploads() {
  174. let that = this;
  175. var host = this.URL + '/index.php?s=/api/';
  176. uni.chooseMessageFile({
  177. count: 5,
  178. type: 'file',
  179. success: (res) => {
  180. console.log(res);
  181. for (let i of res.tempFiles) {
  182. filePath(i.path)
  183. }
  184. function filePath(url) {
  185. uni.showLoading();
  186. uni.uploadFile({
  187. url: host + "Smdcshop/voice_upload",
  188. filePath: url,
  189. name: 'file',
  190. formData: {},
  191. success: (r) => {
  192. console.log(r)
  193. let res = JSON.parse(r.data),
  194. arr = [];
  195. if (res.code === '200') {
  196. that.arr.push({
  197. src: res.data.src,
  198. name: res.data.name
  199. })
  200. }
  201. },
  202. fail: err => {
  203. console.log(err)
  204. },
  205. complete: res => {
  206. uni.hideLoading()
  207. }
  208. })
  209. }
  210. }
  211. });
  212. },
  213. config(e) {
  214. let list = getData(this.material_list);
  215. this.arr = [...this.arr, ...list];
  216. if (!this.arr.length) {
  217. uni.showToast({
  218. title: "请选择素材",
  219. icon: "none"
  220. })
  221. return
  222. }
  223. function getData(col) {
  224. return col
  225. .filter(item => item.checked)
  226. .map(item => item.file_path);
  227. }
  228. this.material_list.forEach((v, i) => {
  229. v.checked = false;
  230. })
  231. this.checkedAll = false
  232. this.$refs.popup.close();
  233. },
  234. detail(id) {
  235. this.request({
  236. url: "Smdcshop/voice_info",
  237. data: {
  238. admin_id: uni.getStorageSync("admin_id"),
  239. id,
  240. },
  241. }).then(res => {
  242. console.log(res, "res")
  243. if (res.code === '200') {
  244. this.arr = res.data.content1;
  245. this.info = res.data;
  246. this.is_zt = res.data.status;
  247. }
  248. }).catch((res) => {
  249. uni.showToast({
  250. title: res.message,
  251. icon: 'none'
  252. })
  253. });
  254. },
  255. delScene(e) {
  256. var index = e.currentTarget.dataset.index;
  257. this.arr.splice(index, 1)
  258. },
  259. del(id) {
  260. uni.showModal({
  261. title: '提示',
  262. content: '是否要删除?',
  263. showCancel: true,
  264. cancelText: '取消',
  265. confirmText: '确定',
  266. success: res => {
  267. if (res.confirm) {
  268. this.request({
  269. url: 'Smdcshop/voice_delect',
  270. data: {
  271. id: id,
  272. },
  273. }).then(res => {
  274. console.log(res, "res")
  275. if (res.code === 200 || res.code === "200") {
  276. uni.showToast({
  277. title: "删除成功",
  278. icon: "none",
  279. })
  280. setTimeout(() => {
  281. uni.navigateBack()
  282. }, 2e3)
  283. }
  284. }).catch(() => {
  285. uni.showToast({
  286. title: res.message,
  287. icon: "none",
  288. })
  289. });
  290. }
  291. },
  292. fail: () => {},
  293. complete: () => {}
  294. });
  295. },
  296. open() {
  297. this.$refs.popup.open();
  298. },
  299. save(e) {
  300. let arr1 = [],
  301. arr2 = [],
  302. url = "Smdcshop/voice_add";
  303. for (let i of this.arr) {
  304. arr1.push(i.name)
  305. arr2.push(i.src)
  306. }
  307. [{
  308. "src": "/uploads/cert/admin_thumb/20211109/22592add3565022b1aefa8f2f523505a.mp3",
  309. "name": "HRq5OiFu8OhSf49d165a0aa9c5dba64bea57813888b5.mp3"
  310. }, {
  311. "src": "/uploads/cert/admin_thumb/20211109/018e73356356ea52a6167dd0807e6350.mp3",
  312. "name": "BUxNW12Mv1waea0b9007242f36525dd1db964e83aec3.mp3"
  313. }]
  314. let data = {
  315. name: e.detail.value.name,
  316. content: JSON.stringify(this.arr),
  317. // 'content[src]':arr2.join(","),
  318. // 'content[name]':arr1.join(","),
  319. status: this.is_zt,
  320. num: e.detail.value.num,
  321. admin_id: uni.getStorageSync("admin_id"),
  322. };
  323. if (this.id) {
  324. data.id = this.id;
  325. url = "Smdcshop/voice_update"
  326. };
  327. if (!data.name || this.arr.length <= 0) {
  328. uni.showToast({
  329. title: "必填项不能为空",
  330. icon: 'none'
  331. })
  332. return false
  333. }
  334. this.request({
  335. url: url,
  336. data,
  337. }).then(res => {
  338. console.log(res, "res")
  339. if (res.code === '200') {
  340. console.log(res)
  341. uni.showToast({
  342. title: "提交成功",
  343. icon: 'none',
  344. duration: 1000
  345. })
  346. setTimeout(() => {
  347. uni.navigateBack({
  348. delta: 1
  349. })
  350. }, 1500)
  351. }
  352. }).catch((err) => {
  353. console.log(err)
  354. uni.showToast({
  355. title: err.message,
  356. icon: 'none',
  357. duration: 2000
  358. })
  359. })
  360. },
  361. }
  362. }
  363. </script>
  364. <style lang="scss">
  365. page {
  366. background: #F1F1F1;
  367. }
  368. .red {
  369. color: red;
  370. }
  371. .item-del {
  372. color: red;
  373. font-size: 35rpx;
  374. }
  375. .hg200rpx {
  376. height: 200rpx;
  377. }
  378. .list-icon {
  379. width: 29rpx;
  380. height: 29rpx;
  381. margin-right: 6rpx;
  382. }
  383. .home-content {
  384. width: 690rpx;
  385. opacity: 1;
  386. border-radius: 14rpx;
  387. box-shadow: 0rpx 8rpx 16rpx 0rpx rgba(204, 215, 230, 0.08);
  388. margin: 0 auto;
  389. position: relative;
  390. .home-content-top {
  391. width: 100%;
  392. opacity: 1;
  393. background: #ffffff;
  394. border-radius: 14rpx;
  395. box-shadow: 0rpx 8rpx 16rpx 0rpx rgba(204, 215, 230, 0.08);
  396. padding: 0 24rpx;
  397. margin-top: 24rpx;
  398. }
  399. }
  400. .col-num {
  401. color: #007AFF;
  402. }
  403. .mar64 {
  404. margin-bottom: 64rpx;
  405. }
  406. .item-bg .mar64:last-child {
  407. margin-bottom: 0rpx;
  408. }
  409. .item_name {
  410. -webkit-box-flex: 0;
  411. -webkit-flex: none;
  412. flex: none;
  413. width: 176rpx;
  414. }
  415. .content {
  416. word-wrap: break-word;
  417. word-break: break-all;
  418. }
  419. .pdr-20 {
  420. padding-right: 20rpx;
  421. word-break: break-all;
  422. }
  423. .item {
  424. padding: 32rpx 0rpx;
  425. }
  426. .item input {
  427. text-align: right;
  428. }
  429. .upimg {
  430. width: 126rpx;
  431. height: 126rpx;
  432. }
  433. .add-home {
  434. color: #FFFFFF;
  435. width: 126rpx;
  436. height: 54rpx;
  437. background: linear-gradient(315deg, #3387ff 2%, #569bff 99%);
  438. border-radius: 8rpx;
  439. box-shadow: 0px 0px 8rpx 0px rgba(51, 135, 255, 0.2);
  440. }
  441. .item-bg {
  442. // width: 670rpx;
  443. background: #f6f8fe;
  444. border-radius: 12rpx;
  445. margin: 0 auto;
  446. font-size: 28rpx;
  447. font-family: PingFang SC, PingFang SC-Regular;
  448. font-weight: 400;
  449. color: #333333;
  450. padding: 36rpx 32rpx;
  451. }
  452. .item-del {
  453. width: 40rpx;
  454. height: 40rpx;
  455. min-width: 40rpx;
  456. }
  457. .item-bg-32 {
  458. margin-right: 32rpx;
  459. }
  460. .bottom-bar {
  461. width: 100%;
  462. background: #fff;
  463. margin-bottom: 0rpx;
  464. position: fixed;
  465. bottom: 0;
  466. left: 0;
  467. background: none;
  468. }
  469. .btn1 {
  470. width: 670rpx;
  471. height: 98rpx;
  472. background: linear-gradient(315deg, #3387ff 2%, #569bff 99%);
  473. border-radius: 8rpx;
  474. box-shadow: 0px 0px 8rpx 0px rgba(51, 135, 255, 0.2);
  475. opacity: 1;
  476. font-size: 32rpx;
  477. color: #FFFFFF;
  478. margin: 0 auto;
  479. margin-bottom: 32rpx;
  480. }
  481. .home {
  482. width: 690rpx;
  483. height: 800rpx;
  484. background: #FFFFFF;
  485. padding: 20rpx;
  486. border-radius: 6rpx;
  487. .home-top {
  488. padding-bottom: 20rpx;
  489. .btn {
  490. height: 60rpx;
  491. padding: 0 20rpx;
  492. font-size: 24rpx;
  493. background: #009688;
  494. color: #FFFFFF;
  495. margin-right: 20rpx;
  496. border-radius: 6rpx;
  497. }
  498. }
  499. .item-li {
  500. padding: 10rpx 0;
  501. word-break: break-all;
  502. font-size: 28rpx;
  503. border-bottom: 1rpx solid #F1F1F1;
  504. }
  505. .rund {
  506. height: 40rpx;
  507. width: 40rpx;
  508. margin-right: 10rpx;
  509. border: 1rpx solid #ccc;
  510. }
  511. }
  512. .checklist-box {
  513. display: -webkit-box;
  514. display: -webkit-flex;
  515. display: flex;
  516. -webkit-box-orient: horizontal;
  517. -webkit-box-direction: normal;
  518. -webkit-flex-direction: row;
  519. flex-direction: row;
  520. -webkit-box-align: center;
  521. -webkit-align-items: center;
  522. align-items: center;
  523. margin: 5px 0;
  524. margin-right: 22px;
  525. }
  526. .radio__inner {
  527. -webkit-flex-shrink: 0;
  528. flex-shrink: 0;
  529. display: -webkit-box;
  530. display: -webkit-flex;
  531. display: flex;
  532. -webkit-box-pack: center;
  533. -webkit-justify-content: center;
  534. justify-content: center;
  535. -webkit-box-align: center;
  536. -webkit-align-items: center;
  537. align-items: center;
  538. position: relative;
  539. border: 1px solid #DCDFE6;
  540. border-radius: 2px;
  541. box-sizing: border-box;
  542. width: 16px;
  543. height: 16px;
  544. border-radius: 16px;
  545. background-color: #fff;
  546. z-index: 1;
  547. -webkit-transition: border-color .3s;
  548. transition: border-color .3s;
  549. }
  550. .radio__inner-icon {
  551. width: 8px;
  552. height: 8px;
  553. border-radius: 10px;
  554. opacity: 0;
  555. -webkit-transition: -webkit-transform .3s;
  556. transition: -webkit-transform .3s;
  557. transition: transform .3s;
  558. transition: transform .3s, -webkit-transform .3s;
  559. }
  560. .is-default-checked {
  561. opacity: 1;
  562. background-color: #007aff;
  563. -webkit-transform: rotate(45deg) scaleY(1);
  564. transform: rotate(45deg) scaleY(1);
  565. }
  566. .checklist-text {
  567. font-size: 28rpx;
  568. margin-left: 5px;
  569. -webkit-transition: color 0.2s;
  570. transition: color 0.2s;
  571. color: #000;
  572. }
  573. page .act_border {
  574. border: 1px solid #007AFF;
  575. }
  576. </style>