edit.vue 18 KB

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