index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" v-show="showSearch" :inline="true">
  4. <el-form-item label="" prop="stage">
  5. <el-input
  6. v-model="queryParams.stage"
  7. placeholder="请输入期数"
  8. clearable
  9. size="small"
  10. style="width: 240px"
  11. @keyup.enter.native="handleQuery"
  12. />
  13. </el-form-item>
  14. <el-form-item label="" prop="name">
  15. <el-input
  16. v-model="queryParams.name"
  17. placeholder="请输入平台"
  18. clearable
  19. size="small"
  20. style="width: 240px"
  21. @keyup.enter.native="handleQuery"
  22. />
  23. </el-form-item>
  24. <el-form-item>
  25. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  26. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  27. </el-form-item>
  28. </el-form>
  29. <el-row :gutter="10" class="mb8">
  30. <el-col :span="1.5">
  31. <el-button
  32. type="primary"
  33. icon="el-icon-plus"
  34. size="mini"
  35. @click="handleAdd"
  36. >新增</el-button>
  37. </el-col>
  38. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  39. </el-row>
  40. <!-- 表格 -->
  41. <el-table :data="bookCityList">
  42. <el-table-column type="expand">
  43. <template slot-scope="props">
  44. <el-form label-position="left" class="demo-table-expand" v-if="props.row.key1 !== ''">
  45. <el-form-item :label="key" v-for="(val, key, index) in JSON.parse(props.row.key1)" :key="index">
  46. <span>{{ val }}</span>
  47. </el-form-item>
  48. </el-form>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="期数" prop="stage" align="center"/>
  52. <el-table-column label="平台" prop="name" align="center"/>
  53. <el-table-column label="平台账号" prop="account" align="center"/>
  54. <el-table-column label="平台密码" prop="passWord" align="center"/>
  55. <el-table-column label="创建时间" prop="createTime" align="center"/>
  56. <el-table-column label="更新时间" prop="updateTime" align="center"/>
  57. <el-table-column label="备注" prop="remarks" align="center"/>
  58. <el-table-column label="操作" align="center" >
  59. <template slot-scope="scope">
  60. <el-button
  61. size="mini"
  62. type="text"
  63. icon="el-icon-edit"
  64. @click="handleEdit(scope.row)"
  65. >编辑</el-button>
  66. <div style="display: inline-block;width: 10px"></div>
  67. <el-popconfirm
  68. title="确定删除吗?"
  69. @confirm="handleDelete(scope.row)"
  70. >
  71. <el-button
  72. slot="reference"
  73. size="mini"
  74. type="text"
  75. icon="el-icon-delete"
  76. >删除</el-button>
  77. </el-popconfirm>
  78. </template>
  79. </el-table-column>
  80. </el-table>
  81. <!-- 翻页 -->
  82. <pagination
  83. v-show="total>0"
  84. :total="total"
  85. :page.sync="queryParams.pageNum"
  86. :limit.sync="queryParams.pageSize"
  87. @pagination="getList"
  88. />
  89. <!-- 新增弹窗 -->
  90. <el-dialog
  91. :title="isAdd ? '新增' : '编辑'"
  92. :visible.sync="openEdit"
  93. width="450px"
  94. @close="dialogClose"
  95. >
  96. <el-form :model="queryPlatform" :rules="rules" ref="platForm" label-position="right" label-width="120px">
  97. <el-form-item label="期数" prop="stage">
  98. <!-- <el-input
  99. clearable
  100. size="small"
  101. v-model="queryPlatform.stage"
  102. /> -->
  103. <el-select v-model="queryPlatform.stage" placeholder="请选择" style="width: 100%" filterable>
  104. <el-option
  105. v-for="item in perodidAll"
  106. :key="item.id"
  107. :label="item.period"
  108. :value="item.period">
  109. </el-option>
  110. </el-select>
  111. </el-form-item>
  112. <el-form-item label="平台" prop="name">
  113. <el-select v-model="queryPlatform.name" placeholder="请选择" @change="platFormChange" filterable style="width: 100%">
  114. <el-option
  115. v-for="item in platFormNames"
  116. :key="item.id"
  117. :label="item.label"
  118. :value="item.label">
  119. </el-option>
  120. </el-select>
  121. </el-form-item>
  122. <el-form-item label="平台账号" prop="account">
  123. <el-input
  124. clearable
  125. size="small"
  126. v-model="queryPlatform.account"
  127. />
  128. </el-form-item>
  129. <el-form-item label="平台密码" prop="passWord">
  130. <el-input
  131. clearable
  132. size="small"
  133. v-model="queryPlatform.passWord"
  134. />
  135. </el-form-item>
  136. <el-form-item :label="pf" :prop="queryPlatform.key1[pf]" v-for="(pf, index) in platFormName.value" :key="index">
  137. <el-input
  138. clearable
  139. size="small"
  140. v-model="queryPlatform.key1[pf]"
  141. />
  142. </el-form-item>
  143. <el-form-item label="备注" prop="remarks">
  144. <el-input
  145. type="textarea"
  146. clearable
  147. size="small"
  148. placeholder="请输入备注"
  149. v-model="queryPlatform.remarks"
  150. />
  151. </el-form-item>
  152. </el-form>
  153. <span slot="footer" class="dialog-footer">
  154. <el-button @click="openEdit = false">取 消</el-button>
  155. <el-button type="primary" @click="submitPlat('platForm')">确 定</el-button>
  156. </span>
  157. </el-dialog>
  158. </div>
  159. </template>
  160. <script>
  161. import { addBookPlatInfo, getBookPlatInfo, delBookPlatInfo, editBookPlatInfo } from "@/api/accounts/bookCity";
  162. import { getPeriodAll } from "@/api/accounts/period";
  163. export default {
  164. name: 'bookCity',
  165. data() {
  166. return {
  167. queryParams: {
  168. pageNum: 1,
  169. pageSize: 10,
  170. name: null,
  171. stage: null
  172. },
  173. showSearch: true,
  174. bookCityList: [],
  175. total: 0,
  176. queryPlatform: {
  177. stage: '', //期数
  178. name: '', //平台名称
  179. account: '', //平台账号
  180. passWord: '', //密码
  181. key1: {},
  182. remarks: '' //备注
  183. },
  184. openEdit: false,
  185. rules: {
  186. stage: [
  187. { required: true, message: '请输入期数', trigger: 'blur' }
  188. ],
  189. name: [
  190. { required: true, message: '请选择平台', trigger: 'change' }
  191. ],
  192. account: [
  193. { required: true, message: '请输入平台账号', trigger: 'blur' }
  194. ],
  195. passWord: [
  196. { required: true, message: '请输入平台账号', trigger: 'blur' }
  197. ]
  198. },
  199. // 所有平台及key
  200. platFormNames: [
  201. {
  202. label: '花生',
  203. id: 1,
  204. value: ["apiKey","apiSecurity"]
  205. },
  206. {
  207. label: '文鼎',
  208. id: 2,
  209. value: ["consumerkey", "secretkey", "siteid"]
  210. },
  211. {
  212. label: '阳光',
  213. id: 3,
  214. value: ["Client_id","Token"]
  215. },
  216. {
  217. label: '悠书阁',
  218. id: 4,
  219. value: ["secert_key"]
  220. },
  221. {
  222. label: '阅文',
  223. id: 5,
  224. value: ["secretkey"]
  225. },
  226. {
  227. label: '掌读',
  228. id: 6,
  229. value: ["appsecret"]
  230. },
  231. {
  232. label: '七悦',
  233. id: 7,
  234. value: ["AccessKey"]
  235. },
  236. {
  237. label: '掌中云',
  238. id: 8,
  239. value: ["APIkey","APISecret"]
  240. },
  241. ],
  242. // 保存key1
  243. platFormName: {
  244. label: '',
  245. value: []
  246. },
  247. // 是否新增
  248. isAdd: true,
  249. perodidAll: []
  250. }
  251. },
  252. created() {
  253. this.getList()
  254. this.getPeroid()
  255. },
  256. methods: {
  257. /** 获取所有分期平台 */
  258. getPeroid() {
  259. getPeriodAll().then(response => {
  260. this.perodidAll = response.data
  261. });
  262. },
  263. /** 新增 */
  264. handleAdd() {
  265. this.openEdit = true
  266. this.isAdd = true
  267. },
  268. /** 搜索 */
  269. handleQuery() {
  270. this.getList()
  271. },
  272. /** 搜索条件重置 */
  273. resetQuery() {
  274. this.resetForm("queryForm");
  275. this.getList()
  276. },
  277. /** 获取列表数据 */
  278. getList() {
  279. getBookPlatInfo(this.queryParams).then(response => {
  280. let data = response.data
  281. this.total = data.total
  282. let records = data.records
  283. this.bookCityList = records
  284. })
  285. },
  286. /** 表格编辑 */
  287. handleEdit(value) {
  288. this.resetQpf()
  289. this.isAdd = false
  290. this.openEdit = true
  291. console.log(value)
  292. let { stage, name, account, passWord, key1, remarks, id } = value
  293. key1 = JSON.parse(key1)
  294. console.log(key1)
  295. this.queryPlatform = { stage, name, account, passWord, key1, remarks, id }
  296. let filterArr = this.platFormNames.filter((item)=> {
  297. return item.label === name
  298. })
  299. this.platFormName = filterArr[0]
  300. },
  301. /** 删除平台 */
  302. handleDelete(value) {
  303. delBookPlatInfo(value.id).then(response => {
  304. if(response.data){
  305. this.msgSuccess("删除成功");
  306. this.getList()
  307. }else{
  308. console.error(response)
  309. }
  310. })
  311. },
  312. /** 保存 */
  313. submitPlat(formName) {
  314. console.log(this.queryPlatform)
  315. let { key1 } = this.queryPlatform
  316. this.$refs[formName].validate((valid) => {
  317. if (valid) {
  318. if(this.isAdd){
  319. addBookPlatInfo({ ...this.queryPlatform, key1: JSON.stringify(key1) }).then(response => {
  320. if(response.data){
  321. this.openEdit = false
  322. this.msgSuccess("新增成功");
  323. this.getList()
  324. this.resetQpf()
  325. }else{
  326. console.error(response)
  327. }
  328. })
  329. }else {
  330. console.log(this.queryPlatform)
  331. editBookPlatInfo({ ...this.queryPlatform, key1: JSON.stringify(key1) }).then(response => {
  332. if(response.data){
  333. this.openEdit = false
  334. this.msgSuccess("修改成功");
  335. this.getList()
  336. this.resetQpf()
  337. }else{
  338. console.error(response)
  339. }
  340. })
  341. }
  342. } else {
  343. return false;
  344. }
  345. });
  346. },
  347. /** 重置添加编辑字段 */
  348. resetQpf() {
  349. this.queryPlatform = { //重置
  350. stage: '', //期数
  351. name: '', //平台名称
  352. account: '', //平台账号
  353. passWord: '', //密码
  354. key1: {},
  355. remarks: '' //备注
  356. }
  357. },
  358. /** 平台选中触发 */
  359. platFormChange(e) {
  360. let filterArr = this.platFormNames.filter((item)=> {
  361. return item.label === e
  362. })
  363. this.platFormName = filterArr[0]
  364. let {label, value} = this.platFormName
  365. this.queryPlatform = {
  366. ...this.queryPlatform,
  367. key1: {}
  368. }
  369. value.forEach((item) => {
  370. this.$set(this.queryPlatform.key1, item, '')
  371. })
  372. },
  373. /** 关闭弹窗触发 */
  374. dialogClose() {
  375. if(!this.isAdd){
  376. this.resetQpf()
  377. this.platFormName = {
  378. label: '',
  379. value: []
  380. }
  381. }
  382. }
  383. }
  384. }
  385. </script>
  386. <style lang="scss">
  387. .demo-table-expand {
  388. font-size: 0;
  389. label {
  390. width: 90px;
  391. color: #99a9bf;
  392. }
  393. .el-form-item {
  394. margin-right: 0;
  395. margin-bottom: 0;
  396. width: 50%;
  397. }
  398. }
  399. </style>