edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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/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.uncomplete = true;
  347. } else {
  348. this.$refs.form.verify();
  349. }
  350. },
  351. uploadCallback(attachmentids, ownertable = 'temporary', ownerid = '99999999') {
  352. if (ownertable == 'temporary') this.imageOnLoading(true)
  353. return new Promise((resolve, reject) => {
  354. this.$Http.basic({
  355. "classname": "system.attachment.Attachment",
  356. "method": "createFileLink",
  357. "content": {
  358. "usetype": "headportrait",
  359. ownertable,
  360. ownerid,
  361. attachmentids
  362. },
  363. }).then(res => {
  364. console.log('绑定附件', res)
  365. if (ownertable == 'temporary') this.imageOnLoading(false)
  366. if (this.cutoff(res.msg)) return resolve(false);
  367. this.headportrait = res.data[0].url;
  368. resolve(true)
  369. if (ownertable == 'temporary' && this.linksid) this.$Http.basic({
  370. "classname": "system.attachment.Attachment",
  371. "method": "deleteFileLink",
  372. "content": {
  373. linksids: [this.linksid]
  374. }
  375. }).then(res => {
  376. console.log("处理删除附件", res)
  377. if (this.cutoff(res.msg)) return;
  378. });
  379. if (ownertable == 'temporary') {
  380. this.attachmentids = attachmentids;
  381. console.log(res.data[0], '结果');
  382. this.headportrait = res.data[0].url;
  383. this.linksid = res.data[0].linksid;
  384. }
  385. })
  386. })
  387. },
  388. },
  389. }
  390. </script>
  391. <style lang="scss" scoped>
  392. .headportrait {
  393. width: 100vw;
  394. padding-left: 10px;
  395. background: #fff;
  396. .content {
  397. display: flex;
  398. align-items: center;
  399. border-bottom: 1px solid #DDDDDD;
  400. box-sizing: border-box;
  401. height: 76px;
  402. padding: 10px;
  403. padding-left: 0;
  404. position: relative;
  405. .avatar-box {
  406. width: 100%;
  407. height: 76px;
  408. position: absolute;
  409. left: 0;
  410. top: 0;
  411. opacity: 0;
  412. }
  413. .label {
  414. font-family: Source Han Sans SC, Source Han Sans SC;
  415. font-size: 14px;
  416. color: #666666;
  417. width: 110px;
  418. }
  419. }
  420. }
  421. .upload-type {
  422. display: flex;
  423. flex-direction: column;
  424. font-family: Source Han Sans SC, Source Han Sans SC;
  425. font-weight: 400;
  426. font-size: 16px;
  427. color: #333333;
  428. .type-line {
  429. padding: 12px 0;
  430. display: flex;
  431. justify-content: space-evenly;
  432. align-items: center;
  433. border-bottom: 1px #DDDDDD solid;
  434. .line-1 {
  435. display: flex;
  436. align-items: center;
  437. align-content: center;
  438. text {
  439. margin-right: 10px;
  440. }
  441. image {
  442. width: 24px !important;
  443. height: 24px !important;
  444. }
  445. }
  446. text {}
  447. }
  448. }
  449. .footer {
  450. position: fixed;
  451. bottom: 0;
  452. width: 100vw;
  453. height: 65px;
  454. background: #FFFFFF;
  455. box-shadow: 0px -2px 6px 1px rgba(0, 0, 0, 0.16);
  456. box-sizing: border-box;
  457. padding: 5px 10px;
  458. display: flex;
  459. .add {
  460. display: flex;
  461. align-items: center;
  462. justify-content: center;
  463. width: 100%;
  464. height: 45px;
  465. background: #C30D23;
  466. border-radius: 5px;
  467. font-family: PingFang SC, PingFang SC;
  468. font-size: 14px;
  469. color: #FFFFFF;
  470. }
  471. .forbidden {
  472. opacity: .6;
  473. }
  474. }</style>