You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

482 lines
16 KiB

  1. <template>
  2. <view class="page">
  3. <view v-if="ready">
  4. <l-select
  5. @input="setValue('orderData.F_CustomerId', $event)"
  6. :value="getValue('orderData.F_CustomerId')"
  7. :disabled="!edit"
  8. :range="dataSource.orderData.F_CustomerId"
  9. title="客户名称"
  10. required
  11. />
  12. <l-organize-picker
  13. @input="setValue('orderData.F_SellerId', $event)"
  14. :value="getValue('orderData.F_SellerId')"
  15. :readonly="!edit"
  16. type="user"
  17. title="销售人员"
  18. required
  19. />
  20. <l-date-picker
  21. @input="setValue('orderData.F_OrderDate', $event)"
  22. :value="getValue('orderData.F_OrderDate')"
  23. :disabled="!edit"
  24. title="单据日期"
  25. required
  26. />
  27. <l-input
  28. :value="getValue('orderData.F_OrderCode')"
  29. title="单据编号"
  30. required
  31. disabled
  32. />
  33. <view
  34. v-for="(tableItem, tableIndex) of current.orderProductData"
  35. :key="tableIndex"
  36. :class="edit ? '' : 'margin-bottom'"
  37. >
  38. <view class="table-item padding-lr flex align-center justify-between" style="font-size: 14px; height: 30px;">
  39. <view class="table-item-title">产品明细 (第{{ tableIndex + 1 }}项)</view>
  40. <view
  41. v-if="tableIndex !== 0 && edit"
  42. class="table-item-delete text-blue"
  43. @click="tableDelete('orderProductData', tableIndex)"
  44. >
  45. 删除
  46. </view>
  47. </view>
  48. <l-layer-picker
  49. @input="layerSet(tableIndex, 'orderProductData', 'F_ProductName', $event)"
  50. :value="getValue(`orderProductData.${tableIndex}.F_ProductName`)"
  51. :readonly="!edit"
  52. :source="dataSource.orderProductData.F_ProductName"
  53. :layerData="scheme.orderProductData.F_ProductName.layerData"
  54. title="商品名称"
  55. />
  56. <l-input :value="getValue(`orderProductData.${tableIndex}.F_ProductCode`)" title="商品编号" disabled />
  57. <l-input
  58. @input="setValue(`orderProductData.${tableIndex}.F_UnitId`, $event)"
  59. :value="getValue(`orderProductData.${tableIndex}.F_UnitId`)"
  60. :disabled="!edit"
  61. title="单位"
  62. />
  63. <l-input
  64. @input="setValue(`orderProductData.${tableIndex}.F_Qty`, $event)"
  65. @change="calcPrice(tableIndex)"
  66. :value="getValue(`orderProductData.${tableIndex}.F_Qty`)"
  67. :disabled="!edit"
  68. title="数量"
  69. />
  70. <l-input
  71. @input="setValue(`orderProductData.${tableIndex}.F_Price`, $event)"
  72. @change="calcPrice(tableIndex)"
  73. :value="getValue(`orderProductData.${tableIndex}.F_Price`)"
  74. :disabled="!edit"
  75. title="单价"
  76. />
  77. <l-input
  78. @input="setValue(`orderProductData.${tableIndex}.F_TaxRate`, $event)"
  79. @change="calcPrice(tableIndex)"
  80. :value="getValue(`orderProductData.${tableIndex}.F_TaxRate`)"
  81. :disabled="!edit"
  82. title="税率 (%)"
  83. />
  84. <l-input :value="getValue(`orderProductData.${tableIndex}.F_Taxprice`)" title="含税单价" disabled />
  85. <l-input :value="getValue(`orderProductData.${tableIndex}.F_Tax`)" title="总税额" disabled />
  86. <l-input :value="getValue(`orderProductData.${tableIndex}.F_Amount`)" title="不含税总金额" disabled />
  87. <l-input :value="getValue(`orderProductData.${tableIndex}.F_TaxAmount`)" title="含税总金额" disabled />
  88. <l-input
  89. @input="setValue(`orderProductData.${tableIndex}.F_Description`, $event)"
  90. :value="getValue(`orderProductData.${tableIndex}.F_Description`)"
  91. :disabled="!edit"
  92. title="说明信息"
  93. />
  94. </view>
  95. <view
  96. v-if="edit"
  97. @click="tableAdd('orderProductData')"
  98. class="bg-white flex flex-wrap justify-center align-center margin-bottom"
  99. >
  100. <view class="add-btn text-blue padding">+ 添加一行表格</view>
  101. </view>
  102. <l-textarea
  103. @input="setValue('orderData.F_Description', $event)"
  104. :value="getValue('orderData.F_Description')"
  105. :readonly="!edit"
  106. title="备注信息"
  107. />
  108. <l-select
  109. @input="setValue('orderData.F_PaymentState', $event)"
  110. :value="getValue('orderData.F_PaymentState')"
  111. :disabled="!edit"
  112. :range="dataSource.orderData.F_PaymentState"
  113. title="收款状态"
  114. required
  115. />
  116. <l-input
  117. @input="setValue('orderData.F_DiscountSum', $event)"
  118. :value="getValue('orderData.F_DiscountSum')"
  119. :disabled="!edit"
  120. title="优惠金额"
  121. required
  122. />
  123. <l-input
  124. @input="setValue('orderData.F_Accounts', $event)"
  125. :value="getValue('orderData.F_Accounts')"
  126. :disabled="!edit"
  127. title="收款金额"
  128. required
  129. />
  130. <l-date-picker
  131. @input="setValue('orderData.F_PaymentDate', $event)"
  132. :value="getValue('orderData.F_PaymentDate')"
  133. :disabled="!edit"
  134. title="收款日期"
  135. required
  136. />
  137. <l-select
  138. @input="setValue('orderData.F_PaymentMode', $event)"
  139. :value="getValue('orderData.F_PaymentMode')"
  140. :disabled="!edit"
  141. :range="dataSource.orderData.F_PaymentMode"
  142. title="收款方式"
  143. required
  144. />
  145. <l-input
  146. @input="setValue('orderData.F_SaleCost', $event)"
  147. :value="getValue('orderData.F_SaleCost')"
  148. :disabled="!edit"
  149. title="销售费用"
  150. required
  151. />
  152. <l-organize-picker
  153. :value="getValue('orderData.F_CreateUserId')"
  154. type="user"
  155. title="销售人员"
  156. readonly
  157. />
  158. <l-input
  159. @input="setValue('orderData.F_ContractCode', $event)"
  160. :value="getValue('orderData.F_ContractCode')"
  161. :disabled="!edit"
  162. title="合同编号"
  163. />
  164. <l-textarea
  165. @input="setValue('orderData.F_AbstractInfo', $event)"
  166. :value="getValue('orderData.F_AbstractInfo')"
  167. :readonly="!edit"
  168. title="摘要信息"
  169. />
  170. </view>
  171. <view v-if="ready" class="bg-white margin-tb padding" style="padding-top: 0; overflow: hidden;">
  172. <l-button v-if="edit" @click="action('save')" size="lg" color="green" class="block margin-top" block>
  173. 提交保存
  174. </l-button>
  175. <l-button
  176. v-if="!edit && mode !== 'create'"
  177. @click="action('edit')"
  178. size="lg"
  179. color="orange"
  180. class="block margin-top"
  181. block
  182. >
  183. 编辑本页
  184. </l-button>
  185. <l-button
  186. v-if="edit && mode !== 'create'"
  187. @click="action('reset')"
  188. size="lg"
  189. line="red"
  190. class="block margin-top"
  191. block
  192. >
  193. 取消编辑
  194. </l-button>
  195. <l-button
  196. v-if="!edit && mode !== 'create'"
  197. @click="action('delete')"
  198. size="lg"
  199. color="red"
  200. class="block margin-top"
  201. block
  202. >
  203. 删除
  204. </l-button>
  205. </view>
  206. </view>
  207. </template>
  208. <script>
  209. /*
  210. * 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn)
  211. * Copyright (c) 2013-2020 上海力软信息技术有限公司
  212. * 创建人:超级管理员
  213. * 日 期:2020-05-27 10:29
  214. * 描 述:1111
  215. */
  216. import get from 'lodash/get'
  217. import set from 'lodash/set'
  218. import moment from 'moment'
  219. import mixins from '@/common/custompage.js'
  220. export default {
  221. mixins: [mixins],
  222. data() {
  223. return {
  224. // 页面参数
  225. id: null,
  226. mode: null,
  227. edit: null,
  228. ready: false,
  229. // 表单数据
  230. current: {},
  231. origin: {},
  232. // 表单项数据结构
  233. scheme: {
  234. orderData: {
  235. F_CustomerId: {
  236. type: 'select',
  237. title: '客户名称',
  238. verify: 'NotNull',
  239. dataSource: '1',
  240. dataSourceId: 'crmCustomer,f_fullname,f_customerid'
  241. },
  242. F_SellerId: { type: 'organize', title: '销售人员', verify: 'NotNull', dataType: 'user' },
  243. F_OrderDate: { type: 'datetime', title: '单据日期', dfvalue: '1', verify: 'NotNull', dateformat: '0' },
  244. F_OrderCode: { type: 'encode', title: '单据编号', rulecode: '10002' },
  245. F_Description: { type: 'textarea', title: '备注信息' },
  246. F_PaymentState: { type: 'select', title: '收款状态', verify: 'NotNull', dataSource: '0' },
  247. F_DiscountSum: { type: 'text', title: '优惠金额', dfvalue: '0', verify: 'Num' },
  248. F_Accounts: { type: 'text', title: '收款金额', dfvalue: '0', verify: 'Num' },
  249. F_PaymentDate: { type: 'datetime', title: '收款日期', verify: 'NotNull', dateformat: '0' },
  250. F_PaymentMode: {
  251. type: 'select',
  252. title: '收款方式',
  253. verify: 'NotNull',
  254. itemCode: 'Client_PaymentMode',
  255. dataSource: '0'
  256. },
  257. F_SaleCost: { type: 'text', title: '销售费用', dfvalue: '0', verify: 'Num' },
  258. F_CreateUserId: { type: 'currentInfo', title: '制单人员', dataType: 'user' },
  259. F_ContractCode: { type: 'text', title: '合同编号' },
  260. F_AbstractInfo: { type: 'textarea', title: '摘要信息' }
  261. },
  262. orderProductData: {
  263. __GIRDTABLE__: '产品明细',
  264. F_ProductName: {
  265. type: 'layer',
  266. title: '商品名称',
  267. itemCode: 'Client_ProductInfo',
  268. dataSource: '0',
  269. layerData: [
  270. { label: '商品名称', name: 'F_ItemName', value: 'F_ProductName' },
  271. { label: '商品编号', name: 'F_ItemValue', value: 'F_ProductCode' }
  272. ]
  273. },
  274. F_ProductCode: { type: 'label', title: '商品编号', dataSource: '0' },
  275. F_UnitId: { type: 'input', title: '单位', dataSource: '0' },
  276. F_Qty: { type: 'input', title: '数量', dataSource: '0' },
  277. F_Price: { type: 'input', title: '单价', dataSource: '0' },
  278. F_TaxRate: { type: 'input', title: '税率 (%)', dataSource: '0' },
  279. F_Taxprice: { type: 'input', title: '含税单价', dataSource: '0' },
  280. F_Tax: { type: 'input', title: '总税额', dataSource: '0' },
  281. F_Amount: { type: 'input', title: '不含税总金额', dataSource: '0' },
  282. F_TaxAmount: { type: 'input', title: '含税总金额', dataSource: '0' },
  283. F_Description: { type: 'input', title: '说明信息', dataSource: '0' }
  284. }
  285. },
  286. // 选单数据
  287. dataSource: {
  288. orderData: {
  289. F_CustomerId: [],
  290. F_PaymentState: [
  291. { text: '未收款', value: '1' },
  292. { text: '部分收款', value: '2' },
  293. { text: '全部收款', value: '3' }
  294. ],
  295. F_PaymentMode: Object.values(this.GET_GLOBAL('dataDictionary').Client_PaymentMode).map(t => ({
  296. value: t.value,
  297. text: t.text
  298. }))
  299. },
  300. orderProductData: {
  301. F_ProductName: Object.values(this.GET_GLOBAL('dataDictionary').Client_ProductInfo).map(t => ({
  302. F_ItemName: t.text,
  303. F_ItemValue: t.value
  304. }))
  305. }
  306. }
  307. }
  308. },
  309. async onLoad({ type, id }) {
  310. await this.init(type, id)
  311. },
  312. methods: {
  313. // 页面初始化
  314. async init(type, id) {
  315. this.LOADING('加载数据中…')
  316. this.id = id
  317. this.mode = type
  318. this.edit = ['create', 'edit'].includes(this.mode)
  319. // 拉取表单数据,同时拉取所有来自数据源的选单数据
  320. await Promise.all([
  321. this.FETCH_DATASOURCE('crmCustomer').then(result => {
  322. this.dataSource.orderData.F_CustomerId = result.data.map(t => ({
  323. text: t.f_fullname,
  324. value: t.f_customerid
  325. }))
  326. }),
  327. this.fetchForm()
  328. ])
  329. this.ready = true
  330. this.HIDE_LOADING()
  331. },
  332. // 加载表单数据
  333. async fetchForm() {
  334. if (this.mode === 'create') {
  335. this.origin = await this.getDefaultForm()
  336. } else {
  337. const result = await this.HTTP_GET('/crm/order/form', this.id)
  338. this.origin = await this.formatFormData(result)
  339. }
  340. this.current = this.COPY(this.origin)
  341. },
  342. // 点击 「编辑」、「重置」、「保存」、「删除」 按钮
  343. async action(type) {
  344. switch (type) {
  345. case 'edit':
  346. this.edit = true
  347. break
  348. case 'reset':
  349. this.current = this.COPY(this.origin)
  350. this.edit = false
  351. break
  352. case 'save':
  353. const verifyResult = this.verifyForm()
  354. if (verifyResult.length > 0) {
  355. this.CONFIRM('表单验证失败', verifyResult.join('\n'))
  356. return
  357. }
  358. if (!(await this.CONFIRM('提交确认', '确定要提交本页表单内容吗?', true))) {
  359. return
  360. }
  361. this.LOADING('正在提交…')
  362. const originPostData = await this.getPostData()
  363. const postData = {
  364. crmOrderJson: originPostData.strEntity,
  365. crmOrderProductJson: originPostData.strorderProductDataEntity
  366. }
  367. if (this.mode !== 'create') {
  368. postData.keyValue = originPostData.keyValue
  369. }
  370. this.HTTP_POST('/crm/order/save', postData, '表单提交保存失败').then(success => {
  371. this.HIDE_LOADING()
  372. if (!success) {
  373. return
  374. }
  375. this.EMIT('crm-order-list-change')
  376. this.NAV_BACK()
  377. this.TOAST('提交保存成功', 'success')
  378. })
  379. break
  380. case 'delete':
  381. if (!(await this.CONFIRM('删除项目', '确定要删除本项吗?', true))) {
  382. return
  383. }
  384. this.LOADING('提交删除中…')
  385. this.HTTP_POST('/crm/order/delete', this.id, '删除失败').then(success => {
  386. this.HIDE_LOADING()
  387. if (!success) {
  388. return
  389. }
  390. this.EMIT('crm-order-list-change')
  391. this.NAV_BACK()
  392. this.TOAST('删除成功', 'success')
  393. })
  394. break
  395. default:
  396. break
  397. }
  398. },
  399. // 计算表单中的单价总价相关项
  400. calcPrice(index) {
  401. const listItem = this.COPY(this.current.orderProductData[index])
  402. const singlePrice = Number(listItem.F_Price) || 0
  403. const num = Number(listItem.F_Qty) || 0
  404. const taxRate = Number(listItem.F_TaxRate) || 0
  405. listItem.F_Amount = (singlePrice * num).toFixed(2)
  406. listItem.F_Taxprice = (singlePrice * (1 + taxRate / 100)).toFixed(2)
  407. listItem.F_Tax = ((singlePrice * num * taxRate) / 100).toFixed(2)
  408. listItem.F_TaxAmount = (singlePrice * num * (1 + taxRate / 100)).toFixed(2)
  409. this.$set(this.current.orderProductData, index, listItem)
  410. },
  411. // 子表格删除一行
  412. tableDelete(tableName, index) {
  413. this.current[tableName].splice(index, 1)
  414. },
  415. // 子表格添加一行
  416. async tableAdd(tableName) {
  417. const newVal = {}
  418. for (const [fieldName, schemeItem] of Object.entries(this.scheme[tableName])) {
  419. if (fieldName !== '__GIRDTABLE__') {
  420. newVal[fieldName] = await this.getDefaultValue(`${tableName}.${fieldName}`, schemeItem)
  421. }
  422. }
  423. this.current[tableName].push(newVal)
  424. },
  425. // 子表格弹层输入,可一次性设置多个字段
  426. layerSet(tableIndex, table, field, layerValue) {
  427. const layerData = get(this.scheme, `${table}.${field}.layerData`, [])
  428. layerData.forEach(({ name, value }) => {
  429. this.setValue(`${table}.${tableIndex}.${value}`, layerValue[name] || '')
  430. })
  431. },
  432. // 获取表单值
  433. getValue(path) {
  434. return get(this.current, path)
  435. },
  436. // 设置表单值
  437. setValue(path, val) {
  438. set(this.current, path, val)
  439. }
  440. }
  441. }
  442. </script>