setting.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. import WxValidate from '../../utils/WxValidate.js';
  4. var status = require('../../utils/index.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. showEditAvatar: false,
  11. showEditUserInfo: false,
  12. showEditFinance: false,
  13. currentFocus: '',
  14. rest: 0, // 1休息 0营业
  15. headInfo: '',
  16. btnLoading: false,
  17. tuanItems: [
  18. { name: 0, value: '跟随系统' },
  19. { name: 1, value: '开启' },
  20. { name: 2, value: '关闭' }
  21. ],
  22. tuanType: ['跟随系统','开启','关闭'],
  23. fareItems: [
  24. { name: 0, value: '跟随系统' },
  25. { name: 1, value: '自定义' }
  26. ],
  27. groupInfo: {
  28. group_name: '社区',
  29. owner_name: '团长'
  30. },
  31. image_o: ''
  32. },
  33. is_modify_shipping_method: 0,
  34. is_modify_shipping_fare: 0,
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad: function (options) {
  39. let that = this;
  40. status.setGroupInfo().then((groupInfo) => {
  41. let owner_name = groupInfo && groupInfo.owner_name || '团长';
  42. wx.setNavigationBarTitle({
  43. title: `${owner_name}中心`,
  44. })
  45. that.setData({ groupInfo })
  46. });
  47. let id = options && (options.id || 0);
  48. if (!util.check_login()) {
  49. wx.switchTab({
  50. url: '/lionfish_comshop/pages/user/me',
  51. })
  52. }
  53. if (!id) wx.switchTab({ url: '/lionfish_comshop/pages/user/me' });
  54. this.initValidate(); //验证规则函数
  55. this.getData(id);
  56. },
  57. /**
  58. * 生命周期函数--监听页面显示
  59. */
  60. onShow: function () {
  61. },
  62. radioChange(e) {
  63. console.log(e)
  64. let name = e.currentTarget.dataset.name;
  65. if (name =='method'){
  66. this.is_modify_shipping_method = e.detail.value;
  67. } else if (name == 'fare'){
  68. this.is_modify_shipping_fare = e.detail.value;
  69. let showFare = false;
  70. if(e.detail.value == 1) showFare = true;
  71. this.setData({ showFare })
  72. }
  73. },
  74. //资料验证函数
  75. initValidate() {
  76. const rules = {
  77. head_name: {
  78. required: true,
  79. minlength: 1
  80. },
  81. head_mobile: {
  82. required: true,
  83. tel: true
  84. }
  85. }
  86. const messages = {
  87. head_name: {
  88. required: '请填写团长名称',
  89. minlength: '请输入正确的团长名称'
  90. },
  91. head_mobile: {
  92. required: '请填写手机号',
  93. tel: '请填写正确的手机号'
  94. }
  95. }
  96. this.WxValidate = new WxValidate(rules, messages)
  97. },
  98. /**
  99. * 获取数据
  100. */
  101. getData: function(id){
  102. let token = wx.getStorageSync('token');
  103. let that = this;
  104. app.util.request({
  105. 'url': 'entry/wxapp/index',
  106. 'data': {
  107. controller: 'community.get_head_info',
  108. id,
  109. token
  110. },
  111. dataType: 'json',
  112. success: function (res) {
  113. if (res.data.code == 0) {
  114. let headInfo = res.data.data;
  115. let showFare = headInfo.is_modify_shipping_fare == 1 ? true : false;
  116. that.setData({
  117. headInfo: headInfo,
  118. rest: res.data.data.rest,
  119. showFare
  120. })
  121. that.is_modify_shipping_method = headInfo.is_modify_shipping_method || 0;
  122. that.is_modify_shipping_fare = headInfo.is_modify_shipping_fare || 0;
  123. } else {
  124. wx.switchTab({
  125. url: '/lionfish_comshop/pages/user/me',
  126. })
  127. }
  128. }
  129. })
  130. },
  131. /**
  132. * 显示头像修改窗口
  133. */
  134. showEdit: function (t) {
  135. let type = t.currentTarget.dataset.type;
  136. if (type == 'avatar') {
  137. this.setData({
  138. showEditAvatar: true
  139. })
  140. } else if (type == 'info') {
  141. this.setData({
  142. showEditUserInfo: true
  143. })
  144. } else if (type == 'finance') {
  145. this.setData({
  146. showEditFinance: true
  147. })
  148. }
  149. },
  150. /**
  151. * 隐藏头像修改窗口
  152. */
  153. hideEdit: function () {
  154. this.setData({
  155. showEditAvatar: false,
  156. showEditUserInfo: false,
  157. showEditFinance: false
  158. })
  159. },
  160. /**
  161. * 输入框获得焦点
  162. */
  163. iptFocus: function (t) {
  164. let name = t.currentTarget.dataset.name;
  165. this.setData({
  166. currentFocus: name
  167. })
  168. },
  169. /**
  170. * 输入框失去焦点
  171. */
  172. iptBlur: function () {
  173. this.setData({
  174. currentFocus: ''
  175. })
  176. },
  177. /**
  178. * 状态切换
  179. */
  180. switchChange(e) {
  181. let rest = e.detail.value ? 0 : 1 ;
  182. let headInfo = this.data.headInfo;
  183. let id = headInfo && (headInfo.id || 0);
  184. let token = wx.getStorageSync('token');
  185. let that = this;
  186. app.util.request({
  187. 'url': 'entry/wxapp/index',
  188. 'data': {
  189. controller: 'community.set_head_rest',
  190. id,
  191. token,
  192. rest
  193. },
  194. dataType: 'json',
  195. success: function (res) {
  196. if (res.data.code == 0) {
  197. that.setData({
  198. rest: rest
  199. })
  200. } else if (res.data.code == 1) {
  201. wx.switchTab({
  202. url: '/lionfish_comshop/pages/user/me',
  203. })
  204. } else {
  205. that.setData({
  206. rest: !rest
  207. })
  208. wx.showToast({
  209. title: '修改失败',
  210. })
  211. }
  212. }
  213. })
  214. },
  215. //报错
  216. showModal(error) {
  217. wx.showModal({
  218. content: error.msg,
  219. showCancel: false,
  220. })
  221. },
  222. /**
  223. * 资料修改表单提交
  224. */
  225. infoFormSubmit(e) {
  226. this.setData({ btnLoading: true })
  227. const params = e.detail.value
  228. //校验表单
  229. if (!this.WxValidate.checkForm(params)) {
  230. const error = this.WxValidate.errorList[0];
  231. this.showModal(error);
  232. this.setData({ btnLoading: false })
  233. return false;
  234. }
  235. let is_modify_shipping_method = this.is_modify_shipping_method;
  236. let is_modify_shipping_fare = this.is_modify_shipping_fare;
  237. let data = Object.assign({}, params, { is_modify_shipping_method, is_modify_shipping_fare });
  238. if (is_modify_shipping_fare==1) {
  239. if (params.shipping_fare*1<=0) {
  240. wx.showToast({
  241. title: '请输入配送费',
  242. icon: 'none'
  243. })
  244. this.setData({ btnLoading: false })
  245. return;
  246. }
  247. }
  248. this.modifyHeadInfo(data);
  249. },
  250. /**
  251. * 资料修改
  252. */
  253. modifyHeadInfo(params) {
  254. let token = wx.getStorageSync('token');
  255. let headInfo = this.data.headInfo;
  256. let id = headInfo.id;
  257. let that = this;
  258. let share_wxcode = this.data.image_o;
  259. if (share_wxcode) params.share_wxcode = share_wxcode;
  260. app.util.request({
  261. 'url': 'entry/wxapp/index',
  262. 'data': {
  263. controller: 'community.modify_head_info',
  264. id,
  265. token,
  266. ...params
  267. },
  268. dataType: 'json',
  269. success: function (res) {
  270. if (res.data.code == 0) {
  271. let share_wxcode_old = headInfo.share_wxcode;
  272. headInfo = Object.assign({}, headInfo, params);
  273. headInfo.share_wxcode = share_wxcode_old;
  274. that.setData({
  275. headInfo
  276. })
  277. that.showModal({
  278. msg: '修改成功'
  279. })
  280. } else if (res.data.code == 1) {
  281. wx.switchTab({
  282. url: '/lionfish_comshop/pages/user/me',
  283. })
  284. } else {
  285. that.showModal({
  286. msg: '修改失败'
  287. })
  288. }
  289. that.hideEdit();
  290. that.setData({ btnLoading: false })
  291. }
  292. })
  293. },
  294. choseImg: function () {
  295. var self = this;
  296. wx.chooseImage({
  297. count: 1, // 默认9
  298. sizeType: ['original', 'compressed'],
  299. sourceType: ['album', 'camera'],
  300. success: function (res) {
  301. var tempFilePaths = res.tempFilePaths;
  302. wx.showLoading({
  303. title: '上传中',
  304. })
  305. wx.uploadFile({
  306. url: app.util.url('entry/wxapp/index', { 'm': 'lionfish_comshop', 'controller': 'goods.doPageUpload' }),
  307. filePath: tempFilePaths[0],
  308. name: 'upfile',
  309. formData: {
  310. 'name': tempFilePaths[0]
  311. },
  312. header: {
  313. 'content-type': 'multipart/form-data'
  314. },
  315. success: function (res) {
  316. wx.hideLoading();
  317. var data = JSON.parse(res.data);
  318. const { image_o, image_o_full, image_thumb } = data;
  319. self.setData({
  320. 'headInfo.share_wxcode': image_o_full,
  321. image_o: image_o
  322. })
  323. }
  324. })
  325. }
  326. })
  327. }
  328. })