index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <div class="brand 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.brand_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 == '0' ? '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 === '1'
  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 === '0'
  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/brand";
  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: "brand",
  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 == "brand"
  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. brand_name: "",
  249. status: "",
  250. creater: "",
  251. },
  252. // 状态
  253. statusOptions: [
  254. { id: "0", label: "禁用" },
  255. { id: "1", label: "启用" },
  256. ],
  257. // 表格 - 数据
  258. tableData: [],
  259. // 表格 - 参数
  260. table: {
  261. stripe: true,
  262. border: true,
  263. _defaultHeader_: ["setcol"],
  264. },
  265. // 表格 - 分页
  266. pageInfo: {
  267. size: 15,
  268. curr: 1,
  269. total: 0,
  270. },
  271. // 表格 - 列参数
  272. columns: [
  273. {
  274. prop: "id",
  275. label: "ID",
  276. },
  277. {
  278. prop: "brand_name",
  279. label: "品牌名称",
  280. },
  281. {
  282. prop: "status",
  283. label: "状态",
  284. sortable: true,
  285. _slot_: "status",
  286. },
  287. {
  288. prop: "creater",
  289. label: "创建人",
  290. },
  291. {
  292. prop: "addtime",
  293. label: "创建时间",
  294. sortable: true,
  295. },
  296. {
  297. prop: "",
  298. label: "操作",
  299. fixed: "right",
  300. _noset_: true,
  301. _slot_: "operation",
  302. },
  303. ],
  304. };
  305. },
  306. mounted() {
  307. this.searchList();
  308. },
  309. methods: {
  310. restSearch() {
  311. // 表格 - 分页
  312. this.pageInfo = {
  313. size: 15,
  314. curr: 1,
  315. total: 0,
  316. };
  317. this.parmValue = {
  318. page: 1, // 页码
  319. size: 15, // 每页显示条数
  320. start: "",
  321. end: "",
  322. brand_name: "",
  323. status: "",
  324. creater: "",
  325. };
  326. this.searchList();
  327. },
  328. // 新建/编辑/详情
  329. openModal(row, type) {
  330. const { status } = row;
  331. if (type === "005" && status === "1") {
  332. this.$message.warning("禁用后,才可以修改!");
  333. return;
  334. }
  335. this.sitem = row;
  336. this.modelId = type;
  337. this.showModel = true;
  338. },
  339. // 时间
  340. async handleTime(e) {
  341. this.parmValue.start = e.startTime || "";
  342. this.parmValue.end = e.endTime || "";
  343. if (
  344. (this.parmValue.start !== "" && this.parmValue.end !== "") ||
  345. (this.parmValue.start === "" && this.parmValue.end === "")
  346. ) {
  347. this.pageInfo.curr = 1;
  348. this.parmValue.page = 1;
  349. await this.searchList();
  350. }
  351. },
  352. /**
  353. * 启用/禁用
  354. * @param {String} id id
  355. * @param {String} status 0-禁用 1-启用
  356. */
  357. async changeStatus(id, status) {
  358. await this.$confirm(`确定要改为${status === "1" ? "禁用" : "启用"}?`, {
  359. confirmButtonText: "确定",
  360. cancelButtonText: "取消",
  361. type: "warning",
  362. })
  363. .then(async () => {
  364. this.loading = true;
  365. const model = {
  366. id: id,
  367. status: status === "1" ? "0" : "1",
  368. };
  369. const res = await asyncRequest.status(model);
  370. if (res && res.code === 0) {
  371. this.loading = false;
  372. this.$notify.success({
  373. title: "状态修改成功!",
  374. message: "",
  375. });
  376. await this.searchList();
  377. } else if (res && res.code >= 100 && res.code <= 104) {
  378. await this.logout();
  379. } else {
  380. this.loading = false;
  381. this.$message.warning(res.message);
  382. }
  383. })
  384. .catch(() => {
  385. console.log("取消");
  386. });
  387. },
  388. async deleteItem(id) {
  389. await this.$confirm("确定要删除?", {
  390. confirmButtonText: "确定",
  391. cancelButtonText: "取消",
  392. type: "warning",
  393. })
  394. .then(async () => {
  395. const model = {
  396. id: id,
  397. };
  398. const res = await asyncRequest.delete(model);
  399. if (res && res.code === 0) {
  400. this.$notify.success({
  401. title: "删除成功",
  402. message: "",
  403. });
  404. this.searchList();
  405. } else if (res && res.code >= 100 && res.code <= 104) {
  406. await this.logout();
  407. } else {
  408. this.$message.warning(res.message);
  409. }
  410. })
  411. .catch(() => {
  412. console.log("取消");
  413. });
  414. },
  415. // 刷新表格
  416. async searchList() {
  417. if (
  418. (this.parmValue.start !== "" && this.parmValue.end === "") ||
  419. (this.parmValue.start === "" && this.parmValue.end !== "")
  420. ) {
  421. this.$message.warning("时间区间不完整!");
  422. return;
  423. }
  424. this.loading = true;
  425. const res = await asyncRequest.list(this.parmValue);
  426. if (res && res.code === 0 && res.data) {
  427. this.tableData = res.data.list;
  428. this.pageInfo.total = Number(res.data.count);
  429. } else if (res && res.code >= 100 && res.code <= 104) {
  430. await this.logout();
  431. } else {
  432. this.tableData = [];
  433. this.pageInfo.total = 0;
  434. }
  435. this.loading = false;
  436. },
  437. },
  438. };
  439. </script>
  440. <style lang="scss" scoped>
  441. </style>