add_goods.blade.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. @extends('layouts.base')
  2. @section('title', "商品列表")
  3. @section('content')
  4. <link rel="stylesheet" type="text/css" href="{{static_url('yunshop/goods/vue-goods.css')}}"/>
  5. <div id="qrcode" ref="qrcode" style="display:none;"></div>
  6. <div class="rightlist">
  7. <div id="app" v-cloak v-loading="all_loading">
  8. <template>
  9. <div class="second-list">
  10. <div class="third-list">
  11. <div class="form-list">
  12. <el-form :inline="true" :model="search_form" ref="search_form" style="margin-left:10px;">
  13. <el-row>
  14. <el-form-item label="" prop="">
  15. <el-select v-model="search_form.status" placeholder="请选择商品状态" clearable>
  16. <el-option v-for="item in status_list" :key="item.id" :label="item.name"
  17. :value="item.id"></el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-select v-model="search_form.id_v1" placeholder="请选择一级分类" clearable
  22. @change="changeV1()">
  23. <el-option v-for="item in category_list" :key="item.id" :label="item.name"
  24. :value="item.id"></el-option>
  25. </el-select>
  26. </el-form-item>
  27. <el-form-item>
  28. <el-select v-model="search_form.id_v2" placeholder="请选择二级分类" clearable
  29. @change="changeV2()">
  30. <el-option v-for="item in category_list_v2" :key="item.id"
  31. :label="item.name" :value="item.id"></el-option>
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item>
  35. <el-select v-model="search_form.id_v3" placeholder="请选择三级分类" clearable
  36. v-if="catlevel==3">
  37. <el-option v-for="item in category_list_v3" :key="item.id"
  38. :label="item.name" :value="item.id"></el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item label="" prop="keyword">
  42. <el-input v-model="search_form.keyword" placeholder="请输入商品ID或关键字"></el-input>
  43. </el-form-item>
  44. <a href="#">
  45. <el-button type="primary" icon="el-icon-search" @click="search(1)">搜索
  46. </el-button>
  47. </a>
  48. </el-row>
  49. </el-form>
  50. </div>
  51. <div class="table-list">
  52. <div style="margin-left:10px;">
  53. <el-checkbox v-model.number="is_all_choose" :true-label="1" :false-label="0"
  54. @change="allChoose">[[is_all_choose==1?'全不选':'全选']]
  55. </el-checkbox>
  56. <el-button size="small" @click="batchPutAway(1)">添加库存商品</el-button>
  57. </div>
  58. <div>
  59. <template>
  60. <el-table :data="goods_list" style="width: 100%"
  61. :class="table_loading==true?'loading-height':''"
  62. v-loading="table_loading">
  63. <el-table-column prop="id" label="选择" width="60" align="center">
  64. <template slot-scope="scope">
  65. <el-checkbox v-model.number="scope.row.is_choose" :true-label="1"
  66. :false-label="0"
  67. @change="oneChange(scope.row)"></el-checkbox>
  68. </template>
  69. </el-table-column>
  70. <el-table-column prop="id" label="ID" width="70"
  71. align="center"></el-table-column>
  72. </el-table-column>
  73. <el-table-column prop="total" label="商品" width="60" align="center">
  74. <template slot-scope="scope">
  75. <img :src="scope.row.thumb" style="width:50px;height:50px;">
  76. </template>
  77. </el-table-column>
  78. <el-table-column prop="down_time" label="" min-width="180" align="left"
  79. class="edit-cell">
  80. <template slot-scope="scope">
  81. <el-popover class="item" placement="top" effect="light">
  82. </el-popover>
  83. [[scope.row.title]]
  84. </template>
  85. </el-table-column>
  86. <el-table-column prop="member_num" label="价格" max-width="80" align="center">
  87. <template slot-scope="scope">
  88. ¥[[scope.row.price]]
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="库存" align="center" max-width="80">
  92. <template slot-scope="scope">
  93. [[scope.row.stock]]
  94. </template>
  95. </el-table-column>
  96. <el-table-column label="状态" prop="status_message" align="center">
  97. <template slot-scope="scope">
  98. [[scope.row.status?'上架':'下架']]
  99. </template>
  100. </el-table-column>
  101. </el-table>
  102. </template>
  103. </div>
  104. </div>
  105. </div>
  106. <div class="vue-page" v-show="total>1">
  107. <el-row>
  108. <el-col align="right">
  109. <el-pagination layout="prev, pager, next,jumper" @current-change="search" :total="total"
  110. :page-size="per_size" :current-page="current_page" background
  111. v-loading="loading"></el-pagination>
  112. </el-col>
  113. </el-row>
  114. </div>
  115. </div>
  116. </template>
  117. </div>
  118. </div>
  119. <script src="{{resource_get('static/js/qrcode.min.js')}}"></script>
  120. <script>
  121. var app = new Vue({
  122. el: "#app",
  123. delimiters: ['[[', ']]'],
  124. data() {
  125. return {
  126. id: "",
  127. catlevel: 0,//是否显示三级分类
  128. is_all_choose: 0,//是否全选
  129. goods_list: [],//商品列表
  130. all_loading: false,
  131. status_list: [
  132. {id: '', name: '全部状态'},
  133. {id: 0, name: '下架'},
  134. {id: 1, name: '上架'},
  135. ],
  136. category_list: [],
  137. category_list_v2: [],
  138. category_list_v3: [],
  139. search_form: {
  140. id_v1: '',
  141. id_v2: '',
  142. id_v3: '',
  143. },
  144. form: {},
  145. loading: false,
  146. table_loading: false,
  147. total: 0,
  148. per_size: 0,
  149. current_page: 0,
  150. }
  151. },
  152. created() {
  153. let that = this;
  154. document.onkeydown = function () {
  155. if (window.event.keyCode == 13)
  156. that.search(1);
  157. }
  158. },
  159. mounted() {
  160. let data = {!! $data !!};
  161. this.setData(data);
  162. console.log(data)
  163. },
  164. methods: {
  165. setData(data) {
  166. this.goods_list = data.list.data;
  167. let arr = [];
  168. this.goods_list.forEach((item, index) => {
  169. item.title = this.escapeHTML(item.title)
  170. arr.push(Object.assign({}, item, {is_choose: 0}))//是否选中
  171. });
  172. this.goods_list = arr;
  173. this.total = data.list.total;
  174. this.current_page = data.list.current_page;
  175. this.per_size = data.list.per_page;
  176. this.category_list = data.category;
  177. this.catlevel = data.cat_level;
  178. },
  179. getData() {
  180. var that = this;
  181. that.table_loading = true;
  182. that.$http.post("{!! yzWebUrl('plugin.agency.admin.goods.add-index') !!}").then(response => {
  183. if (response.data.result == 1) {
  184. this.setData(response.data.data);
  185. } else {
  186. that.$message.error(response.data.msg);
  187. }
  188. that.table_loading = false;
  189. }), function (res) {
  190. that.table_loading = false;
  191. };
  192. },
  193. changeV1() {
  194. let that = this;
  195. this.search_form.id_v2 = "";
  196. this.search_form.id_v3 = "";
  197. this.category_list_v2 = [];
  198. this.category_list_v3 = [];
  199. that.$http.post("{!! yzWebFullUrl('goods.category.get-categorys-json') !!}", {
  200. level: 2,
  201. parent_id: this.search_form.id_v1
  202. }).then(response => {
  203. if (response.data.result == 1) {
  204. this.category_list_v2 = response.data.data;
  205. } else {
  206. that.$message.error(response.data.msg);
  207. }
  208. }), function (res) {
  209. };
  210. this.category_list.find(item => {
  211. if (item.id == this.search_form.id_v1) {
  212. this.category_list_v2 = item.childrens;
  213. }
  214. });
  215. },
  216. changeV2() {
  217. let that = this;
  218. this.search_form.id_v3 = "";
  219. this.category_list_v3 = [];
  220. if (this.catlevel == 3) {
  221. that.$http.post("{!! yzWebFullUrl('goods.category.get-categorys-json') !!}", {
  222. level: 3,
  223. parent_id: this.search_form.id_v2
  224. }).then(response => {
  225. if (response.data.result == 1) {
  226. this.category_list_v3 = response.data.data;
  227. } else {
  228. that.$message.error(response.data.msg);
  229. }
  230. }), function (res) {
  231. };
  232. }
  233. },
  234. search(page) {
  235. var that = this;
  236. console.log(that.search_form)
  237. let product_attr = [];
  238. if (that.search_form.is_new == 1) {
  239. product_attr.push('is_new')
  240. }
  241. if (that.search_form.is_hot == 1) {
  242. product_attr.push('is_hot')
  243. }
  244. if (that.search_form.is_recommand == 1) {
  245. product_attr.push('is_recommand')
  246. }
  247. if (that.search_form.is_discount == 1) {
  248. product_attr.push('is_discount')
  249. }
  250. let json = {
  251. page: page,
  252. search: {
  253. keyword: that.search_form.keyword,
  254. status: that.search_form.status,
  255. sell_stock: that.search_form.sell_stock,
  256. brand_id: that.search_form.brand_id,
  257. min_price: that.search_form.min_price,
  258. max_price: that.search_form.max_price,
  259. product_attr: product_attr,//商品类型
  260. is_spec: that.search_form.is_spec,
  261. },
  262. category: {
  263. parentid: that.search_form.id_v1,
  264. childid: that.search_form.id_v2,
  265. thirdid: that.search_form.id_v3,
  266. }
  267. };
  268. that.table_loading = true;
  269. that.$http.post("{!! yzWebUrl('plugin.agency.admin.goods.get-add-list') !!}", json).then(response => {
  270. console.log(response);
  271. if (response.data.result == 1) {
  272. let arr = [];
  273. that.goods_list = response.data.data.data;
  274. that.goods_list.forEach((item, index) => {
  275. item.title = that.escapeHTML(item.title)
  276. arr.push(Object.assign({}, item, {is_choose: 0}))//是否选中
  277. });
  278. that.goods_list = arr;
  279. that.total = response.data.data.total;
  280. that.current_page = response.data.data.current_page;
  281. that.per_size = response.data.data.per_page;
  282. } else {
  283. that.$message.error(response.data.msg);
  284. }
  285. that.table_loading = false;
  286. }), function (res) {
  287. console.log(res);
  288. that.table_loading = false;
  289. };
  290. },
  291. listCode(index) {
  292. this.qrcodeScan(this.goods_list[index].link);
  293. },
  294. copyList(index) {
  295. that = this;
  296. let Url = that.$refs['list' + index];
  297. console.log(Url)
  298. Url.select(); // 选择对象
  299. document.execCommand("Copy", false);
  300. that.$message({message: "复制成功!", type: "success"});
  301. },
  302. oneChange(item) {
  303. let that = this;
  304. let is_all = 0;
  305. that.goods_list.some((item, index) => {
  306. if (item.is_choose == 1) {
  307. is_all = 1;
  308. } else {
  309. is_all = 0;
  310. return true;
  311. }
  312. })
  313. that.is_all_choose = is_all;
  314. },
  315. allChoose() {
  316. let that = this;
  317. let status = 0;
  318. if (that.is_all_choose == 1) {
  319. status = 1;
  320. } else {
  321. status = 0;
  322. }
  323. that.goods_list.forEach((item, index) => {
  324. item.is_choose = status;
  325. })
  326. },
  327. batchPutAway(data) {
  328. var that = this;
  329. that.table_loading = true;
  330. let ids = [];
  331. that.goods_list.forEach((item, index) => {
  332. if (item.is_choose == 1) {
  333. ids.push(item.id);
  334. }
  335. })
  336. let json = {data: data, ids: ids}
  337. that.$http.post("{!! yzWebUrl('plugin.agency.admin.goods.add') !!}", json).then(response => {
  338. console.log(response);
  339. if (response.data.result == 1) {
  340. that.$message.success('操作成功!');
  341. that.is_all_choose = 0;
  342. that.search(1);
  343. } else {
  344. that.$message.error(response.data.msg);
  345. }
  346. that.table_loading = false;
  347. }), function (res) {
  348. console.log(res);
  349. that.table_loading = false;
  350. };
  351. },
  352. escapeHTML(a) {
  353. a = "" + a;
  354. return a.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"").replace(/&apos;/g, "'");
  355. ;
  356. },
  357. },
  358. })
  359. </script>
  360. @endsection