edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <template>
  2. <view style="background: #ffffff;">
  3. <my_form ref="form" :form="form" @isUncomplete="isUncomplete" @onUploading="onUploading" @isShowAll="isShowAll">
  4. <template v-if="isShow" slot="head">
  5. <view class="headportrait" hover-class="navigator-hover">
  6. <view class="content">
  7. <My_upload maxCount="1" ref="upload" @onLoading="imageOnLoading" @uploadCallback="uploadCallback"></My_upload>
  8. <button class="avatar-box" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  9. </button>
  10. <view style="display: flex;align-items: center;">
  11. <view style="border-radius: 50%;width: 56px;height: 56px;border:2px solid #ffffff">
  12. <u--image :width="56" :height="56" shape="circle" :src="headportrait">
  13. <template v-slot:loading>
  14. <u-loading-icon />
  15. </template>
  16. </u--image>
  17. </view>
  18. <view :style="'width:'+tovw(255)" />
  19. <view class="iconfont icon-a-wodetiaozhuan" />
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. </my_form>
  25. <view v-if="!origin" style="height: 70px;" />
  26. <view class="footer">
  27. <view class="add" :class="uncomplete ? 'forbidden' : ''" hover-class="navigator-hover"
  28. @click="uncomplete || loading ? '' : submit()">
  29. <u-loading-icon v-if="loading" />
  30. <block v-else>
  31. {{ origin == 'my' ? '保存' : '保存名片' }}
  32. </block>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import {formattedFiles} from '../../utils/settleFiles.js'
  39. export default {
  40. data() {
  41. return {
  42. sys_enterpriseid: 0,
  43. form: [],
  44. attachmentids: [],
  45. uncomplete: true,
  46. onUpload:false,
  47. copyUncomplete: false,
  48. loading: false,
  49. headportrait: "https://yossys06593.obs.cn-east-3.myhuaweicloud.com:443/202404231713854678447B26b4363.svg",
  50. userid: 0,
  51. isShow: true,
  52. isSubmit:false,
  53. origin:''
  54. }
  55. },
  56. onLoad(options) {
  57. this.userid = options.id
  58. this.origin = options.origin
  59. this.init()
  60. uni.setNavigationBarTitle({
  61. title: '修改名片'
  62. });
  63. },
  64. onUnload() {
  65. if (!this.isSubmit) this.$refs.form.deleteFiles()
  66. },
  67. methods: {
  68. onChooseAvatar (e) {
  69. let ext = e.detail.avatarUrl.substr(e.detail.avatarUrl.lastIndexOf('.')+1)
  70. let name = `${Date.now()}.${ext}`
  71. let temp = {
  72. name:name,
  73. type:'image',
  74. url:e.detail.avatarUrl
  75. }
  76. this.afterRead({file:[temp]})
  77. },
  78. afterRead({ file }) {
  79. const that = this;
  80. file.forEach(v => {
  81. // #ifdef H5
  82. this.getArrayBuffer(v).then(data => that.handleUploadFile(this.requestType(v), data))
  83. // #endif
  84. // #ifndef H5
  85. uni.getFileSystemManager().readFile({
  86. filePath: v.url,
  87. success: data => that.handleUploadFile(this.requestType(v), data.data),
  88. fail: console.error
  89. })
  90. // #endif
  91. });
  92. },
  93. /* 请求类型 */
  94. requestType(file) {
  95. // #ifdef H5
  96. var ext = file.name.substr(file.name.lastIndexOf(".") + 1);
  97. // #endif
  98. // #ifndef H5
  99. var ext = file.type.split("/")[1] || file.url.substr(file.url.lastIndexOf(".") + 1) || file.name.substr(file.name.lastIndexOf(".") + 1);
  100. // #endif
  101. //文件名称
  102. return {
  103. "classname": "system.attachment.huawei.OBS",
  104. "method": "getFileName",
  105. "content": {
  106. "filename": `${Date.now()}.${ext}`,
  107. "filetype": ext,
  108. "parentid": uni.getStorageSync('siteP').appfolderid
  109. }
  110. }
  111. },
  112. handleUploadFile(file, data) {
  113. this.loading = true;
  114. this.$Http.basic(file).then(res => {
  115. if (res.msg == "成功") {
  116. this.uploadFile(res.data, data)
  117. } else {
  118. uni.showToast({
  119. title: `${data.filename}.${data.serialfilename}`,
  120. icon: "none"
  121. })
  122. }
  123. })
  124. },
  125. getArrayBuffer(file) {
  126. return new Promise((resolve, reject) => {
  127. let xhr = new XMLHttpRequest()
  128. xhr.open('GET', file.url, true)
  129. xhr.responseType = 'blob'
  130. xhr.onload = function () {
  131. if (this.status == 200) {
  132. let myBlob = this.response
  133. let files = new window.File([myBlob], file.name, { type: file.url.substr(file.url.lastIndexOf(".") + 1) }) // myBlob.type 自定义文件名
  134. const reader = new FileReader();
  135. reader.readAsArrayBuffer(files);
  136. reader.onload = () => resolve(reader.result);
  137. reader.onerror = (error) => reject(error);
  138. } else {
  139. reject(false)
  140. }
  141. }
  142. xhr.send()
  143. })
  144. },
  145. /* 上传成功反馈 */
  146. uploadFile(res, data) {
  147. var that = this;
  148. that.loading = true;
  149. uni.request({
  150. url: res.uploadurl,
  151. method: "PUT",
  152. data,
  153. header: {
  154. 'content-type': 'application/octet-stream'
  155. },
  156. success() {
  157. that.$Http.basic({
  158. "classname": "system.attachment.huawei.OBS",
  159. "method": "uploadSuccess",
  160. "content": {
  161. "serialfilename": res.serialfilename
  162. }
  163. }).then(s => {
  164. console.log("文件上传反馈", s)
  165. that.loading = false;
  166. if (!that.cutoff(s.msg)) that.uploadCallback(s.data.attachmentids, "sys_users", that.userid)
  167. }).catch(err => {
  168. that.loading = false;
  169. console.error(err)
  170. })
  171. },
  172. fail(err) {
  173. that.loading = false;
  174. console.log(err)
  175. }
  176. })
  177. },
  178. init() {
  179. let form = [{
  180. key: "name",
  181. type: "text",
  182. label: "姓名",
  183. isMust: true,//是否必填
  184. value: "",
  185. }, {
  186. key: "phonenumber",
  187. type: "text",
  188. label: "手机号",
  189. isMust: true,//是否必填
  190. value: "",
  191. placeholder: "请输入手机号",
  192. inputmode: 'number',
  193. verify: [this.getReg("phonenumber")]
  194. }, {
  195. key: "email",
  196. type: "text",
  197. label: "邮箱",
  198. isMust: false,//是否必填
  199. value: "",
  200. verify: [this.getReg("email")]
  201. }, {
  202. key: "address",
  203. type: "text",
  204. label: "地址",
  205. isMust: false,//是否必填
  206. value: "",
  207. },];
  208. if (!this.origin) {
  209. form.push({
  210. key: "remarks",
  211. type: "textarea",
  212. label: "自我介紹",
  213. isMust: false,//是否必填
  214. value: '',
  215. },{
  216. key: "tag",
  217. type: "tag",
  218. label: "印象标签",
  219. isMust: false,//是否必填
  220. marginTop: 10,
  221. placeholder:'请填写,最多十个字',
  222. verify:[{
  223. reg: '^.{1,10}$',
  224. errText: "限制1-10字!"
  225. }],
  226. value: [],
  227. },{
  228. key: "attachmentids",
  229. type: "upload",
  230. label: "图片",
  231. placeholder: "可上传多个图片",
  232. accept: "image*/",
  233. ownertable: "temporary",
  234. ownerid: 999,
  235. usetype: 'default',
  236. allowUpload: true,
  237. allowDelete: true,
  238. value: [],
  239. marginTop: 10
  240. })
  241. }
  242. this.$Http.basic({
  243. "id": 20240514161502,
  244. "content": {
  245. userid:this.userid
  246. },
  247. }).then(res => {
  248. console.log("获取个人信息", res)
  249. if (this.cutoff(res.msg)) return;
  250. if (res.msg == '成功') {
  251. this.headportraits = res.data.attinfos;
  252. this.headportrait = this.headportraits.find(v => v.usetype == "headportrait") && this.headportraits.find(v => v.usetype == "headportrait").url || this.headportrait;
  253. form = form.map(v => {
  254. if (v.key == 'attachmentids') {
  255. v.value = formattedFiles(res.data.attinfos.filter(item => item.usetype != 'headportrait'))
  256. } else {
  257. v.value = res.data[v.key] || v.value
  258. }
  259. return v
  260. })
  261. }
  262. this.form = form;
  263. })
  264. },
  265. onUploading(ing) {
  266. this.onUpload = ing;
  267. },
  268. isUncomplete(uncomplete) {
  269. console.log(uncomplete);
  270. this.uncomplete = uncomplete;
  271. },
  272. submit() {
  273. this.loading = true;
  274. let that = this;
  275. this.$refs.form.submit().then(data => {
  276. this.$Http.basic({
  277. "id": 20220929090901,
  278. "content": {
  279. "ownertable": "sys_users",
  280. "ownerid": this.userid,
  281. "datatag": data.tag
  282. },
  283. })
  284. this.$Http.basic({
  285. "id": 20240511151602,
  286. "content": {
  287. ...data
  288. }
  289. }).then(async res => {
  290. this.loading = false;
  291. console.log("修改信息", res)
  292. if (this.cutoff(res.msg)) return;
  293. if (!this.origin && data.files.temporarys.length) {
  294. this.onUpload = true;
  295. await this.$Http.basic({
  296. "classname": "system.attachment.Attachment",
  297. "method": "createFileLink",
  298. "content": {
  299. ownertable: 'sys_users',
  300. ownerid: res.data.userid,
  301. usetype: 'default',
  302. attachmentids: data.files.temporarys
  303. }
  304. }).then(async s => {
  305. this.isSubmit = true;
  306. this.onUpload = false;
  307. console.log("绑定附加", s)
  308. if (this.cutoff(s.msg)) return;
  309. })
  310. };
  311. this.loading = true;
  312. if (!this.origin && data.files.linksids.length) {
  313. await this.$Http.basic({
  314. "classname": "system.attachment.Attachment",
  315. "method": "deleteFileLink",
  316. "content": {
  317. linksids: data.files.linksids
  318. }
  319. })
  320. }
  321. if (this.attachmentids.length) {
  322. this.uploadCallback(this.attachmentids, "sys_users", this.userid).then(s => {
  323. if (s) getUserMsg()
  324. });
  325. if (this.headportraits.length) this.$Http.basic({
  326. "classname": "system.attachment.Attachment",
  327. "method": "deleteFileLink",
  328. "content": {
  329. linksids: this.headportraits.map(v => v.linksid)
  330. }
  331. })
  332. } else {
  333. this.$Http.editUser(res.data.userid)
  334. uni.navigateBack()
  335. }
  336. //刷新首页用户信息
  337. this.$Http.refreshUserInfoData && this.$Http.refreshUserInfoData()
  338. })
  339. })
  340. },
  341. isShowAll(e) {
  342. this.isShow = !e;
  343. },
  344. imageOnLoading(e) {
  345. if (e) {
  346. this.copyUncomplete = this.uncomplete;
  347. this.uncomplete = true;
  348. } else {
  349. this.uncomplete = this.copyUncomplete;
  350. }
  351. },
  352. uploadCallback(attachmentids, ownertable = 'temporary', ownerid = '99999999') {
  353. if (ownertable == 'temporary') this.imageOnLoading(true)
  354. return new Promise((resolve, reject) => {
  355. this.$Http.basic({
  356. "classname": "system.attachment.Attachment",
  357. "method": "createFileLink",
  358. "content": {
  359. "usetype": "headportrait",
  360. ownertable,
  361. ownerid,
  362. attachmentids
  363. },
  364. }).then(res => {
  365. console.log('绑定附件', res)
  366. if (ownertable == 'temporary') this.imageOnLoading(false)
  367. if (this.cutoff(res.msg)) return resolve(false);
  368. this.headportrait = res.data[0].url;
  369. resolve(true)
  370. if (ownertable == 'temporary' && this.linksid) this.$Http.basic({
  371. "classname": "system.attachment.Attachment",
  372. "method": "deleteFileLink",
  373. "content": {
  374. linksids: [this.linksid]
  375. }
  376. }).then(res => {
  377. console.log("处理删除附件", res)
  378. if (this.cutoff(res.msg)) return;
  379. });
  380. if (ownertable == 'temporary') {
  381. this.attachmentids = attachmentids;
  382. console.log(res.data[0],'结果');
  383. this.headportrait = res.data[0].url;
  384. this.linksid = res.data[0].linksid;
  385. }
  386. })
  387. })
  388. },
  389. },
  390. }
  391. </script>
  392. <style lang="scss" scoped>
  393. .headportrait {
  394. width: 100vw;
  395. padding-left: 10px;
  396. background: #fff;
  397. .content {
  398. display: flex;
  399. align-items: center;
  400. border-bottom: 1px solid #DDDDDD;
  401. box-sizing: border-box;
  402. height: 76px;
  403. padding: 10px;
  404. padding-left: 0;
  405. position: relative;
  406. .avatar-box {
  407. width: 100%;
  408. height: 76px;
  409. position: absolute;
  410. left: 0;
  411. top: 0;
  412. opacity: 0;
  413. }
  414. .label {
  415. font-family: Source Han Sans SC, Source Han Sans SC;
  416. font-size: 14px;
  417. color: #666666;
  418. width: 110px;
  419. }
  420. }
  421. }
  422. .upload-type {
  423. display: flex;
  424. flex-direction: column;
  425. font-family: Source Han Sans SC, Source Han Sans SC;
  426. font-weight: 400;
  427. font-size: 16px;
  428. color: #333333;
  429. .type-line {
  430. padding: 12px 0;
  431. display: flex;
  432. justify-content: space-evenly;
  433. align-items: center;
  434. border-bottom: 1px #DDDDDD solid;
  435. .line-1 {
  436. display: flex;
  437. align-items: center;
  438. align-content: center;
  439. text {
  440. margin-right: 10px;
  441. }
  442. image {
  443. width: 24px !important;
  444. height: 24px !important;
  445. }
  446. }
  447. text {}
  448. }
  449. }
  450. .footer {
  451. position: fixed;
  452. bottom: 0;
  453. width: 100vw;
  454. height: 65px;
  455. background: #FFFFFF;
  456. box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
  457. box-sizing: border-box;
  458. padding: 5px 10px;
  459. display: flex;
  460. .add {
  461. display: flex;
  462. align-items: center;
  463. justify-content: center;
  464. width: 100%;
  465. height: 45px;
  466. background: #C30D23;
  467. border-radius: 5px;
  468. font-family: PingFang SC, PingFang SC;
  469. font-size: 14px;
  470. color: #FFFFFF;
  471. }
  472. .forbidden {
  473. opacity: .6;
  474. }
  475. }
  476. </style>