index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="名称" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="所属公司" prop="companyId">
  14. <el-select
  15. v-model="queryParams.companyId"
  16. filterable
  17. remote
  18. reserve-keyword
  19. placeholder="请输入公司名称搜索"
  20. :remote-method="searchCompanies"
  21. :loading="companySearchLoading"
  22. style="width: 220px"
  23. clearable
  24. size="small"
  25. >
  26. <el-option
  27. v-for="item in companyOptions"
  28. :key="item.dictValue"
  29. :label="item.dictLabel"
  30. :value="item.dictValue"
  31. />
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="appid" prop="appid">
  35. <el-input
  36. v-model="queryParams.appid"
  37. placeholder="请输入appid"
  38. clearable
  39. size="small"
  40. @keyup.enter.native="handleQuery"
  41. />
  42. </el-form-item>
  43. <el-form-item>
  44. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  45. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  46. </el-form-item>
  47. </el-form>
  48. <el-row :gutter="10" class="mb8">
  49. <el-col :span="1.5">
  50. <el-button
  51. type="primary"
  52. plain
  53. icon="el-icon-plus"
  54. size="mini"
  55. @click="handleAdd"
  56. v-hasPermi="['course:playSourceConfig:add']"
  57. >新增</el-button>
  58. </el-col>
  59. <el-col :span="1.5">
  60. <el-button
  61. type="success"
  62. plain
  63. icon="el-icon-edit"
  64. size="mini"
  65. :disabled="single"
  66. @click="handleUpdate"
  67. v-hasPermi="['course:playSourceConfig:edit']"
  68. >修改</el-button>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button
  72. type="danger"
  73. plain
  74. icon="el-icon-delete"
  75. size="mini"
  76. :disabled="multiple"
  77. @click="handleDelete"
  78. v-hasPermi="['course:playSourceConfig:remove']"
  79. >删除</el-button>
  80. </el-col>
  81. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  82. </el-row>
  83. <!-- 开关配置对话框 -->
  84. <el-dialog title="开关配置" :visible.sync="switchDialogVisible" width="500px" class="switch-dialog">
  85. <el-form :model="switchForm" label-width="100px">
  86. <el-form-item label="AppId">
  87. <el-input v-model="switchForm.appId" :disabled="true"></el-input>
  88. </el-form-item>
  89. <el-form-item label="开关状态">
  90. <el-switch
  91. v-model="switchForm.switchStatus"
  92. active-text="开启"
  93. inactive-text="关闭"
  94. active-value="001"
  95. inactive-value="002">
  96. </el-switch>
  97. </el-form-item>
  98. <el-form-item label="配置信息" v-if="switchForm.configInfo">
  99. <el-input
  100. type="textarea"
  101. :rows="4"
  102. v-model="switchForm.configInfo"
  103. :disabled="true">
  104. </el-input>
  105. </el-form-item>
  106. </el-form>
  107. <span slot="footer" class="dialog-footer">
  108. <el-button @click="switchDialogVisible = false">取 消</el-button>
  109. <el-button type="primary" @click="submitSwitchConfig">确 定</el-button>
  110. </span>
  111. </el-dialog>
  112. <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange" border>
  113. <el-table-column type="selection" width="55" align="center" />
  114. <el-table-column label="ID" align="center" prop="id" />
  115. <el-table-column label="名称" align="center" prop="name" />
  116. <el-table-column label="所属公司" align="center" prop="companyId" :formatter="companyNameFormatter"/>
  117. <el-table-column label="图标" align="center" prop="img">
  118. <template slot-scope="scope">
  119. <el-image
  120. style="width: 80px; height: 80px"
  121. :src="scope.row.img"
  122. :preview-src-list="[scope.row.img]">
  123. </el-image>
  124. </template>
  125. </el-table-column>
  126. <el-table-column label="原始ID" align="center" prop="originalId" />
  127. <el-table-column label="appId" align="center" prop="appid" />
  128. <el-table-column label="secret" align="center" prop="secret" />
  129. <el-table-column label="token" align="center" prop="token" />
  130. <el-table-column label="aesKey" align="center" prop="aesKey" />
  131. <el-table-column label="msgDataFormat" align="center" prop="msgDataFormat" />
  132. <el-table-column label="类型" align="center" prop="type">
  133. <template slot-scope="scope">
  134. <dict-tag :options="typesOptions" :value="scope.row.type"/>
  135. </template>
  136. </el-table-column>
  137. <el-table-column label="互医/商城小程序" align="center" prop="isMall" width="80px">
  138. <template slot-scope="scope">
  139. <el-tag prop="isMall" v-for="(item, index) in isMallOptions" v-if="scope.row.isMall==item.dictValue">{{item.dictLabel}}</el-tag>
  140. </template>
  141. </el-table-column>
  142. <el-table-column label="创建时间" align="center" prop="createTime" />
  143. <el-table-column label="修改时间" align="center" prop="updateTime" />
  144. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  145. <template slot-scope="scope">
  146. <el-button
  147. size="mini"
  148. type="text"
  149. icon="el-icon-edit"
  150. @click="handleUpdate(scope.row)"
  151. v-hasPermi="['course:playSourceConfig:edit']"
  152. >修改</el-button>
  153. <el-button
  154. size="mini"
  155. type="text"
  156. icon="el-icon-delete"
  157. @click="handleDelete(scope.row)"
  158. v-hasPermi="['course:playSourceConfig:remove']"
  159. >删除</el-button>
  160. <el-button
  161. size="mini"
  162. type="text"
  163. icon="el-icon-setting"
  164. @click="handleSwitchConfig(scope.row)"
  165. >是否展示销售</el-button>
  166. </template>
  167. </el-table-column>
  168. </el-table>
  169. <pagination
  170. v-show="total>0"
  171. :total="total"
  172. :page.sync="queryParams.pageNum"
  173. :limit.sync="queryParams.pageSize"
  174. @pagination="getList"
  175. />
  176. <!-- 添加或修改点播配置对话框 -->
  177. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :before-close="resetOption">
  178. <el-form ref="form" :model="form" :rules="rules" label-width="130px">
  179. <el-form-item label="名称" prop="name">
  180. <el-input v-model="form.name" placeholder="请输入名称" />
  181. </el-form-item>
  182. <el-form-item label="所属公司" prop="companyId">
  183. <el-select
  184. v-model="form.companyId"
  185. filterable
  186. remote
  187. reserve-keyword
  188. placeholder="请输入公司名称搜索"
  189. :remote-method="searchCompanies"
  190. :loading="companySearchLoading"
  191. style="width: 220px"
  192. clearable
  193. size="small"
  194. >
  195. <el-option
  196. v-for="item in companyOptions"
  197. :key="item.dictValue"
  198. :label="item.dictLabel"
  199. :value="item.dictValue"
  200. />
  201. </el-select>
  202. </el-form-item>
  203. <el-form-item label="所属部门" prop="createDeptId">
  204. <treeselect v-model="form.createDeptId" :options="deptOptions" :normalizer="normalizer" placeholder="选择上级部门" :disabled="(username !== 'admin' && title === '修改小程序配置')" />
  205. </el-form-item>
  206. <el-form-item label="是否是互医/商城小程序" prop="isMall">
  207. <el-select
  208. v-model="form.isMall"
  209. style="width: 220px"
  210. clearable
  211. size="small"
  212. >
  213. <el-option
  214. v-for="item in isMallOptions"
  215. :key="item.dictValue"
  216. :label="item.dictLabel"
  217. :value="item.dictValue"
  218. />
  219. </el-select>
  220. </el-form-item>
  221. <el-form-item label="商城刷单数据查看权限">
  222. <el-select v-model="form.viewPermissions" placeholder="请选择">
  223. <el-option
  224. v-for="item in authOptions"
  225. :key="item.dictValue"
  226. :label="item.dictLabel"
  227. :value="item.dictValue">
  228. </el-option>
  229. </el-select>
  230. </el-form-item>
  231. <el-form-item label="图标" prop="img">
  232. <image-upload v-model="form.img" :file-type='["png", "jpg", "jpeg"]' :limit="1"/>
  233. </el-form-item>
  234. <el-form-item label="类型" prop="type">
  235. <el-select
  236. v-model="form.type"
  237. placeholder="请选择类型">
  238. <el-option
  239. v-for="item in typesOptions"
  240. :key="item.dictValue"
  241. :label="item.dictLabel"
  242. :value="item.dictValue"/>
  243. </el-select>
  244. </el-form-item>
  245. <el-form-item label="原始id" prop="originalId">
  246. <el-input v-model="form.originalId" placeholder="请输入原始id" />
  247. </el-form-item>
  248. <el-form-item label="appid" prop="appid">
  249. <el-input v-model="form.appid" placeholder="请输入appid" />
  250. </el-form-item>
  251. <el-form-item label="secret" prop="secret">
  252. <el-input v-model="form.secret" placeholder="请输入secret" />
  253. </el-form-item>
  254. <el-form-item label="token" prop="token">
  255. <el-input v-model="form.token" placeholder="请输入token" />
  256. </el-form-item>
  257. <el-form-item label="aesKey" prop="aesKey">
  258. <el-input v-model="form.aesKey" placeholder="请输入aesKey" />
  259. </el-form-item>
  260. <el-form-item label="msgDataFormat" prop="msgDataFormat">
  261. <el-input v-model="form.msgDataFormat" placeholder="请输入msgDataFormat" />
  262. </el-form-item>
  263. </el-form>
  264. <div slot="footer" class="dialog-footer">
  265. <el-button type="primary" @click="submitForm">确 定</el-button>
  266. <el-button @click="cancel">取 消</el-button>
  267. </div>
  268. </el-dialog>
  269. </div>
  270. </template>
  271. <script>
  272. import {list, get, update, add, del} from '@/api/course/coursePlaySourceConfig'
  273. import {updateIsTownOn} from "@/api/system/config";
  274. import { allList } from '@/api/company/company'
  275. import { resetForm } from '@/utils/common'
  276. import Treeselect from "@riophae/vue-treeselect";
  277. import {listDept} from "@/api/system/dept";
  278. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  279. import { getUserProfile } from "@/api/system/user";
  280. export default {
  281. name: 'CoursePlaySourceConfig',
  282. components: {Treeselect},
  283. data() {
  284. return {
  285. authOptions:[
  286. {
  287. dictLabel: "食品",
  288. dictValue: 0
  289. },
  290. {
  291. dictLabel: "药品",
  292. dictValue: 1
  293. }
  294. ],
  295. username:null,
  296. // 部门树选项
  297. deptOptions: [],
  298. switchDialogVisible: false,
  299. // 公司搜索相关
  300. companySearchLoading: false,
  301. companyOptions: [],
  302. formatterCompanyOptions: [],
  303. switchForm: {
  304. appId: '',
  305. switchStatus: '001',
  306. },
  307. queryParams: {
  308. pageNum: 1,
  309. pageSize: 10,
  310. name: null,
  311. appid: null
  312. },
  313. showSearch: true,
  314. single: true,
  315. multiple: true,
  316. ids: [],
  317. loading: false,
  318. list: [],
  319. total: 0,
  320. typesOptions: [],
  321. isMallOptions:[
  322. {
  323. dictLabel: "是",
  324. dictValue: 1
  325. },
  326. {
  327. dictLabel: "否",
  328. dictValue: 0
  329. }
  330. ],
  331. title: null,
  332. open: false,
  333. form: {isMall:0},
  334. rules: {
  335. name: [
  336. { required: true, message: "名称不能为空", trigger: "blur" }
  337. ],
  338. // companyId: [
  339. // { required: true, message: "所属公司不能为空", trigger: "blur" }
  340. // ],
  341. appid: [
  342. { required: true, message: "appid不能为空", trigger: "blur" }
  343. ],
  344. img: [
  345. { required: true, message: "图标不能为空", trigger: "blur" }
  346. ],
  347. type: [
  348. { required: true, message: "类型不能为空", trigger: "blur" }
  349. ],
  350. originalId: [
  351. { required: true, message: "原始id不能为空", trigger: "blur" }
  352. ],
  353. secret: [
  354. { required: true, message: "secret不能为空", trigger: "blur" }
  355. ],
  356. token: [
  357. { required: true, message: "token不能为空", trigger: "blur" }
  358. ],
  359. aesKey: [
  360. { required: true, message: "aesKey不能为空", trigger: "blur" }
  361. ],
  362. msgDataFormat: [
  363. { required: true, message: "msgDataFormat不能为空", trigger: "blur" }
  364. ]
  365. }
  366. }
  367. },
  368. created() {
  369. this.getDicts("play_source_type").then(response => {
  370. this.typesOptions = response.data.map(item => {
  371. return {
  372. ...item,
  373. listClass: 'primary'}
  374. })
  375. });
  376. //初始化formatterCompanyOptions
  377. allList().then(e => {
  378. this.formatterCompanyOptions = e.rows;
  379. });
  380. this.getList();
  381. listDept().then(response => {
  382. this.deptOptions = this.handleTree(response.data, "deptId");
  383. });
  384. getUserProfile().then(response => {
  385. const data = response.data;
  386. this.username = data.userName;
  387. });
  388. },
  389. methods: {
  390. resetForm,
  391. resetOption(){
  392. console.log(1)
  393. this.companyOptions = [];
  394. this.open = false;
  395. },
  396. /** 转换部门数据结构 */
  397. normalizer(node) {
  398. if (node.hasOwnProperty('id') && !node.hasOwnProperty('deptId')) {
  399. return {
  400. id: node.id,
  401. label: this.getDeptNameById(node.id) || '未知部门',
  402. children: node.children || []
  403. };
  404. }
  405. if (node.children && !node.children.length) {
  406. delete node.children;
  407. }
  408. return {
  409. id: node.deptId,
  410. label: node.deptName,
  411. children: node.children
  412. };
  413. },
  414. getDeptNameById(targetId) {
  415. const deptOptions =this.deptOptions
  416. console.log("text:"+JSON.stringify(deptOptions))
  417. for (let i = 0; i < deptOptions.length; i++) {
  418. const dept = deptOptions[i];
  419. if (dept.deptId === targetId) {
  420. return dept.deptName;
  421. }
  422. }
  423. return '未知部门';
  424. },
  425. // 处理开关配置
  426. handleSwitchConfig(row) {
  427. this.switchForm.appId = row.appid;
  428. this.switchForm.switchStatus = "001"; // 默认关闭状态
  429. // 调用接口获取开关状态
  430. this.getSwitchConfig(row.appid);
  431. this.switchDialogVisible = true;
  432. },
  433. /** 搜索公司 */
  434. searchCompanies(query) {
  435. this.companySearchLoading = true;
  436. allList().then(response => {
  437. this.companyOptions = response.rows;
  438. if (query) {
  439. this.companyOptions = this.companyOptions.filter(item =>
  440. item.dictLabel.includes(query)
  441. );
  442. }
  443. this.companySearchLoading = false;
  444. }).catch(()=>{
  445. this.companySearchLoading = false;
  446. });
  447. },
  448. companyNameFormatter(row){
  449. let company = this.formatterCompanyOptions.filter(item => item.dictValue === row.companyId)[0];
  450. return company ? company.dictLabel : '';
  451. },
  452. departmentNameFormatter(row) {
  453. // 容错处理:检查必要参数
  454. if (!this.deptOptions || !this.deptOptions.length || !row.deptId) {
  455. return '';
  456. }
  457. // 使用 deptId 匹配(与表格 prop 保持一致)
  458. const targetId = String(row.deptId);
  459. // 递归查找树形结构中的部门
  460. const findDept = (depts) => {
  461. for (const dept of depts) {
  462. // 先检查当前节点
  463. if (String(dept.deptId) === targetId) {
  464. return dept;
  465. }
  466. // 如果有子节点,递归查找
  467. if (dept.children && dept.children.length > 0) {
  468. const found = findDept(dept.children);
  469. if (found) return found;
  470. }
  471. }
  472. return null;
  473. };
  474. const dept = findDept(this.deptOptions);
  475. return dept?.deptName || '';
  476. },
  477. // 获取开关配置
  478. getSwitchConfig(appId) {
  479. const params = {
  480. appId: this.switchForm.appId
  481. };
  482. updateIsTownOn(params).then(response=>{
  483. if (response.code === 200) {
  484. if ( response.date){
  485. this.switchForm.switchStatus = response.date;
  486. }
  487. } else {
  488. this.$message.error('获取配置失败: ' + response.msg);
  489. }
  490. }).catch(error => {
  491. this.$message.error('请求失败: ' + error.message);
  492. });
  493. },
  494. // 提交开关配置
  495. submitSwitchConfig() {
  496. const params = {
  497. appId: this.switchForm.appId,
  498. bock: this.switchForm.switchStatus
  499. };
  500. updateIsTownOn(params).then(response=>{
  501. if (response.code === 200) {
  502. this.$message.success('配置更新成功');
  503. this.switchDialogVisible = false;
  504. } else {
  505. this.$message.error('更新失败: ' + response.msg);
  506. }
  507. })
  508. },
  509. getList() {
  510. this.loading = true;
  511. list(this.queryParams).then(response => {
  512. this.list = response.rows;
  513. this.total = response.total;
  514. this.loading = false;
  515. });
  516. },
  517. handleQuery() {
  518. this.queryParams.pageNum = 1;
  519. this.getList();
  520. },
  521. resetQuery() {
  522. this.resetForm("queryForm");
  523. this.getList();
  524. },
  525. handleAdd() {
  526. this.reset()
  527. this.open = true
  528. this.form.isMall = 0;
  529. this.title = "添加小程序配置"
  530. },
  531. handleUpdate(row) {
  532. this.reset()
  533. const id = row.id || this.ids
  534. get(id).then(response => {
  535. this.form = {
  536. ...response.data,
  537. type: response.data.type.toString()
  538. }
  539. this.searchCompanies("");
  540. this.open = true
  541. this.title = "修改小程序配置"
  542. })
  543. },
  544. handleDelete(row) {
  545. const id = row.id || this.ids
  546. this.$confirm('是否确认删除小程序配置编号为"' + id + '"的数据项?', "警告", {
  547. confirmButtonText: "确定",
  548. cancelButtonText: "取消",
  549. type: "warning"
  550. }).then(function() {
  551. return del(id);
  552. }).then(() => {
  553. this.getList();
  554. this.msgSuccess("删除成功");
  555. }).catch(() => {});
  556. },
  557. handleSelectionChange(selection) {
  558. this.ids = selection.map(item => item.id)
  559. this.single = selection.length!==1
  560. this.multiple = !selection.length
  561. },
  562. submitForm() {
  563. this.$refs["form"].validate(valid => {
  564. if (valid) {
  565. if (this.form.id != null) {
  566. update(this.form).then(response => {
  567. const {code, msg} = response
  568. if (code !== 200) {
  569. this.msgError(msg)
  570. return
  571. }
  572. this.msgSuccess("修改成功");
  573. this.open = false;
  574. this.getList();
  575. });
  576. } else {
  577. add(this.form).then(response => {
  578. const {code, msg} = response
  579. if (code !== 200) {
  580. this.msgError(msg)
  581. return
  582. }
  583. this.msgSuccess("新增成功");
  584. this.open = false;
  585. this.getList();
  586. });
  587. }
  588. }
  589. });
  590. },
  591. cancel() {
  592. this.open = false;
  593. this.reset();
  594. },
  595. reset() {
  596. this.form = {
  597. id: null,
  598. name: null,
  599. appid: null,
  600. secret: null,
  601. img: null,
  602. originalId: null,
  603. token: 'Ncbnd7lJvkripVOpyTFAna6NAWCxCrvC',
  604. aesKey: 'HlEiBB55eaWUaeBVAQO3cWKWPYv1vOVQSq7nFNICw4E',
  605. msgDataFormat: 'JSON',
  606. type: '1',
  607. isMall: 0
  608. }
  609. this.resetForm("form");
  610. },
  611. },
  612. }
  613. </script>
  614. <style scoped>
  615. </style>