血透系统PC前端

tableson.vue 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <template>
  2. <div class="">
  3. <div class="filter-container">
  4. <el-button style="float: right;" class="filter-item" size="small" :disabled="addState" @click="handleCreate" type="primary" icon="el-icon-circle-plus-outline">{{$t('table.add')}}</el-button>
  5. </div>
  6. <el-table :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)'}" :key='tableKey' :data="list" v-loading="listLoading" border fit highlight-current-row
  7. style="width: 100%;">
  8. <el-table-column align="center" label="名称">
  9. <template slot-scope="scope">
  10. <span @click="handleUpdate(scope.row)">{{scope.row.name}}</span>
  11. </template>
  12. </el-table-column>
  13. <el-table-column align="center" :label="$t('table.actions')" width="230" class-name="small-padding fixed-width">
  14. <template slot-scope="scope">
  15. <el-tooltip class="item" effect="dark" content="编辑" placement="top">
  16. <el-button icon="el-icon-edit-outline" type="primary" size="small" @click="handleUpdate(scope.row)"></el-button>
  17. </el-tooltip>
  18. <el-tooltip class="item" effect="dark" content="删除" placement="top">
  19. <el-button icon="el-icon-delete" v-if="scope.row.status!='deleted'" size="small" type="danger" @click="handleModifyStatus(scope.row,'deleted')">
  20. </el-button>
  21. </el-tooltip>
  22. </template>
  23. </el-table-column>
  24. </el-table>
  25. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
  26. <el-form :rules="rules" ref="dataForm" :model="temp" label-position="right" label-width="70px" >
  27. <el-row>
  28. <el-col :span="12">
  29. <el-form-item :label="$t('data_config.config_name')" prop="name">
  30. <el-input v-model="temp.name" placeholder="请输入名称"></el-input>
  31. </el-form-item>
  32. </el-col>
  33. <el-col :span="12">
  34. <el-form-item label="排序" prop="order">
  35. <el-input type="age" v-model.number="temp.order" placeholder="请输入排序值,数值越大,排序越靠前"></el-input>
  36. </el-form-item>
  37. </el-col>
  38. </el-row>
  39. <el-form-item :label="$t('data_config.remark')">
  40. <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 4}" placeholder="请输入备注" v-model="temp.remark">
  41. </el-input>
  42. </el-form-item>
  43. </el-form>
  44. <div slot="footer" class="dialog-footer">
  45. <el-button @click="dialogFormVisible = false">{{$t('table.cancel')}}</el-button>
  46. <el-button v-if="dialogStatus=='create'" type="primary" @click="createData">{{$t('table.confirm')}}</el-button>
  47. <el-button v-else type="primary" @click="updateData">{{$t('table.confirm')}}</el-button>
  48. </div>
  49. </el-dialog>
  50. <el-dialog title="Reading statistics" :visible.sync="dialogPvVisible">
  51. <el-table :data="pvData" border fit highlight-current-row style="width: 100%">
  52. <el-table-column prop="key" label="Channel"> </el-table-column>
  53. <el-table-column prop="pv" label="Pv"> </el-table-column>
  54. </el-table>
  55. <span slot="footer" class="dialog-footer">
  56. <el-button type="primary" @click="dialogPvVisible = false">{{$t('table.confirm')}}</el-button>
  57. </span>
  58. </el-dialog>
  59. </div>
  60. </template>
  61. <script>
  62. import {
  63. fetchList,
  64. fetchPv,
  65. createArticle,
  66. updateArticle
  67. } from "@/api/article";
  68. import waves from "@/directive/waves"; // 水波纹指令
  69. import { parseTime } from "@/utils";
  70. import store from "@/store";
  71. import bus from "@/assets/eventBus";
  72. import {createConfig,createChildConfig,updateChildConfig, deleteChildConfig} from "@/api/data";
  73. const calendarTypeOptions = [
  74. { key: "CN", display_name: "China" },
  75. { key: "US", display_name: "USA" },
  76. { key: "JP", display_name: "Japan" },
  77. { key: "EU", display_name: "Eurozone" }
  78. ];
  79. // arr to obj ,such as { CN : "China", US : "USA" }
  80. const calendarTypeKeyValue = calendarTypeOptions.reduce((acc, cur) => {
  81. acc[cur.key] = cur.display_name;
  82. return acc;
  83. }, {});
  84. export default {
  85. name: "tableson",
  86. directives: {
  87. waves
  88. },
  89. props: {
  90. type: {
  91. type: String,
  92. default: "patient"
  93. }
  94. },
  95. data() {
  96. return {
  97. currentId: undefined,
  98. tableKey: 0,
  99. total: null,
  100. listLoading: false,
  101. listQuery: {
  102. page: 1,
  103. limit: 20,
  104. importance: undefined,
  105. title: undefined,
  106. type: this.type,
  107. sort: "+id"
  108. },
  109. importanceOptions: [1, 2, 3],
  110. calendarTypeOptions,
  111. sortOptions: [
  112. { label: "ID Ascending", key: "+id" },
  113. { label: "ID Descending", key: "-id" }
  114. ],
  115. statusOptions: ["published", "draft", "deleted"],
  116. showReviewer: false,
  117. temp: {
  118. id: undefined,
  119. parent_id: 0,
  120. module: this.type,
  121. org_id: 0,
  122. name: "",
  123. field_name: undefined,
  124. value: "",
  125. remark: ""
  126. },
  127. dialogFormVisible: false,
  128. dialogStatus: "",
  129. textMap: {
  130. update: "编辑",
  131. create: "新增"
  132. },
  133. dialogPvVisible: false,
  134. pvData: [],
  135. rules: {
  136. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  137. order: [{type :'number', message: '排序必须为数字值', trigger: "blur" }]
  138. // timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
  139. // title: [{ required: true, message: 'title is required', trigger: 'blur' }]
  140. },
  141. downloadLoading: false,
  142. parentConfig: undefined,
  143. addState: true
  144. };
  145. },
  146. computed: {
  147. list: function() {
  148. if (this.parentConfig != undefined) {
  149. this.addState = false;
  150. const list = store.getters.configlist[this.parentConfig.module]
  151. for (var i=0; i< list.length;i++) {
  152. if(list[i].id === this.parentConfig.id) {
  153. return list[i]['childs']
  154. break
  155. }
  156. }
  157. // return store.getters.configlist[this.parentConfig.module][this.parentConfig.index ]["childs"];
  158. }
  159. }
  160. },
  161. filters: {
  162. statusFilter(status) {
  163. const statusMap = {
  164. published: "success",
  165. draft: "info",
  166. deleted: "danger"
  167. };
  168. return statusMap[status];
  169. },
  170. typeFilter(type) {
  171. return calendarTypeKeyValue[type];
  172. }
  173. },
  174. created() {
  175. // this.getList()
  176. },
  177. mounted() {
  178. var _this = this;
  179. bus.$on("parentChangeId", function(parentData) {
  180. _this.parentConfig = parentData;
  181. // _this.list = parentData.childs
  182. _this.temp = {
  183. id: undefined,
  184. parent_id: parentData.id,
  185. module: parentData.module,
  186. org_id: parentData.org_id,
  187. name: "",
  188. field_name: undefined,
  189. value: "",
  190. remark: ""
  191. };
  192. });
  193. },
  194. methods: {
  195. handleRowChange(currentRow, oldCurrentRow) {
  196. this.currentId = currentRow.id;
  197. },
  198. handleFilter() {
  199. this.listQuery.page = 1;
  200. this.getList();
  201. },
  202. handleSizeChange(val) {
  203. this.listQuery.limit = val;
  204. this.getList();
  205. },
  206. handleCurrentChange(val) {
  207. this.listQuery.page = val;
  208. this.getList();
  209. },
  210. handleModifyStatus(row, status) {
  211. this.temp = Object.assign({}, row); // copy obj
  212. this.$confirm("此操作将永久删除该配置项, 是否继续?", "提示", {
  213. confirmButtonText: "确 定",
  214. cancelButtonText: "取 消",
  215. type: "warning"
  216. }).then(() => {
  217. const tempData = Object.assign({}, this.temp);
  218. deleteChildConfig(tempData).then(response => {
  219. if (!response.data) {
  220. // 由于mockjs 不支持自定义状态码只能这样hack
  221. reject("error");
  222. }
  223. if (response.data.state === 0) {
  224. this.$message.error(response.data.msg);
  225. }
  226. const result = response.data.data.dataconfig;
  227. store.dispatch("updateChildConfigList", [tempData, "delete"]).then(() => {
  228. next();
  229. });
  230. });
  231. this.$message({
  232. type: "success",
  233. message: "删除成功!"
  234. });
  235. })
  236. .catch(() => {
  237. this.$message({
  238. type: "info",
  239. message: "已取消删除"
  240. });
  241. });
  242. },
  243. resetTemp() {
  244. this.temp = {
  245. id: undefined,
  246. parent_id: this.parentConfig.id,
  247. module: this.parentConfig.module,
  248. org_id: this.parentConfig.org_id,
  249. name: "",
  250. field_name: undefined,
  251. value: "",
  252. remark: ""
  253. };
  254. },
  255. handleCreate() {
  256. this.resetTemp();
  257. this.dialogStatus = "create";
  258. this.dialogFormVisible = true;
  259. this.$nextTick(() => {
  260. this.$refs["dataForm"].clearValidate();
  261. });
  262. },
  263. createData() {
  264. this.$refs["dataForm"].validate(valid => {
  265. if (valid) {
  266. createChildConfig(this.temp).then(response => {
  267. if (!response.data) {
  268. // 由于mockjs 不支持自定义状态码只能这样hack
  269. reject("error");
  270. }
  271. if (response.data.state === 0) {
  272. this.$message.error(response.data.msg);
  273. }
  274. const result = response.data.data.dataconfig;
  275. // this.list.unshift(tempval)
  276. // 更新store
  277. store.dispatch("updateChildConfigList", [result, "create"]).then(() => {
  278. });
  279. this.dialogFormVisible = false;
  280. this.$message.success("创建成功")
  281. });
  282. }
  283. });
  284. },
  285. handleUpdate(row) {
  286. this.temp = Object.assign({}, row); // copy obj
  287. this.dialogStatus = "update";
  288. this.dialogFormVisible = true;
  289. this.$nextTick(() => {
  290. this.$refs["dataForm"].clearValidate();
  291. });
  292. },
  293. updateData() {
  294. this.$refs["dataForm"].validate(valid => {
  295. if (valid) {
  296. const tempData = Object.assign({}, this.temp);
  297. updateChildConfig(tempData).then(response => {
  298. if (!response.data) {
  299. // 由于mockjs 不支持自定义状态码只能这样hack
  300. reject("error");
  301. }
  302. if (response.data.state === 0) {
  303. this.$message.error(response.data.msg);
  304. }
  305. const result = response.data.data.dataconfig;
  306. store.dispatch("updateChildConfigList", [result, "update"]).then(() => {
  307. });
  308. this.dialogFormVisible = false;
  309. this.$message.success("更新成功")
  310. });
  311. }
  312. });
  313. },
  314. handleDelete(row) {
  315. this.$message.success("删除成功")
  316. const index = this.list.indexOf(row);
  317. this.list.splice(index, 1);
  318. },
  319. handleFetchPv(pv) {
  320. fetchPv(pv).then(response => {
  321. this.pvData = response.data.pvData;
  322. this.dialogPvVisible = true;
  323. });
  324. },
  325. handleDownload() {
  326. this.downloadLoading = true;
  327. import("@/vendor/Export2Excel").then(excel => {
  328. const tHeader = ["timestamp", "title", "type", "importance", "status"];
  329. const filterVal = [
  330. "timestamp",
  331. "title",
  332. "type",
  333. "importance",
  334. "status"
  335. ];
  336. const data = this.formatJson(filterVal, this.list);
  337. excel.export_json_to_excel({
  338. header: tHeader,
  339. data,
  340. filename: "table-list"
  341. });
  342. this.downloadLoading = false;
  343. });
  344. },
  345. formatJson(filterVal, jsonData) {
  346. return jsonData.map(v =>
  347. filterVal.map(j => {
  348. if (j === "timestamp") {
  349. return parseTime(v[j]);
  350. } else {
  351. return v[j];
  352. }
  353. })
  354. );
  355. }
  356. }
  357. };
  358. </script>
  359. <style rel="stylesheet/css" lang="scss" scoped>
  360. </style>