AddWareHouse.vue 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="dialogVisible"
  5. width="30%"
  6. :before-close="closePop"
  7. >
  8. <div class="main_contain">
  9. <el-form
  10. :model="ruleForm"
  11. :rules="rules"
  12. :label-position="labelPosition"
  13. ref="ruleForm"
  14. label-width="100px"
  15. class="demo-ruleForm"
  16. >
  17. <el-form-item label="仓库编号">
  18. <span>{{storehouse_code}}</span>
  19. </el-form-item>
  20. <el-form-item label="仓库名称" prop="storehouse_name">
  21. <el-input v-model="ruleForm.storehouse_name"></el-input>
  22. </el-form-item>
  23. <el-form-item label="仓库地址" prop="address">
  24. <el-input type="textarea" v-model="ruleForm.address" @input="aa"></el-input>
  25. </el-form-item>
  26. <el-form-item label="状态" prop="status">
  27. <el-radio-group v-model="ruleForm.status" >
  28. <el-radio :label="1" >启用</el-radio>
  29. <el-radio :label="0">禁用</el-radio>
  30. <!-- <el-radio :label="1" @click.native="toDisable2">启用</el-radio>-->
  31. <!-- <el-radio :label="0" @click.native="toDisable">禁用</el-radio>-->
  32. </el-radio-group>
  33. </el-form-item>
  34. <el-form-item label="仓库管理员" prop="admin_id" >
  35. <el-select v-model="ruleForm.admin_id" @select="handleSelect" @change="changeadmin">
  36. <el-option
  37. v-for="item in adminnamelist"
  38. :key="item.user_id"
  39. :label="item.user_name"
  40. :value="item.user_id"
  41. ></el-option>
  42. </el-select>
  43. </el-form-item>
  44. </el-form>
  45. </div>
  46. <span slot="footer" class="dialog-footer">
  47. <el-button @click="closePop">取 消</el-button>
  48. <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
  49. </span>
  50. </el-dialog>
  51. </template>
  52. <script>
  53. import { getcode,addstorehouse,updatestorehouse,getusername,updatestatus } from "@/api/warehouse";
  54. import login from '../../../../mock/login'
  55. export default {
  56. data() {
  57. return {
  58. title: "",
  59. show_type: 1,
  60. storehouse_id: "",
  61. storehouse_code:"coco",
  62. dialogVisible: false,
  63. labelPosition:'left',
  64. adminnamelist: [],
  65. ruleForm: {
  66. admin_name:"",//管理员名字
  67. admin_id:"",//管理员id
  68. storehouse_name: "",
  69. date1: "",
  70. date2: "",
  71. delivery: false,
  72. type: [],
  73. status: "",
  74. address: "",
  75. },
  76. //表单验证规则
  77. rules: {
  78. storehouse_name:[{
  79. required:true,message:"仓库名称不能为空",trigger: "change"
  80. }],
  81. address:[{
  82. required:true,message:"仓库地址不能为空",trigger: "change"
  83. }],
  84. // region: [{ required: true, message: "请选择活动区域", trigger: "change" }],
  85. type: [{
  86. type: "array",
  87. required: true,
  88. message: "请至少选择一个活动性质",
  89. trigger: "change",
  90. },],
  91. desc: [{ required: true, message: "请填写活动形式", trigger: "blur" }],
  92. },
  93. type:"",
  94. // storehouse:{
  95. // storehouse_code:"",
  96. // },
  97. };
  98. },
  99. methods: {
  100. aa(){
  101. console.log('op')
  102. },
  103. changeadmin(item) {
  104. },
  105. handleSelect() {
  106. },
  107. usernamelist(){
  108. //获取管理员列表
  109. getusername().then((res) => {
  110. if (res.data.state == 1){
  111. this.adminnamelist = res.data.data.list;
  112. // console.log("adminnamelist",this.adminnamelist)
  113. }
  114. })
  115. .catch((err) => {
  116. console.log(err)
  117. })
  118. },
  119. show(data, type) {
  120. if (type == 1) {
  121. this.initstorehouseData();
  122. this.show_type = 1;
  123. this.title = "新增仓库";
  124. this.dialogVisible = true;
  125. this.usernamelist()
  126. } else if (type == 2) {
  127. this.show_type = 2;
  128. this.storehouse_id = data.ID;
  129. this.title = "编辑仓库";
  130. this.storehouse_code = data.StorehouseCode;
  131. this.ruleForm.address = data.StorehouseAddress;
  132. this.ruleForm.status = data.StorehouseStatus;
  133. this.ruleForm.storehouse_name = data.StorehouseName;
  134. this.ruleForm.admin_name = data.StorehouseAdminName;
  135. this.ruleForm.admin_id = data.StorehouseAdminId;
  136. this.dialogVisible = true;
  137. this.usernamelist()
  138. }
  139. },
  140. // 获取仓库编码接口
  141. initstorehouseData() {
  142. getcode().then((res) => {
  143. if (res.data.state == 1) {
  144. this.storehouse_code =
  145. res.data.data.list;
  146. }
  147. });
  148. },
  149. //清除表单数据
  150. closePop() {
  151. // console.log("this.ruleForm",this.ruleForm)
  152. this.dialogVisible = false;
  153. this.ruleForm.admin_name = "";
  154. this.ruleForm.admin_id = "";
  155. this.ruleForm.storehouse_name = "";
  156. this.ruleForm.date1 = "";
  157. this.ruleForm.date2 = "";
  158. this.ruleForm.type = [];
  159. this.ruleForm.status = "";
  160. this.ruleForm.address = "";
  161. },
  162. // 验证表单内容
  163. submitForm(ruleForm) {
  164. if (this.show_type == 1) {
  165. this.$refs[ruleForm].validate((valid) => {
  166. if (valid) {
  167. let params = {
  168. storehouse_code: this.storehouse_code || "",
  169. storehouse_name: this.ruleForm.storehouse_name || "",
  170. storehouse_address: this.ruleForm.address || "",
  171. storehouse_status:parseInt(this.ruleForm.status),
  172. storehouse_admin_id: this.ruleForm.admin_id || "",
  173. };
  174. addstorehouse(params).then((res) => {
  175. if (res.data.state == 1) {
  176. this.$message.success("新增成功");
  177. this.closePop();
  178. this.$emit("init");
  179. } else {
  180. this.$message.error("新增失败:" + res.data.msg);
  181. setTimeout(() => {
  182. this.closePop();
  183. }, 2000);
  184. }
  185. });
  186. } else {
  187. return false;
  188. }
  189. });
  190. } else if (this.show_type == 2) {
  191. this.$refs[ruleForm].validate((valid) => {
  192. if (valid) {
  193. let params = {
  194. storehouse_code: this.storehouse_code || "",
  195. storehouse_name: this.ruleForm.storehouse_name || "",
  196. storehouse_address: this.ruleForm.address || "",
  197. storehouse_status:parseInt(this.ruleForm.status),
  198. id: this.storehouse_id,
  199. storehouse_admin_id: this.ruleForm.admin_id || "",
  200. };
  201. updatestorehouse(params).then((res) => {
  202. if (res.data.state == 1) {
  203. this.$message.success("保存成功");
  204. this.closePop();
  205. this.$emit("init");
  206. } else {
  207. this.$message.error("保存失败:" + res.data.msg);
  208. setTimeout(() => {
  209. this.closePop();
  210. }, 2000);
  211. }
  212. });
  213. } else {
  214. return false;
  215. }
  216. });
  217. }
  218. this.contactsinfo();
  219. },
  220. },
  221. };
  222. </script>
  223. <style lang="scss" scoped>
  224. .main_contain {
  225. width: 60%;
  226. display: flex;
  227. flex-direction: column;
  228. margin: 0 auto;
  229. .main_list {
  230. height: 30px;
  231. display: flex;
  232. line-height: 30px;
  233. }
  234. }
  235. </style>