index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="供销社名称" prop="name" label-width="auto">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入供销社名称"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="地址" prop="address" label-width="auto">
  13. <el-input
  14. v-model="queryParams.address"
  15. placeholder="请输入地址"
  16. clearable
  17. @keyup.enter.native="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="负责人" prop="chargePeople" label-width="auto">
  21. <el-input
  22. v-model="queryParams.chargePeople"
  23. placeholder="请输入负责人"
  24. clearable
  25. @keyup.enter.native="handleQuery"
  26. />
  27. </el-form-item>
  28. <el-form-item label="负责人电话" prop="chargePhone" label-width="auto">
  29. <el-input
  30. v-model="queryParams.chargePhone"
  31. placeholder="请输入负责人电话"
  32. clearable
  33. @keyup.enter.native="handleQuery"
  34. />
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  38. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  39. </el-form-item>
  40. </el-form>
  41. <el-row :gutter="10" class="mb8">
  42. <el-col :span="1.5">
  43. <el-button
  44. type="primary"
  45. plain
  46. icon="el-icon-plus"
  47. size="mini"
  48. @click="handleAdd"
  49. v-hasPermi="['system:cooperative:add']"
  50. >新增</el-button>
  51. </el-col>
  52. <el-col :span="1.5">
  53. <el-button
  54. type="success"
  55. plain
  56. icon="el-icon-edit"
  57. size="mini"
  58. :disabled="single"
  59. @click="handleUpdate"
  60. v-hasPermi="['system:cooperative:edit']"
  61. >修改</el-button>
  62. </el-col>
  63. <el-col :span="1.5">
  64. <el-button
  65. type="danger"
  66. plain
  67. icon="el-icon-delete"
  68. size="mini"
  69. :disabled="multiple"
  70. @click="handleDelete"
  71. v-hasPermi="['system:cooperative:remove']"
  72. >删除</el-button>
  73. </el-col>
  74. <el-col :span="1.5">
  75. <el-button
  76. type="warning"
  77. plain
  78. icon="el-icon-download"
  79. size="mini"
  80. @click="handleExport"
  81. v-hasPermi="['system:cooperative:export']"
  82. >导出</el-button>
  83. </el-col>
  84. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  85. </el-row>
  86. <el-table v-loading="loading" :data="cooperativeList" @selection-change="handleSelectionChange">
  87. <el-table-column type="selection" width="55" align="center" />
  88. <!--<el-table-column label="id" align="center" prop="id" />-->
  89. <el-table-column label="序号" align="center" type="index">
  90. <template slot-scope="scope">
  91. <span>{{scope.$index + 1 + (queryParams.pageNum-1) * queryParams.pageSize}}</span>
  92. </template>
  93. </el-table-column>
  94. <el-table-column label="供销社名称" align="center" prop="name" />
  95. <el-table-column label="地址" align="center" prop="address" />
  96. <el-table-column label="负责人" align="center" prop="chargePeople" />
  97. <el-table-column label="负责人电话" align="center" prop="chargePhone" />
  98. <!--<el-table-column label="备注信息" align="center" prop="remark" />-->
  99. <el-table-column label="图片" align="center" prop="imgUrl" width="100">
  100. <template slot-scope="scope">
  101. <image-preview :src="scope.row.imgUrl" :width="50" :height="50"/>
  102. </template>
  103. </el-table-column>
  104. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  105. <template slot-scope="scope">
  106. <el-button
  107. size="mini"
  108. type="text"
  109. icon="el-icon-edit"
  110. @click="handleUpdate(scope.row)"
  111. v-hasPermi="['system:cooperative:edit']"
  112. >修改</el-button>
  113. <el-button
  114. size="mini"
  115. type="text"
  116. icon="el-icon-view"
  117. @click="handleView(scope.row)"
  118. v-hasPermi="['system:cooperative:edit']"
  119. >详情</el-button>
  120. <el-button
  121. size="mini"
  122. type="text"
  123. icon="el-icon-delete"
  124. @click="handleDelete(scope.row)"
  125. v-hasPermi="['system:cooperative:remove']"
  126. >删除</el-button>
  127. </template>
  128. </el-table-column>
  129. </el-table>
  130. <pagination
  131. v-show="total>0"
  132. :total="total"
  133. :page.sync="queryParams.pageNum"
  134. :limit.sync="queryParams.pageSize"
  135. @pagination="getList"
  136. />
  137. <!-- 添加或修改供销合作社对话框 -->
  138. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  139. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  140. <el-form-item label="名称" prop="name">
  141. <el-input v-model="form.name" placeholder="请输入供销社名称" maxLength="20" :readonly="view"/>
  142. </el-form-item>
  143. <el-form-item label="地址" prop="address">
  144. <el-input v-model="form.address" placeholder="请输入地址" maxLength="20" :readonly="view"/>
  145. </el-form-item>
  146. <el-form-item label="负责人" prop="chargePeople">
  147. <el-input v-model="form.chargePeople" placeholder="请输入负责人" maxLength="20" :readonly="view"/>
  148. </el-form-item>
  149. <el-form-item label="电话" prop="chargePhone">
  150. <el-input v-model="form.chargePhone" placeholder="请输入负责人电话" maxLength="20" :readonly="view"/>
  151. </el-form-item>
  152. <el-form-item label="图片" prop="imgUrl">
  153. <image-preview :src="form.imgUrl" :width="100" :height="100" v-if="view" />
  154. <image-upload v-model="form.imgUrl" :fileSize="10" :limit="1" v-else />
  155. </el-form-item>
  156. <!--<el-form-item label="备注信息" prop="remark" maxLength="500">-->
  157. <!--<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />-->
  158. <!--</el-form-item>-->
  159. </el-form>
  160. <div slot="footer" class="dialog-footer">
  161. <el-button type="primary" @click="submitForm" v-if="!view">确 定</el-button>
  162. <el-button @click="cancel" v-if="!view">取 消</el-button>
  163. <el-button @click="cancel" v-if="view">关 闭</el-button>
  164. </div>
  165. </el-dialog>
  166. </div>
  167. </template>
  168. <script>
  169. import { listCooperative, getCooperative, delCooperative, addCooperative, updateCooperative } from "@/api/cooperative/cooperative";
  170. export default {
  171. name: "Cooperative",
  172. data() {
  173. return {
  174. // 遮罩层
  175. loading: true,
  176. // 选中数组
  177. ids: [],
  178. // 选中名称数组
  179. names: [],
  180. // 详情只读
  181. view: false,
  182. // 非单个禁用
  183. single: true,
  184. // 非多个禁用
  185. multiple: true,
  186. // 显示搜索条件
  187. showSearch: true,
  188. // 总条数
  189. total: 0,
  190. // 供销合作社表格数据
  191. cooperativeList: [],
  192. // 弹出层标题
  193. title: "",
  194. // 是否显示弹出层
  195. open: false,
  196. // 查询参数
  197. queryParams: {
  198. pageNum: 1,
  199. pageSize: 10,
  200. version: null,
  201. name: null,
  202. address: null,
  203. chargePeople: null,
  204. chargePhone: null,
  205. imgUrl: null
  206. },
  207. // 表单参数
  208. form: {
  209. name: null,
  210. address: null,
  211. chargePeople: null,
  212. chargePhone: null,
  213. imgUrl: null
  214. },
  215. // 表单校验
  216. rules: {
  217. name: [
  218. { required: true, message: "供销社名称不能为空", trigger: "blur" }
  219. ],
  220. chargePhone: [
  221. {
  222. pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
  223. message: "请输入正确的手机号码",
  224. trigger: "blur"
  225. }
  226. ],
  227. }
  228. };
  229. },
  230. created() {
  231. this.getList();
  232. },
  233. methods: {
  234. /** 查询供销合作社列表 */
  235. getList() {
  236. this.loading = true;
  237. listCooperative(this.queryParams).then(response => {
  238. this.cooperativeList = response.rows;
  239. this.total = response.total;
  240. this.loading = false;
  241. });
  242. },
  243. // 取消按钮
  244. cancel() {
  245. this.open = false;
  246. this.reset();
  247. },
  248. // 表单重置
  249. reset() {
  250. this.view = false;
  251. this.form = {
  252. id: null,
  253. createBy: null,
  254. createTime: null,
  255. updateBy: null,
  256. updateTime: null,
  257. remark: null,
  258. delFlag: null,
  259. version: null,
  260. name: null,
  261. address: null,
  262. chargePeople: null,
  263. chargePhone: null,
  264. imgUrl: null
  265. };
  266. this.resetForm("form");
  267. },
  268. /** 搜索按钮操作 */
  269. handleQuery() {
  270. this.queryParams.pageNum = 1;
  271. this.getList();
  272. },
  273. /** 重置按钮操作 */
  274. resetQuery() {
  275. this.resetForm("queryForm");
  276. this.handleQuery();
  277. },
  278. // 多选框选中数据
  279. handleSelectionChange(selection) {
  280. this.ids = selection.map(item => item.id)
  281. this.names = selection.map(item => item.name);
  282. this.single = selection.length!==1
  283. this.multiple = !selection.length
  284. },
  285. /** 新增按钮操作 */
  286. handleAdd() {
  287. this.reset();
  288. this.open = true;
  289. this.title = "添加供销合作社";
  290. },
  291. /** 修改按钮操作 */
  292. handleUpdate(row) {
  293. this.reset();
  294. const id = row.id || this.ids
  295. getCooperative(id).then(response => {
  296. this.form = response.data;
  297. this.open = true;
  298. this.title = "修改供销合作社";
  299. });
  300. },
  301. /** 详情按钮操作 */
  302. handleView(row) {
  303. this.reset();
  304. this.view = true; // 开启详情只读
  305. const id = row.id || this.ids
  306. getCooperative(id).then(response => {
  307. this.form = response.data;
  308. this.open = true;
  309. this.title = "供销合作社详情";
  310. });
  311. },
  312. /** 提交按钮 */
  313. submitForm() {
  314. this.$refs["form"].validate(valid => {
  315. if (valid) {
  316. if (this.form.id != null) {
  317. updateCooperative(this.form).then(response => {
  318. this.$modal.msgSuccess("修改成功");
  319. this.open = false;
  320. this.getList();
  321. });
  322. } else {
  323. addCooperative(this.form).then(response => {
  324. this.$modal.msgSuccess("新增成功");
  325. this.open = false;
  326. this.getList();
  327. });
  328. }
  329. }
  330. });
  331. },
  332. /** 删除按钮操作 */
  333. handleDelete(row) {
  334. const ids = row.id || this.ids;
  335. const names = row.name || this.names;
  336. this.$modal.confirm('是否确认删除供销社名称为"' + names + '"的数据项?').then(function() {
  337. return delCooperative(ids);
  338. }).then(() => {
  339. this.getList();
  340. this.$modal.msgSuccess("删除成功");
  341. }).catch(() => {});
  342. },
  343. /** 导出按钮操作 */
  344. handleExport() {
  345. let _this = this;
  346. this.$modal.confirm('是否确认导出全部供销社数据?').then(function() {
  347. let date = new Date();
  348. let year = date.getFullYear();
  349. let month = date.getMonth() + 1;
  350. month = month >= 10 ? month : '0' + month;
  351. let day = date.getDate() >= 10 ? date.getDate() : '0' + date.getDate();
  352. let hour = date.getHours() >= 10 ? date.getHours() : '0' + date.getHours();
  353. let minute = date.getMinutes() >= 10 ? date.getMinutes() : '0' + date.getMinutes();
  354. let second = date.getSeconds() >= 10 ? date.getSeconds() : '0' + date.getSeconds();
  355. let dateTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
  356. _this.download('system/cooperative/export', {
  357. ..._this.queryParams
  358. }, `供销社_${dateTime}.xlsx`);
  359. }).then(() => {
  360. this.$modal.msgSuccess("供销社数据导出成功,共计:"+this.total+"条");
  361. }).catch(() => {});
  362. }
  363. }
  364. };
  365. </script>
  366. <style scoped lang="scss">
  367. /*::v-deep.hide .el-upload--picture-card {*/
  368. /*display: none;*/
  369. /*}*/
  370. </style>