putSupply.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view class="content">
  3. <view class="supplyInfo">
  4. <view class="flex">
  5. <label>发布标题:</label>
  6. <input type="text" v-model="supplyInfo.title" class="input card" />
  7. </view>
  8. <view class="flex">
  9. <label>选择类型:</label>
  10. <view class="picker">
  11. <picker
  12. @change="bindPickerChange"
  13. :value="index"
  14. :range="array"
  15. range-key="name"
  16. class="pick"
  17. >
  18. <view class="picker_title">
  19. <view class="pickername">
  20. <view>
  21. {{ array[index].name }}
  22. </view>
  23. </view>
  24. <view class="triangle-down"></view>
  25. </view>
  26. </picker>
  27. </view>
  28. </view>
  29. <view class="flex">
  30. <label>详情:</label>
  31. <textarea v-model="supplyInfo.msg" class="area card"></textarea>
  32. </view>
  33. <view class="update_photo">
  34. <view class="title"></view>
  35. <view>上传图片:</view>
  36. <view class="update_container card upload-parent-box">
  37. <view class="update_button display-flex">
  38. <view class="upload-box" @click="getImage('album')">
  39. <view class="img">
  40. <image src="/static/appeal/photo.png" class="photo"></image>
  41. </view>
  42. <view class="txt">上传</view>
  43. </view>
  44. <view
  45. class="display-flex upload-box-photo"
  46. v-for="(item, index) in uploadList"
  47. :key="index"
  48. >
  49. <image
  50. :src="item"
  51. mode="aspectFit"
  52. style="width: 100%; height: 100%"
  53. @click="showLarge(item)"
  54. />
  55. <image
  56. src="../../static/del.png"
  57. class="del-icon"
  58. mode="aspectFit"
  59. style="width: 30rpx; height: 30rpx"
  60. @click="delPhoto(index)"
  61. ></image>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="info">
  68. <view class="title">企业信息</view>
  69. <view class="name flex">
  70. <label>企业名称:</label>
  71. <input type="text" class="card input" v-model="company.name" />
  72. </view>
  73. <view class="tel flex">
  74. <label>统一社会信用代码:</label>
  75. <input type="text" class="card input" v-model="company.code" />
  76. </view>
  77. <view class="tel flex">
  78. <label>联系电话:</label>
  79. <input type="text" class="card input" v-model="company.tel" />
  80. </view>
  81. </view>
  82. <button class="submit" @tap="submit">提交</button>
  83. </view>
  84. </template>
  85. <script>
  86. import md5 from "@/common/md5.js";
  87. export default {
  88. data() {
  89. return {
  90. array: [{ name: "供需" }, { name: "需求" }],
  91. index: 0,
  92. supplyInfo: {
  93. title: "",
  94. msg: "",
  95. },
  96. company: {
  97. name: uni.getStorageSync("supply_name") || "",
  98. code: uni.getStorageSync("supply_code") || "",
  99. tel: uni.getStorageSync("supply_tel") || "",
  100. },
  101. uploadList: [],
  102. imgIdList: [],
  103. };
  104. },
  105. methods: {
  106. submit() {
  107. if (
  108. this.company.name === "" ||
  109. this.company.code === "" ||
  110. this.company.tel === ""
  111. ) {
  112. uni.showToast({
  113. title: "企业信息不完善",
  114. icon: "error",
  115. });
  116. return;
  117. }
  118. let md5Sign = md5(
  119. "method=" +
  120. "need" +
  121. "&timestamp=" +
  122. getApp().globalData.globalTimestamp +
  123. "&secret=" +
  124. getApp().globalData.secret
  125. );
  126. let url =
  127. getApp().globalData.shareUrl +
  128. "api/api.php" +
  129. "?method=need&source=need&action=add&timestamp=" +
  130. getApp().globalData.globalTimestamp +
  131. "&sign=" +
  132. md5Sign;
  133. let postData = {
  134. title: this.supplyInfo.title,
  135. type: +this.index == 0 ? 2 : 1,
  136. content: this.supplyInfo.msg,
  137. company_name: this.company.name,
  138. company_code: this.company.code,
  139. phone: this.company.tel,
  140. attach_ids: this.imgIdList.join(),
  141. openId: getApp().globalData.open_id,
  142. };
  143. uni.request({
  144. url: url,
  145. method: "POST",
  146. header: {
  147. "content-type": "application/x-www-form-urlencoded",
  148. },
  149. data: postData,
  150. success: (res) => {
  151. if (res.data.code === 200) {
  152. uni.showToast({
  153. title: "发布供需成功",
  154. icon: "none",
  155. duration: 2000,
  156. });
  157. uni.setStorageSync("supply_name", this.company.name);
  158. uni.setStorageSync("supply_code", this.company.code);
  159. uni.setStorageSync("supply_tel", this.company.tel);
  160. setTimeout(() => {
  161. uni.navigateBack({});
  162. }, 1500);
  163. } else {
  164. uni.showToast({
  165. title: res.data.msg,
  166. icon: "none",
  167. duration: 2500,
  168. });
  169. }
  170. },
  171. fail: () => {
  172. console.log("连接失败");
  173. },
  174. });
  175. },
  176. bindPickerChange(e) {
  177. this.index = e.detail.value;
  178. },
  179. getImage(type) {
  180. let that = this;
  181. if (that.uploadList.length >= 3) {
  182. uni.showToast({
  183. title: "最多上传3张图片",
  184. icon: "none",
  185. duration: 2500,
  186. });
  187. return;
  188. }
  189. uni.chooseImage({
  190. sourceType: [type],
  191. count: 3 - that.uploadList.length,
  192. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  193. success: (res) => {
  194. for (let i = 0; i < res.tempFilePaths.length; i++) {
  195. that.uploadList.push(res.tempFilePaths[i]);
  196. that.uploadFileRequest(res.tempFilePaths[i]);
  197. }
  198. },
  199. });
  200. },
  201. uploadFileRequest(fileVal) {
  202. uni.showLoading({
  203. title: "上传中",
  204. mask: true,
  205. });
  206. let that = this;
  207. let md5Sign = md5(
  208. "method=" +
  209. "upload" +
  210. "&timestamp=" +
  211. getApp().globalData.globalTimestamp +
  212. "&secret=" +
  213. getApp().globalData.secret
  214. );
  215. let url =
  216. getApp().globalData.shareUrl +
  217. "api/api.php" +
  218. "?method=upload&source=consult&timestamp=" +
  219. getApp().globalData.globalTimestamp +
  220. "&sign=" +
  221. md5Sign;
  222. uni.uploadFile({
  223. url: url, //需要设置为全局
  224. filePath: fileVal,
  225. name: "file",
  226. formData: {
  227. file: fileVal,
  228. },
  229. success: (res) => {
  230. let tmpres = JSON.parse(res.data);
  231. console.log(tmpres);
  232. uni.hideLoading();
  233. that.imgIdList.push(tmpres.data.id);
  234. },
  235. fail: (res) => {
  236. console.log("上传请求失败");
  237. console.log(res);
  238. },
  239. });
  240. },
  241. delPhoto(idx) {
  242. this.uploadList.splice(idx, 1);
  243. this.imgIdList.splice(idx, 1);
  244. },
  245. showLarge(src) {
  246. uni.previewImage({
  247. urls: [src],
  248. longPressActions: {
  249. itemList: ["发送给朋友", "保存图片"],
  250. success: function (data) {},
  251. fail: function (err) {
  252. console.log(err.errMsg);
  253. },
  254. },
  255. });
  256. },
  257. },
  258. };
  259. </script>
  260. <style lang="scss" scoped>
  261. .upload-parent-box {
  262. height: 150rpx;
  263. padding-top: 25rpx;
  264. padding-left: 20rpx;
  265. }
  266. .upload-box {
  267. display: flex;
  268. flex-flow: column;
  269. width: 25%;
  270. background-color: #e0e0e0;
  271. height: 140rpx;
  272. border-radius: 10rpx;
  273. padding-top: 15rpx;
  274. image {
  275. width: 60rpx !important;
  276. height: 60rpx !important;
  277. }
  278. }
  279. .upload-box-photo {
  280. width: 25%;
  281. height: 110rpx;
  282. border-radius: 10rpx;
  283. padding-top: 15rpx;
  284. position: relative;
  285. }
  286. .del-icon {
  287. position: absolute;
  288. right: 0;
  289. width: 30rpx;
  290. height: 30rpx;
  291. }
  292. .update_button {
  293. text-align: center;
  294. display: flex;
  295. }
  296. .content {
  297. font-size: 28rpx;
  298. font-weight: 200;
  299. padding: 1% 2%;
  300. .title {
  301. font-size: 30rpx;
  302. margin: 4% 0;
  303. }
  304. label {
  305. display: inline-block;
  306. width: 25%;
  307. vertical-align: middle;
  308. }
  309. .card {
  310. background-color: rgb(248, 247, 247);
  311. border-radius: 10rpx;
  312. }
  313. .flex {
  314. display: flex;
  315. align-items: center;
  316. margin-bottom: 2%;
  317. }
  318. .input {
  319. padding: 0 2%;
  320. margin: 2% 0;
  321. display: inline-block;
  322. width: 80%;
  323. height: 70rpx;
  324. }
  325. .supplyInfo {
  326. border-radius: 40rpx;
  327. padding: 4%;
  328. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  329. margin: 30rpx 0 30rpx 0;
  330. .area {
  331. height: 200rpx;
  332. padding: 20rpx;
  333. box-sizing: border-box;
  334. }
  335. .picker {
  336. width: 80%;
  337. height: 70rpx;
  338. background: rgb(248, 247, 247);
  339. display: flex;
  340. align-items: center;
  341. position: relative;
  342. .pick {
  343. width: 100%;
  344. }
  345. .picker_title {
  346. display: flex;
  347. width: 100%;
  348. margin-left: 30rpx;
  349. align-items: center;
  350. justify-content: space-between;
  351. .triangle-down {
  352. width: 0;
  353. height: 0;
  354. border-top: 15rpx solid rgb(173, 173, 173);
  355. border-left: 15rpx solid transparent;
  356. border-right: 15rpx solid transparent;
  357. position: absolute;
  358. right: 10rpx;
  359. }
  360. .pickername {
  361. font-weight: 100;
  362. }
  363. }
  364. }
  365. .upload-box {
  366. width: 25%;
  367. background-color: #e0e0e0;
  368. height: 110rpx;
  369. border-radius: 10rpx;
  370. padding-top: 15rpx;
  371. }
  372. .upload-box-photo {
  373. width: 25%;
  374. height: 110rpx;
  375. border-radius: 10rpx;
  376. padding-top: 15rpx;
  377. position: relative;
  378. }
  379. .del-icon {
  380. position: absolute;
  381. right: 0;
  382. width: 30rpx;
  383. height: 30rpx;
  384. }
  385. image {
  386. width: 60rpx;
  387. height: 60rpx;
  388. }
  389. .update_button {
  390. text-align: center;
  391. display: flex;
  392. }
  393. }
  394. .info {
  395. margin-top: 2%;
  396. border-radius: 40rpx;
  397. padding: 2% 4%;
  398. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  399. }
  400. .submit {
  401. color: white;
  402. font-weight: normal;
  403. width: 70%;
  404. border-radius: 20rpx;
  405. background-color: #02a7f0;
  406. margin: 50rpx auto;
  407. }
  408. }
  409. </style>