append.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // pages/append/append.js
  2. const { getCategoryAPI, upLoadGoods } = require('../../API/appraise')
  3. const { upLoad, chooseImage } = require('../../utils/util')
  4. const baseURL = "http://192.168.31.30:8084";
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. latitude: 0,
  11. longtitude: 0,
  12. mapName: "",
  13. columns: [],
  14. id: [],
  15. popShow: false,
  16. clssify: [],
  17. valueKeyName: "",
  18. index: 0,
  19. // 页面数据们
  20. title: "",
  21. desc: "",
  22. price: Number,
  23. address: "",
  24. fileList: [],
  25. maxgoodsURL: 6
  26. // clssify: Number
  27. },
  28. popChange() {
  29. this.setData({
  30. popShow: true
  31. })
  32. this.getClassifyList()
  33. },
  34. onConfirm(e) {
  35. const { value, index} = e.detail;
  36. this.setData({
  37. popShow: false,
  38. valueKeyName: value,
  39. index: index
  40. })
  41. },
  42. onCancel() {
  43. this.setData({
  44. popShow: false,
  45. valueKeyName: ""
  46. })
  47. },
  48. titleInput(e) {
  49. const {value, cursor, keyCode} = e.detail;
  50. this.setData({
  51. title: value
  52. })
  53. },
  54. describeInput(e) {
  55. const {value, cursor, keyCode} = e.detail;
  56. this.setData({
  57. desc: value
  58. })
  59. },
  60. numInput(e){
  61. const {value, cursor, keyCode} = e.detail;
  62. this.setData({
  63. price: value
  64. })
  65. },
  66. adressInput(e) {
  67. const { value, cursor, keyCode} = e.detail;
  68. this.setData({
  69. address: value
  70. })
  71. },
  72. upData(){
  73. // const price = this.data.price;
  74. // const address = this.data.address;
  75. // const classify = this.data.id[this.data.index];
  76. // upLoadGoods(this.data).then((res) => {
  77. // console.log(res);
  78. // }).catch((err) => {
  79. // console.log(err);
  80. // })
  81. wx.request({
  82. url: baseURL + '/goods/create',
  83. method: "POST",
  84. header: {
  85. "content-type": "application/x-www-form-urlencoded"
  86. },
  87. data: {
  88. "categories": [
  89. this.data.id[this.data.index]
  90. ],
  91. "desc": this.data.desc,
  92. "ownerId": 0,
  93. "pic": this.data.fileList,
  94. "place": this.data.address,
  95. "price": this.data.price,
  96. "state": 0,
  97. "title": this.data.title
  98. },
  99. success: function(res) {
  100. console.log(res);
  101. }
  102. })
  103. },
  104. /**
  105. * 生命周期函数--监听页面加载
  106. */
  107. onLoad(options) {
  108. },
  109. getClassifyList() {
  110. getCategoryAPI(this.data)
  111. .then((res) => {
  112. const { code, data, mesage } = res.data;
  113. const name = [];
  114. const id = [];
  115. for (let i = 0; i < data.length; i++) {
  116. name[i] = data[i].Name;
  117. id[i] = data[i].Id;
  118. }
  119. console.log(id);
  120. this.setData({
  121. columns: name,
  122. id: id
  123. })
  124. })
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady() {
  130. },
  131. /**
  132. * 生命周期函数--监听页面显示
  133. */
  134. onShow() {
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide() {
  140. },
  141. /**
  142. * 生命周期函数--监听页面卸载
  143. */
  144. onUnload() {
  145. },
  146. /**
  147. * 页面相关事件处理函数--监听用户下拉动作
  148. */
  149. onPullDownRefresh() {
  150. },
  151. /**
  152. * 页面上拉触底事件的处理函数
  153. */
  154. onReachBottom() {
  155. },
  156. /**
  157. * 用户点击右上角分享
  158. */
  159. onShareAppMessage() {
  160. },
  161. afterRead(e) {
  162. const { file } = e.detail;
  163. upLoad(file.url).then((res) => {
  164. const { fileList = [] } = this.data;
  165. fileList.push({ ...file, url: res.data });
  166. this.setData({
  167. fileList,
  168. })
  169. console.log(this.data.fileList);
  170. })
  171. }
  172. })