categoryList.vue 32 KB

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