putAppeal.vue 7.7 KB

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