index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <div class="unit pagePadding">
  3. <ex-table
  4. v-loading="loading"
  5. v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
  6. :table="table"
  7. :data="tableData"
  8. :columns="columns"
  9. :page="pageInfo"
  10. :size="size"
  11. @page-curr-change="handlePageChange"
  12. @page-size-change="handleSizeChange"
  13. @screen-reset="
  14. pageInfo.curr = 1;
  15. parmValue.page = 1;
  16. searchList();
  17. "
  18. @screen-submit="
  19. pageInfo.curr = 1;
  20. parmValue.page = 1;
  21. searchList();
  22. "
  23. >
  24. <template #table-header="{}">
  25. <div style="width: 100%">
  26. <el-row style="padding: 0 0 10px 80px">
  27. <el-col :span="6" style="width: 303px">
  28. <period-date-picker
  29. :type="1"
  30. :width="'135px'"
  31. :size="searchSize"
  32. :start="parmValue.start"
  33. :end="parmValue.end"
  34. @timeReturned="handleTime"
  35. />
  36. </el-col>
  37. <el-col :span="4" style="width: 160px">
  38. <el-select
  39. v-model="parmValue.status"
  40. filterable
  41. clearable
  42. :size="searchSize"
  43. placeholder="单位状态"
  44. style="width: 100%"
  45. @change="
  46. pageInfo.curr = 1;
  47. parmValue.page = 1;
  48. searchList();
  49. "
  50. >
  51. <el-option
  52. v-for="item in statusList"
  53. :key="'status' + item.code"
  54. :label="item.name"
  55. :value="item.code"
  56. />
  57. </el-select>
  58. </el-col>
  59. <el-col
  60. :span="3"
  61. class="fr"
  62. style="width: 66px; padding: 0 0 0 10px"
  63. >
  64. <el-button type="primary" :size="searchSize" @click="searchList">
  65. 刷新
  66. </el-button>
  67. </el-col>
  68. <el-col
  69. :span="3"
  70. class="fr"
  71. style="width: 66px; padding: 0 0 0 10px"
  72. >
  73. <el-button type="warning" :size="searchSize" @click="restSearch">
  74. 重置
  75. </el-button>
  76. </el-col>
  77. </el-row>
  78. <el-row>
  79. <el-col :span="4" style="width: 373px">
  80. <el-input
  81. :size="searchSize"
  82. v-model="parmValue.name"
  83. :maxlength="40"
  84. @blur="
  85. pageInfo.curr = 1;
  86. parmValue.page = 1;
  87. searchList();
  88. "
  89. placeholder="单位名称"
  90. ></el-input>
  91. </el-col>
  92. <el-col :span="4" style="width: 170px; padding: 0 0 0 10px">
  93. <el-input
  94. :size="searchSize"
  95. v-model="parmValue.creater"
  96. :maxlength="40"
  97. @change="
  98. pageInfo.curr = 1;
  99. parmValue.page = 1;
  100. searchList();
  101. "
  102. placeholder="创建人"
  103. ></el-input>
  104. </el-col>
  105. <el-col
  106. :span="3"
  107. class="fr"
  108. style="width: 66px; padding: 0 0 0 10px"
  109. v-if="powers.some((item) => item == '003')"
  110. >
  111. <el-button
  112. :size="searchSize"
  113. type="success"
  114. style="float: right"
  115. @click="openModal({}, '003')"
  116. >
  117. 添加
  118. </el-button>
  119. </el-col>
  120. </el-row>
  121. </div></template
  122. >
  123. <template #status="{ scope }">
  124. <el-tag
  125. :size="tablebtnSize"
  126. :type="scope.row.status == '1' ? 'warning' : ''"
  127. v-text="
  128. (statusOptions.find((item) => item.id == scope.row.status) || {})
  129. .label || '--'
  130. "
  131. ></el-tag>
  132. </template>
  133. <template #operation="{ scope }">
  134. <el-tooltip
  135. v-if="powers.some((item) => item == '007')"
  136. effect="dark"
  137. content="详情"
  138. placement="top"
  139. >
  140. <i
  141. class="el-icon-view tb-icon"
  142. @click="openModal(scope.row, '007')"
  143. ></i>
  144. </el-tooltip>
  145. <el-tooltip
  146. v-if="powers.some((item) => item == '005')"
  147. effect="dark"
  148. content="修改"
  149. placement="top"
  150. >
  151. <i
  152. class="el-icon-edit tb-icon"
  153. @click="openModal(scope.row, '005')"
  154. ></i>
  155. </el-tooltip>
  156. <el-tooltip
  157. v-if="
  158. powers.some((item) => item == '004') && scope.row.status === '0'
  159. "
  160. effect="dark"
  161. content="禁用"
  162. placement="top"
  163. >
  164. <i
  165. class="el-icon-video-pause tb-icon"
  166. @click="changeStatus(scope.row.id, scope.row.status)"
  167. ></i>
  168. </el-tooltip>
  169. <el-tooltip
  170. v-if="
  171. powers.some((item) => item == '004') && scope.row.status === '1'
  172. "
  173. effect="dark"
  174. content="启用"
  175. placement="top"
  176. >
  177. <i
  178. class="el-icon-video-play tb-icon"
  179. @click="changeStatus(scope.row.id, scope.row.status)"
  180. ></i>
  181. </el-tooltip>
  182. <el-tooltip
  183. v-if="powers.some((item) => item == '006')"
  184. effect="dark"
  185. content="删除"
  186. placement="top"
  187. >
  188. <i
  189. class="el-icon-delete tb-icon"
  190. @click="deleteItem(scope.row.id)"
  191. ></i>
  192. </el-tooltip>
  193. </template>
  194. </ex-table>
  195. <no-auth v-else></no-auth>
  196. <!-- 弹窗 新增/修改 -->
  197. <add-edit
  198. :id="modelId"
  199. :show-model="showModel"
  200. :sitem="sitem"
  201. @refresh="searchList"
  202. @cancel="showModel = false"
  203. />
  204. </div>
  205. </template>
  206. <script>
  207. import addEdit from "./addEdit";
  208. import asyncRequest from "@/apis/service/goodStore/unit";
  209. import statusList from "@/assets/js/statusList";
  210. import roleLevel from "@/assets/js/roleLevel";
  211. import mixinPage from "@/mixins/elPaginationHandle";
  212. import { mapGetters } from "vuex";
  213. import resToken from "@/mixins/resToken";
  214. export default {
  215. name: "unit",
  216. mixins: [mixinPage, resToken],
  217. components: {
  218. addEdit,
  219. },
  220. computed: {
  221. //组件SIZE设置
  222. ...mapGetters(["tablebtnSize", "searchSize", "size"]),
  223. powers() {
  224. let tran =
  225. this.$store.getters.btnList.find(
  226. (item) => item.menu_route == "unit"
  227. ) || {};
  228. if (tran && tran.action && tran.action.length > 0) {
  229. return tran.action;
  230. } else {
  231. return [];
  232. }
  233. },
  234. },
  235. data() {
  236. return {
  237. statusList: statusList,
  238. roleLevel: roleLevel,
  239. loading: true,
  240. showModel: false,
  241. modelId: "000",
  242. sitem: {},
  243. parmValue: {
  244. page: 1, // 页码
  245. size: 15, // 每页显示条数
  246. start: "",
  247. end: "",
  248. status: "",
  249. creater: "",
  250. },
  251. // 状态
  252. statusOptions: [
  253. { id: "0", label: "禁用" },
  254. { id: "1", label: "启用" },
  255. ],
  256. // 表格 - 数据
  257. tableData: [],
  258. // 表格 - 参数
  259. table: {
  260. stripe: true,
  261. border: true,
  262. _defaultHeader_: ["setcol"],
  263. },
  264. // 表格 - 分页
  265. pageInfo: {
  266. size: 15,
  267. curr: 1,
  268. total: 0,
  269. },
  270. // 表格 - 列参数
  271. columns: [
  272. {
  273. prop: "id",
  274. label: "ID",
  275. },
  276. {
  277. prop: "unit",
  278. label: "单位名称",
  279. },
  280. {
  281. prop: "status",
  282. label: "状态",
  283. sortable: true,
  284. _slot_: "status",
  285. },
  286. {
  287. prop: "creater",
  288. label: "创建人",
  289. },
  290. {
  291. prop: "addtime",
  292. label: "创建时间",
  293. sortable: true,
  294. },
  295. {
  296. prop: "",
  297. label: "操作",
  298. fixed: "right",
  299. _noset_: true,
  300. _slot_: "operation",
  301. },
  302. ],
  303. };
  304. },
  305. mounted() {
  306. this.searchList();
  307. },
  308. methods: {
  309. restSearch() {
  310. // 表格 - 分页
  311. this.pageInfo = {
  312. size: 15,
  313. curr: 1,
  314. total: 0,
  315. };
  316. this.parmValue = {
  317. page: 1, // 页码
  318. size: 15, // 每页显示条数
  319. start: "",
  320. end: "",
  321. status: "",
  322. creater: "",
  323. };
  324. this.searchList();
  325. },
  326. // 新建/编辑/详情
  327. openModal(row, type) {
  328. this.sitem = row;
  329. this.modelId = type;
  330. this.showModel = true;
  331. },
  332. // 时间
  333. async handleTime(e) {
  334. this.parmValue.start = e.startTime || "";
  335. this.parmValue.end = e.endTime || "";
  336. if (
  337. (this.parmValue.start !== "" && this.parmValue.end !== "") ||
  338. (this.parmValue.start === "" && this.parmValue.end === "")
  339. ) {
  340. this.pageInfo.curr = 1;
  341. this.parmValue.page = 1;
  342. await this.searchList();
  343. }
  344. },
  345. /**
  346. * 启用/禁用
  347. * @param {String} id id
  348. * @param {String} status 0-禁用 1-启用
  349. */
  350. async changeStatus(id, status) {
  351. await this.$confirm(`确定要改为${status === "0" ? "禁用" : "启用"}?`, {
  352. confirmButtonText: "确定",
  353. cancelButtonText: "取消",
  354. type: "warning",
  355. })
  356. .then(async () => {
  357. this.loading = true;
  358. const model = {
  359. id: id,
  360. status: status === "1" ? "0" : "1",
  361. };
  362. const res = await asyncRequest.status(model);
  363. if (res && res.code === 0) {
  364. this.loading = false;
  365. this.$notify.success({
  366. title: "状态修改成功!",
  367. message: "",
  368. });
  369. await this.searchList();
  370. } else if (res && res.code >= 100 && res.code <= 104) {
  371. await this.logout();
  372. } else {
  373. this.loading = false;
  374. this.$message.warning(res.message);
  375. }
  376. })
  377. .catch(() => {
  378. console.log("取消");
  379. });
  380. },
  381. async deleteItem(id) {
  382. await this.$confirm("确定要删除?", {
  383. confirmButtonText: "确定",
  384. cancelButtonText: "取消",
  385. type: "warning",
  386. })
  387. .then(async () => {
  388. const model = {
  389. id: id,
  390. };
  391. const res = await asyncRequest.delete(model);
  392. if (res && res.code === 0) {
  393. this.$notify.success({
  394. title: "删除成功",
  395. message: "",
  396. });
  397. this.searchList();
  398. } else if (res && res.code >= 100 && res.code <= 104) {
  399. await this.logout();
  400. } else {
  401. this.$message.warning(res.message);
  402. }
  403. })
  404. .catch(() => {
  405. console.log("取消");
  406. });
  407. },
  408. // 刷新表格
  409. async searchList() {
  410. this.loading = true;
  411. const res = await asyncRequest.list(this.parmValue);
  412. if (res && res.code === 0 && res.data) {
  413. this.tableData = res.data.list;
  414. this.pageInfo.total = Number(res.data.count);
  415. } else if (res && res.code >= 100 && res.code <= 104) {
  416. await this.logout();
  417. } else {
  418. this.tableData = [];
  419. this.pageInfo.total = 0;
  420. }
  421. this.loading = false;
  422. },
  423. },
  424. };
  425. </script>
  426. <style lang="scss" scoped>
  427. </style>