Add.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <div>
  3. <common @asynCallBack="asynCallBack"></common>
  4. <top-header :pageTitle="pageTitle" :rightLink="rightLink" :doRightLink="doRightLink"></top-header>
  5. <div class="mui-content">
  6. <div class="mui-content-padded vongi-qingjiadt">
  7. <form class="mui-input-group">
  8. <div class="mui-input-row">
  9. <label>小区名称</label>
  10. <span v-text="subForm.companyName"></span>
  11. </div>
  12. <div class="mui-input-row">
  13. <label>房号</label>
  14. <span v-text="subForm.structureName"></span>
  15. </div>
  16. </form>
  17. </div>
  18. <div class="mui-content-padded vongi-qingjiadt vongi-editme marginbo">
  19. <form class="mui-input-group">
  20. <div class="mui-input-row">
  21. <label style="width:40%">租客姓名<i class="colorfe616c">*</i></label>
  22. <input type="text" style="width: 60%;" v-model="subForm.name" class="mui-input-clear" placeholder="请输入租客姓名">
  23. </div>
  24. <div class="mui-input-row">
  25. <label>手机号码</label>
  26. <input type="number" v-model="subForm.phone" class="mui-input-clear" placeholder="请输入手机号码">
  27. </div>
  28. <div class="mui-input-row">
  29. <label>身份证号</label>
  30. <input type="text" v-model="subForm.idCard" class="mui-input-clear" placeholder="请输入身份证号">
  31. </div>
  32. <div class="mui-input-row">
  33. <label style="width:50%">人脸识别照片<i class="colorfe616c">*</i><i class="iconfont icon-tishi color4fc5f7" @click="valert"></i></label>
  34. <button @click="chooseImage('faceImageUrl') " class="mui-btn mui-btn-block mui-navigate-right" type='button'
  35. style="width:50%">
  36. <img v-if="subForm.faceImageUrl" :src="subForm.faceImageUrl" />
  37. <a v-else>请选择</a>
  38. </button>
  39. </div>
  40. </form>
  41. </div>
  42. </div>
  43. <div class="fyy-footer">
  44. <div class="bindfyy-btn"><button type="button" @click="submit" class="mui-btn mui-btn-primary ">保 存</button></div>
  45. </div>
  46. <loading :visible="isLoading"></loading>
  47. <!--图片裁剪-->
  48. <cropper :cwidth="cropperWidth" :cheight="cropperHeight" :visible="cropperVisible" :field="cropperField" :cropper="cropper"
  49. @cropperFinish="cropperFinish" @cropperCancel="cropperCancel"></cropper>
  50. </div>
  51. </template>
  52. <script>
  53. import * as API_Family from '@/apis/Master/family'
  54. import Common from '$project/components/Common.vue'
  55. import Loading from '$project/components/Loading.vue'
  56. import isReachBottom from '$project/utils/isReachBottom'
  57. import TopHeader from '$project/components/TopHeader.vue'
  58. import {
  59. checkPhone,
  60. checkIdCard
  61. } from '$project/utils'
  62. import {
  63. mapGetters,
  64. mapMutations
  65. } from 'vuex'
  66. import Cropper from '$project/components/Cropper.vue'
  67. import * as WxJsApi from '$project/utils/wxJsApi'
  68. export default {
  69. name: 'MasterTenantAdd',
  70. components: {
  71. Common,
  72. Loading,
  73. TopHeader,
  74. Cropper
  75. },
  76. data() {
  77. return {
  78. pageTitle: '添加租客账号',
  79. isLoading: false,
  80. rightLink: {
  81. show: true,
  82. icon: 'mui-icon-trash',
  83. style: 'color:#FF6666',
  84. title: ''
  85. },
  86. subForm: {
  87. companyName: '',
  88. faceImageUrl: '',
  89. id: this.$route.query.id,
  90. idCard: '',
  91. name: '',
  92. phone: '',
  93. structureName: '',
  94. type: '1'
  95. },
  96. imgBase64: '',
  97. cropperVisible: '',
  98. cropperField: '',
  99. cropperWidth: 250,
  100. cropperHeight: 350,
  101. cropper: {
  102. img: '',
  103. info: true,
  104. size: 1,
  105. outputType: 'jpeg',
  106. canScale: false,
  107. autoCrop: true,
  108. // 只有自动截图开启 宽度高度才生效
  109. autoCropWidth: 250,
  110. autoCropHeight: 350,
  111. fixed: true,
  112. // 真实的输出宽高
  113. infoTrue: true,
  114. fixedNumber: [5, 7]
  115. },
  116. }
  117. },
  118. created() {
  119. if (this.person_popedom.companyName) {
  120. this.subForm.companyName = this.person_popedom.companyName;
  121. }
  122. if (this.person_popedom.structureName) {
  123. this.subForm.structureName = this.person_popedom.structureName;
  124. }
  125. },
  126. methods: {
  127. //获取详情
  128. getDetail() {
  129. this.isLoading = true;
  130. API_Family.getPersonInfo(this.subForm.id).then(response => {
  131. this.isLoading = false;
  132. this.subForm = response;
  133. }).catch(error => {
  134. this.isLoading = false;
  135. mui.toast(error);
  136. })
  137. },
  138. //检测
  139. checkForm() {
  140. let phoneResult = checkPhone(this.subForm.phone);
  141. let idCardResult = checkIdCard(this.subForm.idCard);
  142. if (!this.subForm.name) {
  143. mui.toast('请输入姓名');
  144. return false;
  145. } else if (this.subForm.phone&& typeof phoneResult == 'string') {
  146. mui.toast(phoneResult);
  147. return false;
  148. } else if (this.subForm.idCard && typeof idCardResult == 'string') {
  149. mui.toast(idCardResult);
  150. return false;
  151. } else if (!this.subForm.faceImageUrl) {
  152. mui.toast('请上传人脸识别照片');
  153. return false;
  154. } else {
  155. return true;
  156. }
  157. },
  158. //提交
  159. submit() {
  160. if (this.checkForm()) {
  161. this.isLoading = true;
  162. API_Family.addPerson(this.subForm).then(response => {
  163. this.isLoading = false;
  164. mui.toast(this.actionTitle + '成功');
  165. this.$router.go(-1);
  166. }).catch(error => {
  167. this.isLoading = false;
  168. mui.toast(error);
  169. })
  170. }
  171. },
  172. //微信选择图片
  173. chooseImage(field) {
  174. WxJsApi.chooseImage().then(res => {
  175. var localData = res.localData;
  176. if (localData.indexOf('data:image') != 0) {
  177. //判断是否有这样的头部
  178. localData = 'data:image/jpeg;base64,' + localData
  179. }
  180. localData = localData.replace(/\r|\n/g, '').replace('data:image/jgp', 'data:image/jpeg')
  181. this.imgBase64 = localData;
  182. //显示裁剪图片
  183. this.showCropper(field);
  184. //this.uploadpic(field);
  185. }).catch(error => {
  186. mui.toast(error);
  187. })
  188. },
  189. //显示裁剪图片
  190. showCropper(field) {
  191. this.cropper.img = this.imgBase64;
  192. this.cropperField = field;
  193. this.cropperVisible = true;
  194. },
  195. //裁剪图片
  196. cropperFinish(obj) {
  197. console.log(obj);
  198. this.imgBase64 = obj.data;
  199. this.uploadpic(obj.field);
  200. this.cropperVisible = false;
  201. },
  202. //隐藏裁剪图片
  203. cropperCancel() {
  204. this.cropperVisible = false;
  205. },
  206. //上传图片
  207. uploadpic(field) {
  208. this.isLoading = true;
  209. WxJsApi.uploadPic(this.imgBase64).then(response => {
  210. this.isLoading = false;
  211. this.subForm[field] = response;
  212. }).catch(error => {
  213. this.isLoading = false;
  214. mui.toast(error);
  215. })
  216. },
  217. //弹窗
  218. valert() {
  219. mui.alert("照片将用于人脸识别设备,请上传清晰的免冠登记照或肩部以上近照。", ' ', ['知道了'])
  220. },
  221. del() {
  222. this.isLoading = true;
  223. API_Family.delPerson(this.subForm.popedomId).then(response => {
  224. this.isLoading = false;
  225. mui.toast('删除成功');
  226. this.$router.go(-1);
  227. }).catch(error => {
  228. this.isLoading = false;
  229. mui.toast(error);
  230. })
  231. },
  232. //右上角点击事件
  233. doRightLink() {
  234. var _this = this;
  235. var btnArray = ['否', '是'];
  236. mui.confirm('确认删除此租户?', '确认删除', btnArray, function(e) {
  237. if (e.index == 1) {
  238. _this.del();
  239. }
  240. })
  241. },
  242. asynCallBack() {
  243. },
  244. },
  245. mounted() {
  246. //获取微信配置
  247. WxJsApi.getWxConfig();
  248. if (this.subForm.id) {
  249. //获取详情
  250. this.getDetail();
  251. } else {
  252. this.rightLink.show = false;
  253. }
  254. },
  255. destroyed() {
  256. },
  257. computed: {
  258. actionTitle: {
  259. // getter
  260. get: function() {
  261. return this.subForm.id ? '修改' : '添加';
  262. },
  263. // setter
  264. set: function(newValue) {
  265. console.log(newValue)
  266. }
  267. },
  268. ...mapGetters({
  269. openId: 'wx_openid',
  270. token: 'token',
  271. person_data: 'person_data',
  272. person_popedom: 'person_popedom',
  273. })
  274. }
  275. }
  276. </script>
  277. <style scoped src="$project/assets/css/xpwyfyy.css"></style>
  278. <style src="$project/assets/css/iconfont.css"></style>
  279. <style>
  280. </style>