index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <template>
  2. <template-page ref="pageRef" :get-list="getList" :table-attributes="tableAttributes" :table-events="tableEvents"
  3. :options-evens-group="optionsEvensGroup" :moreParameters="moreParameters" :column-parsing="columnParsing"
  4. :operation="operation" :exportList="exportList">
  5. <el-dialog title="" width="1165px" custom-class="diy-dialog" append-to-body :modal="true" :visible.sync="formDialog"
  6. :show-close="true" :close-on-click-modal="false" :modal-append-to-body="false" :before-close="formCancel">
  7. <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
  8. <zj-form-module :title="formDialogTitles[formDialogType]" label-width="100px" :showPackUp="false"
  9. :form-data="formData" :form-items="formItems">
  10. </zj-form-module>
  11. </zj-form-container>
  12. <div slot="footer" class="dialog-footer">
  13. <el-button size="mini" @click="formCancel">取 消</el-button>
  14. <el-button size="mini" @click="formConfirm" type="primary">确 定</el-button>
  15. </div>
  16. </el-dialog>
  17. <el-dialog title="" width="300px" custom-class="diy-dialog" append-to-body :modal="true" :visible.sync="formDialog2"
  18. :show-close="true" :close-on-click-modal="false" :modal-append-to-body="false" :before-close="formCancel2">
  19. <zj-form-container ref="formRef2" :form-data="formData2" :styleSwitch="false">
  20. <zj-form-module title="地区选择" label-width="0px" :showPackUp="false" :form-data="formData2"
  21. :form-items="formItems2">
  22. </zj-form-module>
  23. </zj-form-container>
  24. <div slot="footer" class="dialog-footer">
  25. <el-button size="mini" @click="formCancel2">取 消</el-button>
  26. <el-button size="mini" @click="formConfirm2" type="primary">确 定</el-button>
  27. </div>
  28. </el-dialog>
  29. </template-page>
  30. </template>
  31. <script>
  32. import TemplatePage from '@/components/template/template-page-1.vue'
  33. import import_mixin from '@/components/template/import_mixin.js'
  34. import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
  35. import { freightListPageV2, freightPageExport, deleteFreight, addOrEditFreight, getFreightDetail, getRegionTree, changeFreightStatus } from "@/api/freight";
  36. export default {
  37. components: { TemplatePage },
  38. mixins: [import_mixin],
  39. data() {
  40. return {
  41. // 事件组合
  42. optionsEvensGroup: [
  43. [
  44. [
  45. {
  46. name: '新建',
  47. isRole: true,
  48. click: this.addData
  49. }
  50. ],
  51. ],
  52. ],
  53. // 表格属性
  54. tableAttributes: {
  55. // 启用勾选列
  56. selectColumn: false
  57. },
  58. // 表格事件
  59. tableEvents: {
  60. 'selection-change': this.selectionChange
  61. },
  62. // 勾选选中行
  63. recordSelected: [],
  64. /** 表单变量 */
  65. formDialogType: 0,
  66. formDialogTitles: ["新增", "编辑"],
  67. formDialog: false,
  68. formData: {
  69. name: '',
  70. freightTemplateDetails: []
  71. },
  72. formDialog2: false,
  73. formData2: {},
  74. regionTree: []
  75. }
  76. },
  77. computed: {
  78. // 更多参数
  79. moreParameters() {
  80. return []
  81. },
  82. formItems() {
  83. return [{
  84. md: 24,
  85. isShow: true,
  86. name: 'el-input',
  87. attributes: { placeholder: '请输入' },
  88. formItemAttributes: {
  89. label: '仓储名称',
  90. prop: 'name',
  91. rules: [...required]
  92. }
  93. }, {
  94. md: 24,
  95. isShow: true,
  96. name: 'slot-component',
  97. formItemAttributes: {
  98. label: '配送区域',
  99. prop: '',
  100. rules: [...required]
  101. },
  102. render: (h, { props, onInput }) => {
  103. var { value } = props
  104. return (
  105. <div>
  106. <div><el-button type="primary" size="mini" onClick={() => {
  107. this.openForm2()
  108. }}>添加地区</el-button></div>
  109. <zj-table
  110. columns={[
  111. {
  112. columnAttributes: {
  113. label: '省',
  114. prop: 'province',
  115. width: "140px",
  116. }
  117. },
  118. {
  119. columnAttributes: {
  120. label: '市',
  121. prop: 'city',
  122. width: "140px",
  123. }
  124. },
  125. {
  126. columnAttributes: {
  127. label: '首件(个)',
  128. prop: 'firstLimit',
  129. width: "160px",
  130. 'render-header': (h, obj) => this.renderHeader(h, obj, 'firstLimit')
  131. },
  132. render: (h, { row, column, index }) => {
  133. return <el-form-item prop={`freightTemplateDetails.${index}.${column.columnAttributes.prop}`} rules={[...required]}>
  134. <el-input type="number" value={this.formData.freightTemplateDetails[index][column.columnAttributes.prop]} onInput={(val) => { this.formData.freightTemplateDetails[index][column.columnAttributes.prop] = val }}></el-input>
  135. </el-form-item>
  136. }
  137. },
  138. {
  139. columnAttributes: {
  140. label: '运费(元)',
  141. prop: 'firstAmount',
  142. width: "160px",
  143. 'render-header': (h, obj) => this.renderHeader(h, obj, 'firstAmount')
  144. },
  145. render: (h, { row, column, index }) => {
  146. return <el-form-item prop={`freightTemplateDetails.${index}.${column.columnAttributes.prop}`} rules={[...required]}>
  147. <el-input type="number" value={this.formData.freightTemplateDetails[index][column.columnAttributes.prop]} onInput={(val) => { this.formData.freightTemplateDetails[index][column.columnAttributes.prop] = val }}></el-input>
  148. </el-form-item>
  149. }
  150. },
  151. {
  152. columnAttributes: {
  153. label: '续件(个)',
  154. prop: 'continuousLimit',
  155. width: "160px",
  156. 'render-header': (h, obj) => this.renderHeader(h, obj, 'continuousLimit')
  157. },
  158. render: (h, { row, column, index }) => {
  159. return <el-form-item prop={`freightTemplateDetails.${index}.${column.columnAttributes.prop}`} rules={[...required]}>
  160. <el-input type="number" value={this.formData.freightTemplateDetails[index][column.columnAttributes.prop]} onInput={(val) => { this.formData.freightTemplateDetails[index][column.columnAttributes.prop] = val }}></el-input>
  161. </el-form-item>
  162. }
  163. },
  164. {
  165. columnAttributes: {
  166. label: '续费(元)',
  167. prop: 'continuousAmount',
  168. width: "160px",
  169. 'render-header': (h, obj) => this.renderHeader(h, obj, 'continuousAmount')
  170. },
  171. render: (h, { row, column, index }) => {
  172. return <el-form-item prop={`freightTemplateDetails.${index}.${column.columnAttributes.prop}`} rules={[...required]}>
  173. <el-input type="number" value={this.formData.freightTemplateDetails[index][column.columnAttributes.prop]} onInput={(val) => { this.formData.freightTemplateDetails[index][column.columnAttributes.prop] = val }}></el-input>
  174. </el-form-item>
  175. }
  176. },
  177. {
  178. columnAttributes: {
  179. label: '操作',
  180. prop: '',
  181. width: "80px"
  182. },
  183. render: (h, { row, column, index }) => {
  184. return <el-button size="mini" type="text" onClick={() => {
  185. this.formData.freightTemplateDetails.splice(index, 1)
  186. }}>删除</el-button>
  187. }
  188. }
  189. ]}
  190. tableData={this.formData.freightTemplateDetails}
  191. tableAttributes={{
  192. size: 'mini',
  193. border: true,
  194. }} />
  195. </div>
  196. )
  197. }
  198. }]
  199. },
  200. formItems2() {
  201. return [{
  202. md: 24,
  203. isShow: true,
  204. name: 'el-tree',
  205. attributes: {
  206. style: "max-height: 400px; overflow-y: scroll;",
  207. placeholder: '请输入', data: this.regionTree, 'show-checkbox': true, 'node-key': "id", props: {
  208. children: 'child',
  209. label: 'name'
  210. }
  211. },
  212. formItemAttributes: {
  213. label: '',
  214. prop: 'val',
  215. rules: [...required]
  216. }
  217. }]
  218. }
  219. },
  220. methods: {
  221. // 列表请求函数
  222. getList: freightListPageV2,
  223. // 列表导出函数
  224. exportList: freightPageExport,
  225. // 表格列解析渲染数据更改
  226. columnParsing(defaultData) {
  227. return defaultData
  228. },
  229. // 监听勾选变化
  230. selectionChange(data) {
  231. this.recordSelected = data
  232. },
  233. // 表格操作列
  234. operation(h, { row, index, column }) {
  235. return (
  236. <div class='operation-btns'>
  237. <el-button type="text" onClick={() => {
  238. getFreightDetail({ freightTemplateId: row.freightTemplateId }).then(res => {
  239. Object.assign(this.formData, res.data)
  240. this.formDialogType = 1
  241. this.openForm()
  242. })
  243. }}>编辑</el-button>
  244. {row.status ? <el-popconfirm style="margin-right: 10px;" title="确定禁用吗?"
  245. onConfirm={() => {
  246. changeFreightStatus({ freightTemplateId: row.freightTemplateId, status: false }).then(res => {
  247. this.$message({ type: 'success', message: '禁用成功!' })
  248. this.$refs.pageRef.refreshList()
  249. })
  250. }}>
  251. <el-button slot="reference" type="text">禁用</el-button>
  252. </el-popconfirm> : <el-popconfirm style="margin-right: 10px;" title="确定启用吗?"
  253. onConfirm={() => {
  254. changeFreightStatus({ freightTemplateId: row.freightTemplateId, status: true }).then(res => {
  255. this.$message({ type: 'success', message: '启用成功!' })
  256. this.$refs.pageRef.refreshList()
  257. })
  258. }}>
  259. <el-button slot="reference" type="text">启用</el-button>
  260. </el-popconfirm>}
  261. <el-popconfirm
  262. title="确定删除吗?"
  263. onConfirm={() => {
  264. deleteFreight({ freightTemplateId: row.freightTemplateId }).then(() => {
  265. this.$message({ type: 'success', message: '删除成功!' })
  266. this.$refs.pageRef.refreshList()
  267. })
  268. }}
  269. >
  270. <el-button type="text" slot="reference">删除</el-button>
  271. </el-popconfirm>
  272. </div>
  273. )
  274. },
  275. addData() {
  276. this.formDialogType = 0
  277. this.openForm()
  278. },
  279. openForm() {
  280. this.formDialog = true;
  281. },
  282. formCancel() {
  283. this.$refs.formRef.$refs.inlineForm.clearValidate()
  284. this.$data.formData = this.$options.data().formData
  285. this.formDialog = false
  286. },
  287. formConfirm() {
  288. this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
  289. if (valid) {
  290. addOrEditFreight(this.formData).then(res => {
  291. this.$message({ type: 'success', message: `${this.formDialogTitles[this.formDialogType]}成功!` })
  292. this.formCancel()
  293. this.$refs.pageRef.refreshList()
  294. })
  295. }
  296. })
  297. },
  298. renderHeader(h, { column, $index }, type) {
  299. let that = this;
  300. return h(
  301. 'div',
  302. [
  303. h('span', column.label),
  304. h('el-button', {
  305. props: {
  306. type: 'text',
  307. size: 'small',
  308. },
  309. style: 'color:#409EFF; margin-left:5px;',
  310. on: {
  311. click: function () {
  312. that.changeInput(type);
  313. }
  314. }
  315. }, '统一修改')
  316. ],
  317. )
  318. },
  319. changeInput(type) {
  320. const typeMap = {
  321. firstLimit: '首件',
  322. firstAmount: '运费',
  323. continuousLimit: '续件',
  324. continuousAmount: '续费'
  325. }
  326. this.$prompt('请输入' + typeMap[type], '编辑', {
  327. confirmButtonText: '确定',
  328. cancelButtonText: '取消',
  329. inputValidator: function (value) {
  330. if (!value) return '请输入' + typeMap[type]
  331. },
  332. }).then(({ value }) => {
  333. this.formData.freightTemplateDetails.forEach(item => {
  334. item[type] = value;
  335. })
  336. }).catch(() => { });
  337. },
  338. openForm2() {
  339. getRegionTree().then((res) => {
  340. this.regionTree = res.data
  341. this.regionTree.forEach(value => {
  342. value.child.forEach(childValue => {
  343. delete childValue.child
  344. })
  345. })
  346. this.formDialog2 = true;
  347. })
  348. },
  349. formCancel2() {
  350. this.$refs.formRef2.$refs.inlineForm.clearValidate()
  351. this.$data.formData2 = this.$options.data().formData2
  352. this.formDialog2 = false
  353. },
  354. formConfirm2() {
  355. var tree = (function getEl(arr) {
  356. var data
  357. for (var item of arr) {
  358. if (item.$el.className === "el-tree") {
  359. return item
  360. } else if (item.$children && item.$children.length) {
  361. data = getEl(item.$children)
  362. }
  363. }
  364. if (data) {
  365. return data
  366. }
  367. })(this.$refs.formRef2.$children)
  368. tree.getCheckedNodes(true, false).forEach(value => {
  369. let province = value.parentName;
  370. let city = value.name;
  371. let exist = this.formData.freightTemplateDetails.find((obj) => {
  372. return obj.province === province && obj.city === city
  373. })
  374. if (!exist) {
  375. this.formData.freightTemplateDetails.push({
  376. province: province,
  377. city: city,
  378. firstLimit: 1,
  379. firstAmount: 1,
  380. continuousLimit: 1,
  381. continuousAmount: 1
  382. })
  383. }
  384. })
  385. this.formCancel2()
  386. },
  387. }
  388. }
  389. </script>
  390. <style lang="scss" scoped></style>