add.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <div class="app-content">
  3. <div v-show="showStaffArea">
  4. <!-- 员工信息 -->
  5. <form @submit="formSubmit" @reset="formReset">
  6. <div class="module-com input-line-wrap">
  7. <tui-list-cell class="line-cell" :hover="false">
  8. <div class="tui-title required">姓名</div>
  9. <input
  10. v-model="form.name"
  11. placeholder-class="phcolor"
  12. class="tui-input"
  13. name="name"
  14. placeholder="请输入姓名"
  15. maxlength="50"
  16. type="text"
  17. />
  18. </tui-list-cell>
  19. <tui-list-cell class="line-cell" :arrow="true">
  20. <div class="tui-title required">角色</div>
  21. <picker
  22. mode="selector"
  23. :value="form.roleId"
  24. :range="roleList"
  25. range-key="roleName"
  26. @change="changeRoleFn"
  27. class="tui-input"
  28. >
  29. <input v-model="form.roleId" name="roleId" type="text" hidden />
  30. <div v-if="form.roleId">{{ roleSelData.roleName }}</div>
  31. <div class="tui-placeholder" v-else>请选择</div>
  32. </picker>
  33. </tui-list-cell>
  34. </div>
  35. <!-- 收款通知 -->
  36. <div class="module-com input-line-wrap">
  37. <tui-list-cell class="line-cell between" padding="14rpx 30rpx" :hover="false">
  38. <div class="tui-title">收款通知</div>
  39. <div>
  40. <switch :checked="form.remind == 0 ? false : true" @change="remindChangeFn" />
  41. </div>
  42. </tui-list-cell>
  43. </div>
  44. <!-- 马上启用 -->
  45. <div class="module-com input-line-wrap">
  46. <tui-list-cell class="line-cell between" padding="14rpx 30rpx" :hover="false">
  47. <div class="tui-title">启用状态</div>
  48. <div>
  49. <switch :checked="form.status == 0 ? false : true" @change="statusChangeFn" />
  50. </div>
  51. </tui-list-cell>
  52. </div>
  53. <!-- 登录信息 -->
  54. <div class="module-com input-line-wrap">
  55. <tui-list-cell class="line-cell" :hover="false">
  56. <div class="tui-title">登录密码</div>
  57. <input
  58. v-model="form.password"
  59. placeholder-class="phcolor"
  60. class="tui-input"
  61. name="password"
  62. placeholder="请输入"
  63. maxlength="50"
  64. type="password"
  65. />
  66. </tui-list-cell>
  67. <tui-list-cell class="line-cell remark-wrap" :hover="false">
  68. <div class="tui-title">备注信息</div>
  69. <div class="tui-input">
  70. <textarea
  71. v-model="form.remark"
  72. class="tui-textarea remark"
  73. placeholder-class="phcolor"
  74. placeholder="请输入内容"
  75. />
  76. </div>
  77. </tui-list-cell>
  78. </div>
  79. <!-- 提交 -->
  80. <div class="confirm-btn">
  81. <button class="admin-button-com big blue" formType="submit">提交</button>
  82. </div>
  83. </form>
  84. </div>
  85. <div v-show="showMiniCodeArea">
  86. <view style="text-align:center;">
  87. <image style="width:200px;height:200px;margin:0 auto;" :src="miniCodeSrc"></image>
  88. <view style="text-align:center;margin-top:20px;margin-bottom:20px;">请让员工扫描上方太阳码完成绑定</view>
  89. <button class="admin-button-com big blue" @click="complete" style="padding-left:23px;padding-right:23px;">完成</button>
  90. </view>
  91. </div>
  92. </div>
  93. </template>
  94. <script>
  95. import TuiListCell from "@/components/plugin/list-cell";
  96. import AppAvatarModule from "@/components/module/app-avatar";
  97. const form = require("@/utils/formValidation.js");
  98. // api
  99. import {
  100. getRoleList,
  101. getStaffDet as getDet,
  102. updateStaff as update
  103. } from "@/api/staff";
  104. import { getDet as getMemberDet } from "@/api/member";
  105. import { prepareBind } from "@/api/shop-admin";
  106. export default {
  107. name: "staff-add",
  108. components: {
  109. TuiListCell,
  110. AppAvatarModule
  111. },
  112. data() {
  113. return {
  114. form: {
  115. name: "",
  116. //mobile: '',
  117. roleId: "",
  118. remind: 1,
  119. password: "",
  120. //userId: '',
  121. status: 1,
  122. remark: "",
  123. },
  124. roleList: [],
  125. roleSelData: {},
  126. showStaffArea: true,
  127. showMiniCodeArea: false,
  128. miniCodeSrc:'',
  129. memberData: {}
  130. };
  131. },
  132. onLoad() {
  133. // this.init()
  134. },
  135. onShow() {
  136. if (this.option.id) {
  137. uni.setNavigationBarTitle({
  138. title: `修改员工`
  139. });
  140. } else {
  141. uni.setNavigationBarTitle({
  142. title: `添加员工`
  143. });
  144. }
  145. },
  146. methods: {
  147. init() {
  148. let data = uni.getStorageSync("addStaffData");
  149. if (data) {
  150. uni.removeStorageSync("addStaffData");
  151. this.form = data.form;
  152. this.roleList = data.roleList;
  153. this.roleSelData = data.roleSelData;
  154. }
  155. let memberData = uni.getStorageSync("addSelMember");
  156. if (memberData) {
  157. uni.removeStorageSync("addSelMember");
  158. this.memberData = memberData;
  159. this.form.userId = memberData.id;
  160. }
  161. if (data) return false;
  162. this._getRoleList().then(res => {
  163. if (this.option.id) {
  164. this._getDet();
  165. }
  166. });
  167. },
  168. // api
  169. async _getRoleList() {
  170. await getRoleList().then(res => {
  171. if (this.$util.isEmpty(res.data)) return false;
  172. this.roleList = res.data.list;
  173. });
  174. },
  175. _getDet() {
  176. getDet({ id: this.option.id }).then(res => {
  177. if (this.$util.isEmpty(res.data)) return;
  178. Object.keys(this.form).forEach((i, index) => {
  179. // if (i != 'password') {
  180. this.form[i] = res.data[i];
  181. // }
  182. });
  183. this.roleSelData = this.roleList.filter(
  184. e => this.form.roleId == e.id
  185. )[0];
  186. if (this.form.userId && this.form.userId != "0") {
  187. this._getMemberDet();
  188. }
  189. });
  190. },
  191. // 获取客户详情
  192. _getMemberDet() {
  193. getMemberDet({ userId: this.form.userId }).then(res => {
  194. if (this.$util.isEmpty(res.data)) return;
  195. this.memberData = res.data;
  196. });
  197. },
  198. // option
  199. // 关联微信
  200. selMemberFn() {
  201. let data = {
  202. form: this.form,
  203. roleList: this.roleList,
  204. roleSelData: this.roleSelData
  205. };
  206. uni.setStorageSync("addStaffData", data);
  207. this.$util.pageTo({
  208. url: "/admin/staff/sel-member",
  209. query: {
  210. ...this.option
  211. }
  212. });
  213. },
  214. changeRoleFn(e) {
  215. this.roleSelData = this.roleList[e.detail.value];
  216. this.form.roleId = this.roleSelData.id;
  217. },
  218. remindChangeFn(e) {
  219. this.form.remind = e.detail.value ? 1 : 0;
  220. },
  221. statusChangeFn(e) {
  222. this.form.status = e.detail.value ? 1 : 0;
  223. },
  224. confirmFn() {
  225. let hostFn = this.option.id ? update : prepareBind;
  226. if (this.option.id) {
  227. this.form.id = this.option.id;
  228. }
  229. hostFn(this.form).then(res => {
  230. console.log('23rh23r23')
  231. console.log(res)
  232. console.log(this.option.id)
  233. if(typeof(this.option.id) == 'undefined'){
  234. this.showMiniCodeArea = true;
  235. this.miniCodeSrc = res.data.miniCode;
  236. this.showStaffArea = false;
  237. console.log(this.miniCodeSrc)
  238. console.log('--oo0oooo---')
  239. }else{
  240. let promptText = this.option.id ? "修改成功!" : "添加成功!";
  241. this.$msg(promptText);
  242. setTimeout(() => {
  243. this.$util.pageTo({
  244. url: "/admin/staff/list",
  245. type: 2
  246. });
  247. }, 1000);
  248. }
  249. });
  250. },
  251. complete(){
  252. this.$util.pageTo(1)
  253. },
  254. // 表单验证
  255. formSubmit(e) {
  256. // 表单规则
  257. let rules = [
  258. {
  259. name: "name",
  260. rule: ["required"],
  261. msg: ["请输入姓名"]
  262. },
  263. // {
  264. // name: 'mobile',
  265. // rule: ['required'],
  266. // msg: ['请输入手机号']
  267. // },
  268. {
  269. name: "roleId",
  270. rule: ["required"],
  271. msg: ["请选择角色"]
  272. }
  273. // {
  274. // name: 'userId',
  275. // rule: ['required'],
  276. // msg: ['请选择关联微信']
  277. // }
  278. // {
  279. // name: 'password',
  280. // rule: ['required'],
  281. // msg: ['请输入密码']
  282. // }
  283. ];
  284. // 进行表单检查
  285. let formData = e.detail.value;
  286. let checkRes = form.validation(formData, rules);
  287. // 验证通过!
  288. if (!checkRes) {
  289. this.confirmFn();
  290. } else {
  291. this.$msg(checkRes);
  292. }
  293. }
  294. }
  295. };
  296. </script>
  297. <style lang="scss" scoped>
  298. .app-content {
  299. min-height: calc(100vh - 20px);
  300. padding-top: 20px;
  301. }
  302. .prompt-text {
  303. color: $fontColor3;
  304. padding-left: 30px;
  305. margin-bottom: 30px;
  306. }
  307. // ---
  308. .module-com {
  309. margin-bottom: 20px;
  310. .member-wrap {
  311. .member-det {
  312. font-size: 24px;
  313. margin-left: 20px;
  314. }
  315. }
  316. .remark-wrap {
  317. align-items: flex-start;
  318. .remark {
  319. height: 240px;
  320. }
  321. }
  322. }
  323. // 按钮
  324. .confirm-btn {
  325. width: calc(100% - 60px);
  326. margin: 60px 30px 20px;
  327. .admin-button-com {
  328. width: 100%;
  329. }
  330. }
  331. </style>