|
不知道诶,我不是很会js,就使用过程中,只有这里出了问题,我把完整代码贴出来你看看:
- var sj_id,modularType,sj_name
- var nav_h
- apiready = function() {
- nav_h=api.safeArea.top
- $api.fixStatusBar($api.dom('.header'));
- $api.fixTabBar($api.dom('.pinglun_wra'))
- $api.css($api.dom(".tijiao"),"bottom:"+api.safeArea.bottom+"px")
- $api.css($api.dom(".djs"),"height:"+(nav_h+45)+"px")
- $api.css($api.dom(".back"),"top:"+nav_h+"px")
-
- sj_id=api.pageParam.id
- modularType=api.pageParam.modularType
- sj_name=api.pageParam.name
- $api.html($api.dom(".dx_r"),sj_name)
-
- api.ajax({
- url: host_p+"select",
- method: 'get', //返回类型
- returnAll:true, //是否全部返回(包括请求头)
- data:{
- values:{
- type:6
- } //传递参数,body如果传json类型,header中必须加上传参类型'Content-Type': "application/json"
- }
- }, function(ret, err) {
- if(ret){
- var baocuo_list=ret.body.data
- var tmpltxt2=doT.template(document.getElementById("label_wra").innerHTML);//生成模板方法
- document.querySelector(".label_wra").innerHTML=tmpltxt2(baocuo_list);//数据渲染
- // alert(JSON.stringify(ret))
- api.parseTapmode();
- } else {
-
- }
- });
- }
- // 错误选择
- var cw_radio=null;
- function radiochange(self){
- $api.removeCls($api.dom(".label_wra .icon.active"),"active")
- cw_radio=self.value
- $api.addCls(self.parentNode.childNodes[1],"active")
- }
- // 备注
- function text_change(self){
- if(self.value.length>300){
- self.value=self.value.slice(0,300)
- $api.html($api.dom(".zishu"),"<span style='color:#f00;'>"+self.value.length+"</span>/300")
- }else{
- $api.html($api.dom(".zishu"),self.value.length+"/300")
- }
- }
- // 提交
- document.querySelector(".pinglun_wra").onsubmit=function(e){
- if(cw_radio==null){
- api.toast({
- msg: '请先选择错误类型',
- duration: 2000,
- location: 'middle'
- });
- return false;
- }
- if($api.dom(".text_area").value==""){
- api.toast({
- msg: '请先填写错误描述',
- duration: 2000,
- location: 'middle'
- });
- return false;
- }
- api.showProgress({
- title: '正在提交...',
- text: '请稍等...',
- modal: false
- });
- api.ajax({
- url: host_p+"saveErrorcorrection",
- method: 'post', //返回类型
- returnAll:true, //是否全部返回(包括请求头)
- data:{
- values:{
- type:cw_radio,
- errorDescribe:$api.dom(".text_area").value,
- shopId:sj_id,
- userId:$api.getStorage("userinfo").userId,
- modularType:modularType,
- shopType:api.pageParam.shopType
- } //传递参数,body如果传json类型,header中必须加上传参类型'Content-Type': "application/json"
- }
- }, function(ret, err) {
- if (ret.body.data) {
- // 上传图片
- if (pic_arr != "") {
- for(let i=0;i<pic_arr.length;i++){
- api.ajax({
- report: false,
- url: host_p + "upload",
- //这里是我们约定好的后台上传图片的位置 ,你可以根据你的需求来改
- method: 'post',
- cache: 'false',
- timeout: 3000,
- data: {
- values: {
- id:ret.body.data,
- modularType:0,
- type:1
- },
- files: {
- file: pic_arr[i],
- },
- }
- }, function(res, err) {
- if (res.code == 1) {
-
- } else {
-
- }
- if(i==pic_arr.length-1){
- api.hideProgress();
- setTimeout(function(){
- api.closeWin()
- },2000)
- api.toast({
- msg: '提交成功',
- duration: 2000,
- location: 'middle'
- });
- }
- })
- }
- }else{
- api.hideProgress();
- setTimeout(function(){
- api.closeWin()
- },2000)
- api.toast({
- msg: '提交成功',
- duration: 2000,
- location: 'middle'
- });
- }
- } else {
-
- }
- });
- return false;
- }
- // 返回
- function back() {
- api.closeWin()
- }
- // 是否匿名
- function niming(self){
- if($api.hasCls(self, 'notniming')){
- $api.removeCls(self, 'notniming')
- $api.addCls(self, 'niming')
- }else{
- $api.removeCls(self, 'niming')
- $api.addCls(self, 'notniming')
- }
- }
- // 选择上传方式
- function sc_tupian(){
- quanxian('camera',function(){
- quanxian('photos',function(){
- api.actionSheet({
- title: '上传图片',
- cancelTitle: '取消',
- buttons: ['拍照','从手机相册选择']
- }, function(ret, err) {
- if (ret) {
- getPicture(ret.buttonIndex);
- }
- });
- })
- })
-
- }
- var pic_arr=[];
- // 上传图片
- function getPicture(sourceType){
- if(sourceType==1){ // 拍照
- api.getPicture({
- sourceType: 'camera',
- encodingType: 'jpg',
- mediaValue: 'pic',
- allowEdit: false,
- quality: 100,
- saveToPhotoAlbum: true
- }, function(ret, err) {
- if (ret.data!="") {
- if(pic_arr!=[]&&pic_arr!=""&&pic_arr){
- if(pic_arr.length>6){
- api.toast({
- msg: '图片最多上传6张',
- duration: 2000,
- location: 'middle'
- });
- return false;
- }
- }
- var img=`<div class="scpic_wra" style="background-image:url(${ret.data})" data-url="${ret.data}" tapmode onclick="pic(this)"><span data-url="${ret.data}" class="icon iconfont " tapmode onclick="del_pic(this)"></span></div>`
- $api.append($api.dom(".img_wra"),img)
- pic_arr.push(ret.data)
- } else {
- }
- });
- }else if(sourceType==2){
- api.getPicture({
- sourceType: 'library',
- encodingType: 'jpg',
- mediaValue: 'pic',
- destinationType: 'url',
- allowEdit: true,
- quality: 100,
- saveToPhotoAlbum: false
- }, function(ret, err) {
- if (ret.data!="") {
- if(pic_arr!=[]&&pic_arr!=""&&pic_arr){
- if(pic_arr.length>6){
- api.toast({
- msg: '图片最多上传6张',
- duration: 2000,
- location: 'middle'
- });
- return false;
- }
- }
- var img=`<div class="scpic_wra" style="background-image:url(${ret.data})" data-url="${ret.data}" tapmode onclick="pic(this)"><span data-url="${ret.data}" class="icon iconfont" tapmode onclick="del_pic(this)"></span></div>`
- $api.append($api.dom(".img_wra"),img)
- pic_arr.push(ret.data)
- } else {
- }
- });
- }
-
-
- }
- //删除图片
- function del_pic(self){
- event.preventDefault();
- event.stopPropagation();
- $api.remove(self.parentNode)
- var index = pic_arr.indexOf($api.attr(self,'data-url'));
- if (index > -1) {
- pic_arr.splice(index, 1);
- }
- }
- // 图片查看
- function pic(self){
- api.openWin({
- name:"pic",
- url:"./pic.html",
- pageParam:{
- pics:[$api.attr(self,'data-url')]
- }
- })
- }
- // 上传图片
- function sctp(){
- api.ajax({
- url: "",
- method: 'get', //是否全部返回(包括请求头)
- data:{
- values:{
- avatar:$api.getStorage('userinfo').avatar.replace("http://dkcs**.**",""),
- nickname:$api.getStorage('userinfo').nickname,
- id:$api.getStorage("userinfo").id,
- token:$api.getStorage("token")
- } //传递参数,body如果传json类型,header中必须加上传参类 型'Content-Type': "application/json"
- }
- }, function(ret, err) {
- api.hideProgress();
- if (ret) {
-
- }else{
-
- }
- });
- }
- }
复制代码 |
|