抖音b端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

339 lines
7.8 KiB

  1. // pages/operation/index.js
  2. const config = require('../../config/config.js')
  3. const Http = require('../../utils/HttpBasics.js')
  4. const util = require('../../utils/util.js')
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. showDetailIf: true,
  12. receiptUrl:null,
  13. type:null,
  14. paramData:'',
  15. array: ['美国', '中国', '巴西', '日本'],
  16. merchentList:[],
  17. spendStr:null,
  18. creditNum:0,
  19. submitAble:true,
  20. shoesList:[],
  21. clothList:[],
  22. business:'',
  23. selectTag:null,
  24. selectTag1:null
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. console.log(options,7777)
  31. console.log(options.business)
  32. this.setData({
  33. businessId: options.businessId ? options.businessId :'' ,
  34. type: options.type,
  35. isAdmin: options.isAdmin ? options.isAdmin:0,
  36. paramData:options,
  37. flag: "cloth",
  38. })
  39. this.getMerchent();
  40. this.getTag()
  41. },
  42. getTag() {
  43. let that = this;
  44. Http.get({
  45. url: config.api.getTag
  46. })
  47. .then(res => {
  48. console.log(res.data.data)
  49. that.setData({
  50. shoesList: res.data.data['28'],
  51. clothList: res.data.data['27'],
  52. })
  53. })
  54. .catch(err => {
  55. tt.showToast({
  56. title: err.message,
  57. icon: 'none',
  58. duration: 2000,
  59. mask: false
  60. });
  61. });
  62. },
  63. //切换衣服尺码
  64. getCloth() {
  65. this.setData({
  66. flag: "cloth",
  67. })
  68. },
  69. //切换鞋子尺码
  70. getShoes() {
  71. this.setData({
  72. flag: "shoes",
  73. })
  74. },
  75. //点击选中衣服鞋子尺码
  76. checkTags(e) {
  77. console.log(e)
  78. let id = e.target.id;
  79. if (this.data.flag == "cloth"){
  80. this.data.clothList.map((item, index) => {
  81. if (id == item.id) {
  82. this.setData({
  83. selectTag: item.id,
  84. })
  85. }
  86. })
  87. }else{
  88. this.data.shoesList.map((item, index) => {
  89. if (id == item.id) {
  90. this.setData({
  91. selectTag1: item.id,
  92. })
  93. }
  94. })
  95. }
  96. },
  97. /**
  98. * 跳转门店选择页面
  99. */
  100. checkMerchant(){
  101. tt.navigateTo({
  102. url: `/pages/getMerchant/index?address=${this.data.paramData.address}&id=${this.data.paramData.id}&levelName=${this.data.paramData.levelName}&name=${this.data.paramData.name}&nickName=${this.data.paramData.nickName}&phone=${this.data.paramData.phone}&score=${this.data.paramData.score}&credit=${this.data.paramData.credit}&type=1`,
  103. })
  104. },
  105. /**
  106. * 保存积分操作数据
  107. */
  108. submitForm(){
  109. let _this=this;
  110. if (_this.data.receiptUrl == null || !_this.data.receiptUrl){
  111. tt.showToast({
  112. title: '请先上传小票照片!',
  113. icon: 'none',
  114. duration: 2000,
  115. mask: false
  116. });
  117. return;
  118. }
  119. const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
  120. if (!reg.test(_this.data.spendStr) || Number(_this.data.spendStr) > 9999999.99 || Number(_this.data.spendStr)<=0) {
  121. tt.showToast({
  122. title: '消费金额限制为大于0且小于9999999.99的保留两位小数的数字!',
  123. icon: 'none',
  124. duration: 2000,
  125. mask: false
  126. });
  127. return;
  128. }
  129. /**
  130. * 判断服务台操作选择店铺
  131. */
  132. if (_this.data.paramData.isAdmin=='1'&&!_this.data.paramData.merchantType && _this.data.paramData.isAdmin == 1) {
  133. tt.showToast({
  134. title: '请选择消费店铺!',
  135. icon: 'none',
  136. duration: 2000,
  137. mask: false
  138. });
  139. return;
  140. }
  141. if (_this.data.creditNum <= 0 || !_this.data.creditNum){
  142. tt.showToast({
  143. title: '本业态消费无积分!',
  144. icon: 'none',
  145. duration: 2000,
  146. mask: false
  147. });
  148. return;
  149. }
  150. _this.setData({
  151. submitAble: false
  152. })
  153. Http.post({
  154. url: config.api.addCredit,
  155. data: {
  156. spendStr: _this.data.spendStr,
  157. creditType: 10,//新增积分
  158. cuserId: _this.data.paramData.id,
  159. operatorType: 3,
  160. receiptUrl: _this.data.receiptUrl,
  161. merchantId: _this.data.paramData.merchant_id,
  162. tags: [_this.data.selectTag, _this.data.selectTag1]
  163. }
  164. })
  165. .then(res => {
  166. this.setData({
  167. submitAble:false
  168. })
  169. tt.showToast({
  170. title: '保存成功!',
  171. icon: 'none',
  172. duration: 2000,
  173. mask: false
  174. });
  175. tt.navigateTo({
  176. url: '/pages/editSuccess/index?type=1&creditNum=' + res.data.creditNum + '&creditAmount='+res.data.creditAmount,
  177. })
  178. _this.setData({
  179. merchentList: res.data,
  180. submitAble: true
  181. })
  182. })
  183. .catch(err => {
  184. _this.setData({
  185. submitAble: true
  186. })
  187. tt.showToast({
  188. title: err.message,
  189. icon: 'none',
  190. duration: 2000,
  191. mask: false
  192. });
  193. });
  194. },
  195. getPrice(e){
  196. let _this=this;
  197. this.setData({
  198. spendStr:e.detail.value
  199. })
  200. const reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
  201. if ((!reg.test(e.detail.value) && e.detail.value != "")||Number(_this.data.spendStr) > 9999999.99 || Number(_this.data.spendStr) <= 0) {
  202. tt.showToast({
  203. title: "消费金额限制为大于0且小于9999999.99的保留两位小数的数字!",
  204. icon: 'none',
  205. duration: 2000,
  206. mask: false
  207. });
  208. return;
  209. }
  210. Http.get({
  211. url: config.api.getCreditNum,
  212. data:{
  213. spendStr: e.detail.value,
  214. merchantId: _this.data.paramData.merchant_id,
  215. userId:_this.data.paramData.id
  216. }
  217. })
  218. .then(res => {
  219. _this.setData({
  220. creditNum: res.data.credit
  221. })
  222. })
  223. .catch(err => {
  224. tt.showToast({
  225. title: err.message,
  226. icon: 'none',
  227. duration: 2000,
  228. mask: false
  229. });
  230. });
  231. },
  232. getMerchent(){
  233. let _this=this;
  234. Http.get({
  235. url: config.api.getMerchentList
  236. })
  237. .then(res => {
  238. _this.setData({
  239. merchentList: res.data
  240. })
  241. })
  242. .catch(err => {
  243. tt.showToast({
  244. title: err.message,
  245. icon: 'none',
  246. duration: 2000,
  247. mask: false
  248. });
  249. });
  250. },
  251. bindPickerChange(e) {
  252. this.setData({
  253. index: e.detail.value
  254. })
  255. },
  256. uploadImg(){
  257. console.log(123);
  258. let that=this;
  259. tt.chooseImage({
  260. count: 1, // 默认9
  261. sizeType: ['compressed'],
  262. success(res) {
  263. const tempFilePaths = res.tempFilePaths
  264. tt.uploadFile({
  265. url:`https://btest.malls.iformall.com/B/api/upload/awsFileUpload`, // 仅为示例,非真实的接口地址
  266. filePath: tempFilePaths[0],
  267. name: 'file',
  268. header: {
  269. 'token': app.globalData.token,
  270. // "content-type": "multipart/form-data",
  271. // "cookie": "TOUTIAOID" + id, // 此处添加cookie
  272. },
  273. success(res) {
  274. that.setData({
  275. receiptUrl:JSON.parse(res.data).data.url
  276. })
  277. // do something
  278. console.log(JSON.parse(res.data).data,"url");
  279. },
  280. fail: (err) => {
  281. console.log("上传失败", err);
  282. },
  283. })
  284. },
  285. fail(err){
  286. console.log(err);
  287. }
  288. })
  289. },
  290. /**
  291. * 生命周期函数--监听页面初次渲染完成
  292. */
  293. onReady: function () {
  294. },
  295. /**
  296. * 生命周期函数--监听页面显示
  297. */
  298. onShow: function () {
  299. // this.setData({
  300. // receiptUrl: null
  301. // })
  302. this.setData({
  303. submitAble: true
  304. })
  305. },
  306. /**
  307. * 生命周期函数--监听页面隐藏
  308. */
  309. onHide: function () {
  310. },
  311. /**
  312. * 生命周期函数--监听页面卸载
  313. */
  314. onUnload: function () {
  315. },
  316. /**
  317. * 页面相关事件处理函数--监听用户下拉动作
  318. */
  319. onPullDownRefresh: function () {
  320. },
  321. /**
  322. * 页面上拉触底事件的处理函数
  323. */
  324. onReachBottom: function () {
  325. }
  326. })