categoryList.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. <template>
  2. <div class="mainBox">
  3. <!--搜索功能 start------------------------------------------------------------>
  4. <div class="layerBox_search">
  5. <el-row>
  6. <el-col :span="8">
  7. <div class="searchBox">
  8. <div class="searchTitle">栏目名称:</div>
  9. <el-input v-model="getApiData.name" placeholder="请输入栏目名称" :clearable="true" @clear="onInputClear"/>
  10. <!-- <el-input placeholder="请输入栏目名称" autocomplete="off" v-model="getApiData.name" /> -->
  11. </div>
  12. </el-col>
  13. </el-row>
  14. </div>
  15. <div class="layerBoxNoBg">
  16. <div>
  17. <el-button type="primary" @click="addCategoryList()">添加栏目名称</el-button>
  18. </div>
  19. <div>
  20. <el-button @click="clearSearchList">重置</el-button>
  21. <el-button type="primary" style="margin-right:20px" @click="getData('search')">搜索</el-button>
  22. </div>
  23. </div>
  24. <!--搜索功能 end------------------------------------------------------------>
  25. <!--表格内容 start------------------------------------------------------------>
  26. <div class="layerBox">
  27. <tableTitle :name="tableDivTitle" />
  28. <el-row>
  29. <template>
  30. <el-table
  31. :data="tableData"
  32. style="width: 100%"
  33. row-key="id"
  34. :default-expand-all="isExpandAll"
  35. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  36. >
  37. <el-table-column fixed prop="id" label="编号" width="150"></el-table-column>
  38. <el-table-column prop="name" label="栏目名称">
  39. <template slot-scope="scope">
  40. <span :class="{ highlight: isHighlight(scope.row, search) }" v-if="scope.row.pid==0">{{ scope.row.name }}</span>
  41. <span :class="{ highlight: isHighlight(scope.row, search)}" v-else>____{{ scope.row.name }}</span>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="是否外链" align="center">
  45. <template slot-scope="scope">
  46. <div>
  47. {{ scope.row.is_url ? '是' : "否" }}
  48. </div>
  49. </template>
  50. </el-table-column>
  51. <el-table-column prop="created_at" label="创建时间"></el-table-column>
  52. <el-table-column prop="updated_at" label="修改时间"></el-table-column>
  53. <el-table-column fixed="right" label="操作" width="230" header-align="center">
  54. <template slot-scope="scope">
  55. <div class="listBtnBox">
  56. <div class="listDeleteBtn" @click="deleteData(scope.row.id, tableData)"><i class="el-icon-delete"></i>删除</div>
  57. <div class="listEditBtn" @click="getDataMain(scope.row.id, tableData)"><i class="el-icon-edit-outline"></i>编辑</div>
  58. <div class="listMainBtn" @click="addCategoryList(scope.row)"><i class="el-icon-document-add"></i>添加</div>
  59. </div>
  60. <!-- <el-button @click.native.prevent="deleteData(scope.row.id, tableData)" type="text" size="small">删除</el-button>
  61. <el-button @click.native.prevent="getDataMain(scope.row.id, tableData)" type="text" size="small">编辑</el-button> -->
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. </template>
  66. </el-row>
  67. </div>
  68. <!--分页 start------------------------------------------------------------>
  69. <div class="alignBox">
  70. <el-row>
  71. <el-col :span="24">
  72. <el-pagination :current-page="getApiData.page" @size-change="handleSizeChange"
  73. @current-change="handleCurrentChange" :page-size="10" layout="total, prev, pager, next, jumper"
  74. :total="allCount"></el-pagination>
  75. </el-col>
  76. </el-row>
  77. </div>
  78. <!--分页 end------------------------------------------------------------>
  79. <!--表格内容 end------------------------------------------------------------>
  80. <!--弹出框 start------------------------------------------------------------>
  81. <el-dialog :title="editId ? '编辑栏目名称' : '添加栏目名称'" :visible.sync="windowStatus" :close-on-click-modal="false"
  82. @close="clearToServe(2)">
  83. <el-form :model="form" ref="form" :rules="formRules" autocomplete="off" label-position="left">
  84. <div class="formDiv">
  85. <el-form-item label="栏目名称:" :label-width="formLabelWidth" prop="name" class="custom-align-right">
  86. <el-input v-model="form.name" autocomplete="off" placeholder="请输入栏目名称"></el-input>
  87. <el-checkbox v-model="show_url" @change="ifUrl">引用外链</el-checkbox>
  88. </el-form-item>
  89. <div v-if="show_url == 1">
  90. <el-form-item label="外链地址:" :label-width="formLabelWidth" prop="web_url" class="custom-align-right">
  91. <el-input v-model="form.web_url" autocomplete="off" placeholder="请输入外链地址"></el-input>
  92. </el-form-item>
  93. <el-form-item label="栏目标题:" :label-width="formLabelWidth" prop="seo_title" class="custom-align-right">
  94. <el-input v-model="form.seo_title" autocomplete="off" placeholder="请输入栏目标题"></el-input>
  95. </el-form-item>
  96. <el-form-item label="栏目关键词:" :label-width="formLabelWidth" prop="seo_keywords" class="custom-align-right">
  97. <!-- <el-input v-model="form.seo_keywords" autocomplete="off" placeholder="请输入栏目关键词"></el-input> -->
  98. <inputTag :initialTags="tags" @tags-updated="updateTags" />
  99. </el-form-item>
  100. <el-form-item label="栏目描述:" :label-width="formLabelWidth" prop="seo_description" class="custom-align-right">
  101. <el-input type="textarea" v-model="form.seo_description" placeholder="请输入栏目描述"></el-input>
  102. </el-form-item>
  103. <!-- <el-form-item label="排序:" :label-width="formLabelWidth" class="custom-align-right">
  104. <el-input v-model="form.sort" autocomplete="off" placeholder="请输入排序"></el-input>
  105. </el-form-item> -->
  106. </div>
  107. <div v-if="show_url == 0">
  108. <!-- <el-form-item label="关联职能部门:" :label-width="formLabelWidth" prop="department_arr_id" class="custom-align-right"> -->
  109. <!-- <el-cascader :key="departmentKey" v-model="form.department_arr_id" placeholder="选择要绑定的职能部门" :props="departmentData" filterable clearable></el-cascader> -->
  110. <!-- <el-cascader :key="departmentKey" :props="{value:'id',label:'name',children:'children'}" :options="allDepartment" v-model="form.department_arr_id" :show-all-levels="false" filterable />
  111. </el-form-item> -->
  112. <!-- <el-form-item label="关联行政区划:" :label-width="formLabelWidth" prop="city_arr_id" class="custom-align-right">
  113. <el-cascader :key="cascaderKey" v-model="form.city_arr_id" placeholder="选择要绑定行政区划" :props="cityData" filterable clearable></el-cascader>
  114. </el-form-item> -->
  115. <el-form-item label="父级栏目:" :label-width="formLabelWidth" class="custom-align-right">
  116. <el-cascader :key="parentKey" v-model="form.pid_arr" placeholder="请选择要绑定的父级栏目" :props="parentData"
  117. filterable clearable></el-cascader>
  118. </el-form-item>
  119. <el-form-item label="栏目标题:" :label-width="formLabelWidth" prop="seo_title" class="custom-align-right">
  120. <template #label>
  121. <span class="askBox">
  122. 栏目标题:
  123. <el-tooltip class="item" effect="dark" content="栏目标题,如:三农市场网_农资产品商城_网站列表_全国信息一体化网络平台_项目大全。"
  124. placement="top">
  125. <i class="el-icon-question"></i>
  126. </el-tooltip>
  127. </span>
  128. </template>
  129. <el-input v-model="form.seo_title" autocomplete="off" placeholder="请输入栏目标题"></el-input>
  130. </el-form-item>
  131. <el-form-item label="栏目关键词:" :label-width="formLabelWidth" prop="seo_keywords" class="custom-align-right">
  132. <template #label>
  133. <span class="askBox">
  134. 栏目关键词:
  135. <el-tooltip class="item" effect="dark" content="栏目关键词,如:三农市场网、农资产品商城、全国三农、信息一体化。" placement="top">
  136. <i class="el-icon-question"></i>
  137. </el-tooltip>
  138. </span>
  139. </template>
  140. <!-- <el-input v-model="form.seo_keywords" autocomplete="off" placeholder="请输入栏目关键词"></el-input> -->
  141. <inputTag :initialTags="tags" @tags-updated="updateTags" />
  142. </el-form-item>
  143. <el-form-item label="栏目描述:" :label-width="formLabelWidth" prop="seo_description" class="custom-align-right">
  144. <template #label>
  145. <span class="askBox">
  146. 栏目描述:
  147. <el-tooltip class="item" effect="dark" content="栏目描述,如:中国三农市场网,农资产品商城属市场类频道,共有5个栏目。" placement="top">
  148. <i class="el-icon-question"></i>
  149. </el-tooltip>
  150. </span>
  151. </template>
  152. <el-input type="textarea" v-model="form.seo_description" class="custom-textarea"
  153. placeholder="请输入栏目描述"></el-input>
  154. </el-form-item>
  155. <!-- <el-form-item label="排序:" :label-width="formLabelWidth" class="custom-align-right">
  156. <el-input v-model="form.sort" autocomplete="off" placeholder="请输入排序"></el-input>
  157. </el-form-item> -->
  158. </div>
  159. </div>
  160. </el-form>
  161. <div slot="footer" class="dialog-footer">
  162. <el-button @click="closeWindow">取 消</el-button>
  163. <el-button type="primary" @click="editToServe" v-if="editBtn == true">确定</el-button>
  164. <el-button type="primary" @click="addToServe" v-else>提交</el-button>
  165. </div>
  166. </el-dialog>
  167. <!--弹出框 end------------------------------------------------------------>
  168. </div>
  169. </template>
  170. <script>
  171. //表格标题
  172. import tableTitle from './components/tableTitle';
  173. import InputTag from '@/components/InputTag';
  174. //引入公用样式
  175. import '@/styles/global.less';
  176. export default {
  177. components: {
  178. tableTitle,//表格标题
  179. InputTag
  180. },
  181. data() {
  182. //0.全局操作 start ------------------------------------------------------------>
  183. //表单验证
  184. const validateEmpty = (rule, value, callback) => {
  185. if (value.length == 0) {
  186. callback(new Error('该项不能为空!'))
  187. } else {
  188. callback()
  189. }
  190. }
  191. // const validateDepartment = (rule,value,callback) => {
  192. // if (value.length === 0) {
  193. // callback(new Error('请选择职能部门!'))
  194. // } else {
  195. // callback()
  196. // }
  197. // }
  198. // const validateCity = (rule,value,callback) => {
  199. // if (value.length === 0) {
  200. // callback(new Error('请选择行政区划!'))
  201. // } else {
  202. // callback()
  203. // }
  204. // }
  205. const validatePid = (rule, value, callback) => {
  206. if (value.length === 0) {
  207. callback(new Error('请选择父级栏目!'))
  208. } else {
  209. callback()
  210. }
  211. }
  212. let self = this;
  213. //0.全局操作 end ------------------------------------------------------------>
  214. return {
  215. isExpandAll: false,
  216. search: '',
  217. tags: [],
  218. //1.列表和分页相关 start ------------------------------------------------------------>
  219. tableDivTitle: "栏目名称列表",
  220. tableData: [],//内容
  221. allCount: 0,//总条数
  222. editId: 0,//要修改的网站id
  223. getApiData: {
  224. name: "",//栏目池名称查询
  225. // department_id:[],//行政职能部门id
  226. // city_id:[],//行政区划
  227. page: 1,//当前是第几页
  228. pageSize: 10,//一共多少条
  229. },
  230. allDepartment: [],//所有职能
  231. //列表和分页相关 end ------------------------------------------------------------>
  232. //2.搜索相关 start ------------------------------------------------------------>
  233. //行政职能部门
  234. searchDepartmentKey: 0, //列表缓存key
  235. // searchDepartmentData: {
  236. // checkStrictly: true,
  237. // lazy: true,
  238. // async lazyLoad (node, resolve) {
  239. // const { level, data } = node;
  240. // if (data && data.children && data.children.length !== 0) {
  241. // return resolve(node)
  242. // }
  243. // console.log(level)
  244. // let parentId = level == 0 ? 0 : data.value
  245. // let parames = {
  246. // 'pid':parentId
  247. // }
  248. // self.$store.dispatch('pool/getDepartment',parames).then(res=> {
  249. // if (res.data) {
  250. // const nodes = res.data.map(item => ({
  251. // value: item.id,
  252. // label: item.name,
  253. // leaf: level >= 3,
  254. // children: []
  255. // }))
  256. // resolve(nodes)
  257. // }
  258. // })
  259. // }
  260. // },
  261. //获取城市列表
  262. searchCascaderKey: 0, //列表缓存key
  263. searchCityData: {
  264. checkStrictly: true,
  265. lazy: true,
  266. async lazyLoad(node, resolve) {
  267. const { level, data } = node;
  268. if (data && data.children && data.children.length !== 0) {
  269. return resolve(node)
  270. }
  271. console.log(level)
  272. let parentId = level == 0 ? 0 : data.value
  273. let parames = {
  274. 'pid': parentId
  275. }
  276. self.$store.dispatch('pool/getcityList', parames).then(res => {
  277. if (res.data) {
  278. const nodes = res.data.map(item => ({
  279. value: item.id,
  280. label: item.name,
  281. leaf: level >= 3,
  282. children: []
  283. }))
  284. resolve(nodes)
  285. }
  286. })
  287. }
  288. },
  289. //搜索相关 end ------------------------------------------------------------>
  290. //3.弹出框设置 start ------------------------------------------------------------>
  291. windowStatus: false, //显示弹出框
  292. formLabelWidth: '140px',
  293. show_url: false, //是否显示外链输入框
  294. editBtn: false,//当显示编辑按钮的时候,就不显示提交
  295. //弹出框设置 end ------------------------------------------------------------>
  296. //4.弹出框中的表单设置 start ------------------------------------------------------------>
  297. //4.1表单收集的数据
  298. form: {
  299. name: '',//栏目池名称
  300. is_url: 0,//是否为外链,0=否 1=是
  301. web_url: "",//外链地址
  302. // department_arr_id:[],//职能部门
  303. // city_arr_id:[],//行政区划
  304. sort: 0,//排序
  305. //pid:2,
  306. seo_title: "",//标题
  307. seo_keywords: "",//关键词
  308. seo_description: "",//描述
  309. pid_arr: []//父级栏目
  310. },
  311. //4.2表单验证规则
  312. formRules: {
  313. //网站名称不能为空
  314. name: [{ required: true, trigger: 'blur', validator: validateEmpty }],//栏目池名称不能为空
  315. web_url: [{ required: true, trigger: 'blur', validator: validateEmpty }],//外链地址不能为空
  316. // department_arr_id: [{type:'array',required:true,trigger:'change',message:'请选择职能部门!',validator:validateDepartment}],
  317. // city_arr_id: [{type:'array',required:true,trigger:'change',message:'请选择行政区划!',validator:validateCity}],
  318. // pid_arr: [{type:'array',required:true,trigger:'change',message:'请选择父级栏目!',validator:validatePid}],
  319. seo_title: [{ required: true, trigger: 'blur', validator: validateEmpty }],//标题不能为空
  320. seo_keywords: [{ required: true, trigger: 'blur', validator: validateEmpty }],//关键词不能为空
  321. seo_description: [{ required: true, trigger: 'blur', validator: validateEmpty }],//描述不能为空
  322. },
  323. //获取城市列表
  324. cascaderKey: 0,//弹窗用的key
  325. cityData: {
  326. checkStrictly: true,
  327. lazy: true,
  328. async lazyLoad(node, resolve) {
  329. const { level, data } = node;
  330. if (data && data.children && data.children.length !== 0) {
  331. return resolve(node)
  332. }
  333. console.log(level)
  334. let parentId = level == 0 ? 0 : data.value
  335. let parames = {
  336. 'pid': parentId
  337. }
  338. self.$store.dispatch('pool/getcityList', parames).then(res => {
  339. if (res.data) {
  340. const nodes = res.data.map(item => ({
  341. value: item.id,
  342. label: item.name,
  343. leaf: level >= 3,
  344. children: []
  345. }))
  346. resolve(nodes)
  347. }
  348. })
  349. }
  350. },
  351. //获取职能部门
  352. departmentKey: 0,//弹窗用的key
  353. // departmentData: {
  354. // checkStrictly: true,//父级不可选
  355. // lazy: true,
  356. // async lazyLoad (node, resolve) {
  357. // const { level, data } = node;
  358. // if (data && data.children && data.children.length !== 0) {
  359. // return resolve(node)
  360. // }
  361. // console.log(level)
  362. // let parentId = level == 0 ? 0 : data.value
  363. // let parames = {
  364. // 'pid':parentId
  365. // }
  366. // self.$store.dispatch('pool/getDepartment',parames).then(res=> {
  367. // if (res.data) {
  368. // const nodes = res.data.map(item => ({
  369. // value: item.id,
  370. // label: item.name,
  371. // leaf: level >= 3,
  372. // children: []
  373. // }))
  374. // resolve(nodes)
  375. // }
  376. // })
  377. // }
  378. // },
  379. parentKey: 0,//获取父级栏目
  380. parentData: {
  381. checkStrictly: true,
  382. lazy: true,
  383. lazyLoad: async (node, resolve) => {
  384. const { level, data } = node;
  385. if (data && data.children && data.children.length !== 0) {
  386. return resolve(node);
  387. }
  388. const parentId = level === 0 ? 0 : data.value;
  389. try {
  390. const res = await this.$store.dispatch('pool/categoryList', { pid: parentId });
  391. if (res.data) {
  392. const nodes = res.data.map(item => ({
  393. value: item.id,
  394. label: item.name,
  395. leaf: level >= 3,
  396. children: []
  397. }));
  398. resolve(nodes);
  399. } else {
  400. resolve([]);
  401. }
  402. } catch (error) {
  403. console.error('Failed to load parent category data:', error);
  404. resolve([]);
  405. }
  406. }
  407. },
  408. //弹出框中的表单设置 end ------------------------------------------------------------>
  409. }
  410. },
  411. methods: {
  412. onInputClear(){
  413. this.isExpandAll = false;
  414. this.getData();
  415. },
  416. //1.列表和分页相关 start ------------------------------------------------------------>
  417. //1.1 开始请求列表信息方法
  418. getData(type) {
  419. if(type=='search'){
  420. this.getApiData.page=1
  421. this.isExpandAll = true;
  422. }else{
  423. this.isExpandAll = false;
  424. }
  425. //搜索条件
  426. // if(this.getApiData.department_id.length>0){
  427. // //网系只提交最后一个
  428. // this.getApiData.department_id = this.getApiData.department_id[this.getApiData.department_id.length - 1];
  429. // }
  430. // if(this.getApiData.city_id.length>0){
  431. // //城市id只提交最后一个
  432. // this.getApiData.city_id = this.getApiData.city_id[this.getApiData.city_id.length - 1];
  433. // }
  434. //如果是搜索,重新加载第一页
  435. this.$store.dispatch('pool/getCategoryList', this.getApiData).then(res => {
  436. // console.log("=============:",res.data)
  437. this.tableData = res.data.rows; //与内容
  438. this.allCount = res.data.total
  439. }).catch(() => {
  440. this.$message({
  441. type: 'warning',
  442. message: '网络错误,请重试!'
  443. });
  444. })
  445. },
  446. //1.2 删除内容
  447. deleteData(id) {
  448. this.$confirm('删除后,该条信息及其绑定关系全部删除,确定吗', '提示', {
  449. confirmButtonText: '确定',
  450. cancelButtonText: '取消',
  451. type: 'warning'
  452. }).then(() => {
  453. console.log("当前删除:" + id)
  454. this.$store.dispatch('pool/delCategory', { id: id }).then(res => {
  455. if (res.code == 200) {
  456. this.$message({
  457. type: 'success',
  458. message: '删除成功!'
  459. });
  460. } else if (res.code == 0) {
  461. this.$message({
  462. type: 'warning',
  463. message: res.message
  464. });
  465. }
  466. this.getData();
  467. }).catch(() => {
  468. this.$message({
  469. type: 'warning',
  470. message: '网络错误,请重试!'
  471. });
  472. })
  473. }).catch(() => {
  474. this.$message({
  475. type: 'warning',
  476. message: '已取消删除'
  477. });
  478. });
  479. },
  480. //1.3 直接跳转
  481. handleSizeChange(val) {
  482. this.getApiData.page = val;
  483. this.getData();
  484. },
  485. //1.4 点击分页
  486. handleCurrentChange(val) {
  487. this.getApiData.page = val;
  488. this.getData();
  489. },
  490. //1.5 重置按钮
  491. clearSearchList() {
  492. this.isExpandAll = false;
  493. this.tableData = [];
  494. this.getApiData.name = "";
  495. // this.getApiData.department_id = [];
  496. // this.getApiData.city_id = [];
  497. this.getApiData.page = 1;
  498. this.getApiData.pageSize = 10;
  499. this.getData();
  500. },
  501. //1.6 获取所有职能
  502. getAllDepartment() {
  503. this.$store.dispatch('cms/getAllDepartment').then(res => {
  504. // console.log(res)
  505. this.allDepartment = res.data;
  506. })
  507. },
  508. //列表和分页相关 end ------------------------------------------------------------>
  509. //2.弹出框设置 start ------------------------------------------------------------>
  510. //2.1 打开弹出框
  511. openWindow() {
  512. //this.clearToServe();
  513. this.windowStatus = true;
  514. },
  515. //2.1.1 添加栏目池
  516. async addCategoryList(row) {
  517. this.form.pid_arr = [];
  518. this.show_url = false;
  519. this.editId = 0;
  520. this.editBtn = false;
  521. this.tags = [];
  522. if(row) {
  523. let pidArr = [];
  524. if(row.pid == 0) {
  525. pidArr = [row.id];
  526. } else {
  527. try {
  528. pidArr = JSON.parse(row.pid_arr);
  529. pidArr.push(row.id);
  530. } catch(e) {
  531. pidArr = [];
  532. }
  533. }
  534. // 先打开窗口
  535. this.openWindow();
  536. // 预加载数据
  537. for(let i = 0; i < pidArr.length; i++) {
  538. const parentId = i === 0 ? 0 : pidArr[i - 1];
  539. await this.$store.dispatch('pool/categoryList', { pid: parentId });
  540. }
  541. // 设置值并更新 key
  542. this.form.pid_arr = pidArr;
  543. this.parentKey += 1;
  544. } else {
  545. this.openWindow();
  546. }
  547. },
  548. //2.2 关闭弹出框
  549. closeWindow() {
  550. this.windowStatus = false;
  551. this.clearToServe(2);
  552. },
  553. //2.3 清理弹出框
  554. clearToServe(type) {
  555. if (type == 1) { //type1 使用了外部链接
  556. // this.form.department_arr_id = [];
  557. // this.form.city_arr_id = [];
  558. this.form.pid_arr = [];
  559. }
  560. if (type == 2) { //type2 全部清理
  561. this.form.name = "";
  562. this.form.is_url = 0;
  563. this.form.web_url = "";
  564. // this.form.department_arr_id = [];
  565. // this.form.city_arr_id = [];
  566. this.form.sort = 0;
  567. this.form.seo_title = "";
  568. this.form.seo_keywords = "";
  569. this.form.seo_description = "";
  570. this.form.pid_arr = [];
  571. //存在验证的时候再清理
  572. if (this.$refs.form && this.$refs.form.fields.some(field => field.validateState === 'error')) {
  573. this.$refs.form.clearValidate();
  574. }
  575. }
  576. },
  577. //弹出框设置 end ------------------------------------------------------------>
  578. //3.添加栏目池 start ------------------------------------------------------------>
  579. ifUrl(value) {
  580. console.log(value)
  581. if (value == true) {
  582. this.form.is_url = 1
  583. } else {
  584. this.form.is_url = 0
  585. }
  586. this.$refs.form.clearValidate();
  587. },
  588. addToServe() {
  589. //先判断是否使用了外链
  590. if (this.show_url == true) {
  591. this.clearToServe(1)
  592. }
  593. //判断有没有添加父级栏目
  594. if (this.form.pid_arr.length == 0) {
  595. this.form.pid_arr = [0];
  596. }
  597. this.$refs.form.validate(valid => {
  598. if (valid) {
  599. this.$store.dispatch('pool/addCategory', this.form).then(res => {
  600. //汇报结果
  601. this.$message({
  602. type: 'success',
  603. message: '已成功添加栏目池!'
  604. });
  605. //清空并退出
  606. this.closeWindow();
  607. this.getData();
  608. }).catch(() => {
  609. this.$message({
  610. type: 'warning',
  611. message: '网络错误,请重试!'
  612. });
  613. })
  614. }
  615. })
  616. },
  617. //添加栏目池 end ------------------------------------------------------------>
  618. //编辑栏目池 start ------------------------------------------------------------>
  619. getDataMain(id) {
  620. //先清空窗口
  621. this.clearToServe(2)
  622. //打开输入窗口
  623. this.openWindow();
  624. //添加修改id
  625. this.editId = id;
  626. //获取网站详情
  627. this.$store.dispatch('pool/getCategoryInfo', { id: id }).then(res => {
  628. //清除错误状态
  629. //this.$refs.form.clearValidate();
  630. // console.log(res)
  631. //回显栏目池名称
  632. this.form.name = res.data.name;
  633. //回显示是否使用外链
  634. if (res.data.is_url == 1) {
  635. this.show_url = true;
  636. } else if (res.data.is_url == 0 || res.data.is_url == null) {
  637. this.show_url = false;
  638. }
  639. // console.log(res.data.is_url)
  640. this.form.is_url = res.data.is_url;
  641. //回显外链
  642. this.form.web_url = res.data.web_url;
  643. //回显行政区划
  644. // this.form.city_arr_id = JSON.parse(res.data.city_arr_id);
  645. // //当cascaderKey的值改变的时候 级联选择器会重置里面的内容
  646. // this.cascaderKey += 1;
  647. // this.loadCascaderPath(this.form.city_arr_id,"xzqh");
  648. //回显父级栏目
  649. this.form.pid_arr = JSON.parse(res.data.pid_arr);
  650. this.parentKey += 1;
  651. // this.loadCascaderPath(this.form.pid_arr,"fjdh");
  652. //回显职能部门
  653. // this.form.department_arr_id = JSON.parse(res.data.department_arr_id);
  654. // this.departmentKey += 1;
  655. // this.loadCascaderPath(this.form.department_arr_id,"znbm");
  656. //回显栏目池标题,描述,关键词
  657. this.form.seo_title = res.data.seo_title;
  658. this.form.seo_keywords = res.data.seo_keywords;
  659. this.tags = res.data.seo_keywords ? res.data.seo_keywords.split(',') : [];
  660. this.form.seo_description = res.data.seo_description;
  661. //回显排序
  662. this.form.sort = res.data.sort;
  663. })
  664. this.editBtn = true;//显示编辑按钮
  665. },
  666. //回显行政区划
  667. // async loadCascaderPath(path,type) {
  668. // for (let i = 0; i < path.length; i++) {
  669. // const parentId = path[i - 1] || 0; // 获取当前层级的父级ID
  670. // const level = i; // 当前层级的索引
  671. // await this.$store.dispatch('pool/getcityList', { pid: parentId })
  672. // .then((res) => {
  673. // const nodes = res.data.map(item => ({
  674. // value: item.id,
  675. // label: item.name,
  676. // leaf: level >= 3, // 这里假设4层结构,设置叶子节点标记
  677. // }));
  678. // // 将数据传递到 resolve,通知 cascader 这一层的数据加载完毕
  679. // if (level === path.length - 1) {
  680. // if(type=="xzqh"){this.form.city_arr_id = path;}
  681. // if(type=="fjdh"){this.form.pid_arr = path;}
  682. // if(type=="znbm"){this.form.department_arr_id = path;}
  683. // }
  684. // });
  685. // }
  686. // },
  687. //修改表单
  688. editToServe() {
  689. //防止提交[1,1]这种重复的数据
  690. // if (this.form.department_arr_id.length > 1) {
  691. // const lastIndex = this.form.department_arr_id.length - 1;
  692. // if (this.form.department_arr_id[lastIndex] === this.form.department_arr_id[lastIndex - 1]) {
  693. // this.form.department_arr_id.pop(); // Remove the last element if it's the same as the previous one
  694. // }
  695. // }
  696. this.form.id = this.editId;
  697. this.$refs.form.validate(valid => {
  698. if (valid) {
  699. //提交表单
  700. this.$store.dispatch('pool/updateCategory', this.form).then(res => {
  701. //汇报结果
  702. this.$message({
  703. type: 'success',
  704. message: '已成功修改栏目池信息!'
  705. });
  706. //清空并退出
  707. this.closeWindow();
  708. this.getData();
  709. }).catch(() => {
  710. this.$message({
  711. type: 'warning',
  712. message: '网络错误,请重试!'
  713. });
  714. })
  715. }
  716. })
  717. },
  718. //关键词
  719. updateTags(newTags) {
  720. // this.foem.seo_keywords = newTags;
  721. this.tags = newTags;
  722. this.form.seo_keywords = newTags.join(',');
  723. },
  724. isHighlight(row, search) {
  725. if (!search) return false;
  726. const lowerSearch = search.toLowerCase();
  727. return row.name.toLowerCase().includes(lowerSearch);
  728. },
  729. //编辑栏目池 end ------------------------------------------------------------>
  730. },
  731. mounted() {
  732. //1.获得初始数据
  733. this.getData();
  734. //2.获取所有网系
  735. //this.getwebsiteColumn();
  736. //本地转换id为文字
  737. //console.log(getLocationNameById("110000"))
  738. this.getAllDepartment();
  739. }
  740. }
  741. </script>
  742. <style scoped lang="less">
  743. ::v-deep .highlight {
  744. background-color: yellow;
  745. }
  746. //表单微调 start------------------------------------------------------------>*/
  747. ::v-deep .custom-form-item>.el-form-item__label {
  748. line-height: 140px !important;
  749. }
  750. ::v-deep .custom-textarea .el-textarea__inner {
  751. resize: none;
  752. /* 禁止用拖拽调整大小 */
  753. }
  754. ::v-deep .custom-align-right .el-form-item__label {
  755. text-align: right;
  756. /* 设置标签文字右对齐 */
  757. }
  758. .collector {
  759. margin-left: 0px;
  760. padding-left: 0px;
  761. margin-right: 20px;
  762. width: 76px;
  763. height: 36px;
  764. line-height: 36px;
  765. position: relative;
  766. .collectorIcon {
  767. display: inline-block;
  768. width: 20px;
  769. height: 20px;
  770. background: url("../../assets/advertise/Graph.png");
  771. vertical-align: middle;
  772. margin-right: 6px;
  773. }
  774. .collectorIcon1 {
  775. position: absolute;
  776. top: 12px;
  777. left: 8px;
  778. }
  779. }
  780. .collector {
  781. text-align: center;
  782. border-radius: 8px;
  783. cursor: pointer;
  784. color: #519C66;
  785. background-color: rgba(81, 156, 102, 0.16);
  786. >i {
  787. padding-right: 8px;
  788. }
  789. }
  790. //表单微调 end------------------------------------------------------------>*/</style>