putAppeal.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <div class="content">
  3. <div class="explain">
  4. <div class="title">问题说明:</div>
  5. <textarea
  6. v-model="question.content"
  7. class="input card"
  8. placeholder="您反映的内容要体现一下几个重点信息:事情有关的地址,具体事情概述以及您的期望是什么?内容不少于5个字。"
  9. ></textarea>
  10. </div>
  11. <div class="update_photo">
  12. <div class="title">选择图片:</div>
  13. <div class="update_container card upload-parent-box">
  14. <div class="update_button display-flex">
  15. <div class="display-flex upload-box" @click="getImage('album')">
  16. <img src="/static/appeal/photo.png" />
  17. <div class="txt">上传</div>
  18. </div>
  19. <div
  20. class="display-flex upload-box-photo"
  21. v-for="(item, index) in uploadList"
  22. :key="index"
  23. >
  24. <image
  25. :src="item"
  26. mode="aspectFit"
  27. style="width: 100%; height: 100%"
  28. @click="showLarge(item)"
  29. />
  30. <image
  31. src="../../static/del.png"
  32. class="del-icon"
  33. mode="aspectFit"
  34. @click="delPhoto(index)"
  35. ></image>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="info">
  41. <div class="name info_msg">
  42. <label>联系人:</label>
  43. <input type="text" class="card ipt" v-model="question.contact_name" />
  44. </div>
  45. <div class="tel info_msg">
  46. <label>联系方式:</label>
  47. <input
  48. type="text"
  49. class="card ipt"
  50. v-model="question.contact_phone"
  51. disabled="true"
  52. />
  53. </div>
  54. </div>
  55. <!-- <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  56. 获取手机号
  57. </button>
  58. <button open-type="getUserInfo" @getuserinfo="getInfo">授权登录</button> -->
  59. <button class="submit" @tap="submit">提交</button>
  60. </div>
  61. </template>
  62. <script>
  63. import md5 from "@/common/md5.js";
  64. export default {
  65. data() {
  66. return {
  67. msg: "提出诉求",
  68. uploadList: [],
  69. imgIdList: [],
  70. question: {
  71. content: "",
  72. contact_name: "",
  73. contact_phone: getApp().globalData.user_phone,
  74. },
  75. };
  76. },
  77. methods: {
  78. getImage(type) {
  79. let that = this;
  80. if (that.uploadList.length >= 3) {
  81. uni.showToast({
  82. title: "最多上传3张图片",
  83. icon: "none",
  84. duration: 2500,
  85. });
  86. return;
  87. }
  88. uni.chooseImage({
  89. sourceType: [type],
  90. count: 3 - that.uploadList.length,
  91. sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
  92. success: (res) => {
  93. for (let i = 0; i < res.tempFilePaths.length; i++) {
  94. that.uploadList.push(res.tempFilePaths[i]);
  95. that.uploadFileRequest(res.tempFilePaths[i]);
  96. // uni.getImageInfo({
  97. // src: res.tempFilePaths[i],
  98. // success: (image)=>{
  99. // let msg = {textValue:res.tempFilePaths[i]};
  100. // console.log(msg)
  101. // //that.uploadFileRequest(msg,4)
  102. // }
  103. // });
  104. }
  105. },
  106. });
  107. },
  108. uploadFileRequest(fileVal) {
  109. uni.showLoading({
  110. title: "上传中",
  111. mask: true,
  112. });
  113. let that = this;
  114. let md5Sign = md5(
  115. "method=" +
  116. "upload" +
  117. "&timestamp=" +
  118. getApp().globalData.globalTimestamp +
  119. "&secret=" +
  120. getApp().globalData.secret
  121. );
  122. let url =
  123. getApp().globalData.shareUrl +
  124. "api/api.php" +
  125. "?method=upload&source=consult&timestamp=" +
  126. getApp().globalData.globalTimestamp +
  127. "&sign=" +
  128. md5Sign;
  129. uni.uploadFile({
  130. url: url, //需要设置为全局
  131. filePath: fileVal,
  132. name: "file",
  133. formData: {
  134. file: fileVal,
  135. },
  136. success: (res) => {
  137. let tmpres = JSON.parse(res.data);
  138. console.log(tmpres);
  139. uni.hideLoading();
  140. that.imgIdList.push(tmpres.data.id);
  141. },
  142. fail: (res) => {
  143. console.log("上传请求失败");
  144. console.log(res);
  145. },
  146. });
  147. },
  148. delPhoto(idx) {
  149. this.uploadList.splice(idx, 1);
  150. this.imgIdList.splice(idx, 1);
  151. },
  152. showLarge(src) {
  153. uni.previewImage({
  154. urls: [src],
  155. longPressActions: {
  156. itemList: ["发送给朋友", "保存图片"],
  157. success: function (data) {},
  158. fail: function (err) {
  159. console.log(err.errMsg);
  160. },
  161. },
  162. });
  163. },
  164. submit() {
  165. let md5Sign = md5(
  166. "method=" +
  167. "consult" +
  168. "&timestamp=" +
  169. getApp().globalData.globalTimestamp +
  170. "&secret=" +
  171. getApp().globalData.secret
  172. );
  173. let url =
  174. getApp().globalData.shareUrl +
  175. "api/api.php" +
  176. "?method=consult&source=consult&action=add&timestamp=" +
  177. getApp().globalData.globalTimestamp +
  178. "&sign=" +
  179. md5Sign;
  180. uni.request({
  181. url: url,
  182. method: "POST",
  183. header: {
  184. "content-type": "application/x-www-form-urlencoded",
  185. },
  186. data: {
  187. content: this.question.content,
  188. contact_name: this.question.contact_name,
  189. contact_phone: this.question.contact_phone,
  190. attach_ids: this.imgIdList.join(),
  191. openId: getApp().globalData.open_id,
  192. },
  193. success: (res) => {
  194. if (res.data.code === 200) {
  195. uni.showToast({
  196. title: "诉求提交成功",
  197. icon: "none",
  198. duration: 2500,
  199. });
  200. setTimeout(() => {
  201. uni.navigateBack({});
  202. }, 2500);
  203. } else {
  204. uni.showToast({
  205. title: res.data.msg,
  206. icon: "none",
  207. duration: 2500,
  208. });
  209. }
  210. },
  211. fail: () => {
  212. console.log("连接失败");
  213. },
  214. });
  215. },
  216. },
  217. };
  218. </script>
  219. <style lang="scss" scoped>
  220. .content {
  221. font-size: 25rpx;
  222. font-weight: 200;
  223. padding: 5%;
  224. .title {
  225. font-size: 30rpx;
  226. margin: 5% 0;
  227. }
  228. .card {
  229. background-color: rgb(248, 247, 247);
  230. border-radius: 20rpx;
  231. }
  232. .explain {
  233. .input {
  234. width: 96%;
  235. padding: 2%;
  236. }
  237. }
  238. .info {
  239. margin-top: 5%;
  240. .info_msg {
  241. display: flex;
  242. align-items: center;
  243. label {
  244. display: inline-block;
  245. width: 20%;
  246. vertical-align: middle;
  247. }
  248. .ipt {
  249. padding: 0 2%;
  250. margin: 2% 0;
  251. display: inline-block;
  252. width: 70%;
  253. height: 70rpx;
  254. }
  255. }
  256. }
  257. .upload-parent-box {
  258. height: 150rpx;
  259. padding-top: 25rpx;
  260. padding-left: 20rpx;
  261. }
  262. .upload-box {
  263. width: 25%;
  264. background-color: #e0e0e0;
  265. height: 110rpx;
  266. border-radius: 10rpx;
  267. padding-top: 15rpx;
  268. }
  269. .upload-box-photo {
  270. width: 25%;
  271. height: 110rpx;
  272. border-radius: 10rpx;
  273. padding-top: 15rpx;
  274. position: relative;
  275. }
  276. .del-icon {
  277. position: absolute;
  278. right: 0;
  279. width: 30rpx;
  280. height: 30rpx;
  281. }
  282. img {
  283. width: 60rpx;
  284. height: 60rpx;
  285. }
  286. .update_button {
  287. text-align: center;
  288. display: flex;
  289. }
  290. .submit {
  291. font-size: 30rpx;
  292. color: white;
  293. width: 75%;
  294. border-radius: 20rpx;
  295. background-color: #02a7f0;
  296. margin: 0 auto;
  297. margin-top: 150rpx;
  298. }
  299. }
  300. </style>