index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <uni-forms ref="valiForm" :rules="rules" :modelValue="form" labelWidth="80px">
  5. <uni-forms-item label="用户名" required name="name">
  6. <uni-easyinput v-model="form.name" placeholder="请输入用户名(厂商可以填写工厂名称)" />
  7. </uni-forms-item>
  8. <uni-forms-item label="性别" required name="gender">
  9. <uni-data-checkbox v-model="form.gender" :localdata="genderList" />
  10. </uni-forms-item>
  11. <uni-forms-item label="联系电话" required name="tel">
  12. <uni-easyinput v-model="form.tel" placeholder="请输入联系电话" />
  13. </uni-forms-item>
  14. <uni-forms-item label="密码" required name="password">
  15. <uni-easyinput type="password" v-model="form.password" placeholder="请输入密码" />
  16. </uni-forms-item>
  17. <uni-forms-item label="角色" required name="role">
  18. <uni-data-select v-model="form.role" :localdata="roleList" @change="rolechange"></uni-data-select>
  19. </uni-forms-item>
  20. <uni-forms-item v-if="disabledOne" label="所属街道" required name="street">
  21. <uni-data-select v-model="form.street" :localdata="streetList" @change="streetchange">
  22. </uni-data-select>
  23. </uni-forms-item>
  24. <uni-forms-item v-if="disabledTwo" label="所属社区">
  25. <uni-data-select v-model="form.community" :localdata="commList" @change="commchange">
  26. </uni-data-select>
  27. </uni-forms-item>
  28. </uni-forms>
  29. <button class="button" type="primary" @click="submit('valiForm')">注册</button>
  30. </view>
  31. <view class="two">
  32. <checkbox-group @change="changeAgree">
  33. <label>
  34. <checkbox :checked="agree" />
  35. <text @tap.stop="toAgree()">我已阅读并同意“用户协议”和“隐私政策”</text>
  36. </label>
  37. </checkbox-group>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import moment from 'moment';
  43. export default {
  44. data() {
  45. return {
  46. disabledOne: true,
  47. disabledTwo: true,
  48. form: {},
  49. // 校验规则
  50. rules: {
  51. name: {
  52. rules: [{
  53. required: true,
  54. errorMessage: '姓名不能为空'
  55. }]
  56. },
  57. tel: {
  58. rules: [{
  59. required: true,
  60. errorMessage: '联系电话不能为空'
  61. }, {
  62. format: 'number',
  63. errorMessage: '联系电话只能输入数字'
  64. }]
  65. },
  66. password: {
  67. rules: [{
  68. required: true,
  69. errorMessage: '密码不能为空'
  70. }]
  71. },
  72. gender: {
  73. rules: [{
  74. required: true,
  75. errorMessage: '性别不能为空'
  76. }]
  77. },
  78. role: {
  79. rules: [{
  80. required: true,
  81. errorMessage: '角色不能为空'
  82. }]
  83. },
  84. },
  85. // 字典表
  86. roleList: [],
  87. genderList: [],
  88. streetList: [],
  89. commList: [],
  90. // 用户协议
  91. agree: false,
  92. }
  93. },
  94. async onLoad() {
  95. const that = this;
  96. await that.search();
  97. await that.searchOther();
  98. },
  99. methods: {
  100. async search() {
  101. const that = this;
  102. uni.getStorage({
  103. key: 'openid',
  104. success: function(res) {
  105. that.$set(that.form, `openid`, res.data);
  106. that.$set(that.form, `status`, '0');
  107. },
  108. fail: async function(err) {
  109. uni.showToast({
  110. title: '未获取到opneid',
  111. icon: 'none'
  112. })
  113. },
  114. })
  115. },
  116. // 角色选择
  117. rolechange(role) {
  118. const that = this;
  119. if (role == 'cs') {
  120. that.$set(that, `disabledOne`, false);
  121. that.$set(that, `disabledTwo`, false);
  122. } else if (role == 'sqry') {
  123. that.$set(that, `disabledOne`, true);
  124. that.$set(that, `disabledTwo`, true);
  125. } else {
  126. that.$set(that, `disabledOne`, true);
  127. that.$set(that, `disabledTwo`, false);
  128. }
  129. },
  130. // 所属街道选择
  131. async streetchange(belong) {
  132. const that = this;
  133. that.$set(that.form, `street`, belong);
  134. //所属社区
  135. const res = await that.$api('/Office', 'GET', {
  136. belong,
  137. type: '1',
  138. is_use: '0'
  139. })
  140. if (res.errcode == '0') {
  141. let commList = []
  142. for (let val of res.data) {
  143. commList.push({
  144. text: val.name,
  145. value: val._id
  146. })
  147. }
  148. that.$set(that, `commList`, commList);
  149. }
  150. },
  151. // 所属社区
  152. commchange(community) {
  153. const that = this;
  154. that.$set(that.form, `community`, community);
  155. },
  156. // 同意隐私协议
  157. changeAgree() {
  158. const that = this;
  159. let agree = !that.agree
  160. that.$set(that, `agree`, agree);
  161. },
  162. // 查看隐私协议
  163. toAgree() {
  164. const that = this;
  165. uni.navigateTo({
  166. url: `/pagesOther/other/agree`
  167. })
  168. },
  169. // 注册
  170. submit(ref) {
  171. const that = this;
  172. that.$refs[ref].validate().then(async params => {
  173. if (that.agree) {
  174. that.form.create_time = moment().format('YYYY-MM-DD HH:mm:ss');
  175. const res = await that.$api(`/User`, 'POST', that.form);
  176. if (res.errcode == '0') {
  177. uni.showToast({
  178. title: '注册信息成功',
  179. icon: 'none'
  180. })
  181. uni.navigateBack({
  182. delta: 1
  183. })
  184. } else {
  185. uni.showToast({
  186. title: res.errmsg,
  187. icon: 'none'
  188. })
  189. }
  190. } else {
  191. uni.showToast({
  192. title: '请阅读并同意用户协议和隐私政策',
  193. icon: 'none'
  194. })
  195. }
  196. }).catch(err => {
  197. console.log('err', err);
  198. })
  199. },
  200. async searchOther() {
  201. const that = this;
  202. let res;
  203. //性别
  204. res = await that.$api('/DictData', 'GET', {
  205. type: 'gender',
  206. is_use: '0'
  207. })
  208. if (res.errcode == '0') {
  209. let genderList = []
  210. for (let val of res.data) {
  211. genderList.push({
  212. text: val.label,
  213. value: val.value
  214. })
  215. }
  216. that.$set(that, `genderList`, genderList);
  217. }
  218. //角色
  219. res = await that.$api('/Role', 'GET', {
  220. is_use: '0'
  221. })
  222. if (res.errcode == '0') {
  223. let roleList = []
  224. for (let val of res.data) {
  225. roleList.push({
  226. text: val.name,
  227. value: val.code
  228. })
  229. }
  230. that.$set(that, `roleList`, roleList);
  231. }
  232. //所属街道
  233. res = await that.$api('/Office', 'GET', {
  234. type: '0',
  235. is_use: '0'
  236. })
  237. if (res.errcode == '0') {
  238. let streetList = []
  239. for (let val of res.data) {
  240. streetList.push({
  241. text: val.name,
  242. value: val._id
  243. })
  244. }
  245. that.$set(that, `streetList`, streetList);
  246. }
  247. },
  248. }
  249. }
  250. </script>
  251. <style lang="scss">
  252. .content {
  253. display: flex;
  254. flex-direction: column;
  255. .one {
  256. padding: 3vw;
  257. .button {
  258. background-color: var(--f3CColor);
  259. color: var(--mainColor);
  260. font-size: var(--font14Size);
  261. }
  262. }
  263. .two {
  264. width: 100vw;
  265. text-align: center;
  266. font-size: var(--font12Size);
  267. }
  268. }
  269. </style>