putSupply.vue 9.1 KB

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