addEdit.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :center="true"
  5. align="left"
  6. top="5vh"
  7. width="1040px"
  8. @close="closeModel"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. v-loading="loading"
  12. element-loading-text="拼命加载中"
  13. element-loading-spinner="el-icon-loading"
  14. element-loading-background="rgba(0, 0, 0, 0.8)"
  15. >
  16. <el-card>
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <ex-table
  20. v-loading="false"
  21. :table="table"
  22. :data="tableData"
  23. :columns="columns"
  24. :page="pageInfo"
  25. :size="size"
  26. @page-curr-change="handlePageChange"
  27. @page-size-change="handleSizeChange"
  28. @screen-reset="
  29. pageInfo.curr = 1;
  30. parmValue.page = 1;
  31. searchList();
  32. "
  33. @screen-submit="
  34. pageInfo.curr = 1;
  35. parmValue.page = 1;
  36. searchList();
  37. "
  38. >
  39. <template #table-header="{}">
  40. <div style="width: 100%; height: 40px"></div>
  41. </template>
  42. </ex-table>
  43. </el-col>
  44. <el-col :span="24" style="text-align: right; margin-top: 10px">
  45. <el-button type="primary" @click="save">保 存 </el-button>
  46. <el-button type="warning" @click="submitForm">123 </el-button>
  47. </el-col>
  48. </el-row>
  49. </el-card>
  50. </el-dialog>
  51. </template>
  52. <script>
  53. import asyncRequest from "@/apis/service/stock/newApply";
  54. import resToken from "@/mixins/resToken";
  55. import {
  56. isnumber,
  57. isMobile,
  58. validEmail,
  59. isAlphanumeric,
  60. isChinese,
  61. isEmoticon,
  62. validAlphabets,
  63. } from "@/utils/validate";
  64. export default {
  65. name: "newApply",
  66. props: ["showModel", "id", "isDetail", "sitem"],
  67. mixins: [resToken],
  68. data() {
  69. const validateusername = (rule, value, callback) => {
  70. // if (value === "") {
  71. // callback(new Error("账号不能为空!"));
  72. // } else {
  73. // if (value.length < 6 || value.length > 18) {
  74. // callback(new Error("账号规则为6~18位数字与字母组合!"));
  75. // } else {
  76. // if (isnumber(value)) {
  77. // callback(new Error("账号规则为6~18位数字与字母组合!"));
  78. // } else if (validAlphabets(value)) {
  79. // callback(new Error("账号规则为6~18位数字与字母组合!"));
  80. // } else if (!isAlphanumeric(value)) {
  81. // callback(new Error("账号规则为6~18位数字与字母组合!"));
  82. // } else {
  83. // callback();
  84. // }
  85. // }
  86. // }
  87. };
  88. const validatename = (rule, value, callback) => {
  89. // if (value === "") {
  90. // callback(new Error("真实姓名不能为空!"));
  91. // } else {
  92. // if (value.length < 2 || value.length > 12) {
  93. // callback(new Error("真实姓名规则为2~12位汉字!"));
  94. // } else {
  95. // if (!isChinese(value)) {
  96. // console.log(9999);
  97. // callback(new Error("真实姓名规则为2~12位汉字!"));
  98. // } else if (isEmoticon(value)) {
  99. // console.log(2345);
  100. // callback(new Error("真实姓名规则为2~12位汉字!"));
  101. // } else {
  102. // callback();
  103. // }
  104. // }
  105. // }
  106. };
  107. const validatemobile = (rule, value, callback) => {
  108. // if (value === "") {
  109. // callback(new Error("手机号不能为空!"));
  110. // } else {
  111. // if (!isMobile(value)) {
  112. // callback(new Error("手机号格式不正确!"));
  113. // } else {
  114. // callback();
  115. // }
  116. // }
  117. };
  118. const validateEmail = (rule, value, callback) => {
  119. // if (value === "") {
  120. // callback();
  121. // } else {
  122. // if (!validEmail(value)) {
  123. // callback(new Error("邮箱格式不正确!"));
  124. // } else {
  125. // callback();
  126. // }
  127. // }
  128. };
  129. return {
  130. loading: true,
  131. showModel: false,
  132. isDetail: false,
  133. modelId: 0,
  134. tableData: [], //渲染表格
  135. //
  136. // 表格 - 数据
  137. tableData: [],
  138. // 表格 - 参数
  139. table: {
  140. stripe: true,
  141. border: true,
  142. _defaultHeader_: ["setcol"],
  143. },
  144. // 表格 - 分页
  145. pageInfo: {
  146. size: 15,
  147. curr: 1,
  148. total: 0,
  149. },
  150. // 表格 - 列参数
  151. columns: [
  152. {
  153. prop: "nickname",
  154. label: "商品编号",
  155. },
  156. {
  157. prop: "role_name",
  158. label: "商品名称",
  159. },
  160. {
  161. prop: "mobile",
  162. label: "数量",
  163. },
  164. ],
  165. loading: false,
  166. title: "添加账号",
  167. showModelThis: this.showModel,
  168. ruleForm: {
  169. username: "", // 账号
  170. name: "", // 真实姓名
  171. mobile: "",
  172. email: "",
  173. role_id: "",
  174. status: "1",
  175. item: [],
  176. },
  177. rulesThis: this.rules,
  178. rules: {
  179. name: [
  180. {
  181. required: true,
  182. validator: validatename,
  183. trigger: "blur",
  184. },
  185. ],
  186. username: [
  187. {
  188. required: true,
  189. validator: validateusername,
  190. trigger: "blur",
  191. },
  192. ],
  193. mobile: [
  194. {
  195. required: true,
  196. validator: validatemobile,
  197. trigger: "blur",
  198. },
  199. ],
  200. email: [
  201. {
  202. required: false,
  203. validator: validateEmail,
  204. trigger: "blur",
  205. },
  206. ],
  207. role_id: [
  208. {
  209. required: true,
  210. message: "请选择角色",
  211. trigger: "change",
  212. },
  213. ],
  214. item: [
  215. {
  216. type: "array",
  217. required: true,
  218. message: "请选择所在部门",
  219. trigger: "change",
  220. },
  221. ],
  222. status: [
  223. {
  224. required: true,
  225. message: "请选择状态",
  226. trigger: "change",
  227. },
  228. ],
  229. },
  230. };
  231. },
  232. watch: {
  233. showModel: function (val) {
  234. this.showModelThis = val;
  235. if (val) {
  236. this.initForm();
  237. }
  238. },
  239. showModelThis(val) {
  240. if (!val) {
  241. this.$emit("cancel");
  242. }
  243. },
  244. },
  245. methods: {
  246. closeModel() {
  247. console.log("closeModel!!");
  248. },
  249. async initForm() {
  250. this.loading = true;
  251. this.title = "可调拨的商品";
  252. {
  253. //await this.getRole();
  254. // if (this.id === "add") {
  255. // this.title = "添加账号";
  256. // this.rulesThis = this.rules;
  257. // await this.resetForm();
  258. // } else {
  259. // if (this.isDetail) {
  260. // this.title = "账号详情";
  261. // this.rulesThis = {};
  262. // } else {
  263. // this.title = "修改账号";
  264. // this.rulesThis = this.rules;
  265. // }
  266. // await this.resetForm(this.sitem);
  267. // // await this.initData()
  268. //}
  269. }
  270. this.loading = false;
  271. },
  272. // async getRole() {
  273. // const model = {
  274. // status: "", // 状态
  275. // level: "", // 姓名
  276. // role_name: "",
  277. // };
  278. // const res = await asyncRequest.getRole(model);
  279. // if (res && res.code === 0 && res.data) {
  280. // this.roleList = res.data;
  281. // this.roleList.map((v1) => {
  282. // v1.id += "";
  283. // v1.status += "";
  284. // return v1;
  285. // });
  286. // }
  287. // },
  288. async initData() {
  289. // const res = await asyncRequest.detail({ id: this.id });
  290. // if (res && res.code === 0 && res.data) {
  291. // this.ruleForm = res.data;
  292. // this.ruleForm.role_id = this.ruleForm.role;
  293. // } else if (res && res.code >= 100 && res.code <= 104) {
  294. // await this.logout();
  295. // } else {
  296. // this.$message.warning(res.message);
  297. // }
  298. },
  299. async resetForm(sitem) {
  300. // 重置
  301. await this.$nextTick(() => {
  302. // if (this.$refs.ruleForm) {
  303. // this.$refs.ruleForm.resetFields();
  304. // this.$refs.ruleForm.clearValidate();
  305. // const { username, nickname, mobile, email, roleid, status, item } =
  306. // sitem;
  307. // this.ruleForm = {
  308. // username: username || "", // 账号
  309. // name: nickname || "", // 真实姓名
  310. // mobile: mobile || "",
  311. // email: email || "",
  312. // role_id: roleid || "",
  313. // status: status || "",
  314. // item: item || [],
  315. // };
  316. // if (this.id === "add" || this.isDetail) {
  317. // this.rules.username[0].required = false;
  318. // }
  319. // }
  320. });
  321. },
  322. save() {
  323. console.log("点击了保存");
  324. },
  325. async submitForm() {
  326. console.log("点击了保存并发起流程");
  327. // await this.$refs.ruleForm.validate(async (valid) => {
  328. // if (valid) {
  329. // this.loading = true;
  330. // const { username, name, mobile, email, role_id, status } = JSON.parse(
  331. // JSON.stringify(this.ruleForm)
  332. // );
  333. // const model = {
  334. // id: this.id,
  335. // username: username || "", // 账号
  336. // nickname: name || "", // 真实姓名
  337. // mobile: mobile || "",
  338. // email: email || "",
  339. // role: role_id || "",
  340. // status: status || "",
  341. // };
  342. // let res = {};
  343. // if (this.id === "add") {
  344. // delete model["id"];
  345. // res = await asyncRequest.add(model);
  346. // } else {
  347. // res = await asyncRequest.update(model);
  348. // }
  349. // this.loading = false;
  350. // if (res && res.code === 0) {
  351. // const title = this.id === "add" ? "添加成功" : "修改成功";
  352. // this.$notify.success({
  353. // title,
  354. // message: "",
  355. // });
  356. // this.showModelThis = false;
  357. // // 刷新
  358. // this.$emit("refresh");
  359. // } else if (res && res.code >= 100 && res.code <= 104) {
  360. // await this.logout();
  361. // } else {
  362. // this.$message.warning(res.message);
  363. // }
  364. // } else {
  365. // console.log("error submit!!");
  366. // return false;
  367. // }
  368. // });
  369. },
  370. },
  371. };
  372. </script>
  373. <style lang="scss" scoped>
  374. .newApply {
  375. }
  376. </style>