verify.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import { post,api_url } from "../../../../utils/http";
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. options: {
  7. addGlobalClass: true
  8. },
  9. properties: {
  10. review: {
  11. type: Object,
  12. value: null,
  13. observer(newVal,oldVal) {
  14. if(newVal) {
  15. console.log(newVal)
  16. console.log(newVal.option_list)
  17. newVal.option_list.forEach((item,index)=> {
  18. item.children.forEach((newItem) => {
  19. console.log(newItem)
  20. newItem.status = true
  21. })
  22. })
  23. this.setData({
  24. check: newVal
  25. })
  26. console.log(this.data.check)
  27. }
  28. console.log(newVal,oldVal)
  29. // this.setData({
  30. // check
  31. // })
  32. }
  33. },
  34. check_id: {
  35. type: String,
  36. value: null,
  37. }
  38. },
  39. /**
  40. * 组件的初始数据
  41. */
  42. data: {
  43. is_list: true,
  44. list: ['','','',''],
  45. more: true,
  46. maxlength: 500,
  47. number: 0,
  48. value: "",
  49. imgs: [],
  50. check: {}
  51. },
  52. /**
  53. * 组件的方法列表
  54. */
  55. methods: {
  56. onOpenList() {
  57. this.setData({
  58. more: false
  59. })
  60. },
  61. /**
  62. * 切换结果
  63. */
  64. onChangeStatus(e) {
  65. let { idx,index,status } = e.currentTarget.dataset;
  66. this.setData({
  67. ['check.option_list[' + idx + '].children['+index+'].status']: status == 'true' ? true : false
  68. })
  69. },
  70. /** 监听文本域 */
  71. bindTextAreaInput(e) {
  72. this.setData({
  73. number: e.detail.cursor,
  74. value: e.detail.value
  75. })
  76. },
  77. /** 选择图片 */
  78. chooseImage() {
  79. let that = this;
  80. let imgs = this.data.imgs;
  81. let count = 9 - this.data.imgs.length
  82. wx.chooseImage({
  83. count,
  84. sizeType: ['original', 'compressed'],
  85. sourceType: ['album', 'camera'],
  86. success (res) {
  87. wx.showLoading({
  88. title: '正在上传图片',
  89. mask: true
  90. });
  91. const tempFiles = res.tempFiles
  92. tempFiles.forEach((item) => {
  93. that.upload(item.path).then((data) => {
  94. imgs.push({
  95. type: 'image',
  96. url: data.data.url,
  97. })
  98. that.setData({ imgs })
  99. wx.hideLoading()
  100. });
  101. })
  102. }
  103. })
  104. },
  105. /** 选择视频 */
  106. chooseVideo(){
  107. let that = this;
  108. let imgs = this.data.imgs;
  109. wx.chooseMedia({
  110. count: 1,
  111. mediaType: ['video'],
  112. sourceType: ['album', 'camera'],
  113. maxDuration: 30,
  114. camera: 'back',
  115. success(res) {
  116. wx.showLoading({
  117. title: '正在上传视频',
  118. mask: true
  119. });
  120. const tempFiles = res.tempFiles
  121. that.upload(tempFiles[0].thumbTempFilePath).then((data) => {
  122. if(imgs.length > 0 && imgs[0].type == 'video') {
  123. that.setData({
  124. ['imgs[' + 0 + '].thumb']: data.data.url
  125. })
  126. } else {
  127. imgs.unshift({
  128. type: 'video',
  129. thumb: data.data.url,
  130. url: ''
  131. })
  132. that.setData({ imgs })
  133. }
  134. // that.setData({ imgs })
  135. wx.hideLoading()
  136. });
  137. that.upload(tempFiles[0].tempFilePath).then((data) => {
  138. if(imgs.length > 0 && imgs[0].type == 'video') {
  139. that.setData({
  140. ['imgs[' + 0 + '].url']: data.data.url
  141. })
  142. } else {
  143. imgs.unshift({
  144. type: 'video',
  145. thumb: '',
  146. url: data.data.url
  147. })
  148. that.setData({ imgs })
  149. }
  150. // imgs.unshift({
  151. // type: 'video',
  152. // thumb: tempFiles[0].thumbTempFilePath,
  153. // url: data.data.url
  154. // })
  155. // that.setData({ imgs })
  156. wx.hideLoading()
  157. });
  158. }
  159. })
  160. },
  161. /** 上传视频/图片 */
  162. upload(filePath) {
  163. let that = this;
  164. // 上传类型/业务类型:avatar头像,order订单反馈,check检查表反馈
  165. return new Promise((resolve,reject) => {
  166. let { imgs } = this.data;
  167. wx.uploadFile({
  168. url: `${api_url}api/upload`,
  169. // url: 'https://store.test-api.ijolijoli.com/api/upload',
  170. header: {
  171. token: wx.getStorageSync('token') || '',
  172. },
  173. filePath,
  174. name: 'file',
  175. formData: {
  176. 'type': 'check'
  177. },
  178. success(res) {
  179. console.log(res)
  180. if(res.statusCode == 200 && res.data) {
  181. let data = JSON.parse(res.data);
  182. if(data.code == 200 && data.data) {
  183. resolve(data)
  184. } else {
  185. wx.showToast({
  186. title: '上传失败',
  187. icon: 'none'
  188. })
  189. }
  190. } else {
  191. wx.showToast({
  192. title: '上传失败',
  193. icon: 'none'
  194. })
  195. }
  196. },
  197. fail(err) {
  198. wx.showToast({
  199. title: '上传失败',
  200. icon: 'none'
  201. })
  202. }
  203. })
  204. })
  205. },
  206. /**
  207. * 删除列表项
  208. */
  209. onDeleteItem(e) {
  210. let imgs = this.data.imgs;
  211. if(this.data.is_list) {
  212. imgs = this.data.check.feedback.media_list
  213. }
  214. imgs.splice(e.currentTarget.dataset.index, 1);
  215. this.setData({ imgs })
  216. console.log(imgs)
  217. },
  218. /**
  219. * /api/check/update
  220. * 添加/修改检查信息
  221. */
  222. onCheckUpdate() {
  223. let { orderId,value,imgs,check,check_id } = this.data;
  224. let option_ids = [], option_values= [];
  225. check.option_list.forEach((item,index) => {
  226. item.children.forEach((newItem,index) => {
  227. option_ids.push(newItem.id)
  228. if(newItem.status) {
  229. option_values.push(1)
  230. } else {
  231. option_values.push(2)
  232. }
  233. })
  234. })
  235. post('api/check/update',{
  236. check_id,
  237. type: check.type,
  238. option_ids: option_ids.toString(),
  239. option_values: option_values.toString(),
  240. content: value,
  241. media_list: JSON.stringify(imgs)
  242. },(res) => {
  243. wx.showToast({
  244. title: res.msg,
  245. icon: 'none'
  246. })
  247. setTimeout(() => {
  248. let pages=getCurrentPages()
  249. let prePage = pages[pages.length-1]
  250. prePage.onShow()
  251. this.setData({
  252. is_list: true
  253. })
  254. }, 1500);
  255. console.log(res)
  256. })
  257. },
  258. /** 预览图片和视频 */
  259. previewMedia(e) {
  260. let arr = this.data.imgs
  261. if(this.data.is_list) {
  262. arr = this.data.check.feedback.media_list
  263. }
  264. let current = e.currentTarget.dataset.index
  265. wx.previewMedia({
  266. sources: arr,
  267. current
  268. })
  269. },
  270. /** 切换编辑 */
  271. onChangeEdit() {
  272. this.setData({
  273. is_list: false
  274. })
  275. }
  276. }
  277. })