edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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">
  8. </My_upload>
  9. <button class="avatar-box" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  10. </button>
  11. <view style="display: flex;align-items: center;">
  12. <view style="border-radius: 50%;width: 56px;height: 56px;border:2px solid #ffffff">
  13. <u--image :width="56" :height="56" shape="circle" :src="headportrait">
  14. <template v-slot:loading>
  15. <u-loading-icon />
  16. </template>
  17. </u--image>
  18. </view>
  19. <view :style="'width:' + tovw(255)" />
  20. <view class="iconfont icon-a-wodetiaozhuan" />
  21. </view>
  22. </view>
  23. </view>
  24. </template>
  25. </my_form>
  26. <view v-if="!origin" style="height: 70px;" />
  27. <view class="footer">
  28. <view class="add" :class="uncomplete ? 'forbidden' : ''" hover-class="navigator-hover"
  29. @click="uncomplete || loading ? '' : submit()">
  30. <u-loading-icon v-if="loading" />
  31. <block v-else>
  32. {{ origin == 'my' ? '保存' : '保存名片' }}
  33. </block>
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { formattedFiles } from '../../utils/settleFiles.js'
  40. export default {
  41. data() {
  42. return {
  43. sys_enterpriseid: 0,
  44. form: [],
  45. attachmentids: [],
  46. uncomplete: true,
  47. onUpload: false,
  48. loading: false,
  49. headportrait: "https://yossys06593.obs.cn-east-3.myhuaweicloud.com:443/202406011717209838416B6150695f.webp",
  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. maxlength:10,
  222. placeholder: '请填写,最多十个字',
  223. verify: [{
  224. reg: '^.{1,10}$',
  225. errText: "限制1-10字!"
  226. }],
  227. value: [],
  228. }, {
  229. key: "attachmentids",
  230. type: "upload",
  231. label: "图片",
  232. placeholder: "可上传多个图片",
  233. accept: "image*/",
  234. ownertable: "temporary",
  235. ownerid: 999,
  236. usetype: 'default',
  237. allowUpload: true,
  238. allowDelete: true,
  239. value: [],
  240. marginTop: 10
  241. })
  242. }
  243. this.$Http.basic({
  244. "id": 20240514161502,
  245. "content": {
  246. userid: this.userid
  247. },
  248. }).then(res => {
  249. console.log("获取个人信息", res)
  250. if (this.cutoff(res.msg)) return;
  251. if (res.msg == '成功') {
  252. this.headportraits = res.data.attinfos;
  253. this.headportrait = this.headportraits.find(v => v.usetype == "headportrait") && this.headportraits.find(v => v.usetype == "headportrait").url || this.headportrait;
  254. form = form.map(v => {
  255. if (v.key == 'attachmentids') {
  256. v.value = formattedFiles(res.data.attinfos.filter(item => item.usetype != 'headportrait'))
  257. } else {
  258. v.value = res.data[v.key] || v.value
  259. }
  260. return v
  261. })
  262. }
  263. this.form = form;
  264. })
  265. },
  266. onUploading(ing) {
  267. this.onUpload = ing;
  268. },
  269. isUncomplete(uncomplete) {
  270. console.log(uncomplete);
  271. this.uncomplete = uncomplete;
  272. },
  273. submit() {
  274. this.loading = true;
  275. let that = this;
  276. this.$refs.form.submit().then(data => {
  277. this.$Http.basic({
  278. "id": 20220929090901,
  279. "content": {
  280. "ownertable": "sys_users",
  281. "ownerid": this.userid,
  282. "datatag": data.tag
  283. },
  284. })
  285. this.$Http.basic({
  286. "id": 20240511151602,
  287. "content": {
  288. ...data
  289. }
  290. }).then(async res => {
  291. this.loading = false;
  292. console.log("修改信息", res)
  293. if (this.cutoff(res.msg)) return;
  294. if (!this.origin && data.files.temporarys.length) {
  295. this.onUpload = true;
  296. await this.$Http.basic({
  297. "classname": "system.attachment.Attachment",
  298. "method": "createFileLink",
  299. "content": {
  300. ownertable: 'sys_users',
  301. ownerid: res.data.userid,
  302. usetype: 'default',
  303. attachmentids: data.files.temporarys
  304. }
  305. }).then(async s => {
  306. this.isSubmit = true;
  307. this.onUpload = false;
  308. console.log("绑定附加", s)
  309. if (this.cutoff(s.msg)) return;
  310. })
  311. };
  312. this.loading = true;
  313. if (!this.origin && data.files.linksids.length) {
  314. await this.$Http.basic({
  315. "classname": "system.attachment.Attachment",
  316. "method": "deleteFileLink",
  317. "content": {
  318. linksids: data.files.linksids
  319. }
  320. })
  321. }
  322. if (this.attachmentids.length) {
  323. this.uploadCallback(this.attachmentids, "sys_users", this.userid).then(s => {
  324. if (s) getUserMsg()
  325. });
  326. if (this.headportraits.length) this.$Http.basic({
  327. "classname": "system.attachment.Attachment",
  328. "method": "deleteFileLink",
  329. "content": {
  330. linksids: this.headportraits.map(v => v.linksid)
  331. }
  332. })
  333. } else {
  334. this.$Http.editUser(res.data.userid)
  335. uni.navigateBack()
  336. }
  337. //刷新首页用户信息
  338. this.$Http.refreshUserInfoData && this.$Http.refreshUserInfoData()
  339. })
  340. })
  341. },
  342. isShowAll(e) {
  343. this.isShow = !e;
  344. },
  345. imageOnLoading(e) {
  346. if (e) {
  347. this.uncomplete = true;
  348. } else {
  349. this.$refs.form.verify();
  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. box-sizing: border-box;
  398. .content {
  399. display: flex;
  400. align-items: center;
  401. border-bottom: 1px solid #DDDDDD;
  402. box-sizing: border-box;
  403. height: 76px;
  404. padding: 10px;
  405. padding-left: 0;
  406. position: relative;
  407. .avatar-box {
  408. width: 100%;
  409. height: 76px;
  410. position: absolute;
  411. left: 0;
  412. top: 0;
  413. opacity: 0;
  414. }
  415. .label {
  416. font-family: Source Han Sans SC, Source Han Sans SC;
  417. font-size: 14px;
  418. color: #666666;
  419. width: 110px;
  420. }
  421. }
  422. }
  423. .upload-type {
  424. display: flex;
  425. flex-direction: column;
  426. font-family: Source Han Sans SC, Source Han Sans SC;
  427. font-weight: 400;
  428. font-size: 16px;
  429. color: #333333;
  430. .type-line {
  431. padding: 12px 0;
  432. display: flex;
  433. justify-content: space-evenly;
  434. align-items: center;
  435. border-bottom: 1px #DDDDDD solid;
  436. .line-1 {
  437. display: flex;
  438. align-items: center;
  439. align-content: center;
  440. text {
  441. margin-right: 10px;
  442. }
  443. image {
  444. width: 24px !important;
  445. height: 24px !important;
  446. }
  447. }
  448. text {}
  449. }
  450. }
  451. .footer {
  452. position: fixed;
  453. bottom: 0;
  454. width: 100vw;
  455. height: 65px;
  456. background: #FFFFFF;
  457. box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
  458. box-sizing: border-box;
  459. padding: 5px 10px;
  460. display: flex;
  461. .add {
  462. display: flex;
  463. align-items: center;
  464. justify-content: center;
  465. width: 100%;
  466. height: 45px;
  467. background: #C30D23;
  468. border-radius: 5px;
  469. font-family: PingFang SC, PingFang SC;
  470. font-size: 14px;
  471. color: #FFFFFF;
  472. }
  473. .forbidden {
  474. opacity: .6;
  475. }
  476. }
  477. </style>