index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <script setup lang="ts">
  2. // import { watch } from "vue";
  3. import { useColumns } from "./columns";
  4. import {
  5. httpList,
  6. httpStatus
  7. } from "/@/api/supplierManage/supplierAccoutManage";
  8. import { reactive, ref, onMounted } from "vue";
  9. import { type FormInstance } from "element-plus";
  10. import { TableProBar } from "/@/components/ReTable";
  11. import { type PaginationProps } from "@pureadmin/table";
  12. import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
  13. import { useNav } from "/@/layout/hooks/nav";
  14. import { statusList } from "/@/utils/status";
  15. import { responseHandle } from "/@/utils/responseHandle";
  16. import { useUserStoreHook } from "/@/store/modules/user";
  17. import { useCompany } from "/@/hooks/core/useCompany";
  18. import { type menuType } from "./types";
  19. import addEdit from "./addEdit.vue";
  20. import resetPassword from "./resetPassword.vue";
  21. const { logout } = useNav();
  22. defineOptions({
  23. name: "supplierAccountManage"
  24. });
  25. const powers = ref([]);
  26. const form = reactive({
  27. nickname: "",
  28. username: "",
  29. status: "",
  30. page: 1,
  31. size: 15
  32. });
  33. const dataList = ref([]);
  34. const loading = ref(true);
  35. const showModel = ref(false);
  36. const itemId = ref("");
  37. const isDetails = ref("add");
  38. const { columns } = useColumns();
  39. const { currentCompany } = useCompany();
  40. const sitem = reactive<menuType>({
  41. id: "", //账户id
  42. nickname: "", //真实姓名
  43. mobile: "", //手机号
  44. role: "", //角色,
  45. companyArr: []
  46. });
  47. const passwordModelId = ref("");
  48. const passwordModel = ref(false);
  49. const formRef = ref<FormInstance>();
  50. const pagination = reactive<PaginationProps>({
  51. total: 0,
  52. pageSize: 15,
  53. currentPage: 1,
  54. background: true
  55. });
  56. // 重置密码
  57. const resetRwd = async row => {
  58. const { id } = row;
  59. passwordModelId.value = id;
  60. passwordModel.value = true;
  61. };
  62. //修改状态
  63. const handleStatus = async row => {
  64. const { id, status } = row;
  65. const { code, message } = await httpStatus({
  66. id,
  67. status: status + "" === "1" ? "0" : "1"
  68. });
  69. responseHandle({
  70. code,
  71. message,
  72. logout,
  73. handler: () => onSearch()
  74. });
  75. };
  76. async function handleCurrentChange(val: number) {
  77. form.page = val;
  78. await onSearch();
  79. }
  80. async function handleSizeChange(val: number) {
  81. form.size = val;
  82. form.page = 1;
  83. await onSearch();
  84. }
  85. function handleSelectionChange(val) {
  86. console.log("handleSelectionChange", val);
  87. }
  88. async function onSearch() {
  89. loading.value = true;
  90. const { code, data, message } = await httpList({
  91. ...form,
  92. // companyNo: currentCompany.value.companyNo,
  93. noRela: true
  94. //currentCompany.value.companyNo === ""
  95. });
  96. responseHandle({
  97. code,
  98. message,
  99. logout,
  100. handler: () => {
  101. const { list, count } = data;
  102. dataList.value = list ?? [];
  103. pagination.total = count ?? 0;
  104. pagination.pageSize = form.size;
  105. pagination.currentPage = form.page;
  106. }
  107. });
  108. loading.value = false;
  109. }
  110. async function resetSearch() {
  111. form.page = 1;
  112. await onSearch();
  113. }
  114. //新建/编辑/详情弹窗
  115. function editItem(id, type, item) {
  116. itemId.value = id;
  117. isDetails.value = type;
  118. for (let key in item) {
  119. sitem[key] = item[key];
  120. }
  121. showModel.value = true;
  122. }
  123. const submitRefresh = () => {
  124. showModel.value = false;
  125. onSearch();
  126. };
  127. const submitCancel = () => {
  128. showModel.value = false;
  129. };
  130. const resetCancel = () => {
  131. passwordModel.value = false;
  132. };
  133. const resetForm = (formEl: FormInstance | undefined) => {
  134. if (!formEl) return;
  135. formEl.resetFields();
  136. form.page = 1;
  137. onSearch();
  138. };
  139. // watch(
  140. // () => currentCompany.value,
  141. // () => onSearch()
  142. // );
  143. onMounted(() => {
  144. powers.value = useUserStoreHook().getMenuActions("supplierAccoutManage");
  145. onSearch();
  146. });
  147. </script>
  148. <template>
  149. <div class="main">
  150. <div v-show="powers.some(i => i == '001')">
  151. <el-form
  152. ref="formRef"
  153. :inline="true"
  154. :model="form"
  155. size="small"
  156. :label-width="0"
  157. class="bg-white w-99/100 pl-8 pt-4"
  158. >
  159. <el-form-item prop="status">
  160. <el-select
  161. v-model="form.status"
  162. style="width: 100%"
  163. placeholder="账号状态"
  164. clearable
  165. >
  166. <el-option
  167. v-for="(si, sii) in statusList"
  168. :key="'status' + si.value + sii"
  169. :label="si.label"
  170. :value="si.value"
  171. />
  172. </el-select>
  173. </el-form-item>
  174. <el-form-item prop="nickname">
  175. <el-input v-model="form.nickname" placeholder="真实姓名" clearable />
  176. </el-form-item>
  177. <el-form-item prop="username">
  178. <el-input v-model="form.username" placeholder="手机号" clearable />
  179. </el-form-item>
  180. <el-form-item>
  181. <el-button
  182. type="primary"
  183. :icon="useRenderIcon('search')"
  184. :loading="loading"
  185. @click="resetSearch"
  186. >
  187. 搜索
  188. </el-button>
  189. <el-button
  190. :icon="useRenderIcon('refresh')"
  191. @click="resetForm(formRef)"
  192. >
  193. 重置
  194. </el-button>
  195. </el-form-item>
  196. </el-form>
  197. <TableProBar
  198. title="公司账号管理"
  199. :loading="loading"
  200. :dataList="dataList"
  201. size="small"
  202. @refresh="onSearch"
  203. >
  204. <template #buttons>
  205. <el-button
  206. type="primary"
  207. size="small"
  208. :icon="useRenderIcon('add')"
  209. @click="editItem('', 'add', {})"
  210. v-if="powers.some(i => i == '002')"
  211. >
  212. 新增账号
  213. </el-button>
  214. </template>
  215. <template v-slot="{ size, checkList }">
  216. <PureTable
  217. border
  218. align="left"
  219. showOverflowTooltip
  220. table-layout="auto"
  221. size="small"
  222. :data="dataList"
  223. :columns="columns"
  224. :checkList="checkList"
  225. :pagination="pagination"
  226. :paginationSmall="size === 'small' ? true : false"
  227. :header-cell-style="{ background: '#fafafa', color: '#606266' }"
  228. @selection-change="handleSelectionChange"
  229. @size-change="handleSizeChange"
  230. @current-change="handleCurrentChange"
  231. >
  232. <template #operation="{ row }">
  233. <el-popconfirm :title="'确认重置密码?'" @confirm="resetRwd(row)">
  234. <template #reference>
  235. <el-button
  236. class="reset-margin"
  237. link
  238. type="primary"
  239. size="small"
  240. v-if="powers.some(i => i == '012')"
  241. :icon="useRenderIcon('refresh-right')"
  242. /> </template
  243. ></el-popconfirm>
  244. <el-button
  245. class="reset-margin"
  246. v-if="powers.some(i => i == '007')"
  247. link
  248. type="primary"
  249. size="small"
  250. @click="editItem(row.id, 'view', row)"
  251. :icon="useRenderIcon('eye-view')"
  252. />
  253. <el-button
  254. class="reset-margin"
  255. link
  256. v-if="powers.some(i => i == '005')"
  257. type="primary"
  258. size="small"
  259. @click="editItem(row.id, 'edit', row)"
  260. :icon="useRenderIcon('edits')"
  261. />
  262. <el-popconfirm
  263. :title="
  264. String(row.status) === '1' ? '改为禁用?' : '改为启用?'
  265. "
  266. v-if="
  267. (powers.some(i => i == '004') && row.status + '' === '1') ||
  268. (powers.some(i => i == '003') && row.status + '' === '0')
  269. "
  270. @confirm="handleStatus(row)"
  271. >
  272. <template #reference>
  273. <el-button
  274. class="reset-margin"
  275. link
  276. type="primary"
  277. size="small"
  278. :icon="
  279. useRenderIcon(
  280. String(row.status) === '1'
  281. ? 'close-circle-line'
  282. : 'checkbox-circle-line'
  283. )
  284. " /></template
  285. ></el-popconfirm>
  286. </template>
  287. </PureTable>
  288. </template>
  289. </TableProBar>
  290. <addEdit
  291. :itemId="itemId"
  292. :isDetails="isDetails"
  293. :show-model="showModel"
  294. @refresh="submitRefresh"
  295. @cancel="submitCancel"
  296. :sitem="sitem"
  297. />
  298. <reset-password
  299. :itemId="passwordModelId"
  300. :show-model="passwordModel"
  301. @refresh="resetCancel"
  302. @cancel="resetCancel"
  303. />
  304. </div>
  305. <NoAuth v-show="!powers.some(i => i == '001')" />
  306. </div>
  307. </template>
  308. <style scoped lang="scss">
  309. :deep(.el-dropdown-menu__item i) {
  310. margin: 0;
  311. }
  312. </style>