index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <div>
  3. <PlusPage
  4. ref="plusPageInstance"
  5. :columns="tableConfig"
  6. :request="getList"
  7. :is-card="true"
  8. :search="{
  9. labelWidth: 100,
  10. showNumber: 3
  11. }"
  12. :table="{
  13. actionBar: { buttons, type: 'link', width: 180 },
  14. adaptive: { offsetBottom: 50 },
  15. hasIndexColumn: true
  16. }"
  17. :pageInfoMap="{ page: 'pageNum', pageSize: 'pageSize' }"
  18. >
  19. <template #table-title>
  20. <el-row class="button-row">
  21. <el-button size="default" type="success" @click="handleCreate">
  22. 新增
  23. </el-button>
  24. </el-row>
  25. </template>
  26. </PlusPage>
  27. <!-- 弹窗编辑 -->
  28. <PlusDialogForm
  29. ref="dialogForm"
  30. v-model="form"
  31. v-model:visible="dialogVisible"
  32. :form="{
  33. columns,
  34. labelPosition: 'left',
  35. labelWidth: 190,
  36. rules
  37. }"
  38. :dialog="{ title: dialogTitle + '菜单', width: 600, confirmLoading }"
  39. @confirm="handleSubmit"
  40. @close="handleClose"
  41. />
  42. </div>
  43. </template>
  44. <script lang="ts" setup>
  45. import {
  46. computed,
  47. onMounted,
  48. reactive,
  49. ref,
  50. resolveDirective,
  51. toRefs
  52. } from "vue";
  53. import type { FormRules } from "element-plus";
  54. import { ElMessage } from "element-plus";
  55. import {
  56. type FieldValues,
  57. type PlusColumn,
  58. PlusDialogForm,
  59. PlusPage,
  60. PlusPageInstance,
  61. useTable
  62. } from "plus-pro-components";
  63. import { useRouter } from "vue-router";
  64. import {
  65. createChildAccount,
  66. getChildAccountList,
  67. merchantUserInfoDetail,
  68. merchantUserInfoupdateAllocationStatus,
  69. merchantUserInfoupdateStatus,
  70. updateChildAccount
  71. } from "@/api/childAccount";
  72. import { AesEncode } from "@/utils/crypto";
  73. import { md5 } from "js-md5";
  74. defineOptions({
  75. name: "ChildAccount"
  76. });
  77. const router = useRouter();
  78. const plusPageInstance = ref<PlusPageInstance | null>(null);
  79. const getList = async (query: Record<string, any>) => {
  80. let res = await getChildAccountList(query);
  81. return {
  82. data: res.data.list,
  83. total: res.data.total
  84. };
  85. };
  86. // 重新请求列表接口
  87. const refresh = () => {
  88. plusPageInstance.value?.getList();
  89. };
  90. const dialogTitle = computed(() => (state.isCreate ? "新增" : "编辑"));
  91. // 表格数据
  92. const tableConfig: PlusColumn[] = [
  93. {
  94. label: "姓名",
  95. prop: "contractName",
  96. hideInSearch: true
  97. },
  98. {
  99. label: "手机号",
  100. prop: "contractMobile",
  101. hideInSearch: true
  102. },
  103. {
  104. label: "备注",
  105. prop: "remark",
  106. hideInSearch: true
  107. },
  108. {
  109. label: "创建人",
  110. prop: "creater",
  111. hideInSearch: true
  112. },
  113. {
  114. label: "创建时间",
  115. prop: "createTime",
  116. hideInSearch: true
  117. },
  118. {
  119. label: "微信号",
  120. prop: "wechat",
  121. hideInSearch: true
  122. },
  123. {
  124. label: "接单状态",
  125. prop: "receiveStatus",
  126. valueType: "select",
  127. options: [
  128. { label: "接单", value: true },
  129. { label: "不接单", value: false }
  130. ],
  131. hideInSearch: true
  132. },
  133. {
  134. label: "当前状态",
  135. prop: "status",
  136. valueType: "select",
  137. options: [
  138. { label: "正常", value: "1" },
  139. { label: "禁用", value: "0" }
  140. ],
  141. hideInSearch: true
  142. }
  143. ];
  144. /*--------------------表单--------------------*/
  145. // 表单实例
  146. const dialogForm = ref(null);
  147. interface State {
  148. dialogVisible: boolean;
  149. detailsVisible: boolean;
  150. confirmLoading: boolean;
  151. selectedIds: number[];
  152. isCreate: boolean;
  153. form: Record<string, any>;
  154. rules: FormRules;
  155. }
  156. const state = reactive<State>({
  157. dialogVisible: false,
  158. detailsVisible: false,
  159. confirmLoading: false,
  160. selectedIds: [],
  161. isCreate: false,
  162. form: {},
  163. rules: {
  164. contractName: [
  165. {
  166. required: true,
  167. message: "请输入姓名",
  168. trigger: "blur"
  169. }
  170. ],
  171. contractMobile: [
  172. {
  173. required: true,
  174. message: "请输入手机号",
  175. trigger: "blur"
  176. },
  177. {
  178. pattern: /^1[3-9]\d{9}$/,
  179. message: "请输入正确的手机号",
  180. trigger: "blur"
  181. }
  182. ],
  183. accountName: [
  184. {
  185. required: true,
  186. message: "请输入账号",
  187. trigger: "blur"
  188. }
  189. ],
  190. password: [
  191. {
  192. required: true,
  193. message: "请输入密码",
  194. trigger: "blur"
  195. }
  196. ],
  197. password1: [
  198. {
  199. required: true,
  200. message: "请输入密码",
  201. trigger: "blur"
  202. },
  203. {
  204. validator: (rule, value, callback) => {
  205. if (value !== form.value.password) {
  206. callback(new Error("密码不一致"));
  207. } else {
  208. callback();
  209. }
  210. }
  211. }
  212. ]
  213. }
  214. });
  215. const columns: PlusColumn[] = [
  216. {
  217. label: "姓名",
  218. prop: "contractName",
  219. fieldProps: {
  220. clearable: true
  221. }
  222. },
  223. {
  224. label: "手机号",
  225. prop: "contractMobile",
  226. fieldProps: {
  227. clearable: true
  228. }
  229. },
  230. {
  231. label: "微信号",
  232. prop: "wechat",
  233. fieldProps: {
  234. clearable: true
  235. }
  236. },
  237. {
  238. label: "账号",
  239. prop: "accountName",
  240. fieldProps: computed(() => {
  241. return {
  242. disabled: !state.isCreate
  243. };
  244. })
  245. },
  246. {
  247. label: "密码",
  248. prop: "contractPassword",
  249. fieldProps: {
  250. type: "password",
  251. clearable: true
  252. }
  253. },
  254. {
  255. label: "确认密码",
  256. prop: "confirmPassword",
  257. fieldProps: {
  258. type: "password",
  259. clearable: true
  260. }
  261. },
  262. {
  263. label: "是否愿意客户主动电话联系",
  264. prop: "isAllowCusContact",
  265. valueType: "radio",
  266. options: [
  267. {
  268. label: "是",
  269. value: true
  270. },
  271. {
  272. label: "否",
  273. value: false
  274. }
  275. ]
  276. },
  277. {
  278. label: "备注",
  279. prop: "remark",
  280. fieldProps: {
  281. type: "textarea",
  282. rows: 4,
  283. clearable: true,
  284. maxlength: 200,
  285. showWordLimit: true
  286. }
  287. }
  288. ];
  289. // 创建
  290. const handleCreate = (): void => {
  291. form.value = {
  292. status: "normal"
  293. };
  294. state.isCreate = true;
  295. state.dialogVisible = true;
  296. };
  297. const handleSubmit = async (values: FieldValues) => {
  298. console.log(values, "Submit");
  299. confirmLoading.value = true;
  300. if (state.isCreate) {
  301. try {
  302. let params = form.value;
  303. params.contractPassword = md5(form.value.contractPassword).toUpperCase();
  304. params.confirmPassword = md5(form.value.confirmPassword).toUpperCase();
  305. let res = await createChildAccount(params);
  306. if (res.code === 0) {
  307. ElMessage.success("新增成功");
  308. confirmLoading.value = false;
  309. dialogVisible.value = false;
  310. refresh();
  311. } else {
  312. ElMessage.error(res.msg);
  313. }
  314. } finally {
  315. confirmLoading.value = false;
  316. }
  317. } else {
  318. // 编辑
  319. try {
  320. let params = form.value;
  321. params.contractPassword = md5(form.value.contractPassword).toUpperCase();
  322. params.confirmPassword = md5(form.value.confirmPassword).toUpperCase();
  323. let res = await updateChildAccount(params);
  324. if (res.code === 0) {
  325. ElMessage.success("修改成功");
  326. confirmLoading.value = false;
  327. dialogVisible.value = false;
  328. refresh();
  329. } else {
  330. ElMessage.error(res.msg);
  331. }
  332. } finally {
  333. confirmLoading.value = false;
  334. }
  335. }
  336. };
  337. const handleClose = () => {
  338. // 重置表单校验状态
  339. console.log(dialogForm.value.formInstance);
  340. };
  341. const { buttons } = useTable();
  342. const perms = resolveDirective("perms");
  343. buttons.value = [
  344. {
  345. // 修改
  346. text: "修改",
  347. code: "edit",
  348. // props v0.1.16 版本新增函数类型
  349. props: {
  350. type: "primary"
  351. },
  352. onClick(params) {
  353. merchantUserInfoDetail(params.row.id).then(res => {
  354. if (res.code === 0) {
  355. form.value = res.data;
  356. state.isCreate = false;
  357. state.dialogVisible = true;
  358. }
  359. });
  360. }
  361. },
  362. {
  363. // 修改
  364. text: "修改状态",
  365. props: {
  366. type: "warning"
  367. },
  368. confirm: {
  369. options: {
  370. draggable: true,
  371. message: "确认修改状态?"
  372. }
  373. },
  374. onConfirm: async params => {
  375. try {
  376. let res = await merchantUserInfoupdateStatus({
  377. id: params.row.id,
  378. status: params.row.status === "1" ? "0" : "1"
  379. });
  380. if (res.code === 0) {
  381. ElMessage.success("修改成功");
  382. refresh();
  383. } else {
  384. ElMessage.error(res.msg);
  385. }
  386. } catch (e) {
  387. ElMessage.error("删除失败");
  388. }
  389. }
  390. },
  391. {
  392. // 修改
  393. text: "修改接单状态",
  394. props: {
  395. type: "warning"
  396. },
  397. confirm: {
  398. options: {
  399. draggable: true,
  400. message: "确认修改接单状态?"
  401. }
  402. },
  403. onConfirm: async params => {
  404. try {
  405. let res = await merchantUserInfoupdateAllocationStatus({
  406. ids: [params.row.id],
  407. allocationStatus: params.row.receiveStatus === true ? false : true
  408. });
  409. if (res.code === 0) {
  410. ElMessage.success("修改成功");
  411. refresh();
  412. } else {
  413. ElMessage.error(res.msg);
  414. }
  415. } catch (e) {
  416. ElMessage.error("删除失败");
  417. }
  418. }
  419. }
  420. ];
  421. const { form, confirmLoading, rules, dialogVisible } = toRefs(state);
  422. </script>