fieldForm.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <view class="content">
  3. <view class="supplyInfo">
  4. <view class="flex">
  5. <label>公司名称:</label>
  6. <input type="text" v-model="supplyInfo.name" class="input card" />
  7. </view>
  8. <view class="flex">
  9. <label>活动人数:</label>
  10. <input type="number" v-model="supplyInfo.nums" class="input card" />
  11. </view>
  12. <view class="update_photo">
  13. <view class="title"></view>
  14. <view style="margin-bottom: 20rpx;">上传资料:</view>
  15. <view class="update_container card upload-parent-box">
  16. <view class="update_button display-flex">
  17. <view class="upload-box" @click="getImage('album')">
  18. <view class="img">
  19. <image src="/static/appeal/photo.png" class="photo"></image>
  20. </view>
  21. <view class="txt">上传</view>
  22. </view>
  23. <view
  24. class="display-flex upload-box-photo"
  25. v-for="(item, index) in uploadList"
  26. :key="index"
  27. >
  28. <image
  29. :src="item"
  30. mode="aspectFit"
  31. style="width: 100%; height: 100%"
  32. @click="showLarge(item)"
  33. />
  34. <image
  35. src="../../static/del.png"
  36. class="del-icon"
  37. mode="aspectFit"
  38. style="width: 30rpx; height: 30rpx"
  39. @click="delPhoto(index)"
  40. ></image>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="approve-box">
  45. <view class="approve-title">请下载格式审批单,填写信息并加盖企业公章后上传</view>
  46. <view class="approve-content"><view>格式审批单下载:</view><text @click="()=>openFile(areaObj.file_path)">{{areaObj.file_name}}</text></view>
  47. </view>
  48. </view>
  49. </view>
  50. <view class="info">
  51. <view class="title">联系信息</view>
  52. <view class="name flex">
  53. <label>联系人:</label>
  54. <input type="text" class="card input" v-model="company.name" />
  55. </view>
  56. <view class="tel flex">
  57. <label>联系电话:</label>
  58. <input type="text" class="card input" v-model="company.tel" />
  59. </view>
  60. </view>
  61. <button class="submit" @tap="submit">提交</button>
  62. </view>
  63. </template>
  64. <script>
  65. import md5 from "@/common/md5.js";
  66. export default {
  67. data() {
  68. return {
  69. supplyInfo: {
  70. name: "",
  71. nums: "",
  72. },
  73. company: {
  74. name: uni.getStorageSync("supply_name") || "",
  75. tel: uni.getStorageSync("supply_tel") || "",
  76. },
  77. uploadList: [],
  78. imgIdList: [],
  79. timeObj:{},
  80. areaObj:{},
  81. };
  82. },
  83. onLoad(option) {
  84. this.timeObj = option;
  85. this.id = option.id
  86. this.getAreaDeatil(option.id);
  87. console.log(this.timeObj)
  88. },
  89. methods: {
  90. openFile(files){
  91. uni.showLoading({
  92. mask:true,
  93. title:'加载中...',
  94. icon:'none'
  95. })
  96. uni.downloadFile({
  97. url: getApp().globalData.shareUrl + files,
  98. success: function(res) {
  99. var filePath = res.tempFilePath;
  100. //打开文件有效值 doc, xls, ppt, pdf, docx, xlsx, pptx
  101. uni.openDocument({
  102. filePath:filePath,
  103. showMenu:true,
  104. success: function(res) {
  105. uni.hideLoading();
  106. //that.downloadFile_onoff = true;
  107. },
  108. fail(res) {
  109. uni.showToast({
  110. title: '暂不支持此类型',
  111. icon:'none',
  112. duration: 2000
  113. });
  114. uni.hideLoading();
  115. //that.downloadFile_onoff = true;
  116. }
  117. });
  118. }
  119. });
  120. },
  121. getAreaDeatil(areaId) {
  122. let md5Sign = md5(
  123. "method=" +
  124. "area" +
  125. "&timestamp=" +
  126. getApp().globalData.globalTimestamp +
  127. "&secret=" +
  128. getApp().globalData.secret
  129. );
  130. let url =
  131. getApp().globalData.shareUrl +
  132. "api/api.php" +
  133. "?method=area&source=area&action=info_by_id&timestamp=" +
  134. getApp().globalData.globalTimestamp +
  135. "&sign=" +
  136. md5Sign;
  137. let postData = {
  138. area_id: areaId,
  139. };
  140. uni.request({
  141. url: url,
  142. method: "POST",
  143. header: {
  144. "content-type": "application/x-www-form-urlencoded",
  145. },
  146. data: postData,
  147. success: (res) => {
  148. if (res.data.code == 200) {
  149. this.areaObj = res.data.data;
  150. }
  151. },
  152. fail: () => {
  153. console.log("连接失败");
  154. },
  155. });
  156. },
  157. submit() {
  158. if (
  159. !this.company.name ||
  160. !this.company.tel
  161. ){
  162. uni.showToast({
  163. title: "联系信息不完善!",
  164. icon: "error",
  165. });
  166. return;
  167. }
  168. if ( !this.supplyInfo.name){
  169. uni.showToast({
  170. title: "公司信息不完善!",
  171. icon: "error",
  172. });
  173. return;
  174. }
  175. if (!Number(this.supplyInfo.nums)) {
  176. uni.showToast({
  177. title: "请正确填写活动人数!",
  178. icon: "error",
  179. });
  180. return;
  181. }
  182. if (!this.imgIdList.join()){
  183. uni.showToast({
  184. title: "资料未上传!",
  185. icon: "error",
  186. });
  187. return;
  188. }
  189. this.subscribeFn()
  190. },
  191. subscribeFn(){ //订阅通知消息
  192. let that = this;
  193. uni.requestSubscribeMessage({
  194. tmplIds: [
  195. //"XQcYMt2Tz4OZnrpXMTjetRIwPVftkJeM_XUkNPBtu8c",
  196. //"ctLFsDd_HZ-lemoovoRPZAqjS8-1Gh2ELFSVz4FYtUY" //第一次上线的时候把这两个都放开,然后再去掉这一条
  197. "iZ3IABacOX7-EjGIyKnPtX2x3eJoYcwVqsOdEdRGvqU",//测试环境模板id
  198. ],
  199. success(res) {
  200. that.submitFieldRequest();
  201. },
  202. });
  203. },
  204. submitFieldRequest(){
  205. let md5Sign = md5(
  206. "method=" +
  207. "area" +
  208. "&timestamp=" +
  209. getApp().globalData.globalTimestamp +
  210. "&secret=" +
  211. getApp().globalData.secret
  212. );
  213. let url =
  214. getApp().globalData.shareUrl +
  215. "api/api.php" +
  216. "?method=area&source=area&action=order&timestamp=" +
  217. getApp().globalData.globalTimestamp +
  218. "&sign=" +
  219. md5Sign;
  220. let postData = {
  221. area_id:this.timeObj.id,
  222. date:this.timeObj.day || getApp().globalData.nowTime, //预约日期
  223. hours:this.timeObj.hour, //预约时段,多个时段之间用,隔开
  224. company_name :this.supplyInfo.name,
  225. number : this.supplyInfo.nums,
  226. contact_name : this.company.name,
  227. contact_phone : this.company.tel,
  228. file_atttach_id : this.imgIdList.join(),
  229. openId: getApp().globalData.open_id,
  230. };
  231. uni.request({
  232. url: url,
  233. method: "POST",
  234. header: {
  235. "content-type": "application/x-www-form-urlencoded",
  236. },
  237. data: postData,
  238. success: (res) => {
  239. if (res.data.code === 200) {
  240. uni.showToast({
  241. title: "提交成功",
  242. icon: "none",
  243. duration: 2000,
  244. });
  245. console.log(postData)
  246. uni.setStorageSync("supply_name", this.company.name);
  247. uni.setStorageSync("supply_tel", this.company.tel);
  248. setTimeout(() => {
  249. uni.navigateTo({
  250. url: "/pages/makeField/viewDetail?id=" + this.timeObj.id,
  251. });
  252. }, 1500);
  253. } else {
  254. uni.showToast({
  255. title: res.data.msg,
  256. icon: "none",
  257. duration: 2500,
  258. });
  259. }
  260. },
  261. fail: () => {
  262. console.log("连接失败");
  263. },
  264. });
  265. },
  266. getImage(type) {
  267. let that = this;
  268. if (that.uploadList.length >= 3) {
  269. uni.showToast({
  270. title: "最多上传3张图片",
  271. icon: "none",
  272. duration: 2500,
  273. });
  274. return;
  275. }
  276. uni.chooseImage({
  277. sourceType: [type],
  278. count: 3 - that.uploadList.length,
  279. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  280. success: (res) => {
  281. for (let i = 0; i < res.tempFilePaths.length; i++) {
  282. that.uploadList.push(res.tempFilePaths[i]);
  283. that.uploadFileRequest(res.tempFilePaths[i]);
  284. }
  285. },
  286. });
  287. },
  288. uploadFileRequest(fileVal) {
  289. uni.showLoading({
  290. title: "上传中",
  291. mask: true,
  292. });
  293. let that = this;
  294. let md5Sign = md5(
  295. "method=" +
  296. "upload" +
  297. "&timestamp=" +
  298. getApp().globalData.globalTimestamp +
  299. "&secret=" +
  300. getApp().globalData.secret
  301. );
  302. let url =
  303. getApp().globalData.shareUrl +
  304. "api/api.php" +
  305. "?method=upload&source=area&timestamp=" +
  306. getApp().globalData.globalTimestamp +
  307. "&sign=" +
  308. md5Sign;
  309. uni.uploadFile({
  310. url: url, //需要设置为全局
  311. filePath: fileVal,
  312. name: "file",
  313. formData: {
  314. file: fileVal,
  315. },
  316. success: (res) => {
  317. let tmpres = JSON.parse(res.data);
  318. console.log(tmpres);
  319. uni.hideLoading();
  320. that.imgIdList.push(tmpres.data.id);
  321. },
  322. fail: (res) => {
  323. console.log("上传请求失败");
  324. console.log(res);
  325. },
  326. });
  327. },
  328. delPhoto(idx) {
  329. this.uploadList.splice(idx, 1);
  330. this.imgIdList.splice(idx, 1);
  331. },
  332. showLarge(src) {
  333. uni.previewImage({
  334. urls: [src],
  335. longPressActions: {
  336. itemList: ["发送给朋友", "保存图片"],
  337. success: function (data) {},
  338. fail: function (err) {
  339. console.log(err.errMsg);
  340. },
  341. },
  342. });
  343. },
  344. },
  345. };
  346. </script>
  347. <style lang="scss" scoped>
  348. .upload-parent-box {
  349. height: 150rpx;
  350. padding-top: 25rpx;
  351. padding-left: 20rpx;
  352. }
  353. .upload-box {
  354. display: flex;
  355. flex-flow: column;
  356. width: 25%;
  357. background-color: #e0e0e0;
  358. height: 140rpx;
  359. border-radius: 10rpx;
  360. padding-top: 15rpx;
  361. color: #000;
  362. .txt {
  363. font-size: 24rpx;
  364. }
  365. image {
  366. width: 60rpx !important;
  367. height: 60rpx !important;
  368. }
  369. }
  370. .upload-box-photo {
  371. width: 25%;
  372. height: 110rpx;
  373. border-radius: 10rpx;
  374. padding-top: 15rpx;
  375. position: relative;
  376. }
  377. .del-icon {
  378. position: absolute;
  379. right: 0;
  380. width: 30rpx;
  381. height: 30rpx;
  382. }
  383. .update_button {
  384. text-align: center;
  385. display: flex;
  386. }
  387. .content {
  388. font-size: 28rpx;
  389. font-weight: 200;
  390. padding: 1% 2%;
  391. .title {
  392. font-size: 30rpx;
  393. margin: 4% 0;
  394. color: #000;
  395. }
  396. label {
  397. display: inline-block;
  398. width: 25%;
  399. vertical-align: middle;
  400. color: #7f7f7f;
  401. }
  402. .card {
  403. background-color: rgb(248, 247, 247);
  404. border-radius: 10rpx;
  405. }
  406. .flex {
  407. display: flex;
  408. align-items: center;
  409. margin-bottom: 2%;
  410. }
  411. .input {
  412. padding: 0 2%;
  413. margin: 2% 0;
  414. display: inline-block;
  415. width: 80%;
  416. height: 70rpx;
  417. }
  418. .supplyInfo {
  419. border-radius: 40rpx;
  420. padding: 4%;
  421. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  422. margin: 30rpx 0 30rpx 0;
  423. color: #7f7f7f;
  424. font-weight: 300;
  425. .area {
  426. height: 200rpx;
  427. padding: 20rpx;
  428. box-sizing: border-box;
  429. }
  430. .picker {
  431. width: 80%;
  432. height: 70rpx;
  433. background: rgb(248, 247, 247);
  434. display: flex;
  435. align-items: center;
  436. position: relative;
  437. .pick {
  438. width: 100%;
  439. }
  440. .picker_title {
  441. display: flex;
  442. width: 100%;
  443. margin-left: 30rpx;
  444. align-items: center;
  445. justify-content: space-between;
  446. .triangle-down {
  447. width: 0;
  448. height: 0;
  449. border-top: 15rpx solid rgb(173, 173, 173);
  450. border-left: 15rpx solid transparent;
  451. border-right: 15rpx solid transparent;
  452. position: absolute;
  453. right: 10rpx;
  454. }
  455. }
  456. }
  457. .upload-box {
  458. width: 25%;
  459. background-color: #e0e0e0;
  460. height: 110rpx;
  461. border-radius: 10rpx;
  462. padding-top: 15rpx;
  463. }
  464. .upload-box-photo {
  465. width: 25%;
  466. height: 110rpx;
  467. border-radius: 10rpx;
  468. padding-top: 15rpx;
  469. position: relative;
  470. }
  471. .del-icon {
  472. position: absolute;
  473. right: 0;
  474. width: 30rpx;
  475. height: 30rpx;
  476. }
  477. image {
  478. width: 60rpx;
  479. height: 60rpx;
  480. }
  481. .update_button {
  482. text-align: center;
  483. display: flex;
  484. }
  485. }
  486. .approve-box {
  487. width: 100%;
  488. font-size: 24rpx;
  489. margin-top: 25rpx;
  490. padding-left: 20rpx;
  491. .approve-content {
  492. display: flex;
  493. margin: 20rpx 0 30rpx 0;
  494. view{
  495. width: 30%;
  496. };
  497. text{
  498. color:#00a7f0;
  499. cursor: pointer;
  500. }
  501. }
  502. }
  503. .info {
  504. margin-top: 2%;
  505. border-radius: 40rpx;
  506. padding: 2% 4%;
  507. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  508. color: #7f7f7f;
  509. font-weight: 300;
  510. }
  511. .submit {
  512. color: white;
  513. font-weight: normal;
  514. width: 70%;
  515. border-radius: 20rpx;
  516. background-color: #02a7f0;
  517. margin: 50rpx auto;
  518. }
  519. }
  520. </style>