edit.vue 15 KB

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