add.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <view style="padding: 20rpx;">
  3. <view style="padding: 30rpx;background-color: white;border-radius:50rpx">
  4. <u--form labelPosition="left" :model="teamInfo" ref="uForm" labelWidth="120">
  5. <u-form-item label="制衣生产车间:" prop="zyProductWorkshop" borderBottom @click="showWorkshop = true" :required="true" ref="uItem">
  6. <u--input v-model="teamInfo.zyProductWorkshop" disabled disabledColor="#ffffff" placeholder="请选择生产车间" border="none"></u--input>
  7. <u-icon slot="right" name="arrow-right"></u-icon>
  8. </u-form-item>
  9. <u-action-sheet :show="showWorkshop" :actions="options" title="请选择车间" @close="showWorkshop = false" @select="workshopSelect" />
  10. <u-form-item label="制衣班组:" prop="zyTeam" borderBottom ref="uItem" :required="true">
  11. <u--input v-model="teamInfo.zyTeam" border="none" placeholder="请输入班组"></u--input>
  12. </u-form-item>
  13. <u-form-item label="启用:" prop="status" borderBottom ref="uItem" v-show="adminType"><u-switch v-model="teamInfo.status"></u-switch></u-form-item>
  14. <u-button type="primary" text="提交" customStyle="margin-top: 50px" @click="submit"></u-button>
  15. <u-button type="error" text="重置" customStyle="margin-top: 10px" @click="reset"></u-button>
  16. </u--form>
  17. </view>
  18. <u-toast ref="uToast"></u-toast>
  19. </view>
  20. </template>
  21. <script>
  22. import { add, workshopData } from '@/api/biz/team.js';
  23. import { getToken, setToken, removeToken, getAdminType, setAdminType, removeAdminType } from '@/utils/auth';
  24. export default {
  25. data() {
  26. return {
  27. teamInfo: {
  28. WorkshopId: 0,
  29. zyProductWorkshop: '',
  30. zyTeam: '',
  31. status: false
  32. },
  33. // deliveryDateShowFlag: false,
  34. options: [],
  35. rules: {
  36. zyProductWorkshop: {
  37. type: 'string',
  38. required: true,
  39. message: '请填写制衣生产车间',
  40. trigger: ['blur', 'change']
  41. },
  42. zyTeam: {
  43. type: 'string',
  44. required: true,
  45. message: '请填写制衣班组',
  46. trigger: ['blur', 'change']
  47. }
  48. },
  49. showWorkshop: false,
  50. adminType: false
  51. };
  52. },
  53. onLoad() {
  54. this.getWorkshop();
  55. uni.$on('loadData', () => {
  56. this.loadData();
  57. });
  58. },
  59. onReady() {
  60. this.$refs.uForm.setRules(this.rules);
  61. this.adminType = this.$store.state.user.adminType;
  62. console.log(getAdminType());
  63. },
  64. methods: {
  65. getWorkshop() {
  66. workshopData().then(res => {
  67. if (res.success) {
  68. for (let i in res.data) {
  69. // console.log(res.data[i]['id'])
  70. // console.log(res.data[i]['zyProductWorkshop'])
  71. let o = {
  72. value: res.data[i]['id'],
  73. name: res.data[i]['zyProductWorkshop']
  74. };
  75. this.options.push(o);
  76. }
  77. } else {
  78. }
  79. });
  80. },
  81. workshopSelect(e) {
  82. console.log(e);
  83. this.teamInfo.zyProductWorkshop = e.name;
  84. this.teamInfo.workshopId = e.value;
  85. },
  86. confirm(e) {
  87. console.log(e);
  88. },
  89. submit() {
  90. this.$refs.uForm.validate().then(val => {
  91. add(this.teamInfo).then(res => {
  92. if (res.success) {
  93. this.$refs.uToast.show({
  94. type: 'success',
  95. message: '新增成功',
  96. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  97. });
  98. this.reset();
  99. } else {
  100. this.$refs.uToast.show({
  101. type: 'error',
  102. message: res.message,
  103. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  104. });
  105. }
  106. });
  107. });
  108. },
  109. reset() {
  110. this.teamInfo = {
  111. zyProductWorkshop: '',
  112. zyTeam: '',
  113. status: false
  114. };
  115. this.$refs.uForm.clearValidate();
  116. }
  117. },
  118. onUnload() {
  119. uni.$emit('loadData');
  120. }
  121. };
  122. </script>
  123. <style></style>