repair.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <template>
  2. <template-page ref="pageRef" :get-list="getList" :table-attributes="tableAttributes" :table-events="tableEvents"
  3. :operationColumnWidth="80" :options-evens-group="optionsEvensGroup" :moreParameters="moreParameters"
  4. :column-parsing="columnParsing" :operation="operation()" :exportList="exportList" :replaceOrNotMap="true" expCode="exp_wx">
  5. </template-page>
  6. </template>
  7. <script>
  8. import TemplatePage from '@/components/template/template-page-1.vue'
  9. import import_mixin from '@/components/template/import_mixin.js'
  10. import ImageUpload from '@/components/file-upload'
  11. import { required, mobileRequired, mobile, httpUrl, email } from '@/components/template/rules_verify.js'
  12. import { del, getMainList, getTypeList } from "@/api/workOrder/settlementStandardInstall";
  13. import { listPageV2, pageExport, add, edit } from "@/api/workOrder/settlementStandardRepair";
  14. import { thousands } from '@/utils/common'
  15. import operation_mixin from '@/components/template/operation_mixin.js'
  16. export default {
  17. components: { TemplatePage, ImageUpload },
  18. mixins: [import_mixin, operation_mixin],
  19. data() {
  20. return {
  21. // 表格属性
  22. tableAttributes: {
  23. // 启用勾选列
  24. selectColumn: false
  25. },
  26. // 表格事件
  27. tableEvents: {
  28. 'selection-change': this.selectionChange
  29. },
  30. // 勾选选中行
  31. recordSelected: [],
  32. /** 表单变量 */
  33. formDialogType: 0,
  34. formDialogTitles: ["新增", "编辑", "详情"],
  35. formDialog: false,
  36. formData: {
  37. companyName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
  38. },
  39. editIndex: null,
  40. mainList: [],
  41. smallList: [],
  42. typeList: []
  43. }
  44. },
  45. computed: {
  46. // 事件组合
  47. optionsEvensGroup() {
  48. return [
  49. [
  50. [
  51. this.optionsEvensAuth("add_wx", {
  52. click: this.addData
  53. })
  54. ]
  55. ]
  56. ]
  57. },
  58. // 更多参数
  59. moreParameters() {
  60. return []
  61. },
  62. formItems() {
  63. return []
  64. }
  65. },
  66. created() {
  67. this.getMainList()
  68. this.getTypeList()
  69. },
  70. methods: {
  71. // 列表请求函数
  72. getList: listPageV2,
  73. getList(p) {
  74. try {
  75. var pam = JSON.parse(JSON.stringify(p))
  76. this.editIndex = null
  77. return listPageV2(pam)
  78. } catch (error) {
  79. console.log(error)
  80. }
  81. },
  82. // 列表导出函数
  83. exportList: pageExport,
  84. // 表格列解析渲染数据更改
  85. columnParsing(item, defaultData) {
  86. if (item.jname === 'typeName') {
  87. defaultData.render = (h, { row, index, column }) => {
  88. return this.editIndex == index ? (
  89. <div class="redbordererr">
  90. <el-form-item prop={`tableData.${index}.type`} rules={[{ required: true, message: '工单类型不能为空', trigger: 'blur' }]}>
  91. <el-select value-key="id" value={{ orderSmallTypeText: row.typeName, id: row.type }} placeholder="请选择"
  92. onInput={(val) => {
  93. row.type = val.id
  94. row.typeName = val.orderSmallTypeText
  95. }}>
  96. {
  97. this.typeList.map((item, index) => {
  98. return <el-option key={item.id} label={item.orderSmallTypeText} value={item}></el-option>
  99. })
  100. }
  101. </el-select>
  102. </el-form-item>
  103. </div>
  104. ) : (<div style="padding: 6px;">{row.typeName}</div>)
  105. }
  106. }
  107. if (item.jname === 'parentCategoryName') {
  108. defaultData.render = (h, { row, index, column }) => {
  109. return this.editIndex == index ? (
  110. <div class="redbordererr">
  111. <el-form-item prop={`tableData.${index}.parentCategoryId`} rules={[{ required: true, message: '产品大类不能为空', trigger: 'blur' }]}>
  112. <el-select value={{ categoryId: row.parentCategoryId, name: row.parentCategoryName }} value-key="name" placeholder="请选择"
  113. onInput={(val) => {
  114. row.parentCategoryId = val.categoryId
  115. row.parentCategoryName = val.name
  116. row.categoryName = ''
  117. row.categoryId = ''
  118. this.smallList = [...[{ name: '通用', categoryId: '0' }], ...(val.children ? val.children : [])]
  119. }}>
  120. {
  121. this.mainList.map((item, index) => {
  122. return <el-option key={item.categoryId} label={item.name} value={item}></el-option>
  123. })
  124. }
  125. </el-select>
  126. </el-form-item>
  127. </div>
  128. ) : (<div style="padding: 6px;">{row.parentCategoryName}</div>)
  129. }
  130. }
  131. if (item.jname === 'categoryName') {
  132. defaultData.render = (h, { row, index, column }) => {
  133. return this.editIndex == index ? (
  134. <div class="redbordererr">
  135. <el-form-item prop={`tableData.${index}.categoryId`} rules={[{ required: true, message: '产品小类不能为空', trigger: 'blur' }]}>
  136. <el-select value={{ categoryId: row.categoryId, name: row.categoryName }} value-key="name" placeholder="请选择"
  137. onInput={(val) => {
  138. row.categoryName = val.name
  139. row.categoryId = val.categoryId
  140. }}>
  141. {
  142. this.smallList.map((item, index) => {
  143. return <el-option key={item.id} label={item.name} value={item}></el-option>
  144. })
  145. }
  146. </el-select>
  147. </el-form-item>
  148. </div>
  149. ) : (<div style="padding: 6px;">{row.categoryName}</div>)
  150. }
  151. }
  152. if (item.jname === 'label') {
  153. defaultData.render = (h, { row, index, column }) => {
  154. return this.editIndex == index ? (
  155. <div class="redbordererr">
  156. <el-form-item prop={`tableData.${index}.label`} rules={[{ required: true, message: '质保类型不能为空', trigger: 'blur' }]}>
  157. <el-select value={row.label} placeholder="请选择"
  158. onInput={(val) => {
  159. row.label = val
  160. }}>
  161. {
  162. [{ id: 'INSIDE', name: '保内' }, { id: 'OUT', name: '保外' }].map((item, index) => {
  163. return <el-option key={item.id} label={item.name} value={item.id}></el-option>
  164. })
  165. }
  166. </el-select>
  167. </el-form-item>
  168. </div>
  169. ) : (<div style="padding: 6px;">{row.label}</div>)
  170. }
  171. }
  172. if (item.jname === 'repairAmount') {
  173. defaultData.render = (h, { row, index, column }) => {
  174. return this.editIndex == index ? (
  175. <div class="redbordererr">
  176. <el-form-item prop={`tableData.${index}.repairAmount`} rules={[{ required: true, message: '上门票不能为空', trigger: 'blur' }]}>
  177. <el-input type="text" value={row.repairAmount} placeholder="请输入"
  178. onInput={(val) => {
  179. row.repairAmount = val
  180. }}>
  181. </el-input>
  182. </el-form-item>
  183. </div>
  184. ) : (<div style="padding: 6px;">{thousands(row.repairAmount)}</div>)
  185. }
  186. }
  187. if (item.jname === 'normAmount') {
  188. defaultData.render = (h, { row, index, column }) => {
  189. return this.editIndex == index ? (
  190. <div class="redbordererr">
  191. <el-form-item prop={`tableData.${index}.normAmount`} rules={[{ required: true, message: '维修费结算比例不能为空', trigger: 'blur' }]}>
  192. <div style="display:flex;">
  193. <el-input type="text" value={row.normAmount} placeholder="请输入"
  194. onInput={(val) => {
  195. row.normAmount = val
  196. }}>
  197. </el-input>
  198. </div>
  199. </el-form-item>
  200. </div>
  201. ) : (<div style="padding: 6px;">{row.normAmount} %</div>)
  202. }
  203. }
  204. if (item.jname === 'remark') {
  205. defaultData.render = (h, { row, index, column }) => {
  206. return this.editIndex == index ? (
  207. <div class="redbordererr">
  208. <el-form-item prop={`tableData.${index}.remark`}>
  209. <el-input type="text" value={row.remark} placeholder="请输入"
  210. onInput={(val) => {
  211. row.remark = val
  212. }}>
  213. </el-input>
  214. </el-form-item>
  215. </div>
  216. ) : (<div style="padding: 6px;">{row.remark}</div>)
  217. }
  218. defaultData.columnAttributes.width = 200
  219. }
  220. return defaultData
  221. },
  222. // 监听勾选变化
  223. selectionChange(data) {
  224. this.recordSelected = data
  225. },
  226. operation() {
  227. return this.operationBtn({
  228. edit_wx: {
  229. conditions: ({ row, index, column }) => {
  230. return row.id
  231. },
  232. name: ({ row, index, column }) => {
  233. return this.editIndex == index ? '确定' : '编辑'
  234. },
  235. click: ({ row, index, column }) => {
  236. this.$refs.pageRef.tableForm().validate((valid) => {
  237. if (valid) {
  238. if (this.editIndex != index) {
  239. row = Object.assign(row, {
  240. label: row.label == '保内' ? 'INSIDE' : 'OUT'
  241. })
  242. this.mainList.forEach(item => {
  243. if (item.categoryId == row.parentCategoryId) {
  244. this.smallList = [...[{ name: '通用', categoryId: '0' }], ...(item.children ? item.children : [])]
  245. }
  246. })
  247. this.editIndex = index
  248. } else {
  249. this.edit(row)
  250. }
  251. } else {
  252. console.log('error submit!!');
  253. return false;
  254. }
  255. });
  256. }
  257. },
  258. save_wx: {
  259. conditions: ({ row, index, column }) => {
  260. return !row.id
  261. },
  262. click: ({ row, index, column }) => {
  263. this.$refs.pageRef.tableForm().validate((valid) => {
  264. if (valid) {
  265. this.add(row)
  266. } else {
  267. console.log('error submit!!');
  268. return false;
  269. }
  270. });
  271. }
  272. },
  273. del_wx: {
  274. prompt: "请确认是否删除该数据, 是否继续?",
  275. click: ({ row, index, column }) => {
  276. if (row.id) {
  277. del({
  278. id: row.id
  279. }).then(res => {
  280. if (res.code == 200) {
  281. this.$message({ type: 'success', message: '删除成功!' })
  282. this.$refs.pageRef.refreshList()
  283. } else {
  284. this.$message.error(res.msg);
  285. }
  286. })
  287. } else {
  288. this.$refs.pageRef.deleteRowData(0);
  289. this.editIndex = null
  290. }
  291. }
  292. }
  293. })
  294. },
  295. getMainList() {
  296. getMainList({ type: 2 }).then(res => {
  297. this.mainList = res.data
  298. })
  299. },
  300. getTypeList() {
  301. getTypeList({ pageNum: 1, pageSize: -1, params: [{ param: 'a.order_type', compare: '=', value: 'REPAIR' }, { param: 'a.status', compare: '=', value: true }] }).then(res => {
  302. this.typeList = res.data.records
  303. })
  304. },
  305. addData() {
  306. this.$refs.pageRef.tableForm().validate((valid) => {
  307. if (valid) {
  308. this.editIndex = 0
  309. this.$refs.pageRef.insertionData(0, {
  310. companyWechatName: JSON.parse(localStorage.getItem('greemall_user')).companyName,
  311. settleNormType: 'REPAIR',
  312. typeName: '',
  313. type: '',
  314. categoryName: '',
  315. categoryId: '',
  316. parentCategoryName: '',
  317. parentCategoryId: '',
  318. label: '',
  319. normAmount: '',
  320. repairAmount: '',
  321. remark: ''
  322. })
  323. } else {
  324. console.log('error submit!!');
  325. return false;
  326. }
  327. });
  328. },
  329. openForm() {
  330. this.formDialog = true;
  331. },
  332. add(row) {
  333. add({
  334. settleNormType: 'REPAIR',
  335. typeName: row.typeName,
  336. type: row.type,
  337. parentCategoryName: row.parentCategoryName,
  338. parentCategoryId: row.parentCategoryId,
  339. categoryName: row.categoryName,
  340. categoryId: row.categoryId,
  341. label: row.label,
  342. normAmount: row.normAmount,
  343. repairAmount: row.repairAmount,
  344. remark: row.remark
  345. }).then(res => {
  346. if (res.code == 200) {
  347. this.editIndex = null
  348. this.$message({ type: 'success', message: `保存成功!` })
  349. this.$refs.pageRef.refreshList()
  350. }
  351. })
  352. },
  353. edit(row) {
  354. edit({
  355. id: row.id,
  356. settleNormType: 'REPAIR',
  357. typeName: row.typeName,
  358. type: row.type,
  359. parentCategoryName: row.parentCategoryName,
  360. parentCategoryId: row.parentCategoryId,
  361. categoryName: row.categoryName,
  362. categoryId: row.categoryId,
  363. label: row.label,
  364. normAmount: row.normAmount,
  365. repairAmount: row.repairAmount,
  366. remark: row.remark
  367. }).then(res => {
  368. if (res.code == 200) {
  369. this.editIndex = null
  370. this.$message({ type: 'success', message: `保存成功!` })
  371. this.$refs.pageRef.refreshList()
  372. }
  373. })
  374. }
  375. }
  376. }
  377. </script>
  378. <style lang="scss" scoped>
  379. .tab {
  380. padding: 20px 20px 0 20px;
  381. }
  382. .redbordererr {
  383. ::v-deep .el-form-item {
  384. margin: 0 !important;
  385. overflow: hidden;
  386. }
  387. }
  388. </style>