fieldForm.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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">格式审批单下载:<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. this.subscribeFn()
  169. },
  170. subscribeFn(){ //订阅通知消息
  171. let that = this;
  172. uni.requestSubscribeMessage({
  173. tmplIds: [
  174. //"XQcYMt2Tz4OZnrpXMTjetRIwPVftkJeM_XUkNPBtu8c",
  175. "iZ3IABacOX7-EjGIyKnPtX2x3eJoYcwVqsOdEdRGvqU",//测试环境模板id
  176. ],
  177. success(res) {
  178. that.submitFieldRequest();
  179. },
  180. });
  181. },
  182. submitFieldRequest(){
  183. let md5Sign = md5(
  184. "method=" +
  185. "area" +
  186. "&timestamp=" +
  187. getApp().globalData.globalTimestamp +
  188. "&secret=" +
  189. getApp().globalData.secret
  190. );
  191. let url =
  192. getApp().globalData.shareUrl +
  193. "api/api.php" +
  194. "?method=area&source=area&action=order&timestamp=" +
  195. getApp().globalData.globalTimestamp +
  196. "&sign=" +
  197. md5Sign;
  198. let postData = {
  199. area_id:this.timeObj.id,
  200. date:this.timeObj.day || getApp().globalData.nowTime, //预约日期
  201. hours:this.timeObj.hour, //预约时段,多个时段之间用,隔开
  202. company_name :this.supplyInfo.name,
  203. number : this.supplyInfo.nums,
  204. contact_name : this.company.name,
  205. contact_phone : this.company.tel,
  206. file_atttach_id : this.imgIdList.join(),
  207. openId: getApp().globalData.open_id,
  208. };
  209. uni.request({
  210. url: url,
  211. method: "POST",
  212. header: {
  213. "content-type": "application/x-www-form-urlencoded",
  214. },
  215. data: postData,
  216. success: (res) => {
  217. if (res.data.code === 200) {
  218. uni.showToast({
  219. title: "提交成功",
  220. icon: "none",
  221. duration: 2000,
  222. });
  223. console.log(postData)
  224. uni.setStorageSync("supply_name", this.company.name);
  225. uni.setStorageSync("supply_tel", this.company.tel);
  226. setTimeout(() => {
  227. uni.navigateBack({});
  228. }, 1500);
  229. } else {
  230. uni.showToast({
  231. title: res.data.msg,
  232. icon: "none",
  233. duration: 2500,
  234. });
  235. }
  236. },
  237. fail: () => {
  238. console.log("连接失败");
  239. },
  240. });
  241. },
  242. getImage(type) {
  243. let that = this;
  244. if (that.uploadList.length >= 3) {
  245. uni.showToast({
  246. title: "最多上传3张图片",
  247. icon: "none",
  248. duration: 2500,
  249. });
  250. return;
  251. }
  252. uni.chooseImage({
  253. sourceType: [type],
  254. count: 3 - that.uploadList.length,
  255. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  256. success: (res) => {
  257. for (let i = 0; i < res.tempFilePaths.length; i++) {
  258. that.uploadList.push(res.tempFilePaths[i]);
  259. that.uploadFileRequest(res.tempFilePaths[i]);
  260. }
  261. },
  262. });
  263. },
  264. uploadFileRequest(fileVal) {
  265. uni.showLoading({
  266. title: "上传中",
  267. mask: true,
  268. });
  269. let that = this;
  270. let md5Sign = md5(
  271. "method=" +
  272. "upload" +
  273. "&timestamp=" +
  274. getApp().globalData.globalTimestamp +
  275. "&secret=" +
  276. getApp().globalData.secret
  277. );
  278. let url =
  279. getApp().globalData.shareUrl +
  280. "api/api.php" +
  281. "?method=upload&source=area&timestamp=" +
  282. getApp().globalData.globalTimestamp +
  283. "&sign=" +
  284. md5Sign;
  285. uni.uploadFile({
  286. url: url, //需要设置为全局
  287. filePath: fileVal,
  288. name: "file",
  289. formData: {
  290. file: fileVal,
  291. },
  292. success: (res) => {
  293. let tmpres = JSON.parse(res.data);
  294. console.log(tmpres);
  295. uni.hideLoading();
  296. that.imgIdList.push(tmpres.data.id);
  297. },
  298. fail: (res) => {
  299. console.log("上传请求失败");
  300. console.log(res);
  301. },
  302. });
  303. },
  304. delPhoto(idx) {
  305. this.uploadList.splice(idx, 1);
  306. this.imgIdList.splice(idx, 1);
  307. },
  308. showLarge(src) {
  309. uni.previewImage({
  310. urls: [src],
  311. longPressActions: {
  312. itemList: ["发送给朋友", "保存图片"],
  313. success: function (data) {},
  314. fail: function (err) {
  315. console.log(err.errMsg);
  316. },
  317. },
  318. });
  319. },
  320. },
  321. };
  322. </script>
  323. <style lang="scss" scoped>
  324. .upload-parent-box {
  325. height: 150rpx;
  326. padding-top: 25rpx;
  327. padding-left: 20rpx;
  328. }
  329. .upload-box {
  330. display: flex;
  331. flex-flow: column;
  332. width: 25%;
  333. background-color: #e0e0e0;
  334. height: 140rpx;
  335. border-radius: 10rpx;
  336. padding-top: 15rpx;
  337. color: #000;
  338. image {
  339. width: 60rpx !important;
  340. height: 60rpx !important;
  341. }
  342. }
  343. .upload-box-photo {
  344. width: 25%;
  345. height: 110rpx;
  346. border-radius: 10rpx;
  347. padding-top: 15rpx;
  348. position: relative;
  349. }
  350. .del-icon {
  351. position: absolute;
  352. right: 0;
  353. width: 30rpx;
  354. height: 30rpx;
  355. }
  356. .update_button {
  357. text-align: center;
  358. display: flex;
  359. }
  360. .content {
  361. font-size: 28rpx;
  362. font-weight: 200;
  363. padding: 1% 2%;
  364. .title {
  365. font-size: 30rpx;
  366. margin: 4% 0;
  367. color: #000;
  368. }
  369. label {
  370. display: inline-block;
  371. width: 25%;
  372. vertical-align: middle;
  373. color: #7f7f7f;
  374. }
  375. .card {
  376. background-color: rgb(248, 247, 247);
  377. border-radius: 10rpx;
  378. }
  379. .flex {
  380. display: flex;
  381. align-items: center;
  382. margin-bottom: 2%;
  383. }
  384. .input {
  385. padding: 0 2%;
  386. margin: 2% 0;
  387. display: inline-block;
  388. width: 80%;
  389. height: 70rpx;
  390. }
  391. .supplyInfo {
  392. border-radius: 40rpx;
  393. padding: 4%;
  394. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  395. margin: 30rpx 0 30rpx 0;
  396. color: #7f7f7f;
  397. .area {
  398. height: 200rpx;
  399. padding: 20rpx;
  400. box-sizing: border-box;
  401. }
  402. .picker {
  403. width: 80%;
  404. height: 70rpx;
  405. background: rgb(248, 247, 247);
  406. display: flex;
  407. align-items: center;
  408. position: relative;
  409. .pick {
  410. width: 100%;
  411. }
  412. .picker_title {
  413. display: flex;
  414. width: 100%;
  415. margin-left: 30rpx;
  416. align-items: center;
  417. justify-content: space-between;
  418. .triangle-down {
  419. width: 0;
  420. height: 0;
  421. border-top: 15rpx solid rgb(173, 173, 173);
  422. border-left: 15rpx solid transparent;
  423. border-right: 15rpx solid transparent;
  424. position: absolute;
  425. right: 10rpx;
  426. }
  427. }
  428. }
  429. .upload-box {
  430. width: 25%;
  431. background-color: #e0e0e0;
  432. height: 110rpx;
  433. border-radius: 10rpx;
  434. padding-top: 15rpx;
  435. }
  436. .upload-box-photo {
  437. width: 25%;
  438. height: 110rpx;
  439. border-radius: 10rpx;
  440. padding-top: 15rpx;
  441. position: relative;
  442. }
  443. .del-icon {
  444. position: absolute;
  445. right: 0;
  446. width: 30rpx;
  447. height: 30rpx;
  448. }
  449. image {
  450. width: 60rpx;
  451. height: 60rpx;
  452. }
  453. .update_button {
  454. text-align: center;
  455. display: flex;
  456. }
  457. }
  458. .approve-box {
  459. width: 100%;
  460. font-size: 24rpx;
  461. margin-top: 25rpx;
  462. padding-left: 20rpx;
  463. .approve-content {
  464. display: flex;
  465. margin: 20rpx 0 30rpx 0;
  466. text{
  467. color:#00a7f0;
  468. cursor: pointer;
  469. }
  470. }
  471. }
  472. .info {
  473. margin-top: 2%;
  474. border-radius: 40rpx;
  475. padding: 2% 4%;
  476. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  477. color: #7f7f7f;
  478. }
  479. .submit {
  480. color: white;
  481. font-weight: normal;
  482. width: 70%;
  483. border-radius: 20rpx;
  484. background-color: #02a7f0;
  485. margin: 50rpx auto;
  486. }
  487. }
  488. </style>