putAppeal.vue 8.0 KB

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