categoryList.vue 32 KB

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