customerInformationEdit.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. var util = require('../../utils/util.js')
  2. const app = getApp();
  3. Page({
  4. data: {
  5. groupNameList: [
  6. // {id: 11, name: "海文牧场"}, {id: 22, name: "成宏牧场"}, {id: 32, name: "瑞福牧业"}
  7. ],
  8. groupIndex:'',
  9. grouprId:'',
  10. customeStatusList: [
  11. // {id: 11, name: "海文牧场"}, {id: 22, name: "成宏牧场"}, {id: 32, name: "瑞福牧业"}
  12. ],
  13. customeStatusIndex:'',
  14. customeStatusId:'',
  15. rangeNameList: [
  16. // {id: 11, name: "海文牧场"}, {id: 22, name: "成宏牧场"}, {id: 32, name: "瑞福牧业"}
  17. ],
  18. rangeIndex:'',
  19. rangeId:'',
  20. provinceList: [
  21. {id: "北京市", name: "北京市"}, {id: "天津市", name: "天津市"}, {id: "河北省", name: "河北省"}, {id: "山西省", name: "山西省"}, {id: "内蒙古自治区", name: "内蒙古自治区"}, {id: "辽宁省", name: "辽宁省"}, {id: "吉林省", name: "吉林省"}, {id: "黑龙江省", name: "黑龙江省"}, {id: "上海市", name: "上海市"}, {id: "江苏省", name: "江苏省"}, {id: "浙江省", name: "浙江省"}, {id: "安徽省", name: "安徽省"}, {id: "福建省", name: "福建省"}, {id: "江西省", name: "江西省"}, {id: "山东省", name: "山东省"}, {id: "河南省", name: "河南省"}, {id: "湖北省", name: "湖北省"}, {id: "湖南省", name: "湖南省"}, {id: "广东省", name: "广东省"}, {id: "广西壮族自治区", name: "广西壮族自治区"}, {id: "海南省", name: "海南省"}, {id: "四川省", name: "四川省"}, {id: "贵州省", name: "贵州省"}, {id: "云南省", name: "云南省"}, {id: "重庆市", name: "重庆市"}, {id: "西藏自治区", name: "西藏自治区"}, {id: "陕西省", name: "陕西省"}, {id: "甘肃省", name: "甘肃省"}, {id: "青海省", name: "青海省"}, {id: "宁夏回族自治区", name: "宁夏回族自治区"}, {id: "新疆维吾尔自治区", name: "新疆维吾尔自治区"}, {id: "香港特别行政区", name: "香港特别行政区"}, {id: "澳门特别行政区", name: "澳门特别行政区"}, {id: "台湾省", name: "台湾省"}
  22. ],
  23. provinceIndex:'',
  24. province:'',
  25. directorNameList: [
  26. // {id: 56, name: "苗舒怡"},{id: 57, name: "颛孙洋洋"},{id: 58, name: "李涛"}
  27. ],
  28. directorIndex:'',
  29. directorId:'',
  30. rules: {
  31. customerName: [{ required: true, message: '客户必填', trigger: 'blur' }],
  32. groupName: [{ required: true, message: '客户集团必填', trigger: 'blur' }],
  33. customeStatusName: [{ required: true, message: '客户状态必填', trigger: 'blur' }],
  34. directorName: [{ required: true, message: '负责人必填', trigger: 'blur' }]
  35. },
  36. // 新增/编辑
  37. create: {
  38. dialogStatus: '',
  39. temp: {
  40. customerId: '', customerName: '', groupId: '', groupName: '', customeStatusId: '', customeStatusName: '', rangeId: '', rangeName: '', province: '', address: '',scode: '', directorId: '',directorName: '',createrName: '', createrId: '', createtime: util.getToday(), remark: '', content: '',
  41. receiverChoose: 'true'
  42. },
  43. }
  44. },
  45. onLoad: function (options) {
  46. // 表单初始化
  47. wx.lin.initValidateForm(this)
  48. var id = options.id;
  49. //获取编辑内容
  50. util.getDataByName({ name:'getCustomerByIdApp', parammaps: {"id":id} }, this.getShowList)
  51. },
  52. getShowList:function(res){
  53. console.log('展示数据======>', res.data.list)
  54. var customerId = res.data.list[0].customerId
  55. this.setData({
  56. ['create.temp']: res.data.list[0],
  57. ['create.temp.createrId']: app.globalData.g_lgNameId,
  58. ['create.temp.createrName']: app.globalData.g_lgName,
  59. customeStatusId: res.data.list[0].customeStatusId,
  60. groupId: res.data.list[0].groupId,
  61. rangeId: res.data.list[0].rangeId,
  62. province: res.data.list[0].province,
  63. directorId: res.data.list[0].directorId
  64. })
  65. const provinceid = res.data.list[0].province
  66. var provinceList = this.data.provinceList
  67. const provinceIndex = provinceList.findIndex(obj => obj.id == provinceid)
  68. this.setData({
  69. provinceIndex: provinceIndex
  70. })
  71. // 客户集团下拉
  72. util.getDataByName({ name: 'getDictListSelect1', parammaps: { "pid": "54" } }, this.getPickerList2)
  73. // 客户区域下拉
  74. util.getDataByName({ name: 'getDictListSelect2', parammaps: { "pid": "53" } }, this.getPickerList3)
  75. // 客户状态下拉
  76. util.getDataByName({ name: 'getDictListSelect3', parammaps: { "pid": "52" } }, this.getPickerList4)
  77. // 负责人下拉
  78. util.getDataByName({ name: 'getEmployeesSelect', parammaps: {} }, this.getPickerList5)
  79. },
  80. getPickerList2: function (res) {
  81. console.log('客户集团下拉数据======>', res.data.list)
  82. const id = this.data.groupId
  83. const groupIndex = res.data.list.findIndex(obj => obj.id == id)
  84. this.setData({
  85. groupNameList: res.data.list,
  86. groupIndex: groupIndex
  87. })
  88. },
  89. getPickerList3: function (res) {
  90. console.log('客户区域下拉数据======>', res.data.list)
  91. const id = this.data.rangeId
  92. const rangeIndex = res.data.list.findIndex(obj => obj.id == id)
  93. this.setData({
  94. rangeNameList: res.data.list,
  95. rangeIndex: rangeIndex
  96. })
  97. },
  98. getPickerList4: function (res) {
  99. console.log('客户状态下拉数据======>', res.data.list)
  100. const id = this.data.customeStatusId
  101. const customeStatusIndex = res.data.list.findIndex(obj => obj.id == id)
  102. this.setData({
  103. customeStatusList: res.data.list,
  104. customeStatusIndex: customeStatusIndex
  105. })
  106. },
  107. getPickerList5: function (res) {
  108. console.log('负责人下拉数据======>', res.data.list)
  109. const id = this.data.directorId
  110. const directorIndex = res.data.list.findIndex(obj => obj.id == id)
  111. this.setData({
  112. directorNameList: res.data.list,
  113. directorIndex: directorIndex
  114. })
  115. },
  116. //下拉框:客户集团
  117. change_group:function(e){
  118. var that = this
  119. console.log('change_group的选项', e.detail.value)
  120. var newId = this.data.groupNameList[e.detail.value]['id']
  121. this.setData({
  122. groupIndex: e.detail.value,
  123. groupId: newId,
  124. ['create.temp.groupId']: newId,
  125. })
  126. },
  127. //下拉框:客户状态
  128. change_customeStatus:function(e){
  129. var that = this
  130. console.log('change_customeStatus的选项', e.detail.value)
  131. var newId = this.data.customeStatusList[e.detail.value]['id']
  132. this.setData({
  133. customeStatusIndex: e.detail.value,
  134. customeStatusId: newId,
  135. ['create.temp.customeStatusId']: newId,
  136. })
  137. },
  138. //下拉框:客户区域
  139. change_range:function(e){
  140. var that = this
  141. console.log('change_range的选项', e.detail.value)
  142. var newId = this.data.rangeNameList[e.detail.value]['id']
  143. this.setData({
  144. rangeIndex: e.detail.value,
  145. rangeId: newId,
  146. ['create.temp.rangeId']: newId,
  147. })
  148. },
  149. //下拉框:客户省份
  150. change_province:function(e){
  151. var that = this
  152. console.log('change_province的选项', e.detail.value)
  153. var newId = this.data.provinceList[e.detail.value]['id']
  154. this.setData({
  155. provinceIndex: e.detail.value,
  156. province: newId,
  157. ['create.temp.province']: newId,
  158. })
  159. },
  160. //下拉框:负责人
  161. change_director:function(e){
  162. var that = this
  163. console.log('change_director的选项', e.detail.value)
  164. var newId = this.data.directorNameList[e.detail.value]['id']
  165. this.setData({
  166. directorIndex: e.detail.value,
  167. directorId: newId,
  168. ['create.temp.directorId']: newId,
  169. })
  170. },
  171. //保存
  172. submit:function(e){
  173. var detail_value = e.detail.values
  174. var detail_errors = e.detail.errors
  175. var detail_errors = e.detail.errors
  176. console.log("detail_value",detail_value)
  177. console.log("create.temp",this.data.create.temp)
  178. const submit_data = Object.assign({}, this.data.create.temp, detail_value)
  179. console.log("保存发送:",submit_data)
  180. var send_data = {
  181. "name": 'updateCustomer',
  182. "parammaps":submit_data
  183. }
  184. //验证必填项是否为空
  185. if(submit_data.customerId == ""){
  186. wx.showToast({title: '客户名称必填',icon: 'none',duration: 2000})
  187. } else if(submit_data.groupId == ""){
  188. wx.showToast({title: '客户集团必填',icon: 'none',duration: 2000})
  189. } else if(submit_data.customeStatusId == ""){
  190. wx.showToast({title: '客户状态必填',icon: 'none',duration: 2000})
  191. } else if(submit_data.directorId == ""){
  192. wx.showToast({title: '负责人必填',icon: 'none',duration: 2000})
  193. } else if(submit_data.scode.length != 18){
  194. wx.showToast({title: '社会统一代码必须18位!',icon: 'none',duration: 2000})
  195. } else {
  196. if( wx.getStorageSync('isLoading') == "true"){
  197. wx.showToast({
  198. title: '正在保存中,请稍等!',
  199. icon: 'none',
  200. duration: 2000
  201. })
  202. } else {
  203. util.postDataByName(send_data, this.getListSuccess)
  204. }
  205. }
  206. },
  207. getListSuccess: function (res) {
  208. console.log('table数据======>', res)
  209. if (res.msg !== 'fail') {
  210. wx.showToast({
  211. title: '保存成功',
  212. icon: 'success',
  213. duration: 2000,
  214. success: function(){
  215. wx.switchTab({ url:"../customerInformation/customerInformation"})
  216. }
  217. })
  218. } else {
  219. wx.showToast({
  220. title: '保存失败'+res.data,
  221. icon: 'error',
  222. duration: 2000,
  223. })
  224. }
  225. },
  226. onReady: function () {
  227. },
  228. onShow: function () {
  229. },
  230. onHide: function () {
  231. },
  232. onUnload: function () {
  233. },
  234. /**
  235. * 页面相关事件处理函数--监听用户下拉动作
  236. */
  237. onPullDownRefresh: function () {
  238. },
  239. /**
  240. * 页面上拉触底事件的处理函数
  241. */
  242. onReachBottom: function () {
  243. },
  244. onShareAppMessage: function () {
  245. }
  246. })