addPerson.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <view class="evan-form-show flex flex_column">
  3. <view class="flex_1">
  4. <evanForm ref="formData" :rules="ruleValidate" :model="formData">
  5. <evanFormItem label="员工姓名" prop="name">
  6. <input class="form-input" placeholder-class="form-input-placeholder" :maxlength="30" placeholder="请输入姓名(最多30个字符)" v-model="formData.name" />
  7. </evanFormItem>
  8. <evanFormItem label="手机号码" prop="mobile">
  9. <input type="number" :disabled="formData.isManager==1 && formData.id?true:false" class="form-input" placeholder="请输入您的手机号码" placeholder-class="form-input-placeholder" v-model="formData.mobile" :maxlength="11"/>
  10. </evanFormItem>
  11. <evanFormItem label="性别" prop="sex">
  12. <view style="width: 100%;display:flex;justify-content: flex-end;">
  13. <u-radio-group v-model="formData.sex">
  14. <u-radio
  15. v-for="(item, index) in sexList" :key="index"
  16. :name="item.value"
  17. shape="circle"
  18. >
  19. {{item.name}}
  20. </u-radio>
  21. </u-radio-group>
  22. </view>
  23. </evanFormItem>
  24. <evanFormItem label="岗位" v-if="!isEdit||formData.isManager==0" prop="roleNames">
  25. <u-input type="select" style="width:100%" input-align="right" placeholder="请选择岗位" @click="showRoles=true" v-model="formData.roleNames"/>
  26. <u-popup v-model="showRoles" mode="bottom">
  27. <view style="padding: 1rem;width: 100%;">
  28. <view style="position: relative;padding: 0.5rem;width: 100%;text-align: center;border-bottom: 1px solid #eee;font-size:1.1rem;">
  29. <text @click="toAddRole()" style="color:#066cff;position: absolute;left:0;top:0.5rem;font-size:0.9rem;">新增岗位</text>
  30. 选择岗位
  31. </view>
  32. <view style="padding:1rem;min-height: 15rem;" v-if="roleList.length">
  33. <u-radio-group wrap v-model="formData.roleIds" @change="radioGroupChange">
  34. <u-radio
  35. v-for="(item, index) in roleList" :key="item.id"
  36. :name="item.id"
  37. :disabled="!item.isEnable"
  38. :icon-size="30"
  39. :label-size="32"
  40. >
  41. {{item.name}}
  42. </u-radio>
  43. </u-radio-group>
  44. </view>
  45. <view style="color: #999;text-align: center;padding:3rem 0;" v-else>
  46. 暂无岗位信息,请点击“新增岗位”
  47. </view>
  48. </view>
  49. </u-popup>
  50. </evanFormItem>
  51. </evanForm>
  52. </view>
  53. <view class="form-footer-btn flex align_center justify_center">
  54. <u-button shape="circle" v-if="isEdit&&formData.isManager==0" @click="delPerson()" :custom-style="{width:'300rpx',marginRight:'20rpx' }">删除</u-button>
  55. <u-button shape="circle" type="info" :custom-style="{ background: '#066cff', color: '#fff',width:'300rpx' }" @click="save('formData')">保存</u-button>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import {saveEmployee, delEmployee } from '@/api/employee'
  61. import { getRoleList } from '@/api/powerRole-md.js'
  62. import evanForm from '@/components/evan-form/evan-form.vue'
  63. import evanFormItem from '@/components/evan-form-item/evan-form-item.vue'
  64. export default{
  65. components:{
  66. evanForm,
  67. evanFormItem,
  68. },
  69. data(){
  70. return{
  71. showRoles: false,
  72. roleList: [], // 角色 数据列表
  73. roleArr: [], // 当前所选角色
  74. formData:{
  75. name: '',
  76. sex: '1',
  77. mobile: '',
  78. },
  79. ruleValidate: {
  80. name: [{ required: true, message: '请输入员工姓名'}],
  81. mobile: [{required: true, min:11, message: '请输入正确手机号码'}],
  82. sex: [{ required: true, message: '请选择性别' }],
  83. },
  84. sexList: [
  85. {
  86. value: 1,
  87. name: '男',
  88. disabled: false,
  89. },
  90. {
  91. value: 0,
  92. name: '女',
  93. disabled: false
  94. }
  95. ],
  96. isManager: '',
  97. isEdit: false
  98. }
  99. },
  100. onLoad() {
  101. this.init()
  102. this.getRole()
  103. const _this = this;
  104. uni.$on("refashRoleList",function(data){
  105. _this.getRole()
  106. if(data){
  107. _this.formData.roleIds = data.id;
  108. _this.formData.roleNames = data.name;
  109. }
  110. })
  111. },
  112. methods:{
  113. // 初始化数据
  114. init(){
  115. let data = this.$store.state.vuex_nowStaffData
  116. console.log(data)
  117. // 编辑信息
  118. if(!!data){
  119. this.isEdit = true
  120. this.formData = Object.assign({},this.formData,data)
  121. }else{
  122. this.isEdit = false
  123. this.formData.workFlag = '1'
  124. this.formData.userType = '1'
  125. }
  126. // 添加员工或非负责人时显示岗位
  127. if(!this.isEdit || this.formData.isManager==0){
  128. this.ruleValidate.roleNames = [{ required: true, message: '请选择岗位' }]
  129. }
  130. uni.setNavigationBarTitle({
  131. title: !!data ? "编辑员工" : '新增员工'
  132. })
  133. },
  134. // 获取角色
  135. getRole(){
  136. getRoleList().then(res => {
  137. this.roleList = res.data || []
  138. })
  139. },
  140. radioGroupChange(e) {
  141. console.log(e);
  142. this.formData.roleIds = e;
  143. const roleNames = this.roleList.find(item => item.id == e);
  144. this.formData.roleNames = roleNames?roleNames.name:'';
  145. this.showRoles = false
  146. },
  147. toAddRole(){
  148. this.showRoles = false
  149. uni.navigateTo({
  150. url:'/pages/storeManage/roleSetting/addRole?type=add'
  151. })
  152. },
  153. // 保存
  154. save(name){
  155. let data=this.formData
  156. this.$refs[name].validate((valid) => {
  157. if (valid) {
  158. if(!this.formData.roleNames && this.formData.isManager==0){
  159. uni.showToast({icon: 'none', title: '请选择岗位'})
  160. }else{
  161. saveEmployee(data).then(res=>{
  162. console.log(res)
  163. if(res.status == 200){
  164. uni.showToast({icon: 'none', title:'保存成功'})
  165. this.cancel()
  166. }else{
  167. uni.showToast({icon: 'none', title: res.message})
  168. }
  169. })
  170. }
  171. }
  172. })
  173. },
  174. // 删除员工
  175. delPerson(){
  176. let _this = this
  177. const item = this.formData
  178. uni.showModal({
  179. title: '提示',
  180. content: '数据删除后无法恢复, 确认删除吗?',
  181. success: (ret) => {
  182. if(ret.confirm||ret.index==0){
  183. // 删除数据
  184. delEmployee({id: item.id}).then(res=>{
  185. if(res.status == 200){
  186. this.cancel()
  187. }
  188. uni.showToast({icon: 'none', title: res.message})
  189. })
  190. }
  191. }
  192. })
  193. },
  194. cancel(){
  195. setTimeout(function(){
  196. uni.navigateBack()
  197. },100)
  198. }
  199. }
  200. }
  201. </script>
  202. <style lang="less">
  203. .evan-form-show {
  204. padding: 0;
  205. background-color: #fff;
  206. height: 100vh;
  207. > view{
  208. padding:0.8rem;
  209. }
  210. .form-footer-btn{
  211. padding: 0.8rem 1.5rem;
  212. }
  213. .form-input {
  214. font-size: 28rpx;
  215. color: #333;
  216. text-align: right;
  217. width: 95%;
  218. box-sizing: border-box;
  219. height: 60rpx;
  220. &.textarea{
  221. height: 240rpx;
  222. padding: 24rpx 0;
  223. text-align: left;
  224. }
  225. }
  226. .form-input-placeholder {
  227. font-size: 28rpx;
  228. color: #999;
  229. }
  230. }
  231. </style>