agency.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <view class="page-body">
  3. <!-- 页面内容开始 -->
  4. <!-- 自定义按钮区域开始 -->
  5. <view>
  6. <el-row>
  7. <el-button type="primary" size="small" icon="el-icon-refresh" @click="refresh">刷新</el-button>
  8. <el-button type="success" size="small" icon="el-icon-circle-plus-outline" @click="addBtn">添加</el-button>
  9. </el-row>
  10. </view>
  11. <!-- 自定义按钮区域结束 -->
  12. <!-- 表格组件开始 -->
  13. <vk-data-table ref="table1" :action="table1.action" :columns="table1.columns"
  14. :right-btns="['detail_auto','update','delete']" :selection="true" :row-no="true" :pagination="true"
  15. @update="updateBtn" @delete="deleteBtn" @current-change="currentChange" @selection-change="selectionChange">
  16. </vk-data-table>
  17. <!-- 表格组件结束 -->
  18. <!-- 添加或编辑的弹窗开始 -->
  19. <vk-data-dialog v-model="form1.props.show" :title="form1.props.title" width="500px" mode="form"
  20. :close-on-click-modal="false">
  21. <vk-data-form v-model="form1.data" :rules="form1.props.rules" :action="form1.props.action"
  22. :form-type="form1.props.formType" :columns='form1.props.columns' label-width="80px"
  23. @success="form1.props.show = false;refresh();"></vk-data-form>
  24. </vk-data-dialog>
  25. <!-- 添加或编辑的弹窗结束 -->
  26. <!-- 页面内容结束 -->
  27. </view>
  28. </template>
  29. <script>
  30. var that; // 当前页面对象
  31. var vk = uni.vk; // vk实例
  32. var originalForms = {}; // 表单初始化数据
  33. export default {
  34. data() {
  35. // 页面数据变量
  36. return {
  37. // 页面是否请求中或加载中
  38. loading: false,
  39. // init请求返回的数据
  40. data: {
  41. },
  42. // 表格相关开始 -----------------------------------------------------------
  43. table1: {
  44. // 表格数据请求地址
  45. action: "admin/yi/goods/category/sys/getList",
  46. // 表格字段显示规则
  47. columns: [
  48. { key: "_id", title: "id", type: "text", width: 120 },
  49. { key: "name", title: "分类名", type: "text", width: 280 },
  50. { key: "image", title: "图标", type: "image", width: 100,imageWidth: 80 },
  51. { key: "sort", title: "排序", type: "text", width: 80, sortable: "custom" },
  52. {
  53. key: "status",
  54. title: "状态",
  55. type: "switch",
  56. width: 120,
  57. activeValue: true,
  58. inactiveValue: false
  59. },
  60. { key: "_add_time", title: "添加时间", type: "time", width: 160, sortable: "custom" },
  61. { key: "_add_time", title: "距离现在", type: "dateDiff", width: 120 },
  62. ],
  63. // 多选框选中的值
  64. multipleSelection: [],
  65. // 当前高亮的记录
  66. selectItem: ""
  67. },
  68. // 表格相关结束 -----------------------------------------------------------
  69. // 表单相关开始 -----------------------------------------------------------
  70. form1: {
  71. // 表单请求数据,此处可以设置默认值
  72. data: {
  73. status: true
  74. },
  75. // 表单属性
  76. props: {
  77. // 表单请求地址
  78. action: "",
  79. // 表单字段显示规则
  80. columns: [
  81. { key: "name", title: "分类名", type: "text", tips: "不宜过长" },
  82. { key: "image", title: "图标", type: "file-select", tips: "200*200px" },
  83. { key: "sort", title: "排序", type: "text", tips: "数字越大越靠前" },
  84. { key: "status", title: "状态", type: "switch", activeValue: true},
  85. ],
  86. // 表单验证规则
  87. rules: {
  88. name: [
  89. // 必填
  90. { required: true, message: "分类名不能为空", trigger: ['blur', 'change'] }
  91. ],
  92. },
  93. // add 代表添加 update 代表修改
  94. formType: "",
  95. // 是否显示表单的弹窗
  96. show: false
  97. }
  98. },
  99. // 其他弹窗表单
  100. formDatas: {},
  101. // 表单相关结束 -----------------------------------------------------------
  102. };
  103. },
  104. // 监听 - 页面每次【加载时】执行(如:前进)
  105. onLoad(options = {}) {
  106. that = this;
  107. vk = that.vk;
  108. that.options = options;
  109. that.init(options);
  110. // 请求所有平台列表
  111. },
  112. // 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快,会在页面进入动画完成前触发
  113. onReady() {},
  114. // 监听 - 页面每次【显示时】执行(如:前进和返回) (页面每次出现在屏幕上都触发,包括从下级页面点返回露出当前页面)
  115. onShow() {},
  116. // 监听 - 页面每次【隐藏时】执行(如:返回)
  117. onHide() {},
  118. // 函数
  119. methods: {
  120. // 页面数据初始化函数
  121. init(options) {
  122. originalForms["form1"] = vk.pubfn.copyObject(that.form1);
  123. },
  124. // 页面跳转
  125. pageTo(path) {
  126. vk.navigateTo(path);
  127. },
  128. // 表单重置
  129. resetForm() {
  130. vk.pubfn.resetForm(originalForms, that);
  131. },
  132. // 搜索
  133. search() {
  134. that.$refs.table1.search();
  135. },
  136. // 刷新
  137. refresh() {
  138. that.$refs.table1.refresh();
  139. },
  140. // 获取当前选中的行的数据
  141. getCurrentRow() {
  142. return that.$refs.table1.getCurrentRow();
  143. },
  144. // 监听 - 行的选中高亮事件
  145. currentChange(val) {
  146. that.table1.selectItem = val;
  147. },
  148. // 当选择项发生变化时会触发该事件
  149. selectionChange(list) {
  150. that.table1.multipleSelection = list;
  151. },
  152. // 显示添加页面
  153. addBtn() {
  154. that.resetForm();
  155. that.form1.props.action = 'admin/yi/goods/category/sys/add';
  156. that.form1.props.formType = 'add';
  157. that.form1.props.title = '添加';
  158. that.form1.props.show = true;
  159. },
  160. // 显示修改页面
  161. updateBtn({ item }) {
  162. that.form1.props.action = 'admin/yi/goods/category/sys/update';
  163. that.form1.props.formType = 'update';
  164. that.form1.props.title = '编辑';
  165. that.form1.props.show = true;
  166. that.form1.data = item;
  167. },
  168. // 删除按钮
  169. deleteBtn({ item, deleteFn }) {
  170. deleteFn({
  171. action: "admin/yi/goods/category/sys/delete",
  172. data: {
  173. _id: item._id
  174. },
  175. });
  176. }
  177. },
  178. // 监听属性
  179. watch: {
  180. },
  181. // 过滤器
  182. filters: {
  183. },
  184. // 计算属性
  185. computed: {
  186. }
  187. };
  188. </script>
  189. <style lang="scss" scoped>
  190. .page-body {}
  191. </style>