putAppeal.vue 6.6 KB

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