insert.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. let _Http = getApp().globalData.http,
  2. getTime = require("../../utils/getTime");
  3. Page({
  4. data: {
  5. loading: false,
  6. showAll: false,
  7. content: {
  8. sat_campaignid: 0
  9. },
  10. disabled: true,
  11. otheramount: 0,
  12. otheramount1: '0.00',
  13. trainingCost: '0.00',
  14. allCost: '0.00',
  15. list: []
  16. },
  17. onLoad(options) {
  18. let form = [{
  19. label: "活动名称",
  20. error: false,
  21. errMsg: "",
  22. type: "textarea",
  23. value: "",
  24. placeholder: "活动名称",
  25. valueName: "name",
  26. checking: "base",
  27. required: true
  28. }, {
  29. label: "活动类型",
  30. error: false,
  31. errMsg: "",
  32. type: "option",
  33. optionNmae: "campaigntype",
  34. optionType: "radio", //复选 radio 单选
  35. value: "",
  36. placeholder: "活动类型",
  37. valueName: "type",
  38. checking: "base",
  39. required: true
  40. }, {
  41. label: "承办医院",
  42. error: false,
  43. errMsg: "",
  44. type: "route",
  45. url: "/prsx/select/hospital/index",
  46. value: "",
  47. placeholder: "承办医院",
  48. valueName: "sa_customersid",
  49. checking: "base",
  50. required: true,
  51. params: {
  52. "content": {
  53. "pageNumber": 1,
  54. "pageSize": 20,
  55. "where": {
  56. "condition": ""
  57. }
  58. },
  59. "id": 2025102814083902,
  60. },
  61. query: "&radio=true",
  62. required: false,
  63. interrupt: true
  64. }, {
  65. label: "科室",
  66. error: false,
  67. errMsg: "",
  68. type: "route",
  69. url: "/prsx/select/department/index",
  70. value: "",
  71. placeholder: "请先选择承办医院",
  72. valueName: "sa_hospitaldepid",
  73. checking: "base",
  74. disabled: true,
  75. params: {
  76. "content": {
  77. "pageNumber": 1,
  78. "pageSize": 20,
  79. "where": {
  80. "condition": ""
  81. }
  82. },
  83. "id": 2025102310143002,
  84. },
  85. query: "&radio=true",
  86. required: false
  87. }, {
  88. label: "开始日期",
  89. error: false,
  90. errMsg: "",
  91. type: "date",
  92. start: '',
  93. value: '',
  94. placeholder: "开始日期",
  95. valueName: "begdate",
  96. checking: "base",
  97. required: true,
  98. interrupt: true
  99. }, {
  100. label: "结束日期",
  101. error: false,
  102. errMsg: "",
  103. type: "date",
  104. start: '',
  105. value: "",
  106. placeholder: "结束时间",
  107. valueName: "enddate",
  108. checking: "base",
  109. required: false
  110. }, {
  111. label: "活动性质",
  112. error: false,
  113. errMsg: "",
  114. type: "option",
  115. optionNmae: "activitytype",
  116. optionType: "radio", //复选 radio 单选
  117. value: "",
  118. placeholder: "活动性质",
  119. valueName: "activitytype",
  120. checking: "base",
  121. required: false
  122. }, {
  123. label: "活动形式",
  124. error: false,
  125. errMsg: "",
  126. type: "option",
  127. optionNmae: "activityformat",
  128. optionType: "radio", //复选 radio 单选
  129. value: "",
  130. placeholder: "活动形式",
  131. valueName: "activityformat",
  132. checking: "base",
  133. required: true
  134. }, {
  135. label: "省市县",
  136. error: false,
  137. errMsg: "",
  138. type: "region",
  139. value: [],
  140. placeholder: "省,市,县",
  141. valueName: "region",
  142. required: true
  143. }, {
  144. label: "详细地址",
  145. error: false,
  146. errMsg: "",
  147. type: "textarea",
  148. value: "",
  149. placeholder: "例: 科创园11栋1103室",
  150. valueName: "address",
  151. required: false,
  152. checking: "base"
  153. }, {
  154. label: "申请金额",
  155. error: false,
  156. errMsg: "",
  157. type: "digit",
  158. value: "",
  159. placeholder: "申请金额",
  160. valueName: "amount",
  161. checking: "base",
  162. required: false
  163. }, {
  164. label: "备注",
  165. error: false,
  166. errMsg: "",
  167. type: "textarea",
  168. value: "",
  169. placeholder: "请填写",
  170. valueName: "remarks",
  171. required: false,
  172. checking: "base"
  173. }, {
  174. label: "其他费用",
  175. error: false,
  176. errMsg: "",
  177. type: "digit",
  178. value: "",
  179. placeholder: "其他费用",
  180. valueName: "otheramount",
  181. checking: "base",
  182. required: false,
  183. interrupt: true
  184. }]
  185. if (options.data) {
  186. let data = JSON.parse(options.data);
  187. let sa_customersid = data.sa_customersid;
  188. data.sa_hospitaldepid = data.sa_hospitaldepid ? [data.hospitaldepname, [data.sa_hospitaldepid]] : ''
  189. data.sa_customersid = data.sa_hospitaldepid ? [data.hospitalname, [data.sa_customersid]] : ''
  190. if (data.city) {
  191. data.region = [data.province, data.city, data.county]
  192. } else {
  193. data.region = []
  194. }
  195. form = form.map(v => {
  196. v.value = data[v.valueName] || "";
  197. console.log("v.valueName", v.label)
  198. if (v.label == '科室' && sa_customersid) {
  199. v.params.content.sa_customersid = sa_customersid;
  200. v.disabled = false;
  201. v.placeholder = '选择科室';
  202. }
  203. return v
  204. })
  205. this.setData({
  206. disabled: false,
  207. content: {
  208. sat_campaignid: data.sat_campaignid,
  209. },
  210. form
  211. })
  212. }
  213. this.setData({
  214. form
  215. })
  216. getApp().globalData.Language.getLanguagePackage(this, options.data ? '编辑市场活动' : '新建市场活动');
  217. },
  218. interrupt({
  219. detail
  220. }) {
  221. let index = ''
  222. switch (detail.temporary.item.label) {
  223. case '承办医院':
  224. index = detail.form.findIndex(v => v.label == '承办医院')
  225. if (index != -1) {
  226. detail.form[index].value = detail.data.value;
  227. detail.form[index + 1].params.content.sa_customersid = detail.data.id[0];
  228. detail.form[index + 1].disabled = false;
  229. detail.form[index + 1].placeholder = '选择科室';
  230. }
  231. wx.navigateBack()
  232. break;
  233. case '开始日期':
  234. index = detail.form.findIndex(v => v.label == '开始日期')
  235. if (index != -1) {
  236. detail.form[index + 1].start = detail.data.value;
  237. if (new Date(detail.form[index + 1].value) < new Date(detail.data.value)) {
  238. detail.form[index + 1].value = '';
  239. }
  240. }
  241. break;
  242. case '其他费用':
  243. this.data.otheramount = detail.data.value;
  244. this.calculatePrice()
  245. break;
  246. }
  247. this.setData({
  248. form: detail.form
  249. })
  250. },
  251. calculatePrice() {
  252. const otheramount = this.data.otheramount,
  253. trainingCost = this.data.list.reduce((sum, item) => {
  254. return sum + (parseFloat(item.amount) || 0);
  255. }, 0);
  256. this.setData({
  257. otheramount1: _Http.formatMoney(otheramount, 2, '', false),
  258. trainingCost: _Http.formatMoney(trainingCost, 2, '', false),
  259. allCost: _Http.formatMoney(((trainingCost - 0) + (otheramount - 0)), 2, '', false)
  260. });
  261. },
  262. /* 表单必填项是否完成 */
  263. onConfirm({
  264. detail
  265. }) {
  266. this.setData({
  267. disabled: detail
  268. })
  269. },
  270. // 是否显示全部
  271. onChange({
  272. detail
  273. }) {
  274. this.setData({
  275. showAll: detail,
  276. })
  277. },
  278. async submit() {
  279. this.setData({
  280. loading: true
  281. })
  282. let data = this.selectComponent("#Form").submit(),
  283. content = this.data.content
  284. data.sa_customersid = data.sa_customersid.length ? data.sa_customersid[1][0] : 0;
  285. data.sa_hospitaldepid = data.sa_hospitaldepid.length ? data.sa_hospitaldepid[1][0] : 0;
  286. content.province = data.region[0];
  287. content.city = data.region[1];
  288. content.county = data.region[2];
  289. data.doctors = this.data.list.map(v => {
  290. return {
  291. "sat_campaign_doctorid": 0,
  292. "sa_doctorid": v.sa_doctorid,
  293. "amount": v.amount
  294. }
  295. });
  296. _Http.basic({
  297. "classname": "webmanage.saletool.orderclue.ordercluecampaign",
  298. "method": "insertormodify_campaign",
  299. "content": {
  300. ...content,
  301. ...data,
  302. }
  303. }).then(res => {
  304. this.setData({
  305. loading: false
  306. })
  307. wx.showToast({
  308. title: res.code != '1' ? res.msg : '保存成功',
  309. icon: "none",
  310. mask: res.code == '1'
  311. })
  312. if (res.code != '1') return;
  313. getCurrentPages().forEach(v => {
  314. if (v.route == 'prsx/activity/detail') v.getDetail()
  315. })
  316. setTimeout(() => {
  317. if (content.sat_campaignid == 0) {
  318. wx.redirectTo({
  319. url: '/prsx/activity/detail?id=' + res.data.sat_campaignid,
  320. })
  321. } else {
  322. wx.navigateBack()
  323. }
  324. }, 300)
  325. })
  326. },
  327. insetr() {
  328. let params = {
  329. "id": 2025103013523102,
  330. "content": {
  331. "sat_campaignid": 0,
  332. pageNumber: 1,
  333. pageSize: 20,
  334. "where": {
  335. "condition": ""
  336. }
  337. }
  338. };
  339. wx.navigateTo({
  340. url: '/prsx/select/docter/index?params=' + JSON.stringify(params) + '&radio=true',
  341. })
  342. let that = this;
  343. getApp().globalData.handleSelect = function ({
  344. item
  345. }) {
  346. wx.showModal({
  347. content: `是否确定添加“${item.doctorname}”`,
  348. complete: ({
  349. confirm
  350. }) => {
  351. if (confirm) {
  352. if (!this.data.list.some(v => v.sa_doctorid == item.sa_doctorid)) {
  353. item.amount = 0
  354. that.setData({
  355. list: this.data.list.concat([item])
  356. })
  357. }
  358. wx.showToast({
  359. title: '添加成功',
  360. icon: "none"
  361. })
  362. }
  363. }
  364. })
  365. }.bind(this)
  366. },
  367. deleteItem(e) {
  368. const {
  369. item
  370. } = e.currentTarget.dataset,
  371. that = this;
  372. wx.showModal({
  373. content: `是否确定删除“${item.doctorname}”`,
  374. complete: ({
  375. confirm
  376. }) => {
  377. if (confirm) {
  378. that.setData({
  379. list: that.data.list.filter(v => v.sa_doctorid != item.sa_doctorid)
  380. })
  381. this.calculatePrice();
  382. }
  383. }
  384. })
  385. },
  386. toSearch() {
  387. if (this.data.showSearch && this.data.content.where.condition) {
  388. this.data.content.where.condition = '';
  389. this.getList("", true);
  390. } else if (this.data.condition) {
  391. this.data.content.where.condition = this.data.condition;
  392. this.setData({
  393. condition: this.data.condition
  394. })
  395. this.getList("", true);
  396. }
  397. this.setData({
  398. showSearch: !this.data.showSearch
  399. })
  400. setTimeout(() => {
  401. this.setData({
  402. focus: this.data.showSearch
  403. })
  404. }, 300)
  405. },
  406. // onChange({
  407. // detail
  408. // }) {
  409. // this.data.condition = detail;
  410. // },
  411. onSearch({
  412. detail
  413. }) {
  414. this.data.content.where.condition = detail;
  415. this.getList("", true)
  416. },
  417. changeAmount(e) {
  418. let value = e.detail.value,
  419. index = e.currentTarget.dataset.index;
  420. this.data.list[index].amount = value;
  421. this.calculatePrice();
  422. }
  423. })