chapterVariety.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div class="classify-page">
  3. <div class="content-box">
  4. <el-tree
  5. :data="list"
  6. node-key="ReportChapterTypeId"
  7. :props="{
  8. label: 'ReportChapterTypeName',
  9. children: 'Child',
  10. }"
  11. check-strictly
  12. empty-text="暂无数据"
  13. draggable
  14. :allow-drop="canDropHandle"
  15. @node-drop="dropOverHandle"
  16. >
  17. <div class="classify-item-wrap" slot-scope="{ data }">
  18. <div>
  19. <span :class="['tag', data.Enabled == 1 ? 'open' : 'close']">{{
  20. data.Enabled == 1 ? "启用" : "禁用"
  21. }}</span>
  22. <span>{{ data.ReportChapterTypeName }}</span>
  23. </div>
  24. <div class="opt-box">
  25. <span
  26. style="cursor: pointer; color: #409eff"
  27. @click.stop="handleShowEdit(data)"
  28. >小程序配置</span
  29. >
  30. </div>
  31. </div>
  32. </el-tree>
  33. </div>
  34. <!-- 分类弹窗 -->
  35. <m-dialog title="小程序配置" :show.sync="aeForm.show" width="650px">
  36. <div style="padding-left: 50px">
  37. <el-form
  38. :model="aeForm"
  39. :rules="aerules"
  40. ref="aeForm"
  41. label-position="left"
  42. hide-required-asterisk
  43. label-width="100px"
  44. >
  45. <el-form-item
  46. label="未选中icon"
  47. prop="UnselectedIcon"
  48. >
  49. <input
  50. type="file"
  51. size="small"
  52. name="file"
  53. @change="fileSelected(1)"
  54. id="file1"
  55. class="true-file"
  56. style="display: none"
  57. />
  58. <el-input
  59. readonly
  60. type="text"
  61. v-model="aeForm.UnselectedIcon"
  62. placeholder="上传icon"
  63. size="medium"
  64. style="width: 400px"
  65. >
  66. <el-button
  67. slot="append"
  68. type="primary"
  69. size="mini"
  70. @click.native="clickinput(1)"
  71. >选择图片</el-button
  72. >
  73. </el-input>
  74. </el-form-item>
  75. <el-form-item
  76. label="选中icon"
  77. prop="selectedIcon"
  78. >
  79. <input
  80. type="file"
  81. size="small"
  82. name="file"
  83. @change="fileSelected(2)"
  84. id="file2"
  85. class="true-file"
  86. style="display: none"
  87. />
  88. <el-input
  89. readonly
  90. type="text"
  91. v-model="aeForm.selectedIcon"
  92. placeholder="上传icon"
  93. size="medium"
  94. style="width: 400px"
  95. >
  96. <el-button
  97. slot="append"
  98. type="primary"
  99. size="mini"
  100. @click.native="clickinput(2)"
  101. >选择图片</el-button
  102. >
  103. </el-input>
  104. </el-form-item>
  105. <el-form-item
  106. label="带字icon"
  107. prop="wordIcon"
  108. >
  109. <input
  110. type="file"
  111. size="small"
  112. name="file3"
  113. @change="fileSelected(3)"
  114. id="file3"
  115. class="true-file"
  116. style="display: none"
  117. />
  118. <el-input
  119. readonly
  120. type="text"
  121. v-model="aeForm.wordIcon"
  122. placeholder="上传icon"
  123. size="medium"
  124. style="width: 400px"
  125. >
  126. <el-button
  127. slot="append"
  128. type="primary"
  129. size="mini"
  130. @click.native="clickinput(3)"
  131. >选择图片</el-button
  132. >
  133. </el-input>
  134. </el-form-item>
  135. <el-form-item
  136. label="章节配图"
  137. prop="bgImg"
  138. >
  139. <input
  140. type="file"
  141. size="small"
  142. name="file4"
  143. @change="fileSelected(4)"
  144. id="file4"
  145. class="true-file"
  146. style="display: none"
  147. />
  148. <el-input
  149. readonly
  150. type="text"
  151. v-model="aeForm.bgImg"
  152. placeholder="上传icon"
  153. size="medium"
  154. style="width: 400px"
  155. >
  156. <el-button
  157. slot="append"
  158. type="primary"
  159. size="mini"
  160. @click.native="clickinput(4)"
  161. >选择图片</el-button
  162. >
  163. </el-input>
  164. </el-form-item>
  165. <el-form-item
  166. label="小程序端隐藏"
  167. prop="IsShow"
  168. >
  169. <el-switch
  170. v-model="aeForm.IsShow"
  171. inactive-color="#ededed"
  172. ></el-switch>
  173. </el-form-item>
  174. </el-form>
  175. </div>
  176. <div slot="footer" style="margin-top: 20px">
  177. <el-button @click="aeForm.show=false" style="width: 132px; height: 40px"
  178. >取消</el-button
  179. >
  180. <el-button
  181. @click="setClassifyHandle"
  182. type="primary"
  183. style="width: 132px; height: 40px"
  184. >保存</el-button
  185. >
  186. </div>
  187. </m-dialog>
  188. </div>
  189. </template>
  190. <script>
  191. import mDialog from '@/components/mDialog.vue';
  192. import { bannerupload, getchapterTypeList,editChapterType } from 'api/api.js';
  193. export default {
  194. components: { mDialog },
  195. beforeRouteEnter(to, from, next) {
  196. if (to.query.reportType == 'day') {
  197. to.matched[1].name = '晨报章节设置'
  198. } else {
  199. to.matched[1].name = '周报章节设置'
  200. }
  201. next()
  202. },
  203. data() {
  204. return {
  205. list: [],
  206. aeForm: {
  207. show: false,
  208. id:0,
  209. UnselectedIcon:'',
  210. selectedIcon:'',
  211. wordIcon:'',
  212. bgImg:'',
  213. IsShow:false
  214. }
  215. }
  216. },
  217. mounted() {
  218. this.getList()
  219. },
  220. methods: {
  221. async getList() {
  222. getchapterTypeList({ ReportType: this.$route.query.reportType == 'week' ? 'week' : 'day' }).then(res => {
  223. if (res.Ret === 200) {
  224. this.list = res.Data.List || []
  225. }
  226. })
  227. },
  228. handleShowEdit(data) {
  229. this.aeForm = {
  230. show: true,
  231. id:data.ReportChapterTypeId,
  232. UnselectedIcon:data.UnselectedImage,
  233. selectedIcon:data.SelectedImage,
  234. wordIcon:data.WordsImage,
  235. bgImg:data.EditImgUrl,
  236. IsShow:data.IsShow==0?true: false
  237. }
  238. },
  239. setClassifyHandle(){
  240. this.$refs.aeForm.validate((valid)=>{
  241. if(valid){
  242. let params={
  243. ReportChapterTypeId:this.aeForm.id,
  244. SelectedImage:this.aeForm.selectedIcon,
  245. UnselectedImage:this.aeForm.UnselectedIcon,
  246. WordsImage:this.aeForm.wordIcon,
  247. EditImgUrl:this.aeForm.bgImg,
  248. IsShow:this.aeForm.IsShow?0:1
  249. }
  250. editChapterType(params).then(res=>{
  251. if(res.Ret===200){
  252. this.$message.success( res.Msg );
  253. this.getList();
  254. this.aeForm.show=false;
  255. }
  256. })
  257. }
  258. })
  259. },
  260. clickinput(type) { //上传模拟点击
  261. $(`#file${type}`).click();
  262. },
  263. fileSelected(type) { //选择文件上传
  264. const that = this;
  265. if (document.getElementById('file' + type).files[0]) {
  266. let hostfile = document.getElementById('file' + type).files[0];
  267. let size = Math.floor(hostfile.size / 1024 / 1024);
  268. if (size > 200) {
  269. that.$message.error('上传文件大小不能大于200M!');
  270. hostfile = {};
  271. return false
  272. }
  273. if (hostfile.name.toLowerCase().includes('.png') || hostfile.name.toLowerCase().includes('.jpg') || hostfile.name.toLowerCase().includes('.jpeg')) {
  274. let form = new FormData();
  275. form.append('file', hostfile); //hostfile.name
  276. that.uploadloading = true;
  277. bannerupload(form).then((res) => {
  278. if (res.Ret === 200) {
  279. if (type == 1) {
  280. that.aeForm.UnselectedIcon = res.Data.ResourceUrl;
  281. } else if (type == 2) {
  282. that.aeForm.selectedIcon = res.Data.ResourceUrl;
  283. } else if (type == 3) {
  284. that.aeForm.wordIcon = res.Data.ResourceUrl
  285. } else if (type == 4) {
  286. that.aeForm.bgImg = res.Data.ResourceUrl
  287. }
  288. }
  289. $("#file" + type).val('');
  290. hostfile = {};
  291. });
  292. } else {
  293. that.$message.error('上传文件格式不正确!');
  294. }
  295. }
  296. },
  297. },
  298. }
  299. </script>
  300. <style lang="scss">
  301. .el-cascader .el-input {
  302. width: 100%;
  303. }
  304. .classify-page {
  305. .content-box {
  306. .el-tree-node__content {
  307. padding-top: 10px;
  308. padding-bottom: 10px;
  309. border-bottom: 1px solid #c8cdd9;
  310. }
  311. }
  312. }
  313. </style>
  314. <style lang="scss" scoped>
  315. .top-wrap {
  316. display: flex;
  317. justify-content: space-between;
  318. background: #ffffff;
  319. border-radius: 4px;
  320. padding: 20px;
  321. }
  322. .content-box {
  323. padding: 20px;
  324. margin-top: 20px;
  325. height: calc(100vh - 260px);
  326. overflow-y: auto;
  327. background-color: #ffffff;
  328. .classify-item-wrap {
  329. flex: 1;
  330. padding-right: 20px;
  331. display: flex;
  332. justify-content: space-between;
  333. align-items: center;
  334. .tag {
  335. display: inline-block;
  336. min-width: 76px;
  337. line-height: 30px;
  338. text-align: center;
  339. &.open {
  340. background-color: #ecf2fe;
  341. color: #0052d9;
  342. }
  343. &.close {
  344. background-color: #0052d9;
  345. color: #fff;
  346. }
  347. }
  348. .opt-box {
  349. .icon-drag,
  350. .icon-set {
  351. width: 16px;
  352. height: 16px;
  353. margin-left: 10px;
  354. }
  355. }
  356. }
  357. }
  358. </style>